/* ── tokens ───────────────────────────────────────────── */
:root {
  --c-olive:    #3E5E3A;
  --c-red:      #C23B22;
  --c-gold:     #C9A552;
  --c-charcoal: #333333;
  --c-bg:       #F2F2F0;
  --c-ivory:    #FAFAF5;
  --c-sage:     #7A8E72;
  --c-stone:    #DAD8D3;
  --c-card:     #FFFFFF;
  --c-secondary:#F5F5F2;
  --t-tsys:     #C23B22;
  --cf-high:    #639922;
  --cf-mid:     #BA7517;
  --cf-low:     #E24B4A;
  --font: 'Open Sans', sans-serif;
  --r-sm: 4px; --r-md: 8px;
}

/* ── reset ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
body   { font-family: var(--font); background: var(--c-bg); color: var(--c-charcoal); font-size: 13px; line-height: 1.55; }
button { font-family: var(--font); cursor: pointer; }
select { font-family: var(--font); }

/* ── topbar ───────────────────────────────────────────── */
#topbar {
  background: var(--c-charcoal);
  color: var(--c-ivory);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--c-red); flex-shrink: 0;
}
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: -.3px; white-space: nowrap; }
.brand-ai   { color: var(--c-gold); font-style: italic; }
.brand-sep  { color: #555; margin: 0 2px; }
.brand-sub  { font-size: 11px; color: #888; white-space: nowrap; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

#btn-refresh {
  padding: 5px 12px; border-radius: 20px; font-size: 11px; font-weight: 500;
  border: 1px solid #555; background: transparent; color: #aaa;
  transition: background .15s, color .15s, border-color .15s;
  line-height: 1.4; white-space: nowrap;
}
#btn-refresh:hover:not(:disabled) { border-color: var(--c-gold); color: var(--c-gold); }
#btn-refresh:disabled { opacity: .4; cursor: default; }

/* ── loading / error states ─────────────────────────── */
#loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 100px 24px; gap: 14px; color: #aaa; font-size: 13px;
}
.spinner {
  width: 28px; height: 28px; border: 3px solid #ddd;
  border-top-color: var(--c-red); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#load-error {
  text-align: center; padding: 80px 24px;
  color: var(--c-red); font-size: 13px; line-height: 1.8;
}

/* ── main layout ───────────────────────────────────────── */
#main {
  max-width: 1380px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── kpi strip ─────────────────────────────────────────── */
