/* Theme tokens scoped to insights/upload pages so they don't leak into
   other pages that extend base.html (login, dashboards, corpus, etc.).
   Task 8 will add body.upload-page; pre-listing it here means no CSS
   edit will be needed then. */
body.insights-page,
body.upload-page {
  --bg-primary: #f5f5f7;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e5e5e7;
  --border: #d1d1d6;
  --text-primary: #1d1d1f;
  --text-secondary: #6b6b70;
  --text-tertiary: #9a9a9f;
  --accent: #0071e3;
  --success: #34c759;
  --warning: #ff9f0a;
  --error: #ff3b30;
}
@media (prefers-color-scheme: dark) {
  body.insights-page,
  body.upload-page {
    --bg-primary: #1d1d1f;
    --bg-secondary: #2d2d2f;
    --bg-tertiary: #3d3d3f;
    --border: #424245;
    --text-primary: #f5f5f7;
    --text-secondary: #a0a0a4;
    --text-tertiary: #636366;
    --accent: #0a84ff;
  }
}

/* Eight-slot month palette. Match _month_slot() output range. */
[data-month-slot="0"] { --month-color: hsl(220, 55%, 55%); }
[data-month-slot="1"] { --month-color: hsl(170, 45%, 48%); }
[data-month-slot="2"] { --month-color: hsl(120, 35%, 50%); }
[data-month-slot="3"] { --month-color: hsl( 40, 65%, 55%); }
[data-month-slot="4"] { --month-color: hsl(  0, 55%, 60%); }
[data-month-slot="5"] { --month-color: hsl(290, 40%, 55%); }
[data-month-slot="6"] { --month-color: hsl(200, 30%, 50%); }
[data-month-slot="7"] { --month-color: hsl( 80, 45%, 50%); }

.insights-wrap {
  max-width: 1056px;
  margin: 0 auto;
  padding: 16px 20px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.5;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
}
.page-head-left { display: flex; align-items: baseline; gap: 10px; }
.page-head-left h1 { font-size: 16px; margin: 0; }
.page-head-meta { font-size: 11px; color: var(--text-secondary); }

.month-legend {
  display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 11px; color: var(--text-secondary);
  margin-bottom: 12px;
}
.month-legend-item { display: inline-flex; align-items: center; gap: 4px; }
.month-swatch {
  display: inline-block;
  width: 4px; height: 12px;
  background: var(--month-color);
  border-radius: 1px;
}

/* List view — 2 columns of day blocks on desktop, multicol auto-balance. */
.view { display: none; }
.insights-wrap[data-view="list"] .view-list { display: block; }
.insights-wrap[data-view="grid"] .view-grid { display: grid; }

.view-list { column-count: 2; column-gap: 16px; }
@media (max-width: 720px) { .view-list { column-count: 1; } }

.day-block {
  break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 16px;
  display: inline-block;
  width: 100%;
}
.day-head {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
  margin: 0 0 6px 8px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px 10px 18px;
  margin-bottom: 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  text-decoration: none;
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.row:hover { border-color: var(--accent); }
.row::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--month-color);
}

.row-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border-radius: 3px;
  font-size: 11px; font-weight: 600;
  flex: 0 0 22px;
}
.row.row-rec .row-icon {
  background: hsl(220, 55%, 25%);
  color: hsl(220, 55%, 85%);
}
.row-title {
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-meta {
  font-size: 11px;
  color: var(--text-tertiary);
  flex: 0 0 auto;
  white-space: nowrap;
}
.row-status {
  font-size: 11px;
  color: var(--text-tertiary);
  flex: 0 0 70px;
  text-align: right;
}
.row-status-done { color: var(--success); }
.row-status-processing { color: var(--warning); }
.row-status-failed { color: var(--error); }

/* Grid view — fixed 4/3/2-col breakpoints. */
.view-grid {
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
@media (max-width: 999px) {
  .view-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 719px) {
  .view-grid { grid-template-columns: repeat(2, 1fr); }
}

.tile {
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  text-decoration: none;
  padding: 12px 12px 10px 16px;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
}
.tile:hover { border-color: var(--accent); }
.tile::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--month-color);
}
.tile.tile-rec .row-icon {
  background: hsl(220, 55%, 25%);
  color: hsl(220, 55%, 85%);
}
.tile-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px;
}
.tile-title {
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-all;
}
.tile-foot {
  margin-top: auto;
  font-size: 11px;
  color: var(--text-tertiary);
  display: flex;
  justify-content: space-between;
}

.view-toggle {
  display: inline-flex;
  background: var(--bg-tertiary);
  border-radius: 4px;
  padding: 2px;
}
.view-toggle-btn {
  background: transparent;
  border: none;
  padding: 4px 10px;
  border-radius: 3px;
  font: inherit;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.view-toggle-btn[aria-pressed="true"] {
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.view-icon {
  font-family: ui-monospace, monospace;
  font-size: 13px;
}

.topnav {
  display: flex;
  gap: 20px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  font-size: 13px;
}
.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
}
.nav-link.active {
  color: var(--text-primary);
  font-weight: 600;
}
.nav-user {
  margin-left: auto;
  color: var(--text-tertiary);
  font-size: 12px;
}
