/* MTTL Remote — "breaker panel" design system.
   Amber is reserved for one meaning: power is flowing. */

:root {
  --panel: #E7EAEE;          /* powder-coated enclosure */
  --surface: #FBFCFD;
  --surface-2: #F2F4F7;
  --ink: #1A2330;
  --ink-2: #4A5869;
  --ink-3: #7A8796;
  --rule: #D3D9E0;
  --lamp: #F2A900;           /* indicator lamp: ON */
  --lamp-ink: #5A3E00;
  --lamp-soft: #FFF3D1;
  --live: #2E9E6A;           /* online */
  --fault: #D64545;
  --fault-soft: #FCE9E9;
  --data: #2F6DB5;           /* validated chart hue (light) */
  --data-soft: #DCE7F5;
  --focus: #2F6DB5;
  --shadow: 0 1px 0 rgba(26, 35, 48, .06), 0 8px 24px -16px rgba(26, 35, 48, .35);
  --r-ctl: 6px;
  --r-panel: 14px;
  --font-ui: "Readex Pro", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --font-label: "Noto Kufi Arabic", "Readex Pro", system-ui, sans-serif;
  --nav-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --panel: #11161D; --surface: #1C2430; --surface-2: #232D3A; --ink: #E6EBF1; --ink-2: #AAB6C4;
    --ink-3: #7D8A99; --rule: #2E3A48; --lamp: #FFB81C; --lamp-ink: #FFE3A3; --lamp-soft: #3A2E10;
    --live: #3FBF85; --fault: #F06A6A; --fault-soft: #3B1F23; --data: #5A93DB; --data-soft: #24364E;
    --focus: #5A93DB; --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 30px -18px rgba(0, 0, 0, .9);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --panel: #11161D; --surface: #1C2430; --surface-2: #232D3A; --ink: #E6EBF1; --ink-2: #AAB6C4;
  --ink-3: #7D8A99; --rule: #2E3A48; --lamp: #FFB81C; --lamp-ink: #FFE3A3; --lamp-soft: #3A2E10;
  --live: #3FBF85; --fault: #F06A6A; --fault-soft: #3B1F23; --data: #5A93DB; --data-soft: #24364E;
  --focus: #5A93DB; --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 30px -18px rgba(0, 0, 0, .9);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--panel); color: var(--ink); font-family: var(--font-ui);
  font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--data); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.muted { color: var(--ink-3); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: minmax(0, 1fr); min-height: 100dvh; }
.main { min-width: 0; padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 1180px; width: 100%; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 0 18px; }
.topbar h1 { font-family: var(--font-label); font-size: 22px; font-weight: 700; margin: 0; letter-spacing: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .back { margin-inline-start: -6px; }

.nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 20; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--rule);
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--ink-3); font-size: 11.5px; text-decoration: none; }
.nav a svg { width: 22px; height: 22px; }
.nav a[aria-current="page"] { color: var(--ink); font-weight: 600; }
.nav a[aria-current="page"] svg { color: var(--data); }
.brand { display: none; }

@media (min-width: 900px) {
  .shell { grid-template-columns: 232px minmax(0, 1fr); }
  .nav {
    position: sticky; top: 0; height: 100dvh; grid-template-columns: 1fr; grid-auto-rows: min-content; align-content: start;
    border-top: 0; border-inline-end: 1px solid var(--rule); padding: 20px 12px; gap: 2px; grid-row: 1; grid-column: 1;
  }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 14.5px; padding: 10px 12px; border-radius: var(--r-ctl); }
  .nav a:hover { background: var(--surface-2); text-decoration: none; }
  .nav a[aria-current="page"] { background: var(--surface-2); }
  .brand { display: flex; align-items: center; gap: 10px; padding: 4px 12px 20px; font-family: var(--font-label); font-weight: 700; font-size: 17px; }
  .brand svg { width: 28px; height: 28px; }
  .main { padding: 8px 32px 48px; grid-column: 2; }
}

