:root {
  color-scheme: dark;
  --page: #0b1119;
  --surface: #111b27;
  --surface-raised: #162332;
  --header: #0e1722;
  --line: #263547;
  --text: #e6edf6;
  --muted: #9eafc2;
  --accent: #7fc0ff;
  --action: #174e77;
  --action-edge: #357eb0;
  --action-text: #eef8ff;
  --up: #ff8a93;
  --down: #66d7a7;
  --stale: #ffc075;
  --row: #101923;
  --alternate: #131e2a;
  --hover: #1b2b3d;
  --shadow: #0004;
  --quote-size: 0.94rem;
}

:root[data-theme="light"] {
  color-scheme: light;
  --page: #edf2f7;
  --surface: #fff;
  --surface-raised: #e7eef6;
  --header: #f8fbfe;
  --line: #c8d5e4;
  --text: #142136;
  --muted: #495d76;
  --accent: #075f9d;
  --action: #135785;
  --action-edge: #135785;
  --action-text: #fff;
  --up: #ad253b;
  --down: #14704b;
  --stale: #914c0d;
  --row: #fff;
  --alternate: #f3f7fb;
  --hover: #e5eef8;
  --shadow: #253c511f;
}

:root[data-size="small"] { --quote-size: 0.82rem; }
:root[data-size="large"] { --quote-size: 1.12rem; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 0.9rem/1.5 "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
}
h1, h2, h3, p { margin: 0; }
.masthead { background: var(--header); border-bottom: 1px solid var(--line); }
.masthead-inner, main { max-width: 1540px; margin-inline: auto; padding-inline: clamp(16px, 3.1vw, 48px); }
.masthead-inner { display: flex; align-items: center; justify-content: space-between; min-height: 83px; gap: 14px; }
.identity, .header-actions, .controls, .board-title, .board-foot, .footnote { display: flex; align-items: center; gap: 12px; }
h1 { font-size: clamp(1.05rem, 2.4vw, 1.55rem); letter-spacing: 0.035em; line-height: 1.28; }
h1 small { color: var(--accent); font: 600 0.66em/1 "Segoe UI", sans-serif; white-space: nowrap; }
.identity p { color: var(--muted); font-size: 0.78rem; margin-top: 4px; }
.brand-mark {
  width: 40px; height: 40px; flex: 0 0 40px; display: flex; justify-content: center; align-items: flex-end;
  padding-bottom: 10px; gap: 3px; background: var(--surface-raised); border: 1px solid var(--line); border-radius: 8px;
}
.brand-mark i { display: block; width: 3px; border-radius: 2px; background: var(--accent); }
.brand-mark i:nth-child(1) { height: 7px; }
.brand-mark i:nth-child(2) { height: 13px; }
.brand-mark i:nth-child(3) { height: 10px; }
.brand-mark i:nth-child(4) { height: 18px; }
button, select, input {
  min-height: 35px; color: var(--text); font: inherit; background: var(--surface-raised);
  border: 1px solid var(--line); border-radius: 6px;
}
button, select { padding: 5px 11px; white-space: nowrap; }
button { cursor: pointer; }
button:hover, select:hover { border-color: var(--accent); }
button:disabled { cursor: wait; opacity: 0.6; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--action); border-color: var(--action-edge); color: var(--action-text); }
main { padding-block: 25px 32px; }
.simulation { color: var(--stale); background: var(--surface-raised); border: 1px solid var(--stale); border-radius: 7px; padding: 10px 14px; margin-bottom: 16px; font-weight: 700; }
.connections {
  display: grid; grid-template-columns: 1fr 1fr 1fr 1.8fr; gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: 9px; overflow: hidden;
  margin-bottom: 21px;
}
.connection, .totals { background: var(--surface); padding: 12px 16px; min-width: 0; }
.metric-label { display: block; color: var(--muted); font-size: 0.76rem; margin-bottom: 5px; white-space: nowrap; }
.connection strong { font-size: 0.94rem; }
.indicator::before, .dot { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: currentColor; vertical-align: 0.12em; }
.indicator[data-tone="ok"] { color: var(--down); }
.indicator[data-tone="warn"] { color: var(--stale); }
.indicator[data-tone="muted"] { color: var(--muted); }
.totals { display: flex; justify-content: space-between; gap: 12px; }
.totals strong { font: 650 1.13rem/1.2 "Segoe UI", sans-serif; font-variant-numeric: tabular-nums; }
#normal { color: var(--down); }
#abnormal { color: var(--stale); }
.board { overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: 0 10px 32px var(--shadow); }
.board-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; }
h2 { font-size: 1.1rem; letter-spacing: 0.06em; }
#results { color: var(--muted); white-space: nowrap; font-size: 0.8rem; }
.controls { gap: 7px; flex-wrap: wrap; }
.search { position: relative; }
.search-icon { position: absolute; top: 11px; left: 12px; width: 11px; height: 11px; border: 1.5px solid var(--muted); border-radius: 50%; pointer-events: none; }
.search-icon::after { content: ""; position: absolute; top: 8px; left: 7px; width: 6px; height: 1.5px; background: var(--muted); transform: rotate(45deg); }
#search { padding: 5px 10px 5px 31px; width: 175px; }
#search::placeholder { color: var(--muted); }
.table-scroll { overflow: auto; }
table { width: 100%; min-width: 760px; border-collapse: collapse; font-size: var(--quote-size); font-variant-numeric: tabular-nums; }
thead { background: var(--surface-raised); }
th, td { padding: 7px 16px; white-space: nowrap; border-block-start: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-size: 0.8em; font-weight: 640; padding-block: 9px; }
th.numeric, td.numeric { text-align: right; }
tbody tr { background: var(--row); }
tbody tr:nth-child(even) { background: var(--alternate); }
tbody tr:hover { background: var(--hover); }
td[data-key="ID"] { color: var(--accent); font-weight: 660; }
td[data-key="Name"] { min-width: 110px; font-weight: 600; }
td[data-key="Price"] { font-weight: 700; }
td[data-key="updated_at"], td[data-key="status"] { font-size: 0.83em; }
.muted { color: var(--muted) !important; }
.up { color: var(--up); }
.down { color: var(--down); }
.stale { color: var(--stale); }
#rows td[data-state="disconnected"], #rows td[data-state="stale"] { color: var(--stale); }
table[data-offline="true"] tbody td.numeric { color: var(--stale); }
.flash-up { animation: flash-up 0.65s ease-out; }
.flash-down { animation: flash-down 0.65s ease-out; }
@keyframes flash-up { from { background: color-mix(in srgb, var(--up) 28%, transparent); } }
@keyframes flash-down { from { background: color-mix(in srgb, var(--down) 28%, transparent); } }
@media (prefers-reduced-motion: reduce) { .flash-up, .flash-down { animation: none; } }
.empty { padding: 28px; text-align: center; color: var(--muted); border-top: 1px solid var(--line); }
.board-foot, .footnote { color: var(--muted); font-size: 0.75rem; justify-content: space-between; flex-wrap: wrap; }
.board-foot { border-top: 1px solid var(--line); padding: 10px 16px; }
.dot { width: 4px; height: 4px; margin-inline: 5px; }
.footnote { margin: 12px 1px 0; }
.footnote span { margin-inline-end: 13px; }
dialog { width: min(460px, calc(100% - 26px)); max-height: 90vh; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); padding: 0; }
dialog::backdrop { background: #040912ae; }
.settings-form { padding: 16px; }
.dialog-head, .order-head, .size-control { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 0 0 14px; }
.columns { display: grid; grid-template-columns: repeat(2, 1fr); }
.columns label { display: flex; align-items: center; }
input[type="checkbox"] { min-height: 26px; margin-inline-end: 7px; accent-color: var(--accent); }
#custom-order { list-style: none; padding: 0; margin: 0; }
#custom-order li { display: flex; align-items: center; gap: 5px; padding: 4px 0; border-top: 1px solid var(--line); }
#custom-order li span { margin-right: auto; }
@media (max-width: 760px) {
  .connections { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .totals { grid-column: 1 / -1; justify-content: space-around; }
  .board-head, .board-foot { padding-inline: 12px; }
  #search { width: 160px; }
}
@media (max-width: 450px) {
  .masthead-inner { flex-wrap: wrap; padding-block: 12px; align-items: flex-start; }
  .brand-mark { width: 34px; height: 34px; flex-basis: 34px; }
  .metric-label { font-size: 0.67rem; white-space: normal; }
  .connection { padding-inline: 8px; }
  .connection strong { font-size: 0.79rem; }
}
