:root {
  --canvas: #f2f4f7;
  --surface: #ffffff;
  --surface-subtle: #f7f8fa;
  --ink: #18212b;
  --muted: #667382;
  --faint: #8d98a5;
  --line: #dce1e7;
  --line-strong: #c7ced7;
  --primary: #126c66;
  --primary-hover: #0d5c57;
  --blue: #2f67c8;
  --danger: #b73e4b;
  --warning: #a7670b;
  --success-bg: #e8f5f1;
  --danger-bg: #faecee;
  --warning-bg: #fff4de;
  --sidebar: #172129;
  --sidebar-muted: #93a1ab;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(20, 30, 40, 0.06), 0 8px 24px rgba(20, 30, 40, 0.04);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  color-scheme: light;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
.hidden { display: none !important; }
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

h1,
h2,
p { margin-top: 0; }

h1,
h2 { letter-spacing: 0; }

h1 { margin-bottom: 0; font-size: 26px; line-height: 1.25; }
h2 { margin-bottom: 0; font-size: 18px; line-height: 1.35; }

.eyebrow,
.section-index {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 11px;
  line-height: 1.2;
  font-weight: 750;
  letter-spacing: 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #ffffff;
  background: var(--primary);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 800;
}

.brand-mark.small { width: 38px; height: 38px; }

/* Login */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--canvas);
}

.login-card {
  width: min(408px, 100%);
  padding: 34px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-brand,
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-brand strong,
.sidebar-brand strong { display: block; font-size: 16px; }
.login-brand span,
.sidebar-brand span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.login-heading { margin: 36px 0 24px; }
.login-heading h1 { font-size: 24px; }

.login-form { display: grid; gap: 18px; }

.login-form label,
.field {
  display: grid;
  gap: 7px;
  color: #465361;
  font-size: 13px;
  font-weight: 650;
}

input,
select,
.device-picker summary {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  outline: none;
}

input::placeholder { color: #9aa3ad; }

input:hover,
select:hover,
.device-picker summary:hover { border-color: #9faab6; }

input:focus,
select:focus,
.device-picker[open] summary {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(18, 108, 102, 0.12);
}

input[type="datetime-local"] {
  min-width: 0;
  color-scheme: light;
}

input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  opacity: 0.72;
  cursor: pointer;
}

.login-form button,
.filter-actions button,
.record-query-button,
.download-button,
.icon-command {
  min-height: 42px;
  padding: 9px 16px;
  color: #ffffff;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  font-weight: 700;
}

.login-form button { margin-top: 4px; }
.login-form button:hover,
.filter-actions button:hover,
.record-query-button:hover,
.download-button:hover,
.icon-command:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.form-error {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 13px;
}

/* Shell */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr);
}

.sidebar {
  min-width: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 18px 18px;
  color: #ffffff;
  background: var(--sidebar);
}