/* ---------- surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-panel); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; }
.panel-head h2, .section-title { font-family: var(--font-label); font-size: 16px; font-weight: 700; margin: 0; flex: 1; min-width: 0; }
.panel-head .sub { color: var(--ink-3); font-size: 13px; }
.panel-body { padding: 4px 16px 16px; }
.section { margin-top: 28px; }
.section > header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
@media (min-width: 700px) { .grid.cols-2 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .grid.cols-3 { grid-template-columns: repeat(3, 1fr); } }
.stack > * + * { margin-top: 14px; }

/* ---------- the meter (hero) ---------- */
.meter { padding: 18px 18px 16px; display: grid; gap: 16px; }
.meter-face { display: flex; align-items: flex-end; gap: 10px; direction: ltr; justify-content: flex-end; }
.meter-face .digits { display: inline-flex; gap: 3px; }
.meter-face .digit {
  display: inline-grid; place-items: center; min-width: 0.78em; padding: 0.06em 0.04em; font-size: clamp(40px, 11vw, 64px);
  font-weight: 600; line-height: 1; background: var(--ink); color: var(--surface); border-radius: 5px;
  font-variant-numeric: tabular-nums;
}
.meter-face .digit.dim { color: color-mix(in srgb, var(--surface) 35%, var(--ink)); }
.meter-face .unit { font-size: 20px; font-weight: 600; color: var(--ink-2); padding-bottom: 6px; }
.meter-caption { display: flex; justify-content: space-between; align-items: center; color: var(--ink-2); font-size: 13.5px; gap: 8px; }
.meter-stats { display: grid; grid-template-columns: repeat(2, 1fr); border-top: 1px solid var(--rule); }
.meter-stats > div { padding: 12px 0 0; }
.meter-stats > div + div { border-inline-start: 1px solid var(--rule); padding-inline-start: 14px; }
.meter-stats .v { font-size: 22px; font-weight: 600; }
.meter-stats .l { font-size: 13px; color: var(--ink-3); }
.meter-stats .c { font-size: 13px; color: var(--ink-2); }

/* ---------- outlet rows (breakers) ---------- */
.breakers { list-style: none; margin: 0; padding: 0; }
.breaker { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--rule); }
.breaker:first-child { border-top: 0; }
.breaker .ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); position: relative; }
.breaker .ic svg { width: 22px; height: 22px; }
.breaker.on .ic { background: var(--lamp-soft); color: var(--lamp-ink); }
.breaker .meta { min-width: 0; }
.breaker .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; color: var(--ink); }
.breaker .name:hover { text-decoration: none; }
.breaker .detail { font-size: 13px; color: var(--ink-3); display: flex; gap: 10px; flex-wrap: wrap; }
.breaker .detail .w { color: var(--ink-2); }
.breaker.on .detail .w { color: var(--ink); font-weight: 600; }

/* rocker switch with indicator lamp */
.rocker {
  --w: 58px; position: relative; width: var(--w); height: 32px; border-radius: 8px; border: 1px solid var(--rule);
  background: var(--surface-2); cursor: pointer; padding: 0; flex: none; transition: background .18s;
}
.rocker::before {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 24px; height: 24px; border-radius: 5px;
  background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: inset-inline-start .18s ease;
}
.rocker::after { content: ""; position: absolute; top: 12px; inset-inline-end: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--rule); }
.rocker[aria-checked="true"] { background: var(--ink); border-color: var(--ink); }
.rocker[aria-checked="true"]::before { inset-inline-start: calc(var(--w) - 29px); }
.rocker[aria-checked="true"]::after { inset-inline-end: auto; inset-inline-start: 9px; background: var(--lamp); box-shadow: 0 0 0 3px color-mix(in srgb, var(--lamp) 30%, transparent), 0 0 10px var(--lamp); }
.rocker[aria-busy="true"] { opacity: .6; }
.rocker:disabled { cursor: not-allowed; opacity: .45; }

/* ---------- rooms ---------- */
.room-head { display: flex; align-items: center; gap: 10px; }
.room-head .ic { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: var(--surface-2); color: var(--ink-2); }
.room-head .ic svg { width: 20px; height: 20px; }
.room-head .load { font-size: 13px; color: var(--ink-3); }
.room-head .load.on { color: var(--lamp-ink); }

