:root {
  color-scheme: dark;
  --bg: #07100d;
  --bg-soft: #0b1713;
  --panel: #101e19;
  --panel-2: #14251f;
  --line: #263b33;
  --line-soft: rgba(144, 176, 163, 0.15);
  --text: #f0f6f3;
  --muted: #91a79e;
  --green: #5ee3a1;
  --green-strong: #22c77a;
  --amber: #ffbe63;
  --red: #ff857d;
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--text); background: radial-gradient(circle at 78% -15%, rgba(41, 170, 108, 0.16), transparent 34%), var(--bg); }
button, a { font: inherit; }
button { color: inherit; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 248px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 30px 22px; background: rgba(7, 16, 13, 0.92); border-right: 1px solid var(--line-soft); display: flex; flex-direction: column; backdrop-filter: blur(18px); z-index: 5; }
.brand { color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 12px; margin: 0 8px 42px; letter-spacing: 0.07em; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid rgba(94, 227, 161, 0.55); border-radius: 11px; color: var(--green); background: linear-gradient(145deg, rgba(94, 227, 161, 0.16), rgba(94, 227, 161, 0.03)); font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 0.96rem; }
.brand small { color: var(--muted); font-size: 0.57rem; letter-spacing: 0.17em; margin-top: 2px; }
nav { display: grid; gap: 8px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 11px 13px; border-radius: 10px; color: var(--muted); text-decoration: none; font-size: 0.91rem; transition: 160ms ease; }
.nav-item span { color: #789187; font-size: 1.05rem; }
.nav-item:hover { color: var(--text); background: rgba(255, 255, 255, 0.035); }
.nav-item.active { color: var(--text); background: rgba(94, 227, 161, 0.1); box-shadow: inset 2px 0 var(--green); }
.nav-item.active span { color: var(--green); }
.nav-group-label { margin: 18px 13px 2px; color: #657b72; font-size: 0.58rem; font-weight: 760; letter-spacing: 0.13em; text-transform: uppercase; }
.nav-item.nav-direct { border: 1px solid rgba(94, 227, 161, 0.12); background: rgba(94, 227, 161, 0.025); }
.nav-item.nav-direct small { margin-left: auto; color: var(--green); font-size: 0.72rem; }
.nav-item.nav-direct:hover { border-color: rgba(94, 227, 161, 0.35); background: rgba(94, 227, 161, 0.08); }
.sidebar-status { margin-top: auto; display: flex; align-items: center; gap: 11px; padding: 14px 10px 2px; border-top: 1px solid var(--line-soft); }
.sidebar-status strong, .sidebar-status small { display: block; }
.sidebar-status strong { font-size: 0.78rem; }
.sidebar-status small { color: var(--muted); font-size: 0.68rem; margin-top: 3px; }
.status-dot, .mini-dot { display: inline-block; border-radius: 999px; background: var(--green); box-shadow: 0 0 0 5px rgba(94, 227, 161, 0.1); }
.status-dot { width: 8px; height: 8px; }

main { min-width: 0; }
.topbar { min-height: 116px; padding: 28px clamp(28px, 5vw, 76px); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line-soft); }
.topbar h1 { margin: 3px 0 0; font-size: clamp(1.65rem, 3vw, 2.25rem); line-height: 1.1; letter-spacing: -0.035em; }
.eyebrow { margin: 0; color: var(--green); text-transform: uppercase; letter-spacing: 0.15em; font-size: 0.66rem; font-weight: 760; }
.avatar { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel-2); font-weight: 750; font-size: 0.76rem; }
.mobile-menu { display: none; border: 0; background: transparent; font-size: 1.3rem; }
.content { padding: 42px clamp(28px, 5vw, 76px) 70px; max-width: 1500px; margin: 0 auto; }
.section-heading, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.section-heading h2 { margin: 0 0 8px; font-size: 1.42rem; letter-spacing: -0.025em; }
.section-heading p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.primary-button { border: 1px solid rgba(94, 227, 161, 0.4); border-radius: 9px; background: var(--green); color: #052215; padding: 10px 15px; font-weight: 800; font-size: 0.82rem; cursor: pointer; box-shadow: 0 10px 34px rgba(34, 199, 122, 0.15); }
.primary-button:hover { background: #7af0b6; }
.primary-button:disabled { opacity: 0.55; cursor: wait; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 28px 0 18px; }
.metric-card { min-height: 146px; padding: 20px; background: linear-gradient(160deg, rgba(20, 37, 31, 0.94), rgba(12, 25, 20, 0.94)); border: 1px solid var(--line-soft); border-radius: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.metric-card.accent-card { background: linear-gradient(145deg, rgba(34, 199, 122, 0.15), rgba(15, 31, 25, 0.94)); }
.metric-label { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.03em; }
.metric-card strong { margin: 17px 0 auto; font-size: 2.1rem; letter-spacing: -0.05em; }
.metric-card strong.endpoint { color: var(--green); font-size: 1.55rem; letter-spacing: 0.08em; }
.metric-card small { color: #a8bbb3; font-size: 0.7rem; }
.mini-dot { width: 6px; height: 6px; margin-right: 7px; box-shadow: none; vertical-align: 1px; }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(310px, 0.85fr); gap: 18px; }
.feature-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 18px; }
.feature-panel { scroll-margin-top: 24px; }
.security-panel { grid-column: 1 / -1; }
.feature-list { min-height: 160px; max-height: 390px; overflow: auto; }
.feature-row, .event-row { min-height: 74px; padding: 14px 22px; display: grid; align-items: center; gap: 14px; border-bottom: 1px solid var(--line-soft); }
.feature-row { grid-template-columns: minmax(0, 1fr) auto auto; }
.event-row { grid-template-columns: minmax(0, 1fr) auto; }
.feature-row:last-child, .event-row:last-child { border-bottom: 0; }
.feature-row strong, .feature-row small, .feature-row em, .event-row strong, .event-row small { display: block; }
.feature-row strong, .event-row strong { font-size: 0.82rem; }
.feature-row small, .event-row small { margin-top: 5px; color: var(--muted); font-size: 0.68rem; line-height: 1.45; }
.feature-row em { margin-top: 5px; color: var(--green); font-size: 0.64rem; font-style: normal; }
.icon-button { width: 31px; height: 31px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); color: var(--muted); cursor: pointer; }
.icon-button:hover { color: var(--red); border-color: rgba(255, 133, 125, 0.45); }
.event-badge { padding: 5px 8px; border-radius: 999px; color: var(--green); background: rgba(94, 227, 161, 0.08); font-size: 0.62rem; font-weight: 800; }
.event-badge.warning { color: var(--amber); background: rgba(255, 190, 99, 0.08); }
.security-content { padding: 22px; }
.security-content p { margin: 0; color: var(--muted); font-size: 0.78rem; }
.security-state { color: var(--green); font-size: 0.72rem; }
.panel { background: rgba(16, 30, 25, 0.88); border: 1px solid var(--line-soft); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.panel-heading { padding: 21px 22px; border-bottom: 1px solid var(--line-soft); }
.panel h3 { margin: 5px 0 0; font-size: 1rem; }
.text-button { border: 0; color: var(--green); background: none; font-size: 0.74rem; cursor: pointer; }
.device-list { min-height: 265px; }
.device-row { min-height: 80px; padding: 15px 22px; display: grid; grid-template-columns: 42px 1fr auto 48px; align-items: center; gap: 13px; border-bottom: 1px solid var(--line-soft); }
.device-row:last-child { border-bottom: 0; }
.device-row.light-device { align-items: start; }
.device-icon { width: 39px; height: 39px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); color: var(--green); }
.device-copy strong, .device-copy small, .device-copy em { display: block; }
.device-copy { min-width: 0; }
.device-copy strong { font-size: 0.85rem; overflow-wrap: anywhere; }
.device-name { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
.rename-device { padding: 5px 0; min-height: 28px; }
.rename-device:hover { text-decoration: underline; }
.rename-device:focus-visible, .delete-device:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; border-radius: 3px; }
.delete-device { color: var(--red); padding: 5px 0; min-height: 28px; }
.delete-device:hover { text-decoration: underline; }
.danger-button { border: 1px solid rgba(255, 100, 100, .5); border-radius: 9px; background: rgba(255, 80, 80, .12); color: #ffb0b0; padding: 10px 15px; font-weight: 750; font-size: .82rem; cursor: pointer; }
.danger-button:hover { background: rgba(255, 80, 80, .2); }
.device-feedback { margin: 14px 22px; color: var(--green); font-size: 0.8rem; overflow-wrap: anywhere; }
.device-feedback:empty { display: none; }
.device-copy small { color: var(--muted); font-size: 0.68rem; margin-top: 4px; }
.device-copy em { color: var(--green); font-size: 0.68rem; font-style: normal; margin-top: 4px; }
.device-state { display: flex; align-items: center; gap: 7px; font-size: 0.68rem; color: var(--muted); }
.device-state i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.device-state.online { color: var(--green); }
.switch { width: 41px; height: 23px; padding: 2px; border: 1px solid var(--line); border-radius: 999px; background: #1a2a24; cursor: pointer; }
.switch span { display: block; width: 17px; height: 17px; border-radius: 50%; background: #769087; transition: 180ms ease; }
.switch.on { background: rgba(34, 199, 122, 0.25); border-color: rgba(94, 227, 161, 0.4); }
.switch.on span { transform: translateX(17px); background: var(--green); }
.light-controls { grid-column: 2 / -1; display: grid; grid-template-columns: 86px minmax(150px, 1fr) minmax(190px, 1.25fr); gap: 12px; width: 100%; padding: 3px 0 5px; }
.light-controls label { min-width: 0; margin: 0; padding: 9px 11px; border: 1px solid var(--line-soft); border-radius: 9px; background: rgba(255,255,255,.018); color: var(--muted); font-size: .67rem; font-weight: 700; }
.light-controls label.active { border-color: rgba(94, 227, 161, .42); background: rgba(94, 227, 161, .06); color: var(--green); }
.light-controls label > span { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 7px; }
.light-controls output { color: var(--text); font-variant-numeric: tabular-nums; }
.light-controls input[type="range"] { width: 100%; accent-color: var(--green); cursor: pointer; }
.color-control input[type="color"] { width: 100%; height: 25px; padding: 0; border: 0; border-radius: 5px; background: transparent; cursor: pointer; }
.device-row.command-error { box-shadow: inset 3px 0 var(--red); }
.loading-row { display: grid; gap: 12px; padding: 28px 22px; }
.loading-row span { height: 36px; border-radius: 7px; background: linear-gradient(90deg, rgba(255,255,255,0.025), rgba(255,255,255,0.065), rgba(255,255,255,0.025)); background-size: 200% 100%; animation: shimmer 1.5s infinite; }
.empty-state { padding: 36px 22px; color: var(--muted); text-align: center; }
.empty-state.error { color: var(--red); }

.alexa-panel { padding: 23px; }
.alexa-status-card { display: flex; align-items: flex-start; gap: 12px; margin: 24px 0 18px; padding: 15px; border: 1px solid var(--line); border-radius: 11px; background: rgba(255,255,255,.018); }
.alexa-status-card strong, .alexa-status-card small { display: block; }
.alexa-status-card strong { font-size: .82rem; }
.alexa-status-card small { margin-top: 5px; color: var(--muted); font-size: .68rem; line-height: 1.45; }
.alexa-status-dot { flex: 0 0 auto; width: 10px; height: 10px; margin-top: 4px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 4px rgba(255,255,255,.06); }
.alexa-status-dot.online { background: var(--green); box-shadow: 0 0 0 4px rgba(94,227,161,.12); }
.alexa-status-dot.pending { background: var(--amber); box-shadow: 0 0 0 4px rgba(244,190,79,.12); }
.alexa-status-dot.unavailable { background: var(--red); box-shadow: 0 0 0 4px rgba(255,107,107,.12); }
.alexa-hint { margin: 0; color: var(--muted); font-size: .72rem; line-height: 1.55; }
.setup-list { list-style: none; margin: 24px 0; padding: 0; display: grid; gap: 0; }
.setup-list li { position: relative; display: grid; grid-template-columns: 30px 1fr; gap: 11px; min-height: 57px; }
.setup-list li:not(:last-child)::after { content: ""; position: absolute; left: 14px; top: 29px; bottom: -1px; width: 1px; background: var(--line); }
.setup-list li > span { width: 29px; height: 29px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); font-size: 0.69rem; background: var(--panel); z-index: 1; }
.setup-list li.done > span { color: #062418; background: var(--green); border-color: var(--green); }
.setup-list li.current > span { color: var(--green); border-color: var(--green); box-shadow: 0 0 0 4px rgba(94, 227, 161, 0.08); }
.setup-list strong, .setup-list small { display: block; }
.setup-list strong { font-size: 0.79rem; margin-top: 2px; }
.setup-list small { color: var(--muted); font-size: 0.66rem; margin-top: 4px; }
.security-note { display: flex; gap: 12px; padding: 13px; background: rgba(94, 227, 161, 0.07); border: 1px solid rgba(94, 227, 161, 0.14); border-radius: 10px; }
.security-note > span { color: var(--green); }
.security-note p { margin: 0; }
.security-note strong, .security-note small { display: block; }
.security-note strong { font-size: 0.73rem; }
.security-note small { color: var(--muted); font-size: 0.64rem; margin-top: 3px; line-height: 1.4; }

dialog { width: min(460px, calc(100vw - 32px)); padding: 0; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 30px 100px rgba(0,0,0,.55); }
dialog::backdrop { background: rgba(1, 8, 5, 0.76); backdrop-filter: blur(5px); }
dialog form { position: relative; padding: 30px; }
dialog h2 { margin: 8px 0 13px; }
dialog p:not(.eyebrow) { color: var(--muted); line-height: 1.65; font-size: 0.86rem; margin-bottom: 24px; }
.dialog-close { position: absolute; top: 15px; right: 15px; border: 0; background: transparent; color: var(--muted); font-size: 1.25rem; cursor: pointer; }
dialog label { display: grid; gap: 7px; margin: 15px 0; color: #c6d4ce; font-size: 0.75rem; font-weight: 700; }
dialog input, dialog select, dialog output { width: 100%; min-height: 43px; padding: 10px 12px; color: var(--text); background: #0a1612; border: 1px solid var(--line); border-radius: 9px; outline: none; }
dialog input:focus, dialog select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(94, 227, 161, 0.09); }
dialog output { display: block; min-height: auto; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--green); user-select: all; }
#recovery-codes-output { white-space: pre-line; line-height: 1.7; max-height: 280px; overflow: auto; }
.form-error { min-height: 1.2em; margin: 10px 0 !important; color: var(--red) !important; }
.token-result p { margin-bottom: 14px !important; }
.token-result code { color: var(--green); }
.token-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.secondary-button { border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); color: var(--text); padding: 10px 15px; font-weight: 750; font-size: 0.82rem; cursor: pointer; }
.secondary-button:hover { border-color: var(--green); color: var(--green); }
.token-warning { color: var(--amber) !important; font-size: 0.72rem !important; margin-top: 17px !important; margin-bottom: 0 !important; }
#auth-dialog { width: min(430px, calc(100vw - 32px)); }
#auth-dialog form { padding: 35px; }
#auth-dialog[open] { animation: dialog-in 160ms ease-out; }

@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }

@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 1050px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .workspace-grid { grid-template-columns: 1fr; }
  .feature-grid { grid-template-columns: 1fr; }
  .security-panel { grid-column: auto; }
}

@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { position: fixed; left: -260px; width: 248px; transition: left 180ms ease; box-shadow: 20px 0 60px rgba(0,0,0,.45); }
  .sidebar.open { left: 0; }
  .mobile-menu { display: block; }
  .topbar { padding: 22px 20px; gap: 14px; }
  .topbar > div { margin-right: auto; }
  .content { padding: 30px 20px 50px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .metrics { grid-template-columns: 1fr; }
  .metric-card { min-height: 132px; }
  .device-row { grid-template-columns: 38px 1fr auto; }
  .device-state { display: none; }
  .light-controls { grid-column: 1 / -1; grid-template-columns: 78px 1fr; }
  .light-controls .light-range:last-child { grid-column: 1 / -1; }
}

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