:root {
  color-scheme: dark;
  --bg: #0a0e15;
  --panel: #111722;
  --panel-2: #151d2a;
  --line: #253145;
  --text: #eef2f8;
  --muted: #8290a6;
  --purple: #9b6cff;
  --purple-2: #7040d9;
  --green: #30d786;
  --red: #f05252;
  --shadow: 0 18px 45px rgba(0, 0, 0, .26);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: radial-gradient(circle at 50% -20%, #1b1534 0, var(--bg) 36%); color: var(--text); }
button, input { font: inherit; }
button { cursor: pointer; }
code { color: #b795ff; overflow-wrap: anywhere; }
.hidden { display: none; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 8px; color: var(--purple); font-size: 11px; font-weight: 800; letter-spacing: .15em; }

.topbar {
  position: sticky; top: 0; z-index: 20; height: 68px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 34px; border-bottom: 1px solid rgba(155,108,255,.16); background: rgba(10,14,21,.88); backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; font-weight: 750; letter-spacing: .03em; }
.brand b { color: var(--purple); }
.brand-mark, .auth-logo { display: grid; place-items: center; color: white; background: linear-gradient(135deg, var(--purple), #5632b9); box-shadow: 0 8px 24px rgba(112,64,217,.4); }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 12px; }
.top-actions { display: flex; align-items: center; gap: 16px; }
.signed-user { color: #b2bdd0; font-size: 13px; }
.top-actions form, .device-footer form { margin: 0; }
.icon-button, .link-button { border: 0; color: #a98afa; background: transparent; }
.icon-button { width: 38px; height: 38px; border-radius: 50%; background: var(--panel-2); }
.link-button:hover { color: #d5c6ff; }

.dashboard-shell { display: grid; grid-template-columns: minmax(0, 1fr) 360px; min-height: calc(100vh - 68px); }
.dashboard-main { padding: 42px clamp(22px, 5vw, 72px) 70px; min-width: 0; }
.debug-strip { display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 10px 16px; border: 1px solid rgba(48,215,134,.55); border-radius: 9px; background: rgba(16,31,31,.45); color: #9cb4ad; font-size: 12px; }
.debug-strip b, .debug-strip code { color: var(--green); }
.debug-strip code { margin-left: auto; }
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 5px rgba(48,215,134,.08); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .4; transform: scale(.75); } }

.dashboard-heading { margin: 38px 0 26px; display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.dashboard-heading h1 { margin: 0; font-size: clamp(27px, 3vw, 40px); letter-spacing: -.035em; text-transform: uppercase; }
.dashboard-heading p:last-child { margin: 8px 0 0; color: var(--muted); }
.add-device-form { display: flex; gap: 9px; }
input { min-width: 0; border: 1px solid var(--line); border-radius: 9px; padding: 11px 13px; color: var(--text); background: #0d131d; outline: none; }
input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(155,108,255,.12); }
.primary-button { border: 0; border-radius: 9px; padding: 11px 16px; color: white; background: linear-gradient(135deg, var(--purple-2), #865de9); font-weight: 750; box-shadow: 0 8px 20px rgba(112,64,217,.25); }
.primary-button:hover { filter: brightness(1.1); }

.pairing-panel { margin-top: 22px; padding: 22px; border: 1px solid rgba(155,108,255,.45); border-radius: 13px; background: linear-gradient(135deg, rgba(112,64,217,.14), rgba(17,23,34,.9)); box-shadow: var(--shadow); }
.pairing-panel h2 { margin: 0; font-size: 19px; }
.pairing-grid { margin-top: 18px; display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 10px 14px; }
.pairing-grid label { color: var(--muted); font-size: 12px; }
.pairing-grid code { display: block; padding: 10px 12px; border-radius: 8px; background: #090d14; border: 1px solid var(--line); }
.copy-button { float: right; border: 0; background: transparent; color: var(--purple); font-size: 11px; }

.device-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.device-card { padding: 22px; border: 1px solid rgba(144,160,185,.09); border-radius: 22px; background: linear-gradient(155deg, rgba(25,34,48,.96), rgba(14,20,30,.96)); box-shadow: var(--shadow); }
.device-title-row { display: grid; grid-template-columns: 54px 1fr auto; align-items: center; gap: 14px; }
.device-icon { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 50%; background: #0d131e; font-size: 25px; box-shadow: inset 0 0 0 1px rgba(155,108,255,.12); }
.device-title-row h2 { margin: 0 0 5px; font-size: 19px; }
.device-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.status-badge { padding: 4px 7px; border-radius: 5px; font-size: 10px; font-weight: 850; }
.status-badge.online { color: #071b12; background: var(--green); }
.status-badge.offline { color: #d4dbe6; background: #445064; }
.live-bell { color: var(--purple); }
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.metric-grid div, .wide-metric { padding: 11px 13px; border-radius: 10px; background: rgba(8,13,21,.5); border: 1px solid rgba(144,160,185,.06); }
.metric-grid small, .wide-metric small { display: block; margin-bottom: 4px; color: #75849a; font-size: 9px; font-weight: 800; letter-spacing: .04em; }
.metric-grid strong, .wide-metric strong { font-size: 12px; }
.wide-metric { margin-top: 9px; text-align: center; }
.command-row { display: grid; grid-template-columns: 1fr 92px; gap: 9px; margin-top: 18px; }
.command-button, .danger-button { border: 1px solid rgba(155,108,255,.14); border-radius: 9px; padding: 10px 12px; color: #b994ff; background: #101722; font-weight: 700; }
.command-button:hover { background: rgba(112,64,217,.17); }
.danger-button { width: 100%; margin-top: 9px; border-color: rgba(240,82,82,.14); color: #ff7777; }
.danger-button:hover { background: rgba(240,82,82,.12); }
.command-button:disabled { opacity: .45; cursor: wait; }
.device-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 17px; padding-top: 13px; border-top: 1px solid rgba(144,160,185,.08); color: var(--muted); font-size: 10px; }
.empty-state { padding: 70px 20px; text-align: center; border: 1px dashed var(--line); border-radius: 20px; color: var(--muted); }
.empty-state span { font-size: 42px; }
.empty-state h2 { color: var(--text); }

.notification-panel { position: sticky; top: 68px; height: calc(100vh - 68px); overflow: hidden; border-left: 1px solid rgba(155,108,255,.13); background: linear-gradient(180deg, #1b2637, #151d2a); }
.notification-panel > header { height: 74px; padding: 0 25px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(144,160,185,.08); }
.notification-panel header div { display: flex; align-items: center; gap: 10px; color: #b994ff; }
.notification-panel h2 { font-size: 16px; }
.notification-panel header button { display: none; border: 0; background: none; color: var(--muted); font-size: 26px; }
.notification-list { height: calc(100% - 74px); overflow-y: auto; padding: 18px; }
.notification-item { margin-bottom: 13px; padding: 16px; border: 1px solid rgba(144,160,185,.09); border-radius: 18px; background: rgba(44,58,78,.65); box-shadow: 0 9px 20px rgba(0,0,0,.12); }
.notification-item > div { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.notification-item b { color: #b994ff; font-size: 11px; }
.notification-item.offline b { color: #ff7777; }
.notification-item.online b { color: #62e5a4; }
.notification-item.commanderror b { color: #ff7777; }
.notification-item time { color: #8d9aab; font-size: 9px; white-space: nowrap; }
.notification-item p { margin: 9px 0 0; color: #aab5c6; font-size: 12px; line-height: 1.55; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(430px, 100%); padding: 34px; border: 1px solid rgba(155,108,255,.22); border-radius: 22px; background: rgba(17,23,34,.94); box-shadow: var(--shadow); }
.auth-logo { width: 54px; height: 54px; margin-bottom: 24px; border-radius: 15px; font-weight: 900; }
.auth-card h1 { margin: 0; font-size: 27px; }
.auth-card > .muted { line-height: 1.55; }
.stack-form { display: grid; gap: 9px; margin-top: 24px; }
.stack-form label { margin-top: 7px; color: #bac4d4; font-size: 12px; font-weight: 700; }
.stack-form input { width: 100%; }
.stack-form .primary-button { margin-top: 14px; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: auto; }
.validation, .validation-summary-errors { color: #ff7c7c; font-size: 12px; }
.alert { margin-top: 18px; padding: 12px 15px; border-radius: 8px; }
.alert-error { color: #ff9999; background: rgba(240,82,82,.12); border: 1px solid rgba(240,82,82,.25); }
.toast { position: fixed; z-index: 50; left: 50%; bottom: 28px; transform: translate(-50%, 20px); padding: 11px 16px; border: 1px solid var(--line); border-radius: 10px; background: #1b2432; color: white; opacity: 0; pointer-events: none; transition: .2s ease; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(240,82,82,.55); }

@media (max-width: 1050px) {
  .dashboard-shell { grid-template-columns: 1fr; }
  .notification-panel { position: fixed; z-index: 40; top: 0; right: 0; width: min(380px, 92vw); height: 100vh; transform: translateX(105%); transition: transform .22s ease; box-shadow: -18px 0 45px rgba(0,0,0,.4); }
  .notification-panel.open { transform: translateX(0); }
  .notification-panel header button { display: block; }
}
@media (max-width: 700px) {
  .topbar { padding: 0 15px; }
  .brand > span:last-child, .signed-user { display: none; }
  .dashboard-main { padding: 24px 14px 50px; }
  .dashboard-heading { align-items: stretch; flex-direction: column; }
  .add-device-form { width: 100%; }
  .add-device-form input { flex: 1; }
  .device-grid { grid-template-columns: 1fr; }
  .pairing-grid { grid-template-columns: 1fr; }
  .pairing-grid label { margin-top: 7px; }
  .token-value { max-height: 70px; overflow-y: auto; }
  .debug-strip span:not(.pulse-dot) { display: none; }
  .debug-strip code { font-size: 10px; }
}
