:root {
  color-scheme: dark;
  --bg: #07101f;
  --panel: #101c31;
  --panel-2: #15243c;
  --line: #29415f;
  --text: #e7efff;
  --muted: #8ea5c5;
  --primary: #2f9cff;
  --primary-2: #6578ff;
  --good: #2bc88a;
  --warn: #f6b84a;
  --bad: #ff6577;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 20% 0%, #132a4a 0, transparent 35%), var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { border: 1px solid var(--line); border-radius: 9px; padding: 9px 14px; background: #14243b; color: var(--text); cursor: pointer; }
button:hover { border-color: #4e78a6; background: #1a2e49; }
button:disabled { cursor: wait; opacity: .55; }
button.primary { border-color: transparent; background: linear-gradient(120deg, var(--primary), var(--primary-2)); color: white; font-weight: 700; }
button.danger { border-color: #773744; color: #ff9daa; background: #2b1721; }
input, select { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; background: #091526; color: var(--text); outline: none; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px #2f9cff22; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(390px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 20px; background: #0d192bd9; box-shadow: 0 24px 80px #0008; backdrop-filter: blur(18px); }
.login-card h1 { margin: 10px 0 4px; text-align: center; font-size: 28px; }
.login-card > p { margin: 0 0 26px; text-align: center; color: var(--muted); }
.login-card button { width: 100%; margin-top: 18px; padding: 11px; }
.brand-mark { width: 54px; height: 54px; margin: auto; display: grid; place-items: center; border-radius: 15px; background: linear-gradient(145deg, #208cff, #7c68ff); font-size: 31px; box-shadow: 0 10px 30px #267cff55; }
.form-error { min-height: 20px; margin-top: 12px; color: #ff9daa; text-align: center; font-size: 13px; }

.topbar { height: 68px; padding: 0 28px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: #091426eb; position: sticky; top: 0; z-index: 5; backdrop-filter: blur(16px); }
.topbar strong { font-size: 20px; }
.topbar span { margin-left: 12px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; }
.content { width: min(1420px, calc(100% - 40px)); margin: 26px auto 60px; display: grid; gap: 20px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat-card { padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(145deg, var(--panel), #0c182b); }
.stat-card small { color: var(--muted); }
.stat-card strong { display: block; margin-top: 7px; font-size: 27px; }
.panel { border: 1px solid var(--line); border-radius: 15px; background: var(--panel); overflow: hidden; }
.panel-title { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 18px; align-items: center; }
.panel-title h2 { margin: 0; font-size: 17px; }
.panel-title p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.generate-grid { display: grid; grid-template-columns: 130px 130px 180px minmax(240px, 1fr) auto; gap: 14px; align-items: end; padding: 20px; }
.generate-grid button { height: 41px; }
.filters { display: grid; grid-template-columns: minmax(220px, 310px) 140px; gap: 10px; }
.table-wrap { overflow: auto; }
table { width: 100%; min-width: 1080px; border-collapse: collapse; }
th, td { padding: 13px 15px; border-bottom: 1px solid #233852; text-align: left; font-size: 13px; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; background: #122039; position: sticky; top: 0; }
tbody tr:hover { background: #17263d; }
.key-cell { display: flex; align-items: center; gap: 8px; }
.key-cell code { color: #bee0ff; font-size: 13px; white-space: nowrap; }
.compact { padding: 5px 8px; font-size: 12px; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 8px; font-size: 12px; font-weight: 700; }
.badge.active { color: #6debb9; background: #173a31; }
.badge.suspended { color: #ff9daa; background: #3a202a; }
.badge.expired { color: #ffd081; background: #3a3020; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; min-width: 190px; }
.muted { color: var(--muted); }
.empty { padding: 50px; text-align: center; color: var(--muted); }

dialog { width: min(620px, calc(100% - 32px)); max-height: 82vh; padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); box-shadow: 0 25px 100px #000b; }
dialog::backdrop { background: #01050cc7; backdrop-filter: blur(5px); }
.dialog-head { padding: 18px 20px; display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-head p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.dialog-head > button { padding: 3px 9px; font-size: 20px; }
dialog > p { padding: 0 20px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--line); }
.generated-keys, .device-list { display: grid; gap: 8px; padding: 12px 20px 20px; overflow: auto; }
.generated-key, .device-item { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #0b1728; }
.generated-key code { color: #bee0ff; }
.device-item strong { display: block; }
.device-item small { display: block; margin-top: 4px; color: var(--muted); }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 420px; padding: 12px 16px; border: 1px solid var(--line); border-radius: 10px; background: #172942; box-shadow: 0 12px 40px #0008; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: #8b4050; background: #351c27; }

@media (max-width: 980px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .generate-grid { grid-template-columns: 1fr 1fr; }
  .note-field { grid-column: 1 / -1; }
  .generate-grid button { grid-column: 1 / -1; }
  .list-title { align-items: stretch; flex-direction: column; }
}

@media (max-width: 620px) {
  .topbar { padding: 0 14px; }
  .topbar span { display: none; }
  .content { width: min(100% - 20px, 1420px); margin-top: 12px; }
  .stats, .generate-grid, .filters { grid-template-columns: 1fr; }
  .note-field, .generate-grid button { grid-column: auto; }
  .panel-title { padding: 15px; }
  .generate-grid { padding: 15px; }
}
