@font-face {
  font-family: "Noto Sans";
  src: url("/fonts/noto-sans-variable.ttf") format("truetype-variations");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #000000;
  --surface: #121212;
  --surface-2: #1b1b1b;
  --border: #636569;
  --border-soft: rgba(99, 101, 105, .72);
  --text: #ffffff;
  --muted: #e6e6e6;
  --subtle: #c4c5c6;
  --green: #3ddc84;
  --amber: #f2c94c;
  --red: #ff6b6b;
  --ipn: #6f1d46;
  --ipn-hover: #551535;
  --ipn-gray: #636569;
  --focus: #ffffff;
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: "Noto Sans", sans-serif; font-synthesis: none; font-weight: 500; line-height: 1.5; }
body.modal-open { overflow: hidden; }
button { font: inherit; }
button, input { touch-action: manipulation; }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login-card { width: min(460px, 100%); padding: 28px; background: var(--surface); border: 1px solid var(--border-soft); border-top: 8px solid var(--ipn); border-radius: 4px; }
.login-card h1 { margin: 14px 0 10px; }
.login-subtitle { margin-bottom: 26px; color: var(--muted); }
.login-card form { display: grid; gap: 8px; }
.login-card label { color: var(--muted); font-size: 13px; font-weight: 600; }
.login-card input { width: 100%; min-height: 48px; margin-bottom: 10px; padding: 0 13px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-2); color: var(--text); font: inherit; color-scheme: dark; }
.login-card input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-color: var(--focus); }
.login-card .button { width: 100%; margin-top: 4px; }
.login-message { min-height: 24px; margin: 0; color: var(--red); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
[hidden] { display: none !important; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 10; padding: 10px 14px; transform: translateY(-160%); background: var(--ipn); color: #ffffff; font-weight: 600; text-decoration: none; }
.skip-link:focus { transform: translateY(0); outline: 3px solid #ffffff; outline-offset: 2px; }
.shell { width: min(2000px, calc(100% - 48px)); margin: 0 auto; padding: 28px 0 48px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 24px; padding: 24px; background: var(--surface); border-top: 8px solid var(--ipn); border-bottom: 1px solid var(--border); }
.title-lockup { padding-left: 16px; border-left: 4px solid var(--ipn); }
.eyebrow { margin: 0 0 8px; padding-left: 9px; border-left: 4px solid var(--ipn); color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .1em; }
.title-lockup .eyebrow { padding-left: 0; border-left: 0; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; color: var(--text); font-size: clamp(28px, 4vw, 44px); font-weight: 600; line-height: 1.1; letter-spacing: -.02em; }
h2 { margin-bottom: 0; color: var(--text); font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.subtitle, .panel-note { color: var(--muted); line-height: 1.5; }
.subtitle { margin-bottom: 0; }
.connection { display: inline-flex; align-items: center; gap: 9px; min-height: 44px; padding: 0 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; color: var(--text); font-size: 14px; white-space: nowrap; }
.connection-dot, .status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--amber); }
.connection-dot.ok, .status-dot.ok { background: var(--green); }
.status-dot.waiting { background: var(--amber); }
.connection-dot.bad, .status-dot.bad { background: var(--red); }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric-card, .panel, .device-card, .route-row { min-width: 0; background: var(--surface); border: 1px solid var(--border-soft); border-radius: 4px; }
.metric-card { padding: 18px; border-top: 4px solid var(--ipn); }
.metric-card span, .metric-card small { display: block; color: var(--subtle); }
.metric-card strong { display: block; margin: 8px 0 2px; color: var(--text); font-size: 30px; font-variation-settings: "wght" 600; }
.panel { padding: 20px; margin-top: 14px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.panel-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal-backdrop { position: fixed; inset: 0; z-index: 9; background: rgba(0, 0, 0, .72); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.config-dialog { position: fixed; inset: 5vh 50% auto auto; z-index: 10; width: min(980px, calc(100% - 32px)); max-height: 90vh; margin: 0; overflow: auto; transform: translateX(50%); box-shadow: 0 22px 70px rgba(0, 0, 0, .7); border-color: var(--ipn); }
.config-dialog .panel-heading { position: sticky; top: -22px; z-index: 1; margin: -22px -22px 18px; padding: 18px 22px; background: rgba(18, 18, 18, .96); border-bottom: 1px solid var(--border-soft); }
.panel-note { margin-bottom: 18px; font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-section { min-width: 0; }
.nested-grid { margin-top: 10px; padding: 14px; background: rgba(0, 0, 0, .18); border: 1px solid var(--border-soft); border-radius: 4px; align-items: start; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; color: var(--text); }
.section-heading span { color: var(--subtle); font-size: 12px; font-weight: 400; }
.form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
.form-grid input:not([type="checkbox"]), .form-grid select { width: 100%; min-height: 46px; padding: 0 12px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-2); color: var(--text); font: inherit; color-scheme: dark; }
.generated-field { display: grid; gap: 6px; min-width: 0; }
.field-hint { color: var(--subtle); font-size: 12px; font-weight: 400; line-height: 1.4; }
.field-with-action { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.field-with-action input { flex: 1 1 260px; min-width: 0; }
.token-input { flex: 1 1 260px; min-width: 0; }
.field-with-action .button { min-height: 46px; white-space: nowrap; }
.form-grid input[readonly] { color: var(--subtle); background: #0a0a0a; cursor: default; }
.form-grid input:focus-visible, .form-grid select:focus-visible, .toggle-row input:focus-visible, .days-grid input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-color: var(--focus); }
.form-grid select:disabled { color: var(--subtle); background: #0a0a0a; cursor: default; opacity: 1; }
.form-grid .wide { grid-column: 1 / -1; }
.schedule-fieldset, .days-fieldset { min-width: 0; margin: 0; border: 1px solid var(--border); border-radius: 4px; }
.schedule-fieldset { display: grid; gap: 14px; padding: 16px; }
.schedule-fieldset > legend, .days-fieldset > legend { padding: 0 7px; color: var(--text); font-size: 14px; font-weight: 600; }
.toggle-row { display: flex !important; grid-template-columns: none; align-items: flex-start; gap: 12px !important; min-height: 48px; padding: 8px 0; cursor: pointer; }
.toggle-row input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--ipn); }
.toggle-row span { display: grid; gap: 3px; }
.toggle-row strong { color: var(--text); font-size: 15px; }
.toggle-row small { color: var(--subtle); font-size: 13px; font-weight: 400; line-height: 1.45; }
.fieldset-help { margin: -3px 0 0; color: var(--subtle); font-size: 13px; line-height: 1.45; }
.weekly-schedule { overflow: hidden; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-2); }
.weekly-schedule-head, .schedule-day-row { display: grid; grid-template-columns: minmax(110px, 1fr) 70px minmax(110px, .8fr) minmax(110px, .8fr); align-items: center; gap: 10px; padding: 10px 12px; }
.weekly-schedule-head { color: var(--subtle); background: #000000; font-size: 12px; font-weight: 700; }
.schedule-day-row { min-height: 58px; border-top: 1px solid var(--border-soft); }
.schedule-day-row strong { color: var(--text); font-size: 14px; }
.schedule-day-row input[type="time"] { width: 100%; min-height: 42px; padding: 0 8px; border: 1px solid var(--border); border-radius: 3px; background: var(--surface); color: var(--text); font: inherit; color-scheme: dark; }
.schedule-day-row input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-color: var(--focus); }
.day-toggle { display: flex; align-items: center; min-height: 44px; cursor: pointer; }
.day-toggle input { width: 22px; height: 22px; margin: 0; accent-color: var(--ipn); }
.schedule-day-row:has([data-day-enabled]:not(:checked)) { opacity: .58; }
.schedule-day-row:has([data-day-enabled]:not(:checked)) input[type="time"] { color: var(--subtle); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.form-help { margin: 0; color: var(--subtle); font-size: 13px; line-height: 1.5; }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.inline-form, .dataset-controls { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; }
.inline-form label, .dataset-controls label { display: grid; gap: 6px; min-width: min(260px, 100%); color: var(--muted); font-size: 13px; font-weight: 600; }
.inline-form input, .dataset-controls select { min-height: 46px; flex: 1 1 280px; min-width: 180px; padding: 0 12px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-2); color: var(--text); font: inherit; color-scheme: dark; }
.inline-form label + input { margin-left: 0; }
.catalog-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.catalog-chip { display: inline-flex; align-items: center; min-height: 38px; padding: 0 11px; background: var(--surface-2); border: 1px solid var(--border-soft); border-left: 3px solid var(--ipn); border-radius: 3px; color: var(--text); }
.compact-empty { width: 100%; padding: 14px; }
.dataset-controls select { flex: 1 1 300px; }
.inline-form input:focus-visible, .dataset-controls select:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-color: var(--focus); }
.button { min-height: 44px; padding: 0 15px; border: 1px solid transparent; border-radius: 4px; color: var(--text); font-weight: 600; cursor: pointer; transition: background-color .15s ease, border-color .15s ease, color .15s ease; }
.button:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.button.primary { background: var(--ipn); color: #ffffff; }
.button.secondary { background: var(--surface-2); border-color: var(--border); }
.button.danger { background: transparent; border-color: var(--red); color: var(--red); }
.button:disabled { cursor: wait; opacity: .55; transform: none; }
.device-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 12px; }
.device-card {
  --person-accent: var(--ipn);
  --person-accent-soft: rgba(111, 29, 70, .14);
  padding: 18px;
  border-top: 4px solid var(--person-accent);
  border-left: 6px solid var(--person-accent);
  background: linear-gradient(135deg, var(--person-accent-soft), transparent 38%), var(--surface);
}
.person-accent-0 { --person-accent: #f0a3c5; --person-accent-soft: rgba(240, 163, 197, .13); }
.person-accent-1 { --person-accent: #8dc7ff; --person-accent-soft: rgba(141, 199, 255, .12); }
.person-accent-2 { --person-accent: #9be7bf; --person-accent-soft: rgba(155, 231, 191, .12); }
.person-accent-3 { --person-accent: #f7c873; --person-accent-soft: rgba(247, 200, 115, .12); }
.person-accent-4 { --person-accent: #c7b5ff; --person-accent-soft: rgba(199, 181, 255, .12); }
.person-accent-5 { --person-accent: #ffab8f; --person-accent-soft: rgba(255, 171, 143, .12); }
.device-head, .route-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.device-head-right { display: grid; justify-items: end; gap: 8px; min-width: 0; }
.device-identity { display: flex; align-items: flex-start; gap: 11px; min-width: 0; }
.device-marker { flex: 0 0 auto; width: 14px; height: 14px; margin-top: 5px; border-radius: 50%; background: var(--person-accent); box-shadow: 0 0 0 4px var(--person-accent-soft); }
.device-name { margin: 0; color: var(--person-accent); font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.device-id, .mono { color: var(--subtle); font-family: "Noto Sans", sans-serif; font-size: 12px; word-break: break-all; }
.device-color-label { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; color: var(--text); font-size: 12px; font-weight: 700; }
.device-color-swatch { width: 13px; height: 13px; flex: 0 0 auto; border-radius: 50%; background: var(--person-accent); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--person-accent), 0 0 0 3px var(--person-accent-soft); }
.state { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 6px 9px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: 999px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.state.active { color: #b7f7d0; border-color: rgba(61, 220, 132, .6); }
.state.offline { color: #ffb4ab; border-color: rgba(255, 107, 107, .6); }
.data-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 10px; margin: 18px 0; }
.data-item { min-width: 0; min-height: 70px; padding: 11px 12px; background: rgba(27, 27, 27, .86); border: 1px solid var(--border-soft); border-left: 3px solid var(--person-accent); border-radius: 3px; }
.data-item span { display: block; color: var(--subtle); font-size: 12px; font-weight: 600; letter-spacing: .01em; }
.data-item strong { display: block; margin-top: 6px; overflow-wrap: anywhere; color: var(--text); font-size: 14px; font-weight: 650; line-height: 1.35; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.route-list { display: grid; gap: 10px; }
.route-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 15px 16px; }
.route-row p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.route-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.empty { padding: 24px; border: 1px dashed var(--border); border-radius: 4px; color: var(--subtle); text-align: center; }
.route-preview { overflow: hidden; }
.preview-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; color: var(--muted); font-size: 13px; }
.preview-meta span { padding: 7px 9px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: 2px; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 20; max-width: min(560px, calc(100% - 32px)); padding: 13px 16px; transform: translate(-50%, calc(100% + 48px)); visibility: hidden; opacity: 0; pointer-events: none; background: #000000; border: 3px solid var(--ipn); border-radius: 4px; color: #ffffff; transition: transform .18s ease, opacity .18s ease; }
.toast.show { transform: translate(-50%, 0); visibility: visible; opacity: 1; }
.app-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; margin-top: 24px; padding: 18px 4px 0; border-top: 6px solid var(--ipn); color: var(--subtle); font-size: 12px; }
.app-footer strong { color: var(--text); font-weight: 600; }
@media (hover: hover) {
  .button.primary:hover { background: var(--ipn-hover); }
  .button.secondary:hover { background: var(--ipn-gray); color: #ffffff; }
}
@media (min-width: 1100px) {
  .shell { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); align-items: start; column-gap: 16px; }
  .shell > .topbar, .shell > .metrics, .shell > .devices-panel, .shell > .dataset-panel, .shell > .app-footer { grid-column: 1 / -1; }
  .shell > .route-catalog-panel, .shell > .routes-panel, .shell > .route-preview { grid-column: 1 / -1; }
}
@media (min-width: 1440px) {
  .metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .device-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .shell { width: 100%; max-width: 620px; padding: 20px 12px 56px; }
  .login-screen { padding: 16px; }
  .login-card { padding: 22px; }
  .topbar { flex-direction: column; padding: 20px 16px; }
  .topbar-actions { justify-content: flex-start; }
  .connection { align-self: flex-start; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .device-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .inline-form, .dataset-controls { align-items: stretch; }
  .inline-form label, .dataset-controls label, .inline-form input, .dataset-controls select, .inline-form .button, .dataset-controls .button { flex: 1 1 100%; min-width: 0; width: 100%; }
  .field-with-action { display: grid; grid-template-columns: 1fr; }
  .field-with-action .button { width: 100%; }
  .weekly-schedule-head { display: none; }
  .schedule-day-row { grid-template-columns: minmax(92px, 1fr) 46px 1fr 1fr; gap: 7px; padding: 9px 10px; }
  .schedule-day-row input[type="time"] { min-height: 44px; padding: 0 5px; font-size: 13px; }
  .form-actions { justify-content: stretch; }
  .form-actions .button { flex: 1 1 100%; }
  .panel-heading, .device-head, .route-head { align-items: flex-start; flex-wrap: wrap; }
  .device-head-right { justify-items: start; }
  .route-row { align-items: flex-start; flex-direction: column; }
  .route-actions { justify-content: flex-start; }
  .metric-card, .panel, .device-card, .route-row, .data-item { overflow-wrap: anywhere; }
}
@media (max-width: 430px) {
  .data-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-actions .button { flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* Visual refresh: control-room surfaces, clearer hierarchy and IPN branding. */
:root {
  --bg: #0b0c11;
  --surface: #14161d;
  --surface-2: #1d2028;
  --border: #3a3e49;
  --border-soft: rgba(126, 131, 145, .34);
  --text: #faf8fb;
  --muted: #e4dfe7;
  --subtle: #c2bdc7;
  --green: #42d995;
  --amber: #f2c75c;
  --red: #ff827f;
  --ipn: #7a1147;
  --ipn-hover: #941956;
  --ipn-gray: #454955;
  --focus: #f6c7dc;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 8% 0%, rgba(122, 17, 71, .23), transparent 36rem),
    radial-gradient(ellipse at 94% 13%, rgba(62, 73, 99, .17), transparent 34rem),
    linear-gradient(155deg, #0b0c11 0%, #101117 52%, #0a0b10 100%);
  background-attachment: fixed;
}

.login-screen { background: transparent; }
.login-card {
  padding: 34px;
  background: linear-gradient(145deg, rgba(27, 29, 38, .97), rgba(17, 18, 24, .98));
  border: 1px solid var(--border-soft);
  border-top: 4px solid var(--ipn);
  border-radius: 20px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, .48), 0 0 48px rgba(122, 17, 71, .12);
}
.login-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 14px; }
.brand-mark { display: block; width: 48px; height: 48px; flex: 0 0 auto; border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .28); }
.login-brand .eyebrow { margin: 0; }
.login-card h1 { margin-top: 8px; font-size: 34px; }
.login-card input,
.form-grid input:not([type="checkbox"]),
.form-grid select,
.schedule-day-row input[type="time"],
.inline-form input,
.dataset-controls select {
  border-color: #424651;
  border-radius: 10px;
  background: #101218;
}
.login-card input:focus-visible,
.form-grid input:focus-visible,
.form-grid select:focus-visible,
.inline-form input:focus-visible,
.dataset-controls select:focus-visible,
.schedule-day-row input:focus-visible { outline-color: var(--focus); }

.shell { width: min(2000px, calc(100% - 56px)); padding: 30px 0 60px; }
.topbar {
  align-items: center;
  margin-bottom: 18px;
  padding: 26px 30px;
  background: linear-gradient(115deg, rgba(28, 26, 34, .98), rgba(19, 21, 28, .96) 58%, rgba(23, 25, 33, .96));
  border: 1px solid var(--border-soft);
  border-top: 4px solid var(--ipn);
  border-radius: 18px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, .24);
}
.title-lockup { display: flex; align-items: center; gap: 18px; min-width: 0; padding: 0; border: 0; }
.title-copy { min-width: 0; }
.title-copy .eyebrow { margin-bottom: 6px; }
.title-copy h1 { margin-bottom: 7px; font-size: clamp(30px, 3vw, 42px); }
.subtitle { color: #d5d0da; }
.eyebrow { color: #e7c9d7; letter-spacing: .04em; }
.topbar-actions { gap: 10px; }
.connection { min-height: 46px; padding: 0 16px; background: rgba(10, 11, 16, .58); border-color: var(--border-soft); border-radius: 999px; }
.button {
  min-height: 46px;
  padding: 0 17px;
  border-radius: 10px;
  transition: background-color .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.button.primary { background: linear-gradient(135deg, #86184f, #6d0f40); box-shadow: 0 6px 18px rgba(122, 17, 71, .22); }
.button.secondary { background: #20232c; border-color: #454a56; }
.button.danger { border-radius: 10px; }
.button:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.button:disabled { opacity: .55; }

.metrics { gap: 14px; margin-bottom: 8px; }
.metric-card {
  position: relative;
  overflow: hidden;
  min-height: 142px;
  padding: 20px 22px;
  background: linear-gradient(145deg, #191b23, #13151b);
  border: 1px solid var(--border-soft);
  border-top: 1px solid var(--border-soft);
  border-radius: 16px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .16);
}
.metric-card::before { position: absolute; top: 0; left: 0; width: 100%; height: 3px; background: var(--ipn); content: ""; }
.metric-card:nth-child(2)::before { background: #3ecb91; }
.metric-card:nth-child(3)::before { background: #d9aa57; }
.metric-card:nth-child(4)::before { background: #8c87da; }
.metric-card span { color: #d7d2dc; font-size: 14px; font-weight: 600; }
.metric-card strong { margin: 11px 0 0; font-size: 36px; line-height: 1; font-variant-numeric: tabular-nums; }
.metric-card small { margin-top: 8px; color: var(--subtle); font-size: 13px; }

.panel {
  margin-top: 14px;
  padding: 22px;
  background: linear-gradient(145deg, rgba(21, 23, 30, .97), rgba(17, 19, 25, .97));
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .18);
}
.panel-heading { margin-bottom: 12px; }
.panel-heading .eyebrow { margin-bottom: 7px; }
.panel-heading h2 { font-size: 22px; letter-spacing: -.02em; }
.panel-note { max-width: 90ch; color: #c9c5cf; }
.route-catalog-panel, .routes-panel { align-self: stretch; }
.route-catalog-panel .panel-note { margin-bottom: 16px; }
.catalog-chip { min-height: 40px; padding: 0 13px; background: #20222b; border-color: #3a3d47; border-left-color: var(--ipn); border-radius: 9px; }
.nested-grid { padding: 16px; background: rgba(7, 8, 12, .28); border-color: var(--border-soft); border-radius: 12px; }
.section-heading { margin-bottom: 7px; }
.section-heading span, .field-hint { color: #bbb6c1; }
.schedule-fieldset, .days-fieldset { border-color: var(--border-soft); border-radius: 12px; }
.schedule-fieldset { padding: 18px; }
.weekly-schedule { border-color: var(--border-soft); border-radius: 12px; background: #111319; }
.weekly-schedule-head { background: #20222b; color: #d3ced8; }
.schedule-day-row { border-color: rgba(126, 131, 145, .2); }
.schedule-day-row input[type="time"] { min-height: 44px; padding: 0 10px; }
.inline-form input, .dataset-controls select { min-height: 46px; }
.button.primary:hover { background: linear-gradient(135deg, #9a205d, #7a1147); box-shadow: 0 8px 22px rgba(122, 17, 71, .32); }
.button.secondary:hover { background: #2a2e39; border-color: #666c7a; color: #fff; }
.button.danger:hover { background: rgba(255, 130, 127, .1); }

.device-grid { gap: 14px; }
.device-card {
  padding: 17px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--person-accent-soft), #181a21 30%), #14161c 58%);
  border: 1px solid var(--border-soft);
  border-top: 1px solid var(--border-soft);
  border-left: 4px solid var(--person-accent);
  border-radius: 16px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .2);
}
.device-name { font-size: 21px; }
.device-id, .mono { color: #cbc6d0; overflow-wrap: anywhere; word-break: normal; }
.device-color-label { color: #ded9e2; }
.state { min-height: 32px; padding: 5px 10px; background: #1d2028; border-color: #3e424e; }
.state.active { color: #a9f0c9; border-color: rgba(66, 217, 149, .52); }
.state.offline { color: #ffc0bb; border-color: rgba(255, 130, 127, .5); }
.data-grid { gap: 9px; margin: 16px 0; }
.data-item { min-height: 76px; padding: 12px; background: rgba(10, 11, 15, .48); border: 1px solid rgba(126, 131, 145, .23); border-left: 2px solid var(--person-accent); border-radius: 10px; }
.data-item span { color: #c6c1cb; font-size: 12px; }
.data-item strong { margin-top: 5px; font-variant-numeric: tabular-nums; }
.card-actions { gap: 8px; }
.card-actions .button { flex: 0 1 auto; padding: 0 13px; }
.route-row {
  padding: 16px;
  background: #191b22;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  transition: border-color .18s ease, background-color .18s ease;
}
.route-row:hover { border-color: rgba(210, 130, 170, .55); background: #1d1f27; }
.route-row p { color: #c9c4ce; }
.route-actions { gap: 8px; }
.empty { border-color: #55505c; border-radius: 12px; background: rgba(15, 16, 21, .42); color: #d0cbd4; }
.preview-meta span { padding: 8px 11px; background: #20222b; border-color: var(--border-soft); border-radius: 9px; }
.toast { bottom: 26px; padding: 14px 18px; background: #22242d; border: 1px solid #b65782; border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .38); }
.app-footer { margin-top: 22px; padding: 18px 4px 0; border-top: 1px solid var(--border-soft); }

@media (min-width: 1100px) {
  .shell { column-gap: 18px; }
  .route-catalog-panel, .routes-panel { margin-top: 16px; }
}
@media (min-width: 1440px) {
  .device-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1840px) {
  .device-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .shell { width: 100%; padding: 16px 12px 42px; }
  .topbar { gap: 18px; padding: 18px; border-radius: 15px; }
  .title-lockup { gap: 12px; }
  .brand-mark { width: 42px; height: 42px; }
  .title-copy h1 { font-size: 29px; }
  .topbar-actions { width: 100%; }
  .topbar-actions .button { flex: 1; }
  .connection { max-width: 100%; white-space: normal; }
  .metric-card { min-height: 126px; padding: 16px; border-radius: 13px; }
  .metric-card strong { font-size: 32px; }
  .panel { padding: 17px; border-radius: 14px; }
  .device-card { padding: 15px; }
  .login-card { padding: 24px; border-radius: 17px; }
}
@media (max-width: 430px) {
  .login-brand { align-items: flex-start; }
  .login-brand .eyebrow { line-height: 1.35; }
  .schedule-day-row { grid-template-columns: minmax(76px, .9fr) 40px 1fr 1fr; }
  .data-grid { gap: 8px; }
  .data-item { min-height: 72px; padding: 10px; }
}

/* Device cards are grouped into separate route sections. */
.device-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.device-route-section {
  min-width: 0; padding: 16px; border: 1px solid var(--border-soft); border-left: 3px solid var(--route-accent, var(--ipn));
  border-radius: 15px; background: linear-gradient(145deg, color-mix(in srgb, var(--route-accent, var(--ipn)) 5%, #151720), #111319 70%);
}
.device-route-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 1px 13px; }
.device-route-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.device-route-title h3 { margin: 0; color: var(--text); font-size: 17px; line-height: 1.35; overflow-wrap: anywhere; }
.device-route-dot { width: 11px; height: 11px; flex: 0 0 auto; border-radius: 50%; background: var(--route-accent, var(--ipn)); box-shadow: 0 0 0 5px color-mix(in srgb, var(--route-accent, var(--ipn)) 18%, transparent); }
.device-route-count { color: var(--subtle); font-size: 12px; text-align: right; }
.device-route-empty { margin: 0; padding: 16px; border: 1px dashed var(--border-soft); border-radius: 11px; color: var(--subtle); font-size: 13px; }
.device-group-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.device-card {
  display: flex; width: 100%; min-height: 190px; flex-direction: column; gap: 18px; padding: 20px;
  border: 1px solid var(--border-soft); border-left: 4px solid var(--route-accent, var(--ipn)); border-radius: 15px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--route-accent, var(--ipn)) 12%, #171922), #14161d 58%);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .18); color: var(--text); font: inherit; text-align: left; cursor: pointer;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.device-card:hover { border-color: var(--route-accent, var(--ipn)); box-shadow: 0 14px 32px rgba(0, 0, 0, .27); }
.device-card:active { transform: scale(.995); }
.device-card:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.device-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.device-identity { display: flex; align-items: flex-start; gap: 13px; min-width: 0; }
.device-marker { width: 13px; height: 13px; margin-top: 7px; background: var(--route-accent, var(--ipn)); box-shadow: 0 0 0 5px color-mix(in srgb, var(--route-accent, var(--ipn)) 19%, transparent); }
.device-title-group { display: grid; gap: 3px; min-width: 0; }
.device-name { color: var(--text); font-size: 21px; line-height: 1.25; overflow-wrap: anywhere; }
.device-route { color: #fff; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.device-transport { color: var(--subtle); font-size: 13px; }
.device-card .state { flex: 0 0 auto; }
.device-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding-top: 15px; border-top: 1px solid var(--border-soft); }
.device-summary > span { display: grid; gap: 3px; min-width: 0; }
.device-summary small { color: var(--subtle); font-size: 12px; }
.device-summary strong { color: var(--text); font-size: 14px; font-weight: 650; overflow-wrap: anywhere; }
.card-open-hint { display: flex; justify-content: space-between; gap: 12px; margin-top: auto; color: #e5c5d5; font-size: 13px; font-weight: 650; }
.card-open-hint span { color: var(--route-accent, #e7a5c4); }
.device-head, .data-grid, .data-item, .card-actions, .device-color-label { display: none; }

.catalog-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 10px; }
.catalog-route { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 12px 14px; border: 1px solid var(--border-soft); border-left: 3px solid var(--route-accent, var(--ipn)); border-radius: 11px; background: #181a22; }
.catalog-route-dot, .route-color-mark { flex: 0 0 auto; width: 11px; height: 11px; border-radius: 50%; background: var(--route-accent, var(--ipn)); box-shadow: 0 0 0 4px color-mix(in srgb, var(--route-accent, var(--ipn)) 18%, transparent); }
.catalog-route-name { display: grid; gap: 2px; min-width: 0; flex: 1; }
.catalog-route-name strong { color: var(--text); font-size: 14px; overflow-wrap: anywhere; }
.catalog-route-name small { color: var(--subtle); font-size: 12px; }
.catalog-route-delete { min-height: 42px; flex: 0 0 auto; padding: 0 11px; border-radius: 9px; font-size: 13px; }
.route-color-picker { display: block !important; min-width: 42px !important; width: 42px; height: 42px; }
.route-color-picker input { width: 42px !important; min-width: 42px !important; height: 42px; padding: 4px !important; border: 1px solid var(--border) !important; border-radius: 9px !important; background: #111319 !important; cursor: pointer; }
.inline-form label[for="newRouteColor"] { min-width: 88px; flex: 0 0 88px; }
.inline-form #newRouteColor { width: 56px; min-width: 56px; height: 46px; flex: 0 0 56px; padding: 4px; cursor: pointer; }
.inline-form #newRouteId { text-transform: uppercase; }

.route-day-filter, .detail-day-filter, .detail-download-form label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 650; }
.route-day-filter { width: min(270px, 100%); }
.route-day-filter select, .detail-day-filter select, .detail-download-form select { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); color: var(--text); font: inherit; color-scheme: dark; }
.route-day-group + .route-day-group { margin-top: 20px; }
.route-day-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 9px; color: var(--text); font-size: 15px; text-transform: none; }
.route-day-heading span { color: var(--subtle); font-size: 12px; font-weight: 500; text-transform: none; }
.route-day-items { display: grid; gap: 9px; }
.route-row { align-items: center; padding: 13px 15px; border-left: 3px solid var(--route-accent, var(--ipn)); background: #191b22; }
.route-row-main { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.route-row-main > div { min-width: 0; }
.route-row-main strong { display: block; color: var(--text); font-size: 14px; overflow-wrap: anywhere; }
.route-row p { margin: 4px 0 0; color: var(--subtle); font-size: 12px; line-height: 1.45; }
.route-row .route-actions { flex: 0 0 auto; }

.detail-dialog { position: fixed; z-index: 11; top: 4vh; left: 50%; width: min(1120px, calc(100% - 36px)); max-height: 92vh; margin: 0; overflow: auto; transform: translateX(-50%); border-color: var(--ipn); background: linear-gradient(145deg, #191b24, #12141a 70%); box-shadow: 0 28px 88px rgba(0, 0, 0, .72); }
.detail-dialog .panel-heading { position: sticky; top: -22px; z-index: 2; margin: -22px -22px 17px; padding: 18px 22px; background: rgba(20, 22, 29, .97); border-bottom: 1px solid var(--border-soft); backdrop-filter: blur(14px); }
.detail-dialog .eyebrow { margin-bottom: 5px; }
.detail-subtitle { margin: 4px 0 0; color: var(--subtle); font-size: 14px; }
.device-detail-info { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 34px; margin-bottom: 18px; }
.detail-info-row { display: grid; grid-template-columns: minmax(135px, .8fr) minmax(0, 1.5fr); align-items: start; gap: 12px; padding: 11px 2px; border-bottom: 1px solid rgba(126, 131, 145, .23); }
.detail-label { display: inline-flex; align-items: center; gap: 7px; color: var(--subtle); font-size: 13px; font-weight: 600; }
.detail-info-row > strong { color: var(--text); font-size: 14px; font-weight: 650; line-height: 1.4; overflow-wrap: anywhere; }
.help-tip { position: relative; display: inline-grid; width: 19px; height: 19px; place-items: center; flex: 0 0 auto; border: 1px solid #8e8994; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 700; line-height: 1; cursor: help; }
.help-tip:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.help-tip::after { position: absolute; z-index: 20; top: calc(100% + 9px); left: -8px; display: none; width: max-content; max-width: min(300px, calc(100vw - 56px)); padding: 10px 12px; border: 1px solid #626674; border-radius: 9px; background: #08090d; box-shadow: 0 10px 28px rgba(0, 0, 0, .48); color: #fff; content: attr(data-help); font-size: 12px; font-weight: 500; line-height: 1.45; white-space: normal; }
.help-tip:hover::after, .help-tip:focus-visible::after { display: block; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 9px; padding: 14px 0 18px; border-top: 1px solid var(--border-soft); border-bottom: 1px solid var(--border-soft); }
.detail-columns { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .8fr); gap: 18px; margin-top: 18px; }
.detail-section { min-width: 0; padding: 15px; border: 1px solid var(--border-soft); border-radius: 12px; background: rgba(8, 9, 13, .28); }
.detail-section .section-heading { display: grid; gap: 3px; margin-bottom: 12px; }
.detail-section .section-heading strong { color: var(--text); }
.detail-section .section-heading span { color: var(--subtle); font-size: 12px; }
.detail-day-filter { margin-bottom: 11px; }
.detail-download-form { display: grid; gap: 10px; }
.detail-download-form .button { width: 100%; }
.detail-section .form-help { margin-top: 10px; }
.detail-dialog .empty { padding: 14px; }

@media (min-width: 761px) and (max-width: 1199px) {
  .device-group-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-columns { grid-template-columns: 1fr; }
}
@media (min-width: 1200px) { .device-group-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .device-route-section { padding: 13px; }
  .device-route-heading { align-items: flex-start; flex-direction: column; gap: 4px; }
  .device-route-count { padding-left: 23px; text-align: left; }
  .device-group-grid { grid-template-columns: 1fr; }
  .device-card { min-height: 180px; padding: 16px; }
  .device-card-head { align-items: flex-start; flex-direction: column; gap: 11px; }
  .device-card .state { margin-left: 25px; }
  .device-summary { gap: 8px; }
  .device-summary small { font-size: 11px; }
  .device-summary strong { font-size: 13px; }
  .detail-dialog { top: 2vh; width: calc(100% - 20px); max-height: 96vh; padding: 16px; }
  .detail-dialog .panel-heading { top: -16px; margin: -16px -16px 14px; padding: 15px 16px; }
  .device-detail-info, .detail-columns { grid-template-columns: 1fr; }
  .detail-info-row { grid-template-columns: minmax(118px, .75fr) minmax(0, 1.25fr); gap: 8px; }
  .detail-actions .button { flex: 1 1 calc(50% - 9px); }
  .route-day-filter { min-width: min(100%, 220px); }
}
@media (max-width: 430px) {
  .detail-info-row { grid-template-columns: 1fr; gap: 3px; }
  .detail-actions .button { flex-basis: 100%; }
  .route-day-heading { align-items: flex-start; flex-direction: column; gap: 2px; }
  .route-row { align-items: flex-start; flex-direction: column; }
  .route-row .route-actions, .route-row .button { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { .device-card { transition: none; } }

/* Use desktop width deliberately and keep every form label attached to its control. */
@media (min-width: 761px) {
  .route-catalog-panel .inline-form {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) 120px auto;
    align-items: end;
    gap: 14px;
  }
  .route-catalog-panel .inline-form label:first-child { min-width: 0; }
  .route-catalog-panel #newRouteId { width: 100%; min-width: 0; }
  .route-catalog-panel .inline-form label[for="newRouteColor"] { width: 120px; }
  .route-catalog-panel #addRouteButton { min-width: 148px; }
  .dataset-controls {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(240px, 1fr) auto;
    align-items: end;
    gap: 14px;
  }
  .dataset-controls label { min-width: 0; width: auto; gap: 7px; }
  .dataset-controls select { width: 100%; min-width: 0; min-height: 46px; }
  .dataset-controls .button { min-width: 156px; min-height: 46px; }
}

@media (max-width: 760px) {
  .route-catalog-panel .inline-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .route-catalog-panel .inline-form label:first-child { min-width: 0; }
  .route-catalog-panel #newRouteId { width: 100%; min-width: 0; }
  .route-catalog-panel .inline-form label[for="newRouteColor"] {
    display: grid; grid-template-columns: minmax(0, 1fr) 56px; align-items: center; gap: 12px; min-width: 0;
  }
  .route-catalog-panel #newRouteColor { width: 56px; min-width: 56px; }
  .route-catalog-panel #addRouteButton { width: 100%; }
  .dataset-controls { display: grid; grid-template-columns: minmax(0, 1fr); align-items: stretch; gap: 12px; }
  .dataset-controls label { min-width: 0; width: 100%; }
  .dataset-controls select, .dataset-controls .button { width: 100%; min-width: 0; }
}