/* ---------- chips / scenes ---------- */
.scroller { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; scroll-snap-type: x proximity; }
.scroller::-webkit-scrollbar { display: none; }
.scene-btn {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 14px 10px 16px; border-radius: 999px; border: 1px solid var(--rule);
  background: var(--surface); cursor: pointer; scroll-snap-align: start; font-weight: 500;
}
.scene-btn svg { width: 18px; height: 18px; color: var(--ink-2); }
.scene-btn:hover { border-color: var(--ink-3); }
.scene-btn[aria-busy="true"] { opacity: .6; }

/* ---------- status ---------- */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot.live { background: var(--live); }
.dot.down { background: var(--fault); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--rule); white-space: nowrap; }
.badge.shared { background: var(--data-soft); color: var(--ink); border-color: transparent; }
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-panel); background: var(--fault-soft); border: 1px solid color-mix(in srgb, var(--fault) 35%, transparent); margin-bottom: 16px; }
.banner svg { width: 20px; height: 20px; color: var(--fault); flex: none; margin-top: 2px; }
.banner.info { background: var(--data-soft); border-color: transparent; }
.banner.info svg { color: var(--data); }
.banner .links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px; border-radius: var(--r-ctl);
  border: 1px solid var(--rule); background: var(--surface); cursor: pointer; font-weight: 500; text-decoration: none; color: var(--ink); white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); text-decoration: none; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.btn.primary:hover { opacity: .92; }
