:root {
  color-scheme: dark;
  --bg: #0b1117;
  --surface: #111a22;
  --surface-2: #17232d;
  --line: #263642;
  --text: #eef4f7;
  --muted: #8ea0ac;
  --cyan: #2fd3c8;
  --blue: #4aa3ff;
  --orange: #f3a83b;
  --red: #ff6b6b;
  --green: #4fdb91;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: radial-gradient(circle at 70% -20%, #15313d 0, transparent 35%), var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { width: min(1420px, 100%); margin: 0 auto; padding: 0 36px 48px; }
.topbar { height: 92px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand, .top-actions, .card-heading, .panel-title, .metric-footer, .dialog-header, .dialog-actions { display: flex; align-items: center; justify-content: space-between; }
.brand { gap: 14px; }
.brand-mark { width: 42px; height: 42px; border: 1px solid #31515a; border-radius: 11px; display: flex; align-items: flex-end; justify-content: center; gap: 4px; padding: 10px; background: #13242b; }
.brand-mark span { width: 5px; border-radius: 3px; background: var(--cyan); }
.brand-mark span:nth-child(1) { height: 10px; opacity: .6; }
.brand-mark span:nth-child(2) { height: 20px; }
.brand-mark span:nth-child(3) { height: 15px; opacity: .8; }
.eyebrow, .section-kicker { margin: 0 0 4px; color: var(--cyan); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.top-actions { gap: 12px; }
.top-actions .secondary-button { width: auto; }
.connection-pill { display: flex; gap: 9px; align-items: center; min-width: 132px; padding: 10px 14px; border: 1px solid #28413c; border-radius: 100px; background: #10221f; color: #8ee8bb; font-size: 12px; font-weight: 800; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 5px #4fdb9120; }
.connection-pill.offline { color: #ff9999; border-color: #4c2929; background: #251617; }
.connection-pill.offline .status-dot { background: var(--red); box-shadow: 0 0 0 5px #ff6b6b20; }
.connection-pill.stale { color: #ffd590; border-color: #4f3e24; background: #251f14; }
.connection-pill.stale .status-dot { background: var(--orange); box-shadow: 0 0 0 5px #f3a83b20; }
.icon-button, .close-button { border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.icon-button { width: 42px; height: 42px; border-radius: 11px; padding: 10px; }
.icon-button svg { width: 100%; fill: none; stroke: currentColor; stroke-width: 1.6; }

.hero { padding: 48px 0 30px; display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.hero h2 { margin: 0; font-size: clamp(26px, 4vw, 42px); letter-spacing: -.045em; }
.hero-copy { margin: 11px 0 0; color: var(--muted); }
.last-update { text-align: right; }
.last-update span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .12em; }
.last-update strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 18px; }

.metrics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.scale-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-bottom: 18px; }
.scale-card { border: 1px solid var(--line); border-radius: 16px; padding: 18px; background: linear-gradient(145deg, #13202a 0%, #0f171f 100%); }
.scale-select-card { width: 100%; color: inherit; text-align: left; }
.scale-select-card:hover { border-color: #3b6866; transform: translateY(-1px); transition: border-color .18s ease, transform .18s ease; }
.scale-select-card.selected { border-color: var(--cyan); box-shadow: inset 0 0 0 1px #2fd3c855, 0 14px 40px #0000001f; }
.scale-card.offline { border-color: #553030; background: linear-gradient(145deg, #211617 0%, #11171d 100%); }
.scale-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 15px; }
.scale-card-head strong { display: block; font-size: 15px; }
.scale-card-head span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.scale-card-head em { padding: 5px 8px; border-radius: 999px; background: #173327; color: #85ebb8; font-size: 10px; font-style: normal; font-weight: 850; text-transform: uppercase; }
.scale-card.offline .scale-card-head em { background: #361d1f; color: #ffaaaa; }
.scale-card-values { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.scale-card-values div { min-width: 0; padding-top: 10px; border-top: 1px solid var(--line); }
.scale-card-values span, .scale-card-values small { display: block; color: var(--muted); font-size: 10px; }
.scale-card-values b { display: block; margin: 4px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 18px; }
.scale-error { margin: 12px 0 0; color: #ffaaaa; font-size: 11px; line-height: 1.45; }
.scale-ok { margin: 12px 0 0; color: var(--green); font-size: 11px; line-height: 1.45; }
.scale-empty { grid-column: 1 / -1; padding: 18px; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); text-align: center; }
.metric-card, .panel { border: 1px solid var(--line); background: linear-gradient(145deg, #15212a 0%, #101820 100%); border-radius: 18px; box-shadow: 0 14px 40px #00000022; }
.metric-card { min-height: 250px; padding: 26px; position: relative; overflow: hidden; }
.metric-card::after { content: ""; position: absolute; right: -70px; bottom: -110px; width: 260px; height: 260px; border-radius: 50%; filter: blur(5px); opacity: .09; }
.flow-card::after { background: var(--cyan); }
.total-card::after { background: var(--blue); }
.card-heading { position: relative; z-index: 1; }
.card-heading p { margin: 0 0 7px; color: #c8d5db; font-size: 12px; font-weight: 850; letter-spacing: .1em; }
.card-heading span { color: var(--muted); font-size: 13px; }
.metric-icon { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 13px; }
.metric-icon svg { width: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.flow-icon { color: var(--cyan); background: #2fd3c817; }
.total-icon { color: var(--blue); background: #4aa3ff17; }
.metric-value { display: flex; align-items: baseline; gap: 12px; margin: 37px 0 30px; position: relative; z-index: 1; }
.metric-value strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: clamp(42px, 6vw, 68px); line-height: .9; letter-spacing: -.07em; }
.metric-value span { color: var(--muted); font-size: 18px; font-weight: 700; }
.metric-footer { position: relative; z-index: 1; padding-top: 17px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; letter-spacing: .04em; }
.live-badge { color: #80e8bd; font-weight: 800; }
.live-badge i { display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--green); }

.content-grid { margin-top: 18px; display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(290px, .7fr); gap: 18px; }
.panel { padding: 24px; }
#dashboardPanel { padding-bottom: 12px; }
#dashboardPanel .scale-summary { margin-bottom: 0; }
.panel h3 { margin: 0; font-size: 18px; }
.range-chip { padding: 7px 10px; border: 1px solid #274742; border-radius: 8px; color: var(--cyan); font-size: 9px; font-weight: 850; letter-spacing: .12em; }
.chart-wrap { height: 260px; margin-top: 22px; position: relative; }
#flowChart, #cloudFlowChart { width: 100%; height: 100%; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.diagnostic-list { margin: 19px 0; }
.diagnostic-list div { display: flex; justify-content: space-between; gap: 15px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.diagnostic-list dt { color: var(--muted); font-size: 12px; }
.diagnostic-list dd { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; text-align: right; }
.ok-text { color: var(--green); }
.error-box { padding: 13px; margin-bottom: 14px; border: 1px solid #633333; border-radius: 10px; background: #2a1718; color: #ffaaaa; }
.error-box strong { font-size: 12px; }
.error-box p { margin: 6px 0 0; font-size: 11px; line-height: 1.45; }
.hidden { display: none !important; }

.primary-button, .secondary-button { min-height: 42px; padding: 0 16px; border-radius: 9px; font-weight: 800; }
.primary-button { border: 0; background: var(--cyan); color: #071315; }
.secondary-button { width: 100%; border: 1px solid var(--line); background: #17232d; color: var(--text); }

dialog { width: min(900px, calc(100% - 28px)); max-height: 92vh; padding: 0; border: 1px solid #344a57; border-radius: 18px; background: #101820; color: var(--text); box-shadow: 0 30px 100px #000c; }
dialog::backdrop { background: #03070ac9; backdrop-filter: blur(6px); }
#settingsForm, #scaleForm { padding: 26px; overflow: auto; max-height: 92vh; }
.dialog-header h2 { margin: 0; font-size: 25px; }
.close-button { width: 38px; height: 38px; border-radius: 10px; font-size: 26px; line-height: 1; }
.warning-banner { margin: 22px 0; padding: 14px 16px; border: 1px solid #604822; border-radius: 11px; background: #2b2214; color: #ffd799; }
.warning-banner strong { font-size: 12px; }
.warning-banner p { margin: 5px 0 0; font-size: 11px; line-height: 1.5; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.form-grid .wide { grid-column: span 3; }
label { display: grid; gap: 7px; color: #aab8c1; font-size: 11px; font-weight: 700; }
input, select { width: 100%; min-height: 42px; padding: 0 11px; border: 1px solid #31434e; border-radius: 8px; outline: none; background: #0c141a; color: var(--text); }
input:focus, select:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px #2fd3c815; }
.register-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-top: 19px; }
.register-grid fieldset:last-child { grid-column: span 2; grid-template-columns: repeat(4, 1fr); }
fieldset { margin: 0; padding: 17px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; border: 1px solid var(--line); border-radius: 12px; }
legend { padding: 0 7px; color: var(--text); font-size: 12px; font-weight: 850; }
.dialog-actions { justify-content: flex-end; gap: 10px; padding-top: 22px; }
.dialog-actions .secondary-button { width: auto; }
.form-error { padding: 12px; border-radius: 8px; color: #ffaaaa; background: #2a1718; font-size: 12px; }

.admin-grid { display: grid; gap: 16px; }
.admin-customer-card { border: 1px solid var(--line); border-radius: 16px; padding: 18px; background: linear-gradient(145deg, #13202a 0%, #0f171f 100%); }
.admin-add-scale { width: auto; min-height: 34px; }
.admin-table { display: grid; gap: 8px; margin-top: 14px; }
.admin-users { display: grid; gap: 8px; margin-top: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #0d151c; }
.admin-users > strong { color: #c8d5db; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.admin-user-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 8px; border-top: 1px solid var(--line); }
.admin-user-row span, .admin-user-row small { display: block; }
.admin-user-row small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.admin-user-row .secondary-button { width: auto; min-height: 34px; }
.admin-table-head, .admin-table-row { display: grid; grid-template-columns: 1.4fr .5fr .8fr 1fr auto; gap: 12px; align-items: center; }
.admin-table-head { padding: 0 10px 6px; color: var(--muted); font-size: 10px; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.admin-table-row { min-height: 54px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: #0d151c; }
.admin-table-row b, .admin-table-row small { display: block; }
.admin-table-row small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.admin-table-row code { color: var(--cyan); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.admin-table-row .secondary-button { width: auto; min-height: 34px; }
.admin-empty-row { padding: 14px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: 12px; }

@media (max-width: 850px) {
  .app-shell { padding: 0 18px 30px; }
  .metrics-grid, .content-grid, .scale-summary { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .wide { grid-column: span 2; }
}

@media (max-width: 560px) {
  .topbar { height: 80px; }
  .brand .eyebrow { display: none; }
  .brand h1 { font-size: 15px; }
  .connection-pill { min-width: auto; }
  .hero { align-items: flex-start; flex-direction: column; padding-top: 34px; }
  .last-update { text-align: left; }
  .metric-card { min-height: 230px; padding: 21px; }
  .scale-card-values { grid-template-columns: 1fr; }
  .admin-table-head { display: none; }
  .admin-table-row { grid-template-columns: 1fr; }
  .form-grid, .register-grid, fieldset, .register-grid fieldset:last-child { grid-template-columns: 1fr; }
  .register-grid fieldset:last-child { grid-column: auto; }
  .form-grid .wide { grid-column: auto; }
}
