/* ============================================================
   Design tokens
   ------------------------------------------------------------
   Palette: warm paper background, ink text, a single muted teal
   accent for structure. Category colors are deliberately desaturated
   (this is a tool for understanding, not a dashboard trying to alarm).
   Type: Source Serif 4 for headings (ledger/report feel — this is a
   record, not a SaaS product), Inter for UI text, IBM Plex Mono for
   all numeric data (time, percentages) so figures read as precise
   measurements rather than decoration.
   ============================================================ */
:root {
  --paper: #f7f4ee;
  --paper-raised: #fffdf9;
  --ink: #2a2622;
  --ink-soft: #6b6358;
  --line: #e3ddd0;
  --line-strong: #cfc6b4;
  --accent: #3d6b66;
  --accent-soft: #e4ede9;

  --cat-education: #3d6b66;
  --cat-school: #4f7fa6;
  --cat-research: #8a7a3f;
  --cat-entertainment: #b6603f;
  --cat-gaming: #8b5a8c;
  --cat-social_media: #b04a5a;
  --cat-other: #9a9488;

  --radius: 10px;
  --shadow-soft: 0 1px 2px rgba(42,38,34,0.06), 0 4px 14px rgba(42,38,34,0.04);

  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --font-ui: -apple-system, "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Cascadia Mono", "Consolas", "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------------- Topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-raised);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  font-size: 26px;
  color: var(--accent);
  line-height: 1;
}
.brand-text h1 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}
.brand-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.btn {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: var(--paper-raised);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-ghost { background: transparent; }
.btn-secondary { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn-block { width: 100%; margin-top: 8px; }

/* ---------------- Layout ---------------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 22px 18px;
  background: var(--paper-raised);
}
.sidebar-section { margin-bottom: 28px; }
.sidebar-title {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin: 0 0 8px;
}
.sidebar-hint {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 0 0 10px;
}

.device-list { display: flex; flex-direction: column; gap: 6px; }
.device-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 7px;
  cursor: pointer;
  border: 1px solid transparent;
  text-align: left;
  background: none;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink);
  width: 100%;
}
.device-item:hover { background: var(--accent-soft); }
.device-item.is-selected { background: var(--accent-soft); border-color: var(--accent); }
.device-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.device-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.device-dot.tracked { background: var(--accent); }
.device-dot.untracked { background: var(--line-strong); }
.device-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-edit {
  font-size: 13px; cursor: pointer; color: var(--ink-soft); opacity: 0;
  transition: opacity 0.15s; padding: 0 4px; flex-shrink: 0;
}
.device-item:hover .device-edit { opacity: 1; }
.device-edit:hover { color: var(--accent); }
.device-tag {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--ink-soft);
  flex-shrink: 0;
}
.loading-text, .empty-list-text {
  font-size: 12.5px;
  color: var(--ink-soft);
  padding: 6px 10px;
}

.range-toggle { display: flex; border: 1px solid var(--line-strong); border-radius: 7px; overflow: hidden; }
.range-btn {
  flex: 1;
  padding: 7px 0;
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 500;
  background: var(--paper-raised);
  border: none;
  border-right: 1px solid var(--line-strong);
  cursor: pointer;
  color: var(--ink-soft);
}
.range-btn:last-child { border-right: none; }
.range-btn.is-active { background: var(--accent); color: #fff; }
.range-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.date-picker-row { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.date-picker-select { width: 100%; padding: 7px 10px; font-size: 13px; border-radius: 7px; border: 1px solid var(--line-strong); background: var(--paper-raised); color: var(--ink); cursor: pointer; }

.threshold-input {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 6px 10px;
  background: var(--paper-raised);
}
.threshold-input input {
  border: none;
  background: none;
  font-family: var(--font-mono);
  font-size: 14px;
  width: 100%;
  color: var(--ink);
}
.threshold-input input:focus { outline: none; }
.threshold-input span { color: var(--ink-soft); font-family: var(--font-mono); font-size: 13px; }
.status-text { font-size: 11.5px; color: var(--accent); margin: 6px 2px 0; min-height: 14px; }

/* ---------------- Content ---------------- */
.content { padding: 28px 32px; }

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50vh;
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 16px;
}
.empty-state[hidden] { display: none; }

.device-banner-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.device-banner {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
}
.btn-sm { font-size: 12.5px; padding: 5px 12px; }

.stale-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fef3cd;
  border: 1px solid #d4a827;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 14px;
  font-size: 13.5px;
  color: #664d03;
}
.stale-notice[hidden] { display: none; }

.untracked-notice {
  background: var(--paper-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
}
.untracked-notice h3 { margin: 0 0 8px; font-family: var(--font-display); font-size: 16px; }
.untracked-notice p { margin: 0; color: var(--ink-soft); max-width: 640px; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.stat-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-soft);
  border-left: 3px solid var(--line-strong);
}
.stat-edu { border-left-color: var(--cat-education); }
.stat-nonedu { border-left-color: var(--cat-entertainment); }
.stat-ratio { border-left-color: var(--accent); }
.stat-idle { border-left-color: var(--line-strong); }
.stat-label {
  display: block;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.stat-value {
  display: block;
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 500;
}

.alert-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f6e9e3;
  border: 1px solid #d9a98c;
  color: #7a3a1f;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 13px;
}
.alert-banner[hidden] { display: none; }
.alert-icon { font-size: 16px; }

