/* Warm light theme: cream background, terracotta/amber/sage accents. */
:root {
  color-scheme: light;
  --bg: #faf5ee;
  --panel: #fffdf9;
  --panel-hover: #f7efe3;
  --text: #3d3229;
  --muted: #94836f;
  --accent: #c96f4a;      /* terracotta */
  --accent-soft: #f3ded2;
  --amber: #dfa14f;
  --sage: #7d9b76;
  --border: #e9dccb;
  --shadow: 0 1px 3px rgba(96, 64, 32, 0.07), 0 4px 14px rgba(96, 64, 32, 0.05);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: ui-monospace, monospace;
  font-size: 0.92em;
  background: var(--panel-hover);
  padding: 1px 5px;
  border-radius: 4px;
}
code.copy { cursor: pointer; }
code.copy:hover { color: var(--accent); }
.muted { color: var(--muted); }

.topbar {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.7rem 1.4rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.topbar .brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--accent);
  letter-spacing: 0.01em;
}
.topbar nav { display: flex; gap: 1.1rem; }
.topbar nav a {
  color: var(--muted);
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}
.topbar nav a:hover { color: var(--accent); text-decoration: none; }
.topbar nav a.active {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-soft);
}

main { max-width: 1200px; margin: 0 auto; padding: 1.4rem; }

/* Narrow viewports: stack the topbar, shrink gutters. */
@media (max-width: 640px) {
  main { padding: 0.8rem; }
  .topbar {
    flex-wrap: wrap;
    gap: 0.3rem 1rem;
    padding: 0.55rem 0.9rem;
  }
  .topbar nav {
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 0.15rem;
  }
  .filterbar select { flex: 1 1 45%; }
  .stat-card.hero { padding: 1.1rem 1.2rem; }
  .stat-big { font-size: 2.3rem; }
  .stat-breakdown { gap: 0.25rem 1rem; }
  .chart-head { flex-wrap: wrap; }
  .list-head { align-items: flex-start; flex-direction: column; gap: 0.4rem; }
  dl.detail { grid-template-columns: 1fr; gap: 0.25rem; }
  dl.detail dt { margin-top: 0.3rem; }
}

.filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  margin-bottom: 1.3rem;
}
.filterbar .presets { display: flex; gap: 0.25rem; }
.filterbar .presets a {
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  color: var(--muted);
}
.filterbar .presets a:hover { color: var(--accent); text-decoration: none; background: var(--accent-soft); }
.filterbar .presets a.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.filterbar select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.28rem 0.45rem;
}
.filterbar a.chip {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  color: var(--text);
  max-width: 18rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
a.conv { color: var(--muted); font-family: ui-monospace, monospace; font-size: 0.85em; }
a.conv:hover { color: var(--accent); }
.filterbar button, .close {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 0.32rem 0.85rem;
  cursor: pointer;
}

/* Dashboard stat cards */
.hero-row { margin-bottom: 0.9rem; }
.period-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 0.9rem;
}
.stat-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1.1rem 1.3rem;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(96, 64, 32, 0.1), 0 8px 22px rgba(96, 64, 32, 0.08);
}
.stat-card.hero { padding: 1.6rem 1.8rem; }
.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}
.stat-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.badge {
  display: inline-block;
  background: rgba(125, 155, 118, 0.14);
  color: var(--sage);
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.12rem 0.6rem;
  white-space: nowrap;
}
.stat-big {
  font-size: clamp(2.6rem, 6vw, 4rem);
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin-top: 0.5rem;
}
.stat-mid { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 0.35rem; }
.stat-unit { margin-top: 0.05rem; }
.stat-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.4rem;
  margin-top: 0.9rem;
  color: var(--muted);
}
.stat-breakdown b { color: var(--text); font-variant-numeric: tabular-nums; }
.stat-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-top: 0.9rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
}

/* Inline period detail expansion */
.period-detail {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1rem 1.3rem 1.2rem;
  margin-top: 1.1rem;
}
.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.detail-head h2 { margin: 0.2rem 0 0.7rem; }
.close {
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  padding: 0.1rem 0.5rem;
}
.close:hover { color: var(--accent); }
dl.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.8rem;
  margin: 0;
}
dl.detail-grid > div {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
}
dl.detail-grid dt { color: var(--muted); font-size: 0.78rem; }
dl.detail-grid dd {
  margin: 0.15rem 0 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Panels and charts */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 0.9rem 1.1rem 0.7rem;
  margin-bottom: 1.2rem;
}
.panel h3 { margin: 0.1rem 0 0.4rem; font-size: 1rem; color: var(--text); }
.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}
.chart-head h2 { margin: 0.2rem 0; font-size: 1.15rem; }
.chart-head select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.28rem 0.45rem;
}
.chart { background: transparent; }

h2 { font-size: 1.15rem; margin: 1.2rem 0 0.5rem; }

/* Tables (horizontally scrollable on narrow screens) */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-scroll table { min-width: 640px; }
.table-scroll table.rows { min-width: 840px; }
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
th, td { padding: 0.42rem 0.7rem; text-align: right; border-bottom: 1px solid var(--border); }
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg);
}
th:first-child, td:first-child { text-align: left; }
tbody tr:nth-child(even):not(.totals) { background: rgba(233, 220, 203, 0.18); }
tbody tr:hover:not(.totals) { background: var(--panel-hover); }
tr.totals td { font-weight: 700; border-top: 2px solid var(--border); background: var(--accent-soft); }
td { font-variant-numeric: tabular-nums; }

/* Sessions page */
.list-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin: 0.4rem 0 0.9rem;
}
.tabs { display: flex; gap: 0.35rem; }
.tab {
  padding: 0.28rem 0.85rem;
  border-radius: 999px;
  color: var(--muted);
  border: 1px solid transparent;
}
.tab.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.tab:not(.active):hover { color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.sort-toggle { display: flex; gap: 0.5rem; align-items: center; }
.sort-toggle a { color: var(--muted); }
.sort-toggle a.active { color: var(--accent); font-weight: 600; }
.sort-toggle a:hover { text-decoration: none; color: var(--accent); }

.conv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(290px, 100%), 1fr));
  gap: 0.9rem;
}
.conv-card {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 0.9rem 1.1rem;
  color: var(--text);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.conv-card:hover {
  border-color: var(--accent);
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(96, 64, 32, 0.1), 0 8px 22px rgba(96, 64, 32, 0.08);
}
.conv-title { font-weight: 700; font-size: 0.98rem; }
.conv-sub {
  margin-top: 0.1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1.1rem;
  margin-top: 0.6rem;
  color: var(--muted);
  font-size: 0.88rem;
}
.conv-stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.conv-cost { color: var(--amber); font-weight: 600; font-variant-numeric: tabular-nums; }
.conv-time { margin-top: 0.55rem; font-size: 0.8rem; }
.list-count { margin: 0.9rem 0 0; }

.pager { display: flex; justify-content: flex-end; gap: 0.5rem; margin: 0.8rem 0; }
.pager button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.32rem 0.85rem;
  cursor: pointer;
}
.pager button:hover { border-color: var(--accent); color: var(--accent); }

dl.detail {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 0.3rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 1rem;
}
dl.detail dt { color: var(--muted); }
dl.detail dd { margin: 0; font-variant-numeric: tabular-nums; }

footer { text-align: center; padding: 1rem; }
