:root {
    color-scheme: dark;
    --bg: #08090b;
    --panel: rgba(17, 18, 21, .9);
    --panel-2: rgba(24, 25, 29, .78);
    --line: rgba(255, 255, 255, .08);
    --text: #f4f4f2;
    --muted: #858992;
    --accent: #e0b458;
    --accent-soft: rgba(224, 180, 88, .13);
    --ok: #51c982;
    --bad: #ef6a6a;
    --warn: #e0b458;
    --surface-cut: 12px;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: radial-gradient(circle at 20% 0, #17140e 0, var(--bg) 36rem); color: var(--text); min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 232px; padding: 30px 22px; border-right: 1px solid var(--line); background: rgba(8,9,11,.92); display: flex; flex-direction: column; z-index: 2; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; background: var(--accent); color: #0b0b0c; font-weight: 950; clip-path: polygon(15% 0,85% 0,100% 15%,100% 85%,85% 100%,15% 100%,0 85%,0 15%); }
.brand b { display:block; letter-spacing: .12em; }
.brand small, td small, .recipient small { display:block; color: var(--muted); margin-top: 4px; }
nav { margin-top: 42px; display:grid; gap: 7px; }
nav a, .nav-logout { color: #b8bbc2; background: transparent; border: 0; border-left: 2px solid transparent; padding: 12px 14px; text-align:left; cursor:pointer; }
nav a:hover, .nav-logout:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.sidebar form { margin-top:auto; }
.shell { margin-left: 232px; padding: 42px clamp(26px, 4vw, 64px); max-width: 1580px; min-height: 100vh; }
.login-shell { display:grid; place-items:center; min-height:100vh; padding:20px; }
.login-card { width:min(430px,100%); padding:32px; }
.login-brand { margin-bottom:34px; }
h1 { font-size: 29px; margin: 5px 0 0; letter-spacing:-.025em; }
h2 { font-size:18px; margin:6px 0 16px; }
.eyebrow { color:var(--muted); text-transform:uppercase; letter-spacing:.14em; font-size:10px; font-weight:800; }
.muted { color:var(--muted); line-height:1.55; }
.page-header { display:flex; align-items:center; justify-content:space-between; gap:20px; margin-bottom:28px; }
.back { color:var(--muted); font-size:13px; }
.stats { display:grid; grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); gap:12px; margin-bottom:22px; }
.login-card, .stats article, .panel, .recipient, .template-item, .flash {
    position:relative;
    isolation:isolate;
    border:0;
    background:var(--line);
    clip-path:polygon(
        var(--surface-cut) 0,
        calc(100% - var(--surface-cut)) 0,
        100% var(--surface-cut),
        100% calc(100% - var(--surface-cut)),
        calc(100% - var(--surface-cut)) 100%,
        var(--surface-cut) 100%,
        0 calc(100% - var(--surface-cut)),
        0 var(--surface-cut));
}
.login-card::before, .stats article::before, .panel::before,
.recipient::before, .template-item::before, .flash::before {
    content:"";
    position:absolute;
    inset:1px;
    z-index:-1;
    background:var(--panel);
    clip-path:polygon(
        calc(var(--surface-cut) - 1px) 0,
        calc(100% - var(--surface-cut) + 1px) 0,
        100% calc(var(--surface-cut) - 1px),
        100% calc(100% - var(--surface-cut) + 1px),
        calc(100% - var(--surface-cut) + 1px) 100%,
        calc(var(--surface-cut) - 1px) 100%,
        0 calc(100% - var(--surface-cut) + 1px),
        0 calc(var(--surface-cut) - 1px));
}
.recipient::before, .template-item::before { background:var(--panel-2); }
.stats article { padding:18px; min-height:92px; }
.stats article::after {
    content:"";
    position:absolute;
    inset:1px var(--surface-cut) auto;
    height:2px;
    background:rgba(224,180,88,.45);
}
.stats span { color:var(--muted); font-size:12px; }
.stats b { display:block; margin-top:14px; font-size:23px; }
.text-ok { color:var(--ok); }
.panel { padding:20px; margin-bottom:18px; overflow:hidden; }
.panel-head { display:flex; justify-content:space-between; align-items:center; gap:16px; }
.table-wrap { overflow:auto; margin:0 -20px -20px; }
table { width:100%; border-collapse:collapse; font-size:13px; }
th { color:var(--muted); font-size:10px; text-transform:uppercase; letter-spacing:.1em; text-align:left; }
th, td { padding:13px 16px; border-top:1px solid var(--line); vertical-align:middle; }
tbody tr:hover { background:rgba(255,255,255,.025); }
.mono { font-family:"Cascadia Mono","Consolas",monospace; font-size:12px; word-break:break-all; }
.badge { display:inline-flex; border:1px solid var(--line); padding:5px 8px; color:#c6c8ce; font-size:10px; font-weight:800; text-transform:uppercase; letter-spacing:.05em; white-space:nowrap; }
.badge.ok { border-color:rgba(81,201,130,.45); color:var(--ok); background:rgba(81,201,130,.08); }
.badge.bad { border-color:rgba(239,106,106,.45); color:var(--bad); background:rgba(239,106,106,.08); }
.badge.warn { border-color:rgba(224,180,88,.45); color:var(--warn); background:var(--accent-soft); }
.empty { color:var(--muted); padding:28px 4px; }
.search-row { display:flex; gap:10px; margin-bottom:20px; }
input, select, textarea { width:100%; color:var(--text); background:#0b0c0e; border:1px solid rgba(255,255,255,.1); outline:none; padding:11px 12px; border-radius:3px; }
input:focus, select:focus, textarea:focus { border-color:var(--accent); box-shadow:0 0 0 2px var(--accent-soft); }
textarea { resize:vertical; }
.button { display:inline-flex; align-items:center; justify-content:center; min-height:40px; padding:0 16px; color:var(--text); border:1px solid rgba(255,255,255,.12); background:#151619; cursor:pointer; white-space:nowrap; }
.button:hover { border-color:var(--accent); }
.button.primary { background:var(--accent); border-color:var(--accent); color:#0b0b0c; font-weight:850; }
.button.ghost { background:transparent; color:var(--muted); }
.button:disabled { opacity:.45; cursor:not-allowed; }
.form-stack { display:grid; gap:15px; }
.form-stack label { display:grid; gap:7px; color:#c5c7cc; font-size:12px; font-weight:650; }
.optional { color:var(--muted); font-weight:400; margin-left:5px; }
.validation { color:var(--bad); font-size:12px; }
.validation ul { margin:0; padding-left:18px; }
.flash { margin-bottom:18px; padding:13px 16px; }
.flash.success { background:var(--ok); }
.flash.error { background:var(--bad); }
.detail-grid, .grant-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:18px; }
dl { display:grid; grid-template-columns:150px 1fr; gap:0; margin:10px 0 0; }
dt, dd { margin:0; padding:11px 0; border-top:1px solid var(--line); }
dt { color:var(--muted); font-size:11px; }
dd { font-size:13px; }
.step { display:grid; place-items:center; width:26px; height:26px; color:var(--accent); border:1px solid var(--accent); font-weight:900; margin-bottom:18px; }
.disabled-panel { opacity:.72; }
.recipient { display:flex; align-items:center; gap:12px; padding:12px; margin-bottom:18px; }
.recipient .badge { margin-left:auto; }
.avatar-fallback { display:grid; place-items:center; width:38px; height:38px; border:1px solid rgba(224,180,88,.45); color:var(--accent); font-weight:900; }
.warning-box { color:#cdbf9e; background:var(--accent-soft); border-left:2px solid var(--accent); padding:12px; font-size:12px; line-height:1.5; }
.recovery-box { display:grid; gap:8px; margin-bottom:18px; }
.recovery-code { display:block; width:max-content; max-width:100%; padding:10px 12px; color:var(--text); background:#0b0c0e; border:1px solid rgba(224,180,88,.45); font:800 16px "Cascadia Mono","Consolas",monospace; letter-spacing:.08em; user-select:all; }
.button.danger { color:var(--bad); }
.license-operations { display:grid; gap:14px; }
.operation-reason { display:grid; gap:7px; color:#c5c7cc; font-size:12px; font-weight:650; }
.license-operations .panel-actions { justify-content:flex-start; }
.bot-grid { align-items:start; }
.button-row { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; }
.button-editor { display:grid; gap:8px; padding-top:4px; }
.check-row { display:flex !important; grid-template-columns:none !important; align-items:center; gap:9px !important; }
.check-row input { width:auto; accent-color:var(--accent); }
.preview-box { border:1px solid var(--line); background:rgba(255,255,255,.025); padding:12px; display:grid; gap:8px; }
.preview-message { min-height:54px; white-space:pre-wrap; color:#ece6d8; line-height:1.5; }
.preview-message strong { color:var(--text); font-weight:850; }
.preview-message em { color:#d6c18e; }
.preview-message a { color:var(--accent); text-decoration:underline; }
.actions { display:flex; flex-wrap:wrap; gap:6px; align-items:center; }
.panel-actions { display:flex; flex-wrap:wrap; gap:10px; align-items:center; justify-content:flex-end; }
.panel-actions form { margin:0; }
.actions form { display:flex; gap:5px; align-items:center; }
.actions input { width:120px; min-height:32px; padding:7px 8px; }
.actions .button { min-height:32px; padding:0 10px; font-size:12px; }
.role-editor { display:grid; gap:6px; margin-top:8px; min-width:150px; }
.role-editor select { min-height:54px; padding:6px 8px; font-size:11px; }
.template-list { display:grid; gap:8px; }
.template-item { display:flex; align-items:center; justify-content:space-between; gap:14px; padding:11px 12px; }
.template-item > div:first-child { min-width:0; }
.template-item b, .template-item small { display:block; }
.template-item small { color:var(--muted); margin-top:4px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:360px; }

@media (max-width: 900px) {
    .sidebar { position:static; width:auto; height:auto; padding:18px; flex-direction:row; align-items:center; gap:24px; overflow:auto; }
    .sidebar nav { margin:0; display:flex; }
    .sidebar form { margin:0 0 0 auto; }
    .shell { margin:0; padding:24px 18px; }
    .detail-grid, .grant-grid { grid-template-columns:1fr; }
}

@media (max-width: 620px) {
    .sidebar .brand span:last-child, .nav-logout { display:none; }
    .page-header { align-items:flex-start; flex-direction:column; }
    .search-row { flex-wrap:wrap; }
    .search-row input { flex-basis:100%; }
    dl { grid-template-columns:1fr; }
    dt { padding-bottom:3px; }
    dd { padding-top:3px; }
    .button-row { grid-template-columns:1fr; }
}
