:root {
  --bg: #f4f5f8; --surface: #ffffff; --surface-2: #f7f8fa; --surface-3: #eef0f4;
  --border: #e4e7ec; --text: #16181d; --muted: #6b7280; --faint: #9aa1ad;
  --primary: #5b5bf0; --primary-ink: #fff; --primary-soft: #ecebff;
  --danger: #e02424; --success: #12a150; --warn: #d98410; --info:#2e6bd6;
  --tier-standard:#64748b; --tier-pro:#2e6bd6; --tier-premium:#8b5cf6; --tier-enterprise:#c08a2d;
  --radius: 12px; --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.08);
  --shadow-lg: 0 12px 40px rgba(16,24,40,.18);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:#0d0f13; --surface:#161920; --surface-2:#1c2028; --surface-3:#232833;
    --border:#2a303b; --text:#e8eaee; --muted:#9aa2b1; --faint:#6b7480;
    --primary:#6d6df5; --primary-soft:#242248; --shadow:none;
    --shadow-lg:0 12px 40px rgba(0,0,0,.5);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif; background: var(--bg); color: var(--text); }
h1,h2,h3,h4 { margin: 0; }
a { color: var(--primary); text-decoration: none; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

button { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 9px 15px; border-radius: var(--radius-sm); transition: .12s; font-weight: 500; }
button:hover { border-color: var(--primary); }
button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); border-color: color-mix(in srgb,var(--danger) 35%,var(--border)); }
button.danger:hover { background: var(--danger); color:#fff; border-color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { background: var(--surface-3); border-color: transparent; }
button.small { padding: 5px 11px; font-size: 12.5px; }
input, select, textarea { font: inherit; width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
label { display:block; font-weight: 600; margin: 13px 0 5px; font-size: 12px; color: var(--muted); }
.row { display:flex; gap: 12px; } .row > * { flex: 1; }

/* login */
.login-wrap { display:grid; place-items:center; height:100vh; padding:20px; }
.login-card { background: var(--surface); border:1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 34px; width:100%; max-width: 380px; }
.login-card .logo { display:flex; align-items:center; gap:10px; font-weight:800; font-size:17px; margin-bottom: 4px; }
.login-logo { display:block; height:104px; width:auto; margin:0 auto 16px; }
.dot { width:11px; height:11px; border-radius:50%; background: var(--primary); box-shadow:0 0 0 4px var(--primary-soft); }

/* shell */
.shell { display:grid; grid-template-columns: 250px 1fr; height:100vh; }
.sidebar { background: var(--surface); border-right:1px solid var(--border); padding: 16px 12px; display:flex; flex-direction:column; }
.brand { display:flex; align-items:center; gap:9px; font-weight:800; font-size:15px; padding: 8px 10px 14px; }
.brand-mark { height:24px; width:auto; }
.nav-section { font-size:10.5px; text-transform:uppercase; letter-spacing:.06em; color: var(--faint); padding: 12px 12px 6px; font-weight:700; }
.nav a { display:flex; align-items:center; gap:11px; padding:9px 12px; border-radius:var(--radius-sm); color:var(--text); margin-bottom:2px; font-weight:500; }
.nav a:hover { background: var(--surface-3); }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight:600; }
.nav a .ic { width:17px; text-align:center; opacity:.85; }
.sidebar .spacer { flex:1; }
.sidebar .foot { font-size:11.5px; color: var(--faint); padding: 8px 10px; }
.main { overflow:auto; }
.topbar { display:flex; align-items:center; justify-content:space-between; padding: 14px 30px; border-bottom:1px solid var(--border); background: var(--surface); position: sticky; top:0; z-index:10; }
.crumbs { display:flex; align-items:center; gap:8px; font-size:13.5px; color: var(--muted); }
.crumbs a { color: var(--muted); } .crumbs a:hover{ color: var(--primary); }
.crumbs .sep { color: var(--faint); }
.crumbs .here { color: var(--text); font-weight:600; }
.content { padding: 26px 30px; max-width: 1150px; }
.page-head { display:flex; align-items:center; justify-content:space-between; gap:14px; margin-bottom:20px; flex-wrap:wrap; }
.page-head h2 { font-size: 21px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* stat cards */
.cards { display:grid; grid-template-columns: repeat(auto-fit,minmax(150px,1fr)); gap:14px; margin-bottom: 22px; }
.card { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:16px 18px; box-shadow:var(--shadow); }
.card .k { color:var(--muted); font-size:12px; font-weight:600; }
.card .v { font-size:27px; font-weight:800; margin-top:5px; letter-spacing:-.02em; }

/* app grid */
.app-grid { display:grid; grid-template-columns: repeat(auto-fill,minmax(260px,1fr)); gap:16px; }
.app-card { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:18px; box-shadow:var(--shadow); cursor:pointer; transition:.14s; }
.app-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.app-card .title { font-weight:700; font-size:16px; }
.app-card .slug { font-size:12px; color:var(--muted); margin-top:2px; }
.app-card .desc { color:var(--muted); font-size:13px; margin:10px 0 14px; min-height:34px; }
.app-card .stats { display:flex; gap:16px; font-size:12.5px; color:var(--muted); border-top:1px solid var(--border); padding-top:12px; }
.app-card .stats b { color:var(--text); font-size:15px; display:block; }

/* panels + tables */
.panel { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); box-shadow:var(--shadow); overflow:hidden; margin-bottom:18px; }
.panel-head { padding: 13px 18px; border-bottom:1px solid var(--border); font-weight:700; display:flex; justify-content:space-between; align-items:center; }
.panel-body { padding: 18px; }
table { width:100%; border-collapse:collapse; }
th,td { text-align:left; padding: 11px 18px; border-bottom:1px solid var(--border); font-size:13.5px; vertical-align: middle; }
th { font-size:11px; text-transform:uppercase; letter-spacing:.04em; color:var(--muted); font-weight:700; }
tbody tr:last-child td { border-bottom:none; }
tbody tr.clickable { cursor:pointer; } tbody tr.clickable:hover { background: var(--surface-2); }

/* badges + tiers */
.badge { display:inline-block; padding:2px 10px; border-radius:999px; font-size:11.5px; font-weight:700; }
.badge.active,.badge.success,.badge.paid { color:var(--success); background:color-mix(in srgb,var(--success) 13%,transparent); }
.badge.revoked,.badge.danger,.badge.canceled,.badge.deactivated,.badge.blocked,.badge.unpaid { color:var(--danger); background:color-mix(in srgb,var(--danger) 13%,transparent); }
.badge.suspended,.badge.warn,.badge.past_due,.badge.pending { color:var(--warn); background:color-mix(in srgb,var(--warn) 15%,transparent); }
.badge.muted,.badge.refunded { color:var(--muted); background:var(--surface-3); }
.tier { display:inline-block; padding:2px 10px; border-radius:999px; font-size:11.5px; font-weight:700; color:#fff; }
.tier.standard{ background:var(--tier-standard);} .tier.pro{ background:var(--tier-pro);} .tier.premium{ background:var(--tier-premium);} .tier.enterprise{ background:var(--tier-enterprise);}

/* plan cards */
.plan-grid { display:grid; grid-template-columns: repeat(auto-fit,minmax(230px,1fr)); gap:16px; }
.plan-card { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); box-shadow:var(--shadow); overflow:hidden; }
.plan-card .top { padding:16px 18px; color:#fff; }
.plan-card.standard .top{ background:var(--tier-standard);} .plan-card.pro .top{ background:var(--tier-pro);} .plan-card.premium .top{ background:var(--tier-premium);} .plan-card.enterprise .top{ background:var(--tier-enterprise);}
.plan-card .top .name { font-weight:800; font-size:17px; }
.plan-card .top .price { font-size:13px; opacity:.9; margin-top:2px; }
.plan-card .body { padding:16px 18px; }
.plan-card .feat { display:flex; flex-wrap:wrap; gap:6px; margin-bottom:10px; }
.chip { font-size:11.5px; background:var(--surface-3); color:var(--text); padding:2px 9px; border-radius:6px; }
.kv { display:flex; justify-content:space-between; font-size:12.5px; color:var(--muted); padding:3px 0; }

/* calendar */
.cal { display:grid; grid-template-columns: repeat(7,1fr); gap:6px; }
.cal .dow { font-size:11px; text-transform:uppercase; color:var(--faint); font-weight:700; text-align:center; padding:4px 0; }
.cal .cell { background:var(--surface); border:1px solid var(--border); border-radius:8px; min-height:82px; padding:6px; font-size:11px; }
.cal .cell.other { opacity:.4; }
.cal .cell .num { font-weight:700; color:var(--muted); font-size:11px; }
.cal .ev { margin-top:3px; padding:2px 5px; border-radius:5px; font-size:10.5px; color:#fff; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ev.license_issued{ background:var(--tier-pro);} .ev.machine_activated{ background:var(--success);} .ev.period_end{ background:var(--warn);}
.cal-legend { display:flex; gap:16px; margin: 4px 0 14px; font-size:12px; color:var(--muted); }
.cal-legend span::before { content:""; display:inline-block; width:10px; height:10px; border-radius:3px; margin-right:6px; vertical-align:middle; }
.lg-issued::before{ background:var(--tier-pro);} .lg-act::before{ background:var(--success);} .lg-end::before{ background:var(--warn);}
.cal-head { display:flex; align-items:center; gap:12px; margin-bottom:14px; }

/* modal */
.modal-back { position:fixed; inset:0; background:rgba(10,12,16,.5); display:grid; place-items:center; padding:20px; z-index:60; }
.modal { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); width:100%; max-width:600px; max-height:90vh; overflow:auto; box-shadow:var(--shadow-lg); }
.m-head { padding:16px 20px; border-bottom:1px solid var(--border); font-weight:800; font-size:16px; display:flex; justify-content:space-between; align-items:center; position:sticky; top:0; background:var(--surface); }
.m-body { padding:20px; } .m-foot { padding:14px 20px; border-top:1px solid var(--border); display:flex; gap:10px; justify-content:flex-end; position:sticky; bottom:0; background:var(--surface); }
.close-x { background:none; border:none; font-size:22px; color:var(--muted); padding:0 4px; }
.keybox { background:var(--surface-2); border:1px dashed var(--primary); border-radius:8px; padding:15px; font-family:ui-monospace,Consolas,monospace; font-size:17px; text-align:center; letter-spacing:.05em; word-break:break-all; }
.hint { color:var(--muted); font-size:12.5px; margin-top:6px; }
.empty { color:var(--muted); text-align:center; padding:44px 20px; }
.empty .big { font-size:30px; margin-bottom:8px; }
.err { color:var(--danger); font-size:13px; margin-top:8px; min-height:16px; }
.toast { position:fixed; bottom:22px; right:22px; background:var(--text); color:var(--bg); padding:12px 18px; border-radius:8px; box-shadow:var(--shadow-lg); z-index:100; opacity:0; transform:translateY(8px); transition:.2s; font-weight:500; }
.toast.show { opacity:1; transform:none; }
.section-title { font-size:12px; text-transform:uppercase; letter-spacing:.04em; color:var(--muted); font-weight:700; margin: 18px 0 8px; }
.flag-banner { display:flex; align-items:center; gap:10px; background:color-mix(in srgb,var(--danger) 12%,transparent); color:var(--danger); border:1px solid color-mix(in srgb,var(--danger) 35%,var(--border)); border-radius:8px; padding:10px 14px; margin-bottom:14px; font-weight:600; font-size:13px; }
.flag-banner button { margin-left:auto; }
.alert-panel .panel-head { color:var(--danger); }
@media (max-width:760px){ .shell{ grid-template-columns:1fr; } .sidebar{ display:none; } .content{ padding:18px; } }