.kpi-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi-card  {
  background: var(--c-card); border-radius: var(--r-md);
  padding: 16px 18px; border: 1px solid var(--c-stone);
}
.kpi-lbl  { font-size: 11px; color: #999; margin-bottom: 6px; }
.kpi-val  { font-size: 24px; font-weight: 500; line-height: 1.15; margin-bottom: 5px; }
.kpi-sub  { font-size: 11px; color: #aaa; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.dot-low  { width: 6px; height: 6px; border-radius: 50%; background: var(--cf-low); flex-shrink: 0; }

/* ── charts row ────────────────────────────────────────── */
.charts-row { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
.chart-panel {
  background: var(--c-card); border-radius: var(--r-md);
  padding: 16px 18px; border: 1px solid var(--c-stone);
}
.chart-title  { font-size: 12px; font-weight: 600; color: #666; margin-bottom: 8px; }
.chart-legend { display: flex; gap: 16px; margin-bottom: 10px; flex-wrap: wrap; }
.leg-item  { display: flex; align-items: center; gap: 5px; font-size: 11px; color: #666; }
.leg-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
#chart-volume { max-height: 210px; }
#chart-donut  { max-height: 200px;  }

/* ── session log ───────────────────────────────────────── */
#session-log {
  background: var(--c-card); border-radius: var(--r-md);
  border: 1px solid var(--c-stone); overflow: hidden;
}
.tbl-controls {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-bottom: 1px solid var(--c-stone); justify-content: flex-end;
}
.tbl-controls label { font-size: 11px; color: #999; }
.tbl-controls select {
  font-size: 12px; padding: 4px 8px; border: 1px solid var(--c-stone);
  border-radius: var(--r-sm); background: white; color: var(--c-charcoal);
}
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 1px solid var(--c-stone); }
th {
  font-size: 11px; font-weight: 600; color: #999; text-align: left;
  padding: 9px 14px; white-space: nowrap;
}
th.ctr { text-align: center; }
td { padding: 10px 14px; font-size: 12px; border-bottom: 1px solid #f0eeec; vertical-align: top; }
.tbl-row { cursor: pointer; transition: background .1s; }
.tbl-row:hover { background: var(--c-secondary); }
.tbl-row:last-child td { border-bottom: none; }

.col-ts { white-space: nowrap; }
.ts-d   { font-size: 12px; }
.ts-t   { font-size: 10px; color: #bbb; }
.col-q  { max-width: 260px; }
.col-a  { max-width: 320px; color: #999; font-size: 11px; }
.col-src{ text-align: center; color: #888; }
.trunc  { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

/* ── badges ────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 10px;
  font-size: 10px; font-weight: 600; color: white; white-space: nowrap;
}
.bh { background: var(--cf-high); }
.bm { background: var(--cf-mid); }
.bl { background: var(--cf-low); }

/* ── pagination ─────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-top: 1px solid var(--c-stone);
  font-size: 11px; color: #aaa;
}
.pg-btns { display: flex; gap: 6px; }
.pg-btn {
  font-size: 11px; padding: 4px 12px; border: 1px solid var(--c-stone);
  border-radius: var(--r-sm); background: white; color: var(--c-charcoal);
  transition: background .1s;
}
.pg-btn:hover:not(:disabled) { background: var(--c-secondary); }
.pg-btn:disabled { opacity: .38; cursor: default; }
.empty-msg td { text-align: center; color: #ccc; padding: 36px; font-size: 12px; }

/* ── modal ─────────────────────────────────────────────── */
#overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 24px;
}
#overlay.hidden { display: none; }
#modal {
  background: white; border-radius: var(--r-md);
  max-width: 620px; width: 100%; max-height: 82vh;
  display: flex; flex-direction: column; position: relative;
  box-shadow: 0 24px 64px rgba(0,0,0,.28);
}
.m-header {
  padding: 14px 44px 14px 16px; border-bottom: 1px solid var(--c-stone);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.m-ts { font-size: 11px; color: #aaa; }
#m-close {
  position: absolute; top: 10px; right: 10px;
  width: 28px; height: 28px; border-radius: 50%; border: none;
  background: #ededeb; font-size: 13px; color: #666;
  display: flex; align-items: center; justify-content: center;
}
#m-close:hover { background: var(--c-stone); }
.m-body {
  padding: 16px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
}
.m-q { font-size: 14px; font-weight: 600; color: var(--c-charcoal); }
.m-a-lbl { font-size: 10px; font-weight: 600; color: #bbb; text-transform: uppercase; letter-spacing: .6px; margin-bottom: 5px; }
.m-a {
  font-size: 12px; color: #666; white-space: pre-wrap; line-height: 1.75;
  max-height: 300px; overflow-y: auto; background: var(--c-secondary);
  padding: 10px 12px; border-radius: var(--r-sm);
}
.m-meta {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 11px; color: #aaa;
  border-top: 1px solid var(--c-stone); padding-top: 10px;
}
.m-session { font-family: monospace; font-size: 10px; color: #ccc; }

/* ── responsive ─────────────────────────────────────────── */
@media (max-width: 960px) {
  .kpi-strip    { grid-template-columns: repeat(2, 1fr); }
  .charts-row   { grid-template-columns: 1fr; }
  .brand-sub, .brand-sep { display: none; }
}
@media (max-width: 520px) {
  #topbar { padding: 0 12px; }
  #main   { padding: 12px; }
}