.sidebar-brand { padding: 0 4px 24px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }
.sidebar-brand strong { color: #ffffff; }
.sidebar-brand span { color: var(--sidebar-muted); }

nav { min-width: 0; max-width: 100%; display: grid; gap: 4px; margin-top: 22px; }

nav a {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 10px;
  color: #dbe1e5;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 600;
}

nav a:hover { color: #ffffff; background: rgba(255, 255, 255, 0.08); }
nav a.is-active { color: #ffffff; background: rgba(18, 108, 102, 0.34); }

.sidebar-footer { display: grid; gap: 12px; margin-top: auto; }
.environment { display: flex; align-items: center; gap: 8px; color: var(--sidebar-muted); font-size: 12px; }
.environment i { width: 7px; height: 7px; border-radius: 50%; background: #50c878; box-shadow: 0 0 0 3px rgba(80, 200, 120, 0.13); }

.quiet-button {
  min-height: 40px;
  color: #dbe1e5;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  font-weight: 650;
}

.quiet-button:hover { background: rgba(255, 255, 255, 0.08); }

.content {
  min-width: 0;
  padding: 28px clamp(20px, 3vw, 42px) 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding-bottom: 24px;
}

.topbar-actions { display: flex; align-items: center; gap: 16px; }
.account-chip {
  min-width: 112px;
  display: grid;
  gap: 2px;
  padding-right: 16px;
  border-right: 1px solid var(--line);
  text-align: right;
}
.account-chip span { color: var(--ink); font-size: 13px; font-weight: 700; }
.account-chip small { color: var(--faint); font-size: 11px; }
.sync-status { display: grid; justify-items: end; gap: 3px; }
.sync-status small { color: var(--faint); font-size: 12px; }
.page-status { position: relative; padding-left: 14px; color: var(--muted); font-size: 13px; }
.page-status::before { content: ""; position: absolute; left: 0; top: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--primary); }
.page-status.error { color: var(--danger); }
.page-status.error::before { background: var(--danger); }
.auto-refresh-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.auto-refresh-control > input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.toggle-track {
  width: 34px;
  height: 20px;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  padding: 2px;
  background: #a8b2bc;
  border-radius: 999px;
  transition: background 160ms ease;
}
.toggle-track i {
  width: 16px;
  height: 16px;
  display: block;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(20, 30, 40, 0.2);
  transition: transform 160ms ease;
}
.auto-refresh-control > input:checked + .toggle-track { background: var(--primary); }
.auto-refresh-control > input:checked + .toggle-track i { transform: translateX(14px); }
.auto-refresh-control > input:focus-visible + .toggle-track { box-shadow: 0 0 0 3px rgba(18, 108, 102, 0.16); }
.auto-refresh-copy { display: grid; gap: 1px; color: var(--ink); font-size: 12px; font-weight: 650; }
.auto-refresh-copy small { color: var(--faint); font-size: 10px; font-weight: 500; }
.icon-command { display: inline-flex; align-items: center; justify-content: center; }

/* Metrics */
.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric-strip article {
  min-width: 0;
  padding: 20px 22px;
  border-right: 1px solid var(--line);
}

.metric-strip article:last-child { border-right: 0; }
.metric-strip span { display: block; color: var(--muted); font-size: 13px; font-weight: 650; }
.metric-strip strong { display: block; margin: 8px 0 4px; font-size: 28px; line-height: 1; font-variant-numeric: tabular-nums; }
.metric-strip small { color: var(--faint); font-size: 11px; }
.metric-strip .positive { color: var(--primary); }
.metric-strip .warning { color: var(--warning); }
.overview-recent { margin-top: 28px; }
.overview-table { min-width: 720px; }

/* Workspaces */
.workspace-section { padding-top: 34px; scroll-margin-top: 20px; }
.workspace-view.workspace-section { padding-top: 0; }

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
  margin-bottom: 14px;
}

.section-meta { color: var(--muted); font-size: 13px; }

.filter-bar,
.record-filter,
.export-form {
  display: grid;
  align-items: end;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
}

.device-filters { grid-template-columns: minmax(240px, 2fr) minmax(140px, 0.8fr) minmax(140px, 0.8fr) auto; }
.filter-actions { display: flex; gap: 8px; }
.filter-actions .secondary-button { color: var(--ink); background: var(--surface); border-color: var(--line-strong); }
.filter-actions .secondary-button:hover { background: var(--surface-subtle); border-color: #9faab6; }

.record-filter { grid-template-columns: minmax(220px, 0.8fr) minmax(490px, 2fr) auto; }
.export-form {
  grid-template-columns: minmax(220px, 0.8fr) minmax(490px, 2fr) minmax(180px, auto);
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.device-picker-field { align-self: stretch; }
.device-picker { position: relative; }
.device-picker summary { display: flex; align-items: center; justify-content: space-between; list-style: none; cursor: pointer; font-weight: 500; }
.device-picker summary::-webkit-details-marker { display: none; }
.device-picker summary::after { content: "⌄"; color: var(--muted); font-size: 16px; }
.device-picker[open] summary::after { content: "⌃"; }

.device-picker-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  width: min(360px, 82vw);
  max-height: 330px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 16px 34px rgba(20, 30, 40, 0.14);
}

.picker-heading { display: flex; align-items: center; justify-content: space-between; padding: 11px 12px; border-bottom: 1px solid var(--line); }
.picker-heading strong { font-size: 13px; }
.picker-heading button { padding: 4px 7px; color: var(--primary); background: transparent; border: 0; font-size: 12px; font-weight: 700; }
.device-picker-options { max-height: 270px; overflow-y: auto; padding: 6px; }
.device-picker-options label { display: flex; align-items: center; gap: 9px; min-height: 38px; padding: 7px 8px; border-radius: 4px; color: var(--ink); font-weight: 500; cursor: pointer; }
.device-picker-options label:hover { background: var(--surface-subtle); }
.device-picker-options input { width: 16px; min-height: 16px; height: 16px; margin: 0; accent-color: var(--primary); box-shadow: none; }
.device-picker-options .picker-empty { padding: 18px 10px; color: var(--muted); font-size: 13px; text-align: center; }
.device-picker-field > small,
.time-filter > small { margin-top: auto; color: var(--faint); font-size: 11px; font-weight: 500; }

.time-filter {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.time-filter legend { margin-bottom: 7px; padding: 0; color: #465361; font-size: 13px; font-weight: 650; }
.range-switch { display: inline-flex; margin-bottom: 10px; padding: 3px; background: #e9edf1; border-radius: var(--radius); }
.range-switch button { min-height: 28px; padding: 4px 10px; color: var(--muted); background: transparent; border: 0; border-radius: 4px; font-size: 12px; font-weight: 650; }
.range-switch button:hover { color: var(--ink); }
.range-switch button.is-active { color: var(--ink); background: var(--surface); box-shadow: 0 1px 3px rgba(20, 30, 40, 0.1); }

.date-fields { display: grid; grid-template-columns: minmax(190px, 1fr) auto minmax(190px, 1fr); align-items: end; gap: 8px; }
.date-separator { padding-bottom: 12px; color: var(--faint); font-size: 12px; }
.record-query-button { min-width: 98px; }
.export-action {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-end;
  gap: 9px;
}
.export-action > span { color: var(--faint); font-size: 11px; text-align: center; }

/* Tables */
.table-frame {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
}

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; min-width: 980px; border-collapse: collapse; }
th,
td { padding: 12px 14px; text-align: left; border-bottom: 1px solid #e7eaee; font-size: 13px; white-space: nowrap; }
th { color: #4f5c69; background: var(--surface-subtle); font-size: 11px; font-weight: 750; text-transform: uppercase; }
td { color: #4b5865; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: 0; }
.empty-cell { height: 112px; color: var(--faint); text-align: center; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  color: var(--muted);
  background: #edf0f3;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #87929d; }
.badge.online { color: #126c52; background: var(--success-bg); }
.badge.online::before { background: #25966e; }
.badge.offline { color: #98414c; background: var(--danger-bg); }
.badge.offline::before { background: #ca5965; }

.pager { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 14px; border-top: 1px solid var(--line); }
.pager > span { color: var(--muted); font-size: 12px; }
.pager > div { display: flex; gap: 6px; }
.pager-button { width: 34px; height: 34px; padding: 0; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); font-size: 22px; line-height: 1; }
.pager-button:hover:not(:disabled) { color: var(--primary); border-color: var(--primary); }

.download-button { display: inline-flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.download-button span { font-size: 18px; line-height: 1; }

/* Administrator management */
.primary-button {
  min-height: 40px;
  padding: 8px 14px;
  color: #ffffff;
  background: var(--blue);
  border: 1px solid var(--blue);
  border-radius: var(--radius);
  font-weight: 700;
}
.primary-button:hover { background: #2458b1; border-color: #2458b1; }
.rounded-frame { border-radius: var(--radius); }
.admin-table { min-width: 760px; }
.table-status { min-height: 44px; display: flex; align-items: center; padding: 9px 14px; color: var(--muted); border-top: 1px solid var(--line); font-size: 12px; }
.table-status.error { color: var(--danger); }
.row-actions { display: flex; align-items: center; gap: 6px; }
.row-action {
  min-height: 30px;
  padding: 5px 9px;
  color: var(--blue);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 650;
}
.row-action:hover { border-color: var(--blue); }
.row-action.danger { color: var(--danger); }
.row-action.danger:hover { border-color: var(--danger); }
.row-action.success { color: var(--primary); }
.role-label { color: var(--blue); font-weight: 700; }
.config-state { color: var(--muted); font-size: 12px; }
.config-state.pending { color: var(--warning); font-weight: 700; }

.admin-dialog {
  width: min(480px, calc(100vw - 32px));
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(20, 30, 40, 0.22);
}
.admin-dialog::backdrop { background: rgba(23, 33, 41, 0.5); }
.admin-dialog form { display: grid; gap: 16px; padding: 24px; }
.device-config-dialog { width: min(560px, calc(100vw - 32px)); }
.config-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.config-summary span { display: grid; gap: 4px; min-width: 0; }
.config-summary strong { overflow-wrap: anywhere; color: var(--ink); font-size: 13px; }
.checkbox-field { display: flex; align-items: center; gap: 9px; color: var(--ink); font-size: 13px; font-weight: 650; }
.checkbox-field input { width: 17px; height: 17px; min-height: 17px; margin: 0; accent-color: var(--primary); }
.wifi-config-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 4px; }
.dialog-close { width: 34px; height: 34px; padding: 0; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: var(--radius); font-size: 22px; line-height: 1; }
.dialog-close:hover { color: var(--ink); background: var(--surface-subtle); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions .secondary-button {
  min-height: 40px;
  padding: 8px 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-weight: 650;
}

@media (max-width: 1120px) {
  .device-filters { grid-template-columns: 1fr 1fr; }
  .filter-actions { justify-content: flex-end; }
  .record-filter,
  .export-form { grid-template-columns: 1fr; }
  .record-query-button { justify-self: end; }
  .export-action { align-items: flex-end; }
  .export-action .download-button { min-width: 180px; justify-content: center; }
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 14px 16px; }
  .sidebar-brand { padding: 0 0 14px; }
  nav { grid-template-columns: repeat(5, max-content); overflow-x: auto; margin: 12px -4px 0; }
  nav a { min-height: 36px; padding: 0 10px; }
  .sidebar-footer { display: none; }
  .content { padding: 20px 14px 36px; }
  .topbar { align-items: flex-start; }
  .topbar-actions { align-items: center; gap: 9px; }
  .sync-status,
  .account-chip { display: none; }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-strip article:nth-child(2) { border-right: 0; }
  .metric-strip article:nth-child(-n + 2) { border-bottom: 1px solid var(--line); }
  .device-filters { grid-template-columns: 1fr; }
  .filter-actions { justify-content: stretch; }
  .filter-actions button { flex: 1; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 5px; }
  .date-fields { grid-template-columns: 1fr; }
  .date-separator { display: none; }
  .range-switch { width: 100%; }
  .range-switch button { flex: 1; padding-inline: 4px; }
  .record-query-button { width: 100%; }
  .export-action { align-items: stretch; }
  .export-action .download-button { width: 100%; }
  .dialog-actions button { flex: 1; }
  .config-summary,
  .wifi-config-fields { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .login-card { padding: 26px 22px; }
  .topbar h1 { font-size: 22px; }
  .topbar { gap: 10px; flex-wrap: wrap; }
  .auto-refresh-copy { font-size: 11px; }
  .icon-command { min-width: 64px; padding-inline: 12px; }
  .metric-strip article { padding: 16px; }
  .metric-strip strong { font-size: 24px; }
}