.btn.danger { color: var(--fault); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { width: 42px; padding: 0; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label, .field .label { font-size: 13.5px; font-weight: 500; color: var(--ink-2); }
.field .hint { font-size: 12.5px; color: var(--ink-3); }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: var(--r-ctl); border: 1px solid var(--rule); background: var(--surface); color: var(--ink);
}
.input:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.input[dir="ltr"] { text-align: left; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--r-ctl); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 7px 14px; cursor: pointer; font-size: 14px; color: var(--ink-2); }
.seg button + button { border-inline-start: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days button { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--rule); background: var(--surface); cursor: pointer; font-size: 13px; }
.days button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.check-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--rule); }
.check-row:first-child { border-top: 0; }
.check-row .grow { flex: 1; min-width: 0; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--rule); }
.list > li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { font-size: 13px; color: var(--ink-3); }
a.row-link { color: inherit; display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
a.row-link:hover { text-decoration: none; }
.chev { width: 18px; height: 18px; color: var(--ink-3); flex: none; }
[dir="rtl"] .chev { transform: scaleX(-1); }

.kv { display: grid; grid-template-columns: auto 1fr auto; gap: 8px 12px; align-items: center; }
.kv dt { color: var(--ink-3); font-size: 13.5px; }
.kv dd { margin: 0; font-weight: 500; direction: ltr; text-align: end; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.kv .copy { width: 34px; height: 34px; min-height: 34px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--rule); border-radius: var(--r-panel); overflow: hidden; border: 1px solid var(--rule); }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stats > div { background: var(--surface); padding: 14px 16px; }
.stats .v { font-size: 20px; font-weight: 600; }
.stats .l { font-size: 12.5px; color: var(--ink-3); }

.empty { text-align: center; padding: 36px 20px; color: var(--ink-2); }
.empty svg { width: 40px; height: 40px; color: var(--ink-3); margin-bottom: 8px; }
.empty p { margin: 4px 0 16px; }

/* ---------- charts ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--rule); stroke-width: 1; }
.chart .axis-label { fill: var(--ink-3); font-size: 11px; font-family: var(--font-ui); }
.chart .line { fill: none; stroke: var(--data); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--data); opacity: .12; }
.chart .bar { fill: var(--data); }
.chart .bar.dim { opacity: .35; }
.chart .cross { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .marker { fill: var(--data); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: crosshair; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--surface); padding: 6px 10px; border-radius: 6px;
  font-size: 12.5px; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); z-index: 5; font-variant-numeric: tabular-nums;
}
.tooltip[hidden] { display: none; }
.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.hbars li { display: grid; grid-template-columns: minmax(80px, 34%) 1fr auto; align-items: center; gap: 10px; font-size: 14px; }
.hbars .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbars .track { height: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbars .fill { height: 100%; background: var(--data); border-radius: 4px; }
.hbars .val { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.chart-table summary { cursor: pointer; color: var(--ink-3); font-size: 13px; margin-top: 8px; }
.chart-table table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.chart-table td, .chart-table th { padding: 4px 6px; border-bottom: 1px solid var(--rule); text-align: start; }

/* ---------- overlays ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 20, .45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; border-radius: 18px 18px 0 0;
  padding: 8px 18px calc(20px + env(safe-area-inset-bottom)); animation: rise .2s ease-out;
}
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--rule); margin: 4px auto 12px; }
.sheet h2 { font-family: var(--font-label); font-size: 18px; margin: 0 0 14px; }
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 16px; padding-bottom: 20px; }
  .sheet .grab { display: none; }
}
@keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.toasts { position: fixed; inset-inline: 0; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 8px; z-index: 60; pointer-events: none; padding: 0 16px; }
@media (min-width: 900px) { .toasts { bottom: 24px; } }
.toast { background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); max-width: 480px; }
.toast.err { background: var(--fault); color: #fff; }

/* ---------- auth ---------- */
.auth { min-height: 100dvh; display: grid; }
@media (min-width: 900px) { .auth { grid-template-columns: 1.1fr 1fr; } }
.auth-art { display: none; background: var(--ink); color: var(--surface); padding: 48px; position: relative; overflow: hidden; }
@media (min-width: 900px) { .auth-art { display: flex; flex-direction: column; justify-content: space-between; } }
.auth-art h1 { font-family: var(--font-label); font-size: 34px; line-height: 1.3; margin: 0; max-width: 14em; }
.auth-art p { color: color-mix(in srgb, var(--surface) 70%, var(--ink)); max-width: 30em; }
.auth-art .panel-sketch { display: grid; grid-template-columns: repeat(4, 56px); gap: 12px; }
.auth-art .panel-sketch span { height: 96px; border-radius: 8px; border: 1px solid color-mix(in srgb, var(--surface) 25%, var(--ink)); position: relative; }
.auth-art .panel-sketch span::after { content: ""; position: absolute; top: 12px; inset-inline: 0; margin: auto; width: 10px; height: 10px; border-radius: 50%; background: color-mix(in srgb, var(--surface) 20%, var(--ink)); }
.auth-art .panel-sketch span.on::after { background: var(--lamp); box-shadow: 0 0 14px var(--lamp); }
.auth-form { display: grid; place-items: center; padding: 32px 20px; }
.auth-form form { width: 100%; max-width: 380px; }
.auth-form h2 { font-family: var(--font-label); font-size: 24px; margin: 0 0 6px; }
.auth-form .lead { color: var(--ink-2); margin: 0 0 24px; }
.auth-logo { display: flex; align-items: center; gap: 10px; font-family: var(--font-label); font-weight: 700; margin-bottom: 28px; }
.auth-logo svg { width: 30px; height: 30px; }
.err-text { color: var(--fault); font-size: 13.5px; min-height: 1.4em; margin: 0 0 8px; }

.skeleton { background: var(--surface-2); border-radius: 8px; min-height: 120px; }
.lang-ltr { direction: ltr; unicode-bidi: isolate; }

.linkish { background: none; border: 0; padding: 0; font-weight: 600; cursor: pointer; text-align: start; color: var(--ink); display: block; }
.linkish:hover { text-decoration: underline; }
.list .ic { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: var(--surface-2); color: var(--ink-2); flex: none; }
.list .ic svg, .list > li > a > svg:first-child { width: 20px; height: 20px; }
.check-row select.input { width: auto; flex: 1; min-width: 0; }
.check-row input.input[type="number"] { width: 110px; }
.grow { flex: 1; min-width: 0; }
.days button svg { width: 20px; height: 20px; }
.days button[aria-pressed="true"] svg { color: var(--surface); }
.toolbar { display: flex; justify-content: flex-start; margin: -6px 0 14px; }
