:root {
  color-scheme: dark;
  --bg: #070a12;
  --surface: #0d1220;
  --surface-2: #121929;
  --surface-3: #182135;
  --border: #25304a;
  --text: #f3f5fb;
  --muted: #9aa6bd;
  --primary: #8b5cf6;
  --primary-strong: #7c3aed;
  --primary-soft: rgba(139, 92, 246, .14);
  --green: #39d98a;
  --orange: #fb923c;
  --red: #fb7185;
  --shadow: 0 24px 70px rgba(0, 0, 0, .36);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--text); background: radial-gradient(circle at 80% 0%, #16142d 0, transparent 30%), var(--bg); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(167, 139, 250, .7); outline-offset: 2px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }
.muted { color: var(--muted); line-height: 1.65; }
.eyebrow { margin: 0 0 8px; color: #bda8ff; font-size: 12px; font-weight: 700; letter-spacing: .14em; }

.ambient { position: fixed; width: 380px; height: 380px; border-radius: 50%; filter: blur(100px); opacity: .13; pointer-events: none; }
.ambient-one { top: -140px; right: -80px; background: var(--primary); }
.ambient-two { left: -180px; bottom: -180px; background: #2563eb; }

.login-layout { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(460px, 100%); padding: 44px; background: rgba(13, 18, 32, .9); border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow); backdrop-filter: blur(20px); }
.login-card h1 { margin: 0; font-size: clamp(29px, 5vw, 40px); line-height: 1.15; letter-spacing: -.035em; }
.login-card h1 span { display: block; }
.login-card > .muted { margin: 18px 0 28px; }
.brand-mark { width: 52px; height: 52px; display: grid; place-items: center; margin-bottom: 28px; color: white; background: linear-gradient(145deg, var(--primary), #5b21b6); border-radius: 15px; box-shadow: 0 10px 35px rgba(124, 58, 237, .32); }
.brand-mark svg { width: 30px; height: 30px; }
.brand-mark-small { width: 42px; height: 42px; margin: 0; border-radius: 12px; flex: 0 0 auto; }
.brand-mark-small svg { width: 24px; height: 24px; }

.stack { display: flex; flex-direction: column; gap: 10px; }
label { color: #dbe1ee; font-size: 14px; font-weight: 600; }
input, select { width: 100%; min-height: 46px; padding: 0 14px; color: var(--text); background: #090e19; border: 1px solid var(--border); border-radius: 11px; transition: border-color .2s, box-shadow .2s; }
input:hover, select:hover { border-color: #3b496b; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); outline: none; }
.form-error { min-height: 20px; margin: 2px 0; color: #fda4af; font-size: 14px; }

.button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; padding: 0 17px; color: var(--text); background: var(--surface-3); border: 1px solid var(--border); border-radius: 11px; font-weight: 700; transition: background-color .2s, border-color .2s, box-shadow .2s; }
.button:hover { background: #202b43; border-color: #435171; }
.button:disabled { cursor: wait; opacity: .58; }
.button-primary { color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-strong)); border-color: transparent; box-shadow: 0 9px 25px rgba(124, 58, 237, .25); }
.button-primary:hover { background: linear-gradient(135deg, #9c75fa, #8550eb); border-color: transparent; }
.button-wide { width: 100%; margin-top: 8px; }
.button svg { width: 19px; height: 19px; }
.icon-button { width: 44px; height: 44px; display: grid; place-items: center; flex: 0 0 auto; color: #c9d1e2; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; transition: color .2s, background-color .2s, border-color .2s; }
.icon-button:hover { color: #fff; background: var(--surface-3); border-color: #46536f; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 24px 16px; background: rgba(9, 13, 23, .93); border-right: 1px solid rgba(37, 48, 74, .8); backdrop-filter: blur(16px); z-index: 10; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; color: var(--text); text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 17px; letter-spacing: -.02em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .11em; }
.sidebar nav { display: flex; flex-direction: column; gap: 7px; }
.nav-item { min-height: 46px; display: flex; align-items: center; gap: 12px; padding: 0 13px; color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: 11px; text-align: left; font-weight: 650; transition: color .2s, background-color .2s, border-color .2s; }
.nav-item:hover { color: #e7eaff; background: rgba(255,255,255,.035); }
.nav-item.active { color: #e8ddff; background: var(--primary-soft); border-color: rgba(139, 92, 246, .28); }
.nav-item svg { width: 20px; height: 20px; }
.sidebar-footer { display: flex; align-items: center; gap: 9px; margin-top: auto; padding: 15px 12px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); }
.security-dot { width: 8px; height: 8px; background: var(--green); border-radius: 50%; box-shadow: 0 0 12px rgba(57, 217, 138, .7); }

.content { width: 100%; max-width: 1500px; padding: 30px clamp(20px, 4vw, 54px) 60px; overflow: hidden; }
.topbar { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.topbar h1 { margin: 0; font-size: clamp(26px, 4vw, 36px); letter-spacing: -.035em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.metric-card { min-height: 124px; display: flex; align-items: center; gap: 18px; padding: 22px; background: linear-gradient(145deg, rgba(18,25,41,.96), rgba(13,18,32,.96)); border: 1px solid var(--border); border-radius: 17px; }
.metric-card span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.metric-card strong { font-size: 30px; letter-spacing: -.04em; }
.metric-card .metric-word { font-size: 24px; }
.metric-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 13px; }
.metric-icon.violet { color: #c4b5fd; background: rgba(139,92,246,.15); }
.metric-icon.green { color: #6ee7b7; background: rgba(16,185,129,.13); }
.metric-icon.orange { color: #fdba74; background: rgba(249,115,22,.13); }

.panel { background: rgba(13, 18, 32, .84); border: 1px solid var(--border); border-radius: 18px; overflow: hidden; box-shadow: 0 18px 50px rgba(0,0,0,.15); }
.panel-header { min-height: 82px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.panel-header h2 { margin: 0 0 5px; font-size: 18px; }
.panel-header p, .update-time { margin: 0; color: var(--muted); font-size: 13px; }
.device-list { display: grid; }
.device-row { display: grid; grid-template-columns: minmax(190px, 1.4fr) minmax(140px, 1fr) minmax(120px, .8fr) minmax(160px, 1fr) auto; align-items: center; gap: 20px; min-height: 94px; padding: 18px 24px; border-bottom: 1px solid rgba(37,48,74,.7); }
.device-row:last-child { border-bottom: 0; }
.device-main { min-width: 0; display: flex; align-items: center; gap: 13px; }
.device-avatar { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; color: #c4b5fd; background: var(--primary-soft); border-radius: 12px; }
.device-avatar svg { width: 21px; height: 21px; }
.device-main strong, .device-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-main small, .cell-label { margin-top: 4px; color: var(--muted); font-size: 12px; }
.cell-value { font-size: 14px; font-weight: 650; }
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 700; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; }
.status.online { color: #6ee7b7; }
.status.online::before { background: var(--green); box-shadow: 0 0 10px rgba(57,217,138,.7); }
.status.offline { color: #fda4af; }
.status.offline::before { background: var(--red); }
.empty-state { padding: 70px 24px; text-align: center; }
.empty-state > svg { width: 54px; height: 54px; color: #69748b; }
.empty-state h3 { margin: 18px 0 8px; }
.empty-state p { margin: 0 auto 22px; color: var(--muted); }

.audit-list { display: grid; }
.audit-entry { display: grid; grid-template-columns: 150px 1fr auto; gap: 18px; padding: 18px 24px; border-bottom: 1px solid var(--border); }
.audit-entry:last-child { border-bottom: 0; }
.audit-entry strong { font-size: 14px; }
.audit-entry span { color: var(--muted); font-size: 13px; }

.dialog { width: min(540px, calc(100% - 28px)); padding: 0; color: var(--text); background: transparent; border: 0; }
.dialog::backdrop { background: rgba(2,5,11,.75); backdrop-filter: blur(7px); }
.dialog-card { padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 19px; box-shadow: var(--shadow); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 25px; }
.dialog-header h2 { margin: 0; font-size: 25px; }
.token-result > p { line-height: 1.6; }
.token-box { display: flex; align-items: center; gap: 10px; margin: 16px 0; padding: 12px; background: #070b13; border: 1px solid var(--border); border-radius: 12px; }
.token-box code { min-width: 0; flex: 1; overflow-wrap: anywhere; color: #c4b5fd; font-size: 13px; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: min(390px, calc(100% - 44px)); padding: 13px 16px; color: #fff; background: #222c42; border: 1px solid #46536f; border-radius: 11px; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: #3a1721; border-color: #7f3345; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 82px minmax(0, 1fr); }
  .sidebar { padding-inline: 12px; }
  .brand { justify-content: center; padding-inline: 0; }
  .brand > span:last-child, .nav-item span, .sidebar-footer span:last-child { display: none; }
  .nav-item { justify-content: center; padding: 0; }
  .sidebar-footer { justify-content: center; }
  .device-row { grid-template-columns: minmax(190px, 1fr) minmax(120px, .7fr) minmax(150px, .8fr) auto; }
  .device-row > div:nth-child(3) { display: none; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; top: auto; bottom: 12px; left: 12px; right: 12px; width: auto; height: 66px; flex-direction: row; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: 17px; box-shadow: var(--shadow); }
  .brand, .sidebar-footer { display: none; }
  .sidebar nav { width: 100%; flex-direction: row; }
  .nav-item { flex: 1; }
  .nav-item span { display: inline; }
  .content { padding: 22px 16px 110px; }
  .topbar { align-items: flex-start; margin-bottom: 22px; }
  .topbar-actions .button span { display: none; }
  .topbar-actions .button { width: 44px; padding: 0; }
  .metrics { grid-template-columns: 1fr; }
  .metric-card { min-height: 96px; }
  .device-list { gap: 12px; padding: 14px; }
  .device-row { grid-template-columns: 1fr auto; gap: 15px; min-height: 0; padding: 18px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; }
  .device-row > div:nth-child(2), .device-row > div:nth-child(3) { display: block; grid-column: 1 / -1; }
  .device-row > div:nth-child(4) { grid-column: 1; }
  .device-row > button { grid-column: 2; grid-row: 2 / span 2; }
  .audit-entry { grid-template-columns: 1fr; gap: 6px; }
}

@media (max-width: 470px) {
  .login-card { padding: 30px 22px; border-radius: 18px; }
  .topbar h1 { font-size: 25px; }
  .topbar .eyebrow { display: none; }
  .panel-header { align-items: flex-start; flex-direction: column; }
  .nav-item span { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