.panel-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
}
.panel-trend, .panel-top-sites { grid-column: 1; }
.panel-breakdown, .panel-alert-history { grid-column: 2; }

.panel {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-soft);
  margin-bottom: 16px;
}
.panel-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 14px;
}

.chart-wrap { position: relative; width: 100%; }
.chart-wrap-donut { display: flex; justify-content: center; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-soft); }
.legend-swatch { width: 9px; height: 9px; border-radius: 2px; }

.top-sites-list { display: flex; flex-direction: column; gap: 10px; }
.top-site-row { display: flex; align-items: center; gap: 10px; }
.top-site-rank { font-family: var(--font-mono); font-size: 11px; color: var(--ink-soft); width: 18px; flex-shrink: 0; }
.top-site-info { flex: 1; min-width: 0; }
.top-site-domain { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-site-bar-track { height: 5px; background: var(--line); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.top-site-bar-fill { height: 100%; border-radius: 3px; }
.top-site-duration { font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); flex-shrink: 0; width: 64px; text-align: right; }

.alert-history-list { display: flex; flex-direction: column; gap: 10px; }
.alert-history-row {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.alert-history-row:last-child { border-bottom: none; padding-bottom: 0; }
.alert-history-date { color: var(--ink-soft); font-family: var(--font-mono); font-size: 11.5px; }
.alert-history-detail { font-family: var(--font-mono); font-size: 11.5px; }
.empty-panel-text { color: var(--ink-soft); font-size: 12.5px; }

/* ---------------- Timeline ---------------- */
.panel-timeline {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-top: 16px;
}
.panel-timeline[hidden] { display: none; }
.timeline-list { display: flex; flex-direction: column; gap: 0; }
.timeline-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.timeline-row:last-child { border-bottom: none; }
.timeline-time {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-soft);
  flex-shrink: 0;
  width: 110px;
}
.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}
.timeline-detail { flex: 1; min-width: 0; }
.timeline-domain {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.timeline-title {
  font-size: 11.5px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}
.timeline-duration {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  flex-shrink: 0;
  width: 50px;
  text-align: right;
}
.timeline-idle-row {
  color: var(--ink-soft);
  font-style: italic;
}
.timeline-profile {
  font-size: 10px;
  font-family: var(--font-mono);
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 4px;
  vertical-align: middle;
  font-weight: 500;
  font-style: normal;
}
.timeline-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  padding: 12px 0 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.filter-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  white-space: nowrap;
}
.filter-input {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
}
.filter-text { width: 130px; }
.filter-select { width: 120px; cursor: pointer; }
.timeline-summary {
  font-size: 12px;
  color: var(--ink-soft);
  padding-bottom: 10px;
}
@media (max-width: 880px) {
  .timeline-filters { flex-direction: column; align-items: stretch; }
  .filter-group { flex-wrap: wrap; }
}

/* ---------------- Top split: chat + KPIs ---------------- */
.top-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 18px;
}
.kpi-side { display: flex; flex-direction: column; justify-content: flex-start; }
.kpi-side .stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 0;
}

@media (max-width: 880px) {
  .top-split { grid-template-columns: 1fr; }
  .kpi-side .stat-row { grid-template-columns: 1fr; }
}

/* ---------------- Chat panel ---------------- */
.panel-chat { margin-bottom: 0; }
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
  padding: 8px 0;
  margin-bottom: 12px;
}
.chat-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.45;
  word-wrap: break-word;
}
.chat-bubble-parent {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-radius: 12px 4px 12px 12px;
}
.chat-bubble-child {
  align-self: flex-start;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px 12px 12px 12px;
}
.chat-bubble-time {
  font-size: 10px;
  margin-top: 4px;
  font-family: var(--font-mono);
}
.chat-bubble-parent .chat-bubble-time { color: rgba(255,255,255,0.7); }
.chat-bubble-child .chat-bubble-time { color: var(--ink-soft); }
.chat-bubble-sender {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 3px;
}
.chat-bubble-parent .chat-bubble-sender { color: rgba(255,255,255,0.8); }
.chat-bubble-child .chat-bubble-sender { color: var(--ink-soft); }
.chat-delivered {
  font-size: 10px;
  color: rgba(255,255,255,0.6);
  display: inline;
  margin-left: 6px;
}
.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.45;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  resize: none;
  box-sizing: border-box;
}
.chat-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.chat-empty { color: var(--ink-soft); font-size: 13px; text-align: center; padding: 20px 0; }

.device-banner-actions { display: flex; gap: 8px; align-items: center; }

/* ---------------- Footer ---------------- */
.footer {
  padding: 14px 32px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--ink-soft);
}
.footer code {
  font-family: var(--font-mono);
  background: var(--accent-soft);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); }
  .panel-grid { grid-template-columns: 1fr; }
  .panel-trend, .panel-breakdown, .panel-top-sites, .panel-alert-history { grid-column: 1; }
  .stat-row { grid-template-columns: 1fr; }
}
