/* SPM — shared styles for the customer app and the staff console */
@font-face { font-family: "Plex"; src: url("fonts/IBMPlexSans-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex"; src: url("fonts/IBMPlexSans-Medium.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex"; src: url("fonts/IBMPlexSans-SemiBold.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "PlexMono"; src: url("fonts/IBMPlexMono-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "PlexMono"; src: url("fonts/IBMPlexMono-Medium.woff2") format("woff2"); font-weight: 500; font-display: swap; }

:root {
  --navy: #13203a;
  --navy-2: #1c2c4d;
  --navy-text: #c9d3e6;
  --canvas: #f3f5f8;
  --panel: #ffffff;
  --ink: #18212f;
  --muted: #5a6576;
  --line: #dde2ea;
  --line-strong: #c5ccd8;
  --accent: #1f6feb;
  --accent-soft: #e6effd;
  --run: #15803d;
  --stop: #b45309;
  --trip: #b91c1c;
  --idle: #7c3aed;
  --offline: #6b7280;
  --good: #15803d;
  --reject: #b91c1c;
  --radius: 6px;
  --gap: 16px;
  --font: "Plex", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "PlexMono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
#app { min-height: 100vh; }
body { font: 15px/1.45 var(--font); color: var(--ink); background: var(--canvas); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 8px; }
a { color: var(--accent); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------ shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.nav { background: var(--navy); color: var(--navy-text); display: flex; flex-direction: column; padding: 18px 12px; gap: 2px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; }
.brand-mark { width: 30px; height: 30px; border-radius: 7px; background: var(--accent); display: grid; place-items: center;
  font: 600 13px var(--font); letter-spacing: 0.02em; }
.brand-name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--navy-text); }
.nav button { all: unset; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 5px; color: var(--navy-text); font-size: 14px; }
.nav button:hover { background: var(--navy-2); color: #fff; }
.nav button[aria-current="page"] { background: var(--navy-2); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav button:focus-visible { outline: 2px solid #8fb5ff; }
.nav .lock { font-size: 11px; color: #8d9ab3; border: 1px solid #3a4a6b; border-radius: 10px; padding: 0 7px; white-space: nowrap; }
.nav .group { margin-top: 14px; padding: 6px 10px 4px; font-size: 12px; color: #8d9ab3; }
.nav .spacer { flex: 1; }
.nav .who { padding: 10px; font-size: 13px; border-top: 1px solid var(--navy-2); margin-top: 8px; }
.nav .who strong { color: #fff; font-weight: 500; display: block; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 28px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar h1 { flex: 1; }
.menu-btn { display: none; }
.content { padding: 24px 28px 48px; max-width: 1320px; width: 100%; }
.banner { background: #fff7e6; border-bottom: 1px solid #f1d8a6; color: #6b4300; padding: 8px 28px; font-size: 14px; }
.banner.support { background: #eef3ff; border-color: #c9d8fb; color: #19366f; }

/* ------------------------------------------------ controls */
button, .btn { font: 500 14px var(--font); border-radius: var(--radius); padding: 7px 14px; border: 1px solid var(--line-strong);
  background: var(--panel); color: var(--ink); cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #1a5fd0; }
button.danger { color: var(--trip); border-color: #e7b4b4; }
button.link { all: unset; color: var(--accent); cursor: pointer; font-size: 14px; }
button:disabled { opacity: 0.55; cursor: default; }
input, select, textarea { font: 15px var(--font); color: var(--ink); padding: 7px 10px; border: 1px solid var(--line-strong);
  border-radius: var(--radius); background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label > span { font-weight: 500; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.kpis { display: flex; gap: 12px 32px; flex-wrap: wrap; margin: 4px 0 14px; }
.kpis .num { font-size: 17px; }
.toolbar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 18px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line-strong); padding: 7px 12px; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: #0f3f99; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px 20px; margin-bottom: var(--gap); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.error-box { background: #fdecec; color: #7f1d1d; border: 1px solid #f3c2c2; border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; }
.ok-box { background: #e9f7ef; color: #14532d; border: 1px solid #bfe5cd; border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; }

/* ------------------------------------------------ status glyphs: shape + colour + word */
.state { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; font-size: 14px; white-space: nowrap; }
.glyph { width: 11px; height: 11px; flex: none; }
.state.run .glyph { background: var(--run); border-radius: 50%; }
.state.stop .glyph { background: var(--stop); }
.state.idle .glyph { background: var(--idle); border-radius: 2px; transform: rotate(45deg); width: 9px; height: 9px; }
.state.trip .glyph { width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-bottom: 11px solid var(--trip); }
.state.offline .glyph, .state.unknown .glyph { border: 2px solid var(--offline); border-radius: 50%; }
.state.run { color: var(--run); } .state.stop { color: var(--stop); } .state.trip { color: var(--trip); }
.state.idle { color: var(--idle); } .state.offline, .state.unknown { color: var(--offline); }

/* ------------------------------------------------ overview: one row per line */
.lines { display: grid; gap: 12px; }
.line-row { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px 20px 14px;
  display: grid; grid-template-columns: minmax(180px, 1.3fr) repeat(3, minmax(120px, 1fr)); gap: 6px 24px; align-items: start; }
.line-row.is-trip { border-left: 4px solid var(--trip); padding-left: 17px; }
.line-row.is-offline { border-left: 4px solid var(--offline); padding-left: 17px; }
.line-title { display: grid; gap: 3px; }
.line-title h2 { font-size: 18px; }
.metric { display: grid; gap: 1px; }
.metric .label { font-size: 12.5px; color: var(--muted); }
.metric .value { font-family: var(--mono); font-size: 26px; font-weight: 500; line-height: 1.15; font-variant-numeric: tabular-nums; }
.metric .value small { font-family: var(--font); font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.metric .sub { font-size: 12.5px; color: var(--muted); }
.strip-wrap { grid-column: 1 / -1; margin-top: 10px; }
.strip { display: block; width: 100%; height: 30px; }
.strip-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 4px; }
.strip-legend i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; vertical-align: -1px; border-radius: 2px; }

.meters { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.meter { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; display: grid; gap: 4px; }
.meter .utility { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.meter .value { font-family: var(--mono); font-size: 24px; font-weight: 500; font-variant-numeric: tabular-nums; }
.meter .value small { font-family: var(--font); font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 0 12px; }

/* ------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.n, th.n { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.tag-pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--canvas); border: 1px solid var(--line); color: var(--muted); }
.tag-pill.bad { background: #fdecec; border-color: #f3c2c2; color: #7f1d1d; }
.tag-pill.good { background: #e9f7ef; border-color: #bfe5cd; color: #14532d; }

/* ------------------------------------------------ charts */
.chart { width: 100%; display: block; }
.chart text { font: 11px var(--font); fill: var(--muted); }
.chart .axis { stroke: var(--line-strong); }
.chart .grid { stroke: var(--line); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.chart-tip { position: fixed; pointer-events: none; background: var(--navy); color: #fff; font-size: 12.5px; padding: 6px 9px;
  border-radius: 5px; z-index: 50; white-space: pre; }

/* ------------------------------------------------ locked feature page */
.locked { max-width: 560px; padding: 32px; }
.locked h2 { margin-bottom: 8px; }

/* ------------------------------------------------ sign-in */
.signin { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 440px) 1fr; }
.signin-form { background: var(--panel); padding: 48px 44px; display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.signin-form form { display: grid; gap: 14px; }
.signin-form h1 { font-size: 26px; margin: 18px 0 4px; }
.signin-art { background: var(--navy); color: var(--navy-text); padding: 48px; display: flex; flex-direction: column; justify-content: flex-end; }
.signin-art svg { width: 100%; max-width: 640px; }
.signin-art p { max-width: 520px; font-size: 16px; }

/* ------------------------------------------------ dialogs */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 22px 24px; max-width: min(560px, calc(100vw - 32px)); width: 100%; }
dialog::backdrop { background: rgba(19, 32, 58, 0.45); }
dialog form { display: grid; gap: 12px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.secret { font-family: var(--mono); font-size: 18px; background: var(--canvas); border: 1px dashed var(--line-strong); padding: 10px 12px; border-radius: 6px; user-select: all; }
.secret.small { font-size: 13px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); word-break: break-all; }

/* ------------------------------------------------ staff console accent */
body.staff .nav { background: #1d2430; }
body.staff .nav button:hover, body.staff .nav button[aria-current="page"] { background: #2b3444; }
body.staff .brand-mark { background: #0e8a7e; }
body.staff .nav button[aria-current="page"] { box-shadow: inset 3px 0 0 #2bb3a3; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.tree { display: grid; gap: 10px; }
.tree .plant { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.tree .line { margin: 8px 0 0 14px; padding-left: 12px; border-left: 2px solid var(--line); }
.tree .device { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); flex-wrap: wrap; }
.tree .device:last-child { border-bottom: 0; }

/* ------------------------------------------------ phones */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform 0.18s ease; }
  .nav.open { transform: none; box-shadow: 0 0 0 100vmax rgba(19, 32, 58, 0.45); }
  .menu-btn { display: inline-block; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px 16px 40px; }
  .banner { padding: 8px 16px; }
  .line-row { grid-template-columns: 1fr 1fr; }
  .line-title { grid-column: 1 / -1; }
  .metric .value { font-size: 22px; }
  .signin { grid-template-columns: 1fr; }
  .signin-art { display: none; }
  .signin-form { padding: 32px 22px; }
  .split { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .nav { transition: none; } }
