/* VASTTagTester Web — light theme matching the desktop palette (ui_style.py). */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-sunken: #f8fafc;
  --border: #e1e7ef;
  --border-strong: #cfd8e3;
  --text: #172033;
  --text-body: #27344a;
  --muted: #66748a;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eef5ff;
  --green: #16a34a;
  --red: #dc2626;
  --warn: #b45309;
  --sidebar: #172033;
  --sidebar-hover: #222e44;
  --sidebar-text: #bdc8d8;
  --sidebar-muted: #93a4bd;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(23, 32, 51, 0.05);
  --shadow-md: 0 8px 24px rgba(23, 32, 51, 0.10);
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-body);
  font: 13.5px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  position: sticky; top: 0; align-self: flex-start;
  width: 224px; flex: none; height: 100vh;
  display: flex; flex-direction: column;
  padding: 20px 14px 16px;
  background: var(--sidebar);
  color: var(--sidebar-text);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px 20px; }
.brand-mark {
  width: 36px; height: 36px; flex: none; display: grid; place-items: center;
  border-radius: 10px; background: var(--accent); color: #fff;
  font-weight: 700; font-size: 12px; letter-spacing: 0.02em;
}
.brand-title { color: #fff; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { color: var(--sidebar-muted); font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; }
.nav-item {
  display: block; width: 100%; height: auto; padding: 9px 12px;
  border: 0; border-radius: var(--radius-sm); background: transparent; box-shadow: none;
  color: var(--sidebar-text); font: inherit; font-size: 13px; font-weight: 500;
  text-align: left; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover:not(.active) { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.nav-sep { height: 1px; margin: 10px 6px; background: rgba(147, 164, 189, 0.25); }
.sidebar-foot {
  margin-top: auto; display: flex; align-items: center; gap: 9px;
  padding: 12px 6px 0; color: var(--sidebar-muted); font-size: 12px;
}

.status-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  background: #64748b; box-shadow: 0 0 0 4px rgba(100, 116, 139, 0.22);
}
.status-dot.running { background: #22c55e; box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.25); animation: pulse 1.6s ease-in-out infinite; }
.status-dot.stopping { background: #f59e0b; box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.25); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ---------- content ---------- */
.content { flex: 1; min-width: 0; padding: 28px 32px 48px; }
.page { display: none; flex-direction: column; gap: 18px; max-width: 1180px; }
.page.active { display: flex; }
.page-head { display: flex; flex-direction: column; gap: 3px; }
.page-title { margin: 0; font-size: 25px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.page-sub { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-narrow { max-width: 980px; }
.card h3 { margin: 0; font-size: 14px; font-weight: 650; color: var(--text); }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-grid label > span { font-size: 12px; font-weight: 600; color: #47546b; }
.form-grid .full, .tag-multi { grid-column: 1 / -1; }

input, select, textarea {
  width: 100%; height: 38px; padding: 0 11px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: #fff; color: var(--text-body);
  font: inherit; font-size: 13px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="number"] { font-variant-numeric: tabular-nums; }
input[type="password"] { font-family: var(--mono); letter-spacing: 0.08em; }
input[type="checkbox"] { width: 17px; height: 17px; margin: 2px 0 0; padding: 0; accent-color: var(--accent); cursor: pointer; }
input[type="file"] { display: none; }
textarea {
  height: auto; min-height: 96px; padding: 10px 11px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55; resize: vertical;
}
input:hover, select:hover, textarea:hover { border-color: #b6c2d1; }
input:focus, select:focus, textarea:focus { outline: none; border-color: #93b4f5; box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.13); }
select {
  appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2366748a' d='M6 8.2 1.8 4h8.4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}

.prob-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; }
.prob-row input { text-align: center; }
.inline-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.chip-text { color: var(--muted); font-size: 12.5px; }

/* ---------- collapsible ---------- */
.collapsible { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 4px; }
.collapsible > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 10px; padding: 9px 0;
  font-size: 11px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted);
}
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary::before {
  content: ""; width: 6px; height: 6px; flex: none; margin-left: 3px;
  border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor;
  transform: rotate(-45deg); transition: transform 0.15s;
}
.collapsible[open] > summary::before { transform: rotate(45deg); }
.collapsible > summary:hover { color: var(--text-body); }
.collapsible > summary::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.collapsible > .form-grid { padding: 8px 0 4px; }

/* ---------- buttons ---------- */
button {
  height: 38px; padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff;
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; box-shadow: var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button.ghost { background: #fff; color: var(--text-body); border-color: var(--border-strong); box-shadow: none; }
button.ghost:hover:not(:disabled) { background: var(--accent-soft); border-color: #bcd2f7; color: var(--accent-hover); }
button.danger { background: #fff; color: var(--red); border-color: #f4b5b5; box-shadow: none; }
button.danger:hover:not(:disabled) { background: #fef2f2; border-color: #ef9a9a; }
button:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
button:focus-visible { outline: 3px solid rgba(37, 99, 235, 0.25); outline-offset: 1px; }
.btn-sm { height: 30px; padding: 0 11px; font-size: 12px; }
td button { height: 26px; padding: 0 9px; font-size: 11.5px; }

.row-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.action-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 18px; padding-top: 4px; }

/* ---------- plan ---------- */
.plan {
  margin: 16px 0 0; padding: 11px 14px;
  border: 1px solid #d7e5fb; border-radius: var(--radius-sm);
  background: linear-gradient(180deg, #f6f9ff, #eef5ff);
  color: #28405f; font-size: 12.5px; line-height: 1.6;
  font-variant-numeric: tabular-nums;
}
.plan:empty { display: none; }

/* ---------- metrics ---------- */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 12px; }
.metric {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow-sm);
  border-bottom: 3px solid var(--accent);
}
.metric.m-ok { border-bottom-color: var(--green); }
.metric.m-bad { border-bottom-color: var(--red); }
.metric.m-live { border-bottom-color: #7c3aed; }
.metric.m-cancel { border-bottom-color: #94a3b8; }
.metric.m-rate { border-bottom-color: #0891b2; }
.metric.m-slots { border-bottom-color: #d97706; }
.metric .val { display: block; font-size: 24px; font-weight: 680; letter-spacing: -0.02em; color: var(--text); font-variant-numeric: tabular-nums; }
.metric .val.ok { color: var(--green); }
.metric .val.bad { color: var(--red); }
.metric .label { display: block; margin-top: 2px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-sunken);
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fbfcfe; }
td input:not([type="checkbox"]) { height: 30px; font-size: 12.5px; }
.row-tools { white-space: nowrap; }
.row-tools button + button { margin-left: 4px; }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-sunken); border: 1px solid var(--border);
  font-size: 11px; color: var(--muted);
}
.tag-ok { background: #ecfdf3; border-color: #bbf7d0; color: #15803d; }
.tag-err { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }

/* ---------- log ---------- */
.log {
  height: clamp(280px, 52vh, 640px); overflow: auto;
  padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  font-family: var(--mono); font-size: 11.5px; line-height: 1.65; color: #33415a;
}
.log > div { padding: 1px 0; border-bottom: 1px solid #f1f3f8; word-break: break-word; }
.log > div:last-child { border-bottom: none; }
.log .session { color: #1d4ed8; }
.log .proxy { color: var(--warn); }
.log .done { color: #15803d; font-weight: 600; }
.log .error { color: #b91c1c; font-weight: 600; }
.log .dashboard, .log .slots, .log .state { color: var(--muted); }

/* ---------- devices ---------- */
.device-groups { display: flex; flex-direction: column; gap: 18px; }
.device-group-title { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.device-group-items { display: flex; flex-direction: column; gap: 1px; }
.device-brand { display: flex; align-items: center; gap: 4px; }
.device-brand .chev {
  width: 22px; height: 22px; padding: 0; flex: none;
  border: 1px solid transparent; background: transparent; box-shadow: none;
  color: var(--muted); font-size: 10px; line-height: 1;
}
.device-brand .chev:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent-hover); }
.device-item { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-body); cursor: pointer; }
.device-models { margin: 3px 0 9px 30px; }
.model-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 3px 16px; }
.device-model { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-body); cursor: pointer; }
.device-model.readonly { cursor: default; color: var(--muted); }
.device-model .dot { width: 17px; height: 17px; flex: none; }
.device-model .model-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- toasts ---------- */
#toasts {
  position: fixed; bottom: 18px; right: 18px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.message {
  max-width: 460px; padding: 11px 14px;
  border: 1px solid var(--border); border-left: 3px solid var(--green);
  border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-md);
  font-size: 12.5px; color: var(--text-body); pointer-events: auto;
  animation: toast-in 0.18s ease-out;
}
.message.err { border-left-color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- login overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center;
  background: rgba(23, 32, 51, 0.45);
  backdrop-filter: blur(2px);
}
.login-card {
  width: min(380px, 92vw); padding: 24px;
  display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-md);
}
.login-card h2 { margin: 0; font-size: 17px; font-weight: 680; color: var(--text); }
.login-card p { margin: 0; }
.login-card button { width: 100%; }

/* ---------- misc ---------- */
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 12.5px; }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-sunken); padding: 1px 5px; border-radius: 4px; }
td.message { border-left-width: 0; box-shadow: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cfd8e3; border: 2px solid transparent; background-clip: content-box; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #b6c2d1; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { position: static; width: 100%; height: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-item { width: auto; }
  .nav-sep { display: none; }
  .sidebar-foot { margin-top: 12px; }
  .content { padding: 18px; }
}

/* ---------- schedule ---------- */
.schedule-entry { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 12px; }
.schedule-entry:first-child { border-top: none; margin-top: 0; padding-top: 0; }
.schedule-entry input[type="date"], .schedule-entry input[type="time"] { width: auto; min-width: 132px; }
.schedule-entry table { font-size: 12.5px; }
.schedule-entry td, .schedule-entry th { padding: 6px 10px; }
.schedule-entry .table-wrap { border: none; }

/* ---------- per-slot table ---------- */
.slot-state {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-sunken); color: var(--muted);
}
.slot-state.running { background: #e8f0ff; color: #1d4ed8; }
.slot-state.preflight { background: #fff6e5; color: var(--warn); }
.slot-state.completed { background: #e8f7ee; color: #15803d; }
.slot-state.failed { background: #fdeaea; color: #b91c1c; }
.slot-state.cancelled { background: #eef0f4; color: #475569; }
#slots-table td { font-variant-numeric: tabular-nums; }
