:root {
    color-scheme: dark;
    --bg: #070b10;
    --sidebar: #090e15;
    --surface: #0d141d;
    --surface-2: #111b27;
    --surface-3: #162231;
    --line: #213044;
    --line-soft: #182434;
    --text: #f2f5f9;
    --muted: #8d9caf;
    --muted-2: #627287;
    --accent: #a33bea;
    --accent-soft: #261535;
    --cyan: #36b9dc;
    --green: #37c98b;
    --yellow: #e2b94f;
    --red: #e66879;
    --sidebar-width: 236px;
    font-family: "Segoe UI", Inter, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--text); background: var(--bg); font-size: 14px; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { color: inherit; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: grid; grid-template-rows: auto 1fr auto; padding: 20px 14px 16px; background: var(--sidebar); border-right: 1px solid var(--line-soft); z-index: 20; }
.brand { display: flex; align-items: center; gap: 11px; min-height: 48px; padding: 4px 10px 16px; border-bottom: 1px solid var(--line-soft); }
.brand img { display: block; }
.brand span, .sidebar-foot > span:nth-child(2) { display: grid; gap: 2px; min-width: 0; }
.brand strong { font-size: 16px; }
.brand small, .sidebar-foot small { color: var(--muted-2); font-size: 10px; text-transform: uppercase; }
.main-nav { display: grid; align-content: start; gap: 4px; padding-top: 18px; }
.nav-item { display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 8px; min-height: 44px; padding: 0 10px; color: #9dacbf; border-radius: 6px; font-weight: 600; }
.nav-item:hover { color: var(--text); background: #101925; }
.nav-item.active { color: #f4e9fb; background: var(--accent-soft); }
.nav-mark { display: grid; place-items: center; width: 28px; height: 28px; color: #9baabe; background: #111b27; border: 1px solid #1c2a3b; border-radius: 5px; font-size: 11px; font-weight: 800; }
.nav-item.active .nav-mark { color: #f4e9fb; border-color: #5f2c7e; background: #321a43; }
.sidebar-foot { display: grid; grid-template-columns: 34px minmax(0, 1fr) 28px; align-items: center; gap: 9px; padding: 14px 8px 2px; border-top: 1px solid var(--line-soft); }
.sidebar-foot strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.icon-link { display: grid; place-items: center; width: 28px; height: 28px; color: var(--muted); border-radius: 4px; font-size: 18px; }
.icon-link:hover { color: var(--text); background: var(--surface-3); }

.main-area { min-width: 0; }
.topbar { min-height: 76px; display: flex; align-items: center; gap: 20px; padding: 14px 28px; border-bottom: 1px solid var(--line-soft); background: rgba(9, 14, 21, .96); position: sticky; top: 0; z-index: 15; }
.page-heading { min-width: 0; margin-right: auto; }
.page-heading h1 { margin: 0; font-size: 20px; letter-spacing: 0; }
.page-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.content { width: min(1500px, 100%); margin: 0 auto; padding: 24px 28px 40px; }
.mobile-menu { display: none; border: 0; background: transparent; font-size: 20px; }

.button { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; padding: 0 14px; border: 1px solid transparent; border-radius: 5px; cursor: pointer; font-weight: 700; font-size: 12px; }
.button.primary { color: #fff; background: #8e32cb; border-color: #aa4be8; }
.button.primary:hover { background: #9b3ad9; }
.button.secondary { color: #bfcbda; background: #121d2a; border-color: #2a3b50; }
.button.secondary:hover { color: #fff; border-color: #40536c; }
.button.danger { color: #ffd8de; background: #32151d; border-color: #70303e; }
.button.danger:hover { color: #fff; background: #451b26; border-color: #914052; }
.button.full { width: 100%; }
.button-link { min-height: 0; padding: 0; border: 0; background: transparent; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { min-height: 128px; display: grid; align-content: center; gap: 7px; padding: 18px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.stat-card strong { font-size: 28px; line-height: 1; }
.stat-card small { color: var(--muted-2); font-size: 11px; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.positive { color: var(--green) !important; }
.warning-text { color: var(--yellow) !important; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, .7fr); gap: 18px; align-items: start; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); overflow: hidden; }
.panel.spaced { margin-top: 18px; }
.panel-head { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); }
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.panel-head > a:not(.button) { color: #b87ce0; font-size: 11px; font-weight: 700; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { height: 42px; padding: 0 16px; color: var(--muted-2); background: #0b1119; border-bottom: 1px solid var(--line-soft); text-align: left; font-size: 10px; text-transform: uppercase; white-space: nowrap; }
td { min-height: 60px; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); color: #bac5d3; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #101923; }
.entity { display: inline-flex; align-items: center; gap: 10px; min-width: 0; }
.entity > span:last-child { min-width: 0; display: grid; gap: 3px; }
.entity strong { color: var(--text); font-size: 12px; }
.entity small { max-width: 270px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted-2); font-size: 10px; }
.avatar { display: grid; place-items: center; flex: 0 0 auto; width: 34px; height: 34px; color: #f5eaff; background: #71359a; border-radius: 6px; font-weight: 800; }
.avatar.small { width: 34px; height: 34px; font-size: 12px; }
.device-icon, .resource-mark { display: grid; place-items: center; flex: 0 0 auto; width: 36px; height: 36px; color: #a9c5dc; background: #132337; border: 1px solid #243a53; border-radius: 6px; font-size: 10px; font-weight: 800; }
.device-icon.large { width: 54px; height: 54px; font-size: 14px; }
.resource-mark { color: #e1b4f6; background: #2c193b; border-color: #4a2762; }
.danger-mark { color: #ffacb7; background: #321821; border-color: #65303c; }
.row-link { color: #b87ce0; font-size: 11px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.row-link:hover { color: #d6a2ee; }
.danger-link { color: #e88b9a; }
.danger-link:hover { color: #ffb4c0; }
.action-group { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.action-group form { margin: 0; }
.muted { color: var(--muted-2); }
code { padding: 4px 6px; color: #9bcce0; background: #101d29; border-radius: 4px; font-family: Consolas, monospace; font-size: 10px; }
.empty-cell { height: 120px; color: var(--muted-2); text-align: center; }

.badge { display: inline-flex; align-items: center; gap: 6px; width: max-content; padding: 5px 8px; color: #a8b5c5; background: #151f2b; border: 1px solid #233246; border-radius: 12px; font-size: 9px; font-weight: 800; text-transform: uppercase; white-space: nowrap; }
button.badge { cursor: pointer; }
.badge > span, .status-dot { width: 6px; height: 6px; border-radius: 50%; background: #7b899b; }
.badge.active > span, .badge.trial > span, .status-dot.active { background: var(--green); }
.badge.pending > span { background: var(--yellow); }
.badge.expired > span { background: var(--red); }
.badge.blocked > span { background: #8b5e67; }
.count-pill { min-width: 28px; padding: 5px 8px; color: var(--muted); background: #131e2b; border-radius: 12px; text-align: center; font-size: 10px; }

.pending-list { display: grid; }
.pending-item { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 65px; padding: 10px 16px; border-bottom: 1px solid var(--line-soft); }
.pending-item:last-child { border-bottom: 0; }
.pending-item:hover { background: #101923; }
.pending-details { display: grid; gap: 4px; min-width: 0; }
.pending-item strong { font-size: 12px; }
.pending-item small { color: var(--muted-2); font-size: 10px; }
.chevron { color: var(--muted-2); font-size: 22px; }
.empty-state { min-height: 150px; display: grid; place-items: center; align-content: center; gap: 6px; padding: 20px; color: var(--muted); text-align: center; }
.empty-state strong { color: #c9d2dd; font-size: 13px; }
.empty-state span:not(.device-icon) { color: var(--muted-2); font-size: 11px; }
.empty-state.large { min-height: 380px; gap: 10px; }

.list-toolbar { display: flex; align-items: center; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--line-soft); }
.search-box { width: min(380px, 100%); min-height: 38px; display: grid; grid-template-columns: 34px 1fr; align-items: center; color: var(--muted-2); background: #090e15; border: 1px solid var(--line); border-radius: 5px; }
.search-box > span { text-align: center; font-size: 18px; }
.search-box input { width: 100%; height: 36px; padding: 0 10px 0 0; color: var(--text); background: transparent; border: 0; outline: 0; }
.filter-note { margin-left: auto; color: var(--muted-2); font-size: 10px; }

label { display: grid; gap: 7px; color: #9dabbd; font-size: 11px; font-weight: 600; }
input, select, textarea { width: 100%; color: var(--text); background: #090e15; border: 1px solid #27364a; border-radius: 5px; outline: 0; }
input, select { height: 40px; padding: 0 11px; }
textarea { min-height: 76px; padding: 10px 11px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #75469b; box-shadow: 0 0 0 2px rgba(163, 59, 234, .08); }
select { color-scheme: dark; }
.form-grid { display: grid; gap: 12px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: 1.4fr .6fr 1fr; }
.stack-form, .inline-create, .activation-form { display: grid; gap: 13px; padding: 18px; }
.stack-form > .button, .inline-create > .button { justify-self: start; }
.form-divider { height: 1px; background: var(--line-soft); }
.renew-bar { display: grid; grid-template-columns: 1fr 120px auto; align-items: center; gap: 10px; padding: 13px 18px; background: #0a1119; border-top: 1px solid var(--line-soft); }
.renew-bar span { color: var(--muted); font-size: 11px; font-weight: 600; }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; background: #130d12; border-top: 1px solid #3c2028; }
.danger-zone > span { display: grid; gap: 3px; }
.danger-zone strong { color: #efb6c0; font-size: 11px; }
.danger-zone small { color: var(--muted-2); font-size: 10px; }
.resource-list { display: grid; border-top: 1px solid var(--line-soft); }
.resource-item { min-height: 64px; display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line-soft); }
.resource-item:last-child { border-bottom: 0; }
.resource-item > span:nth-child(2) { display: grid; gap: 4px; }
.resource-item strong { font-size: 12px; }
.resource-item small { color: var(--muted-2); font-size: 10px; }

.pair-layout { display: grid; grid-template-columns: minmax(280px, .7fr) minmax(420px, 1.2fr); gap: 18px; align-items: start; }
.pair-lookup { padding-bottom: 18px; }
.pair-lookup > label { padding: 18px 18px 0; }
.qr-scanner { display: grid; gap: 12px; padding: 18px 18px 0; border-bottom: 1px solid var(--line-soft); padding-bottom: 18px; }
.scanner-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.file-scan-button { cursor: pointer; }
.qr-reader { width: 100%; max-width: 390px; min-height: 260px; justify-self: center; overflow: hidden; border: 1px solid #314258; border-radius: 6px; background: #05090e; }
.qr-reader video { width: 100% !important; min-height: 260px; object-fit: cover; }
.scanner-status { min-height: 17px; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.scanner-status.success { color: #70d9ae; }
.scanner-status.error { color: #ef9cac; }
.code-input { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.code-input input { font-family: Consolas, monospace; font-size: 16px; text-transform: uppercase; letter-spacing: 1px; }
.device-summary { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; align-items: center; gap: 12px; }
.device-summary small { color: var(--cyan); font-size: 9px; font-weight: 800; }
.device-summary h2 { margin: 4px 0; font-size: 16px; }
.device-summary p { margin: 0; color: var(--muted-2); font-size: 10px; }

.alert { margin-bottom: 16px; padding: 11px 13px; border: 1px solid #2a3b50; border-radius: 5px; background: #111b27; font-size: 12px; }
.alert.success { color: #b7f2d6; border-color: #235a47; background: #10251d; }
.alert.danger { color: #f6b7c0; border-color: #67303c; background: #2b151c; }

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2, 5, 8, .78); }
.modal-panel { position: relative; width: min(590px, 100%); display: grid; gap: 14px; padding: 20px; background: #0d141d; border: 1px solid #2c3c50; border-radius: 7px; box-shadow: 0 24px 80px rgba(0,0,0,.55); }
.modal-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--line-soft); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-head p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.close-button { width: 30px; height: 30px; border: 0; border-radius: 4px; color: var(--muted); background: #131e2a; cursor: pointer; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: #070b10; }
.auth-shell { width: min(420px, 100%); }
.install-shell { width: min(780px, 100%); }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 20px; }
.auth-brand > div { display: grid; gap: 3px; }
.auth-brand strong { font-size: 18px; }
.auth-brand span { color: var(--muted); font-size: 11px; }
.auth-card { display: grid; gap: 15px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; box-shadow: 0 24px 80px rgba(0,0,0,.3); }
.form-heading h1 { margin: 0; font-size: 20px; }
.form-heading p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.success-card { justify-items: center; text-align: center; }
.success-card h1 { margin: 4px 0 0; }
.success-card p { margin: 0 0 8px; color: var(--muted); }

@media (max-width: 1050px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid, .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 780px) {
    .app-shell { display: block; }
    .sidebar { position: fixed; left: 0; transform: translateX(-100%); width: var(--sidebar-width); transition: transform .18s ease; box-shadow: 18px 0 50px rgba(0,0,0,.45); }
    .sidebar.open { transform: translateX(0); }
    .mobile-menu { display: inline-grid; place-items: center; width: 34px; height: 34px; }
    .topbar { padding: 12px 16px; }
    .topbar-actions .secondary { display: none; }
    .content { padding: 18px 14px 32px; }
    .pair-layout { grid-template-columns: 1fr; }
    .scanner-actions .button { flex: 1 1 145px; }
    .form-grid.three { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
    .stats-grid, .form-grid.two { grid-template-columns: 1fr; }
    .topbar-actions .primary { min-width: 40px; width: 40px; overflow: hidden; color: transparent; position: relative; padding: 0; }
    .topbar-actions .primary::after { content: '+'; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 20px; }
    .page-heading h1 { font-size: 17px; }
    .renew-bar { grid-template-columns: 1fr auto; }
    .renew-bar span { grid-column: 1 / -1; }
    .device-summary { grid-template-columns: 56px 1fr; }
    .device-summary .badge { grid-column: 1 / -1; }
    .modal { padding: 8px; }
    .modal-panel { max-height: 96vh; overflow-y: auto; }
}
