:root {
  color-scheme: dark;
  --bg: #120f17;
  --bg-soft: #1a1521;
  --panel: rgba(35, 27, 43, .76);
  --panel-strong: #251d2d;
  --line: rgba(255, 245, 213, .1);
  --cream: #fff5d5;
  --text: #f8f2f9;
  --muted: #b9afc1;
  --purple: #a973b7;
  --purple-light: #d49be0;
  --green: #61d7a6;
  --yellow: #f4c96b;
  --red: #ef718a;
  --blue: #77a7ff;
  --radius: 22px;
  --shadow: 0 22px 60px rgba(0, 0, 0, .32);
  font-family: Inter, ui-rounded, "SF Pro Rounded", "SF Pro Display", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--text); background: radial-gradient(circle at 82% 8%, #39223f 0, transparent 38%), radial-gradient(circle at 8% 92%, #251c3a 0, transparent 36%), var(--bg); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
.hidden { display: none !important; }
.glass { background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 8px; color: var(--purple-light); font-size: .72rem; font-weight: 800; letter-spacing: .18em; }

#ambient::before, #ambient::after { content: ""; position: fixed; width: 320px; height: 320px; border-radius: 50%; filter: blur(90px); opacity: .18; pointer-events: none; z-index: -1; }
#ambient::before { background: var(--purple); top: -130px; right: -80px; }
#ambient::after { background: #6c4bb8; left: -100px; bottom: -150px; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(440px, 100%); border-radius: 32px; padding: 40px; text-align: center; }
.login-card h1 { font-size: clamp(2rem, 6vw, 3rem); line-height: 1; margin: 12px 0; }
.login-card h1 span { color: var(--purple-light); }
.login-card form { display: grid; gap: 16px; margin-top: 30px; text-align: left; }
.brand-mark { width: 76px; height: 76px; display: grid; place-items: center; margin: 0 auto 22px; border-radius: 24px; color: #19121e; font-weight: 950; font-size: 1.45rem; background: linear-gradient(135deg, var(--cream), var(--purple-light)); box-shadow: 0 12px 35px rgba(169, 115, 183, .35); }
.brand-mark.small { width: 44px; height: 44px; margin: 0; border-radius: 14px; font-size: .86rem; }

label { display: grid; gap: 8px; color: var(--muted); font-size: .82rem; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; color: var(--text); background: rgba(10, 8, 13, .5); outline: none; transition: border .2s, box-shadow .2s; }
input:focus, select:focus, textarea:focus { border-color: var(--purple-light); box-shadow: 0 0 0 3px rgba(169, 115, 183, .18); }
textarea { min-height: 92px; resize: vertical; }
.form-error { margin: 0; color: #ffc1cc; background: rgba(239, 113, 138, .12); border: 1px solid rgba(239, 113, 138, .3); border-radius: 12px; padding: 10px 12px; font-size: .86rem; }

button, .button { border: 0; border-radius: 14px; padding: 11px 16px; font-weight: 800; cursor: pointer; transition: transform .16s ease, filter .16s ease, background .16s ease; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
button:hover, .button:hover { filter: brightness(1.08); }
button:active, .button:active { transform: scale(.975); }
button:disabled { opacity: .46; cursor: not-allowed; transform: none; }
.primary { color: #1c1420; background: linear-gradient(135deg, var(--cream), #e9c8eb); }
.secondary { background: rgba(169, 115, 183, .2); border: 1px solid rgba(212, 155, 224, .3); color: var(--purple-light); }
.danger { background: rgba(239, 113, 138, .16); border: 1px solid rgba(239, 113, 138, .35); color: #ffabb9; }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.full { width: 100%; }
.small-button { padding: 7px 10px; border-radius: 10px; font-size: .78rem; }
.icon-button { width: 42px; height: 42px; padding: 0; border-radius: 13px; background: rgba(255,255,255,.04); border: 1px solid var(--line); }

.app-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: fixed; inset: 16px auto 16px 16px; width: 244px; z-index: 30; border-radius: 26px; padding: 18px 12px; display: flex; flex-direction: column; overflow-y: auto; }
.brand-row { display: flex; align-items: center; gap: 12px; padding: 3px 7px 18px; }
.brand-row strong { display: block; font-size: 1.08rem; }
.brand-row small { color: var(--muted); font-size: .7rem; }
#main-nav { display: grid; gap: 4px; }
#main-nav button { width: 100%; justify-content: flex-start; padding: 10px 12px; background: transparent; color: var(--muted); font-size: .84rem; }
#main-nav button span { width: 22px; color: var(--purple-light); font-size: 1.05rem; text-align: center; }
#main-nav button:hover { background: rgba(255,255,255,.04); color: var(--text); }
#main-nav button.active { color: var(--cream); background: linear-gradient(90deg, rgba(169,115,183,.24), rgba(169,115,183,.06)); }
.badge { margin-left: auto; min-width: 20px; padding: 2px 6px; border-radius: 20px; color: #201523; background: var(--purple-light); font-style: normal; font-size: .67rem; text-align: center; }
.sidebar-bottom { margin-top: auto; display: grid; gap: 8px; padding-top: 20px; }
.sidebar-bottom a { color: var(--muted); text-decoration: none; padding: 10px 12px; font-size: .82rem; }
.mobile-header { display: none; }
.content-shell { grid-column: 2; min-width: 0; padding: 35px 38px 80px 26px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 28px; }
.topbar h1 { margin: 0; font-size: clamp(2rem, 4vw, 3.2rem); letter-spacing: -.04em; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 7px 12px; border-radius: 20px; font-size: .76rem; font-weight: 800; border: 1px solid var(--line); }
.status-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-pill.online::before { background: var(--green); box-shadow: 0 0 12px var(--green); }
.status-pill.offline::before { background: var(--red); }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; background: rgba(37, 29, 45, .72); box-shadow: 0 15px 45px rgba(0,0,0,.16); }
.card.soft { background: rgba(255,255,255,.025); box-shadow: none; }
.card h2, .card h3 { margin: 0 0 10px; }
.card h2 { font-size: 1.1rem; }
.card h3 { font-size: .92rem; }
.card p { margin: 6px 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.card-head h2, .card-head p { margin: 0; }
.metric { min-height: 130px; }
.metric .value { display: block; margin-top: 16px; color: var(--cream); font-size: clamp(1.8rem, 4vw, 2.65rem); font-weight: 900; letter-spacing: -.04em; }
.metric .label { color: var(--muted); font-size: .78rem; }
.metric .spark { position: absolute; width: 90px; height: 90px; right: -15px; bottom: -25px; border-radius: 50%; background: var(--purple); opacity: .12; filter: blur(3px); }
.section { margin-top: 24px; }
.section-title { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 0 0 14px; }
.section-title h2 { margin: 0; font-size: 1.15rem; }
.section-title p { margin: 4px 0 0; color: var(--muted); font-size: .82rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.device-hero { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 18px; }
.device-icon { width: 62px; height: 62px; border-radius: 20px; display: grid; place-items: center; background: linear-gradient(135deg, rgba(255,245,213,.16), rgba(169,115,183,.24)); font-size: 1.7rem; }
.device-hero h2 { margin-bottom: 4px; }
.device-stats { display: grid; grid-template-columns: repeat(4, auto); gap: 22px; }
.device-stats span { display: grid; gap: 3px; color: var(--muted); font-size: .72rem; }
.device-stats strong { color: var(--text); font-size: .9rem; }
.progress { height: 8px; overflow: hidden; border-radius: 10px; background: rgba(255,255,255,.07); }
.progress > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--purple), var(--purple-light)); }
.donut { --value: 50; width: 112px; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--purple-light) calc(var(--value) * 1%), rgba(255,255,255,.07) 0); }
.donut::before { content: ""; width: 80px; aspect-ratio: 1; border-radius: 50%; background: var(--panel-strong); }
.donut > span { position: absolute; font-weight: 900; }

.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 12px; }
.mode-card { min-height: 145px; display: flex; flex-direction: column; justify-content: space-between; text-align: left; background: rgba(255,255,255,.025); border: 1px solid var(--line); }
.mode-card.active { border-color: var(--mode-color, var(--purple)); box-shadow: inset 0 0 0 1px var(--mode-color, var(--purple)), 0 14px 32px rgba(0,0,0,.2); }
.mode-card .mode-icon { width: 37px; height: 37px; border-radius: 12px; display: grid; place-items: center; background: color-mix(in srgb, var(--mode-color, var(--purple)) 25%, transparent); color: var(--mode-color, var(--purple-light)); }
.mode-card small { color: var(--muted); line-height: 1.35; }

.list { display: grid; gap: 9px; }
.list-row { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; background: rgba(255,255,255,.018); }
.list-row .grow { flex: 1; min-width: 0; }
.list-row strong, .list-row small { display: block; overflow: hidden; text-overflow: ellipsis; }
.list-row small { margin-top: 3px; color: var(--muted); font-size: .74rem; }
.avatar { width: 39px; height: 39px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 12px; background: rgba(169,115,183,.17); color: var(--purple-light); font-weight: 900; }
.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 20px; padding: 4px 8px; background: rgba(255,255,255,.06); color: var(--muted); font-size: .68rem; font-weight: 800; }
.chip.green { color: var(--green); background: rgba(97,215,166,.1); }
.chip.yellow { color: var(--yellow); background: rgba(244,201,107,.1); }
.chip.red { color: #ff9bad; background: rgba(239,113,138,.1); }
.chip.purple { color: var(--purple-light); background: rgba(169,115,183,.13); }

.request-card { border-left: 3px solid var(--purple-light); }
.request-card blockquote { margin: 12px 0; padding: 12px 14px; border-radius: 12px; background: rgba(255,255,255,.035); color: var(--cream); }
.time-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.time-buttons button.selected { background: var(--purple); color: white; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 17px; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: .8rem; }
th { color: var(--muted); font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; background: rgba(255,255,255,.025); }
tr:last-child td { border-bottom: 0; }
.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty .empty-icon { display: block; margin-bottom: 12px; color: var(--purple-light); font-size: 2.2rem; }

.capability-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.capability { display: flex; align-items: center; gap: 10px; padding: 11px; border-radius: 14px; border: 1px solid var(--line); }
.capability i { width: 10px; height: 10px; border-radius: 50%; background: var(--red); }
.capability.ready i { background: var(--green); box-shadow: 0 0 10px rgba(97,215,166,.5); }
.capability small { display: block; color: var(--muted); }
.warning-box, .info-box, .danger-box { border-radius: 16px; padding: 14px 16px; font-size: .82rem; line-height: 1.5; }
.warning-box { color: #ffe0a0; background: rgba(244,201,107,.1); border: 1px solid rgba(244,201,107,.25); }
.info-box { color: #bed4ff; background: rgba(119,167,255,.09); border: 1px solid rgba(119,167,255,.23); }
.danger-box { color: #ffc1cc; background: rgba(239,113,138,.09); border: 1px solid rgba(239,113,138,.25); }

.map-card { min-height: 330px; background: radial-gradient(circle at 65% 45%, rgba(169,115,183,.2), transparent 6%), linear-gradient(32deg, transparent 49%, rgba(255,255,255,.03) 50%, transparent 51%), linear-gradient(-28deg, transparent 49%, rgba(255,255,255,.025) 50%, transparent 51%), #1c1722; background-size: auto, 68px 68px, 88px 88px; }
.map-pin { position: absolute; left: 62%; top: 42%; width: 20px; height: 20px; border: 5px solid var(--cream); border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--purple); box-shadow: 0 0 0 8px rgba(169,115,183,.18); }
.map-label { position: absolute; left: calc(62% - 54px); top: calc(42% + 38px); padding: 8px 11px; border-radius: 11px; background: rgba(18,15,23,.86); border: 1px solid var(--line); font-size: .72rem; }

.toggle { appearance: none; width: 46px; height: 26px; border-radius: 20px; padding: 0; background: rgba(255,255,255,.1); position: relative; cursor: pointer; }
.toggle::after { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%; background: var(--muted); transition: .2s; }
.toggle:checked { background: rgba(169,115,183,.55); }
.toggle:checked::after { transform: translateX(20px); background: var(--cream); }

.toast-region { position: fixed; z-index: 100; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); display: grid; gap: 10px; width: min(390px, calc(100vw - 36px)); }
.toast { padding: 14px 16px; border-radius: 15px; background: #2a2132; border: 1px solid var(--line); box-shadow: var(--shadow); animation: toast-in .25s ease; font-size: .84rem; }
.toast.error { border-color: rgba(239,113,138,.4); }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

dialog { width: min(560px, calc(100vw - 28px)); max-height: 88vh; overflow: auto; border: 1px solid var(--line); border-radius: 24px; padding: 0; color: var(--text); background: #211a28; box-shadow: 0 40px 100px rgba(0,0,0,.6); }
dialog::backdrop { background: rgba(5,4,7,.7); backdrop-filter: blur(8px); }
#modal-body { padding: 25px; position: relative; }
.dialog-close { position: absolute; right: 13px; top: 13px; width: 36px; height: 36px; padding: 0; border-radius: 11px; background: rgba(255,255,255,.05); font-size: 1.4rem; z-index: 2; }
#modal-body h2 { margin: 0 45px 8px 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 20px 0; }
.form-grid .wide { grid-column: 1 / -1; }
.weekday-field { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; }
.weekday-field legend { padding: 0 6px; color: var(--muted); font-size: .78rem; font-weight: 700; }
.weekday-field label { display: flex; align-items: center; gap: 5px; }
.weekday-field input { width: auto; }

@media (max-width: 1100px) {
  .grid.four { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid.three { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .device-hero { grid-template-columns: auto 1fr; }
  .device-stats { grid-column: 1 / -1; justify-content: space-between; }
}

@media (max-width: 760px) {
  .app-shell { display: block; padding-top: calc(64px + env(safe-area-inset-top)); }
  .mobile-header { display: flex; position: fixed; z-index: 35; top: 0; left: 0; right: 0; height: calc(64px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 14px 0; align-items: center; justify-content: space-between; border-width: 0 0 1px; }
  .sidebar { inset: 10px auto 10px 10px; width: min(285px, calc(100vw - 52px)); transform: translateX(calc(-100% - 22px)); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .content-shell { padding: 24px 14px calc(80px + env(safe-area-inset-bottom)); }
  .topbar h1 { font-size: 2rem; }
  .top-actions .status-pill { display: none; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .grid.four { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .card { padding: 16px; border-radius: 18px; }
  .device-stats { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .login-card { padding: 30px 22px; }
}

@media (max-width: 420px) {
  .grid.four { grid-template-columns: 1fr; }
  .topbar { align-items: center; }
  .topbar .eyebrow { display: none; }
  .topbar h1 { font-size: 1.7rem; }
}

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