﻿/* Huninn Regular — global display/body face */
@font-face {
  font-family: "Huninn";
  src: url("https://www.aiixi.cc/fonts/Huninn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
/* IG Chat Analyzer — private conversation archive */

:root {
  --bg: #f7f4ee;
  --surface: #fdfbf7;
  --surface-raised: #f0ece4;
  --ink: #1f1b16;
  --muted: #625c53;
  --line: #e3ddd2;
  --rose: #a44753;
  --rose-soft: #f2e4e3;
  --peri: #625d55;
  --peri-soft: #efebe4;
  --ok: #625c53;
  --warn: #a44753;
  --chart-rgb: 164, 71, 83;
  --radius: 16px;
  --shadow: none;
  --font: "Huninn", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--surface-raised);
  padding: 2px 8px;
  border-radius: 4px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  color: var(--rose);
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
}
.brand h1 { margin: 0; font-size: 18px; font-weight: 500; }
.brand-sub { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

.top-actions { display: flex; align-items: center; gap: 8px; }
.tz-toggle {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
}
.tz-toggle select {
  border: 0; background: transparent; color: var(--ink);
  font-family: inherit; font-size: 13px; font-weight: 500;
  outline: none;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color 160ms cubic-bezier(0.22, 1, 0.36, 1), background-color 160ms cubic-bezier(0.22, 1, 0.36, 1), border-color 160ms cubic-bezier(0.22, 1, 0.36, 1);
}
.btn:hover { background: var(--surface-raised); }
.btn-primary {
  background: var(--rose);
  border-color: var(--rose);
  color: #fff;
}
.btn-primary:hover { background: #893b46; border-color: #893b46; }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn:focus-visible,
.tab:focus-visible,
.chip:focus-visible,
.lightbox-close:focus-visible {
  outline: 2px solid var(--rose);
  outline-offset: 2px;
}

.drop-zone {
  width: calc(100% - 48px);
  max-width: 1440px;
  margin: 16px auto 24px;
  min-height: max(360px, calc(100vh - 160px));
  border: 1px dashed var(--line);
  border-radius: 16px;
  background: var(--surface);
  display: grid;
  place-items: center;
  transition: border-color 160ms cubic-bezier(0.22, 1, 0.36, 1), background-color 160ms cubic-bezier(0.22, 1, 0.36, 1);
}
.drop-zone.dragover {
  border-color: var(--rose);
  background: var(--rose-soft);
}
.drop-inner { text-align: center; padding: 32px; }
.drop-icon {
  width: 48px; height: 48px; margin: 0 auto 16px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 24px; color: var(--rose);
  background: var(--rose-soft);
  font-weight: 400;
}
.drop-inner h2 { margin: 0 0 12px; font-size: 20px; font-weight: 500; }
.drop-inner p { margin: 8px 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.hint { color: var(--muted); }

.status-bar {
  max-width: 1440px;
  margin: 16px auto 0;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.status-bar strong { font-size: 14px; }
.status-actions { display: flex; gap: 8px; }

.layout {
  max-width: 1440px;
  margin: 16px auto 48px;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.rail { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 80px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.card h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}
.card-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; margin-bottom: 12px;
}
.card-head h3 { margin: 0; font-size: 15px; color: var(--ink); }

input[type="search"],
input[type="date"],
select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  font-size: 14px;
  outline: none;
}
input[type="search"]:focus,
input[type="date"]:focus {
  border-color: var(--rose);
  outline: 2px solid rgba(var(--chart-rgb), 0.3);
  outline-offset: 1px;
}

.row { display: grid; gap: 8px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: color 160ms cubic-bezier(0.22, 1, 0.36, 1), background-color 160ms cubic-bezier(0.22, 1, 0.36, 1), border-color 160ms cubic-bezier(0.22, 1, 0.36, 1);
}
.chip.active {
  background: var(--rose-soft);
  border-color: var(--line);
  color: var(--rose);
}
.chip[data-speaker="a"].active { background: var(--rose-soft); border-color: var(--line); color: var(--rose); }
.chip[data-speaker="b"].active { background: var(--peri-soft); border-color: var(--line); color: var(--peri); }

.stat-mini {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat-mini div {
  background: var(--surface-raised);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-mini strong {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.main { min-width: 0; }
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  width: fit-content;
}
.tab {
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
  cursor: pointer;
  transition: color 160ms cubic-bezier(0.22, 1, 0.36, 1), background-color 160ms cubic-bezier(0.22, 1, 0.36, 1);
}
.tab.active {
  background: var(--surface-raised);
  color: var(--ink);
}

.panel { display: block; }

.stats-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.stats-toolbar strong { font-size: 15px; font-weight: 500; }
.stats-toolbar .muted { margin-left: 8px; }
.stats-toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.chat-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  min-height: 32px;
}

.chat-stream {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  min-height: 420px;
  max-height: 70vh;
  overflow: auto;
}

.date-sep {
  text-align: center;
  margin: 16px 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.date-sep:first-child { margin-top: 0; }

.msg-group {
  display: flex;
  flex-direction: column;
  margin: 12px 0;
  gap: 8px;
}
.msg-group.me {
  align-items: flex-end;
}
.msg-group.them {
  align-items: flex-start;
}
.msg-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: min(72%, 560px);
}
.msg-group.me .msg-stack {
  align-items: flex-end;
}
.msg-group.them .msg-stack {
  align-items: flex-start;
}
.msg-group .bubble {
  max-width: 100%;
  margin: 0;
}
.bubble-follow {
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}
.msg-meta {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  padding: 0 4px;
}
.msg-row {
  display: flex;
  margin: 8px 0;
  gap: 8px;
}
.msg-row.me { justify-content: flex-end; }
.msg-row.them { justify-content: flex-start; }

.bubble {
  max-width: min(72%, 560px);
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
}

.msg-row.me .bubble,
.msg-group.me .bubble {
  background: var(--rose-soft);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-right-radius: 6px;
}

.msg-row.them .bubble,
.msg-group.them .bubble {
  background: var(--surface-raised);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

/* Light / transparent surfaces must never keep white text */
.bubble.meta {
  background: var(--surface) !important;
  color: var(--muted) !important;
  border: 1px dashed var(--line) !important;
  font-size: 12px;
}

.bubble.sticker {
  background: transparent !important;
  color: var(--ink) !important;
  border: 0 !important;
  box-shadow: none !important;
  padding: 4px 8px;
  opacity: 1;
}

.bubble.image,
.bubble.video {
  padding: 8px;
  background: var(--surface) !important;
  color: var(--ink) !important;
  border: 1px solid var(--line) !important;
}

.bubble.image img {
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  display: block;
  object-fit: contain;
  background: var(--surface-raised);
  cursor: zoom-in;
}

.bubble a {
  color: var(--rose);
  text-decoration: underline;
}

.msg-row.me .bubble a,
.msg-group.me .bubble a {
  color: var(--rose);
}

.bubble.sticker a,
.bubble.image a,
.bubble.video a,
.bubble.meta a {
  color: var(--rose) !important;
}

/* Placeholder text inside bubbles */
.msg-row.me .bubble .muted,
.msg-group.me .bubble .muted {
  color: var(--muted);
}

.bubble.sticker .muted,
.bubble.image .muted,
.bubble.video .muted,
.bubble.meta .muted {
  color: var(--muted) !important;
}

.msg-time {
  display: block;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.msg-row.me .bubble .msg-time,
.msg-group.me .bubble .msg-time {
  border-top-color: var(--line);
  color: var(--muted);
}

.bubble.sticker .msg-time,
.bubble.image .msg-time,
.bubble.video .msg-time,
.bubble.meta .msg-time {
  border-top-color: var(--line) !important;
  color: var(--muted) !important;
}

/* Search highlight: always dark text on yellow */
.hl {
  background: #e8cf8d;
  color: #1f1b16 !important;
  border-radius: 4px;
  padding: 0 2px;
}

.msg-row.me .bubble .hl,
.msg-group.me .bubble .hl {
  background: #e8cf8d;
  color: #1f1b16 !important;
}

.chat-footer {
  display: flex;
  justify-content: center;
  padding: 16px 0 4px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.kpi .label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}
.kpi .value {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.kpi .sub { margin-top: 4px; font-size: 12px; color: var(--muted); }
.kpi.accent-rose .value { color: var(--rose); }
.kpi.accent-peri .value,
.kpi.accent-ok .value { color: var(--ink); }

.chart-card { margin-bottom: 16px; }
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 180px;
  padding-top: 12px;
}
.bar-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  gap: 8px;
}
.bar {
  width: 100%;
  border-radius: 6px 6px 2px 2px;
  background: var(--surface-raised);
  min-height: 2px;
  transition: background-color 160ms cubic-bezier(0.22, 1, 0.36, 1);
  position: relative;
}
.bar:hover { background: var(--peri-soft); }
.bar.peak { background: var(--rose); }
.bar-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.bar-val {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .rail { position: static; }
  .two-col { grid-template-columns: 1fr; }
}

#hourClock {
  width: 100%;
  max-width: 360px;
  height: auto;
  display: block;
  margin: 0 auto;
}
.legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}
.legend i {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 4px;
  margin-right: 8px;
}
.legend .legend-activity { background: var(--rose); }
.legend .legend-low { background: var(--surface-raised); }

.sender-chart { display: flex; flex-direction: column; gap: 12px; }
.sender-row .top {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin-bottom: 8px;
}
.progress {
  height: 8px;
  background: var(--surface-raised);
  border-radius: 4px;
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
}
.progress > span.a { background: var(--rose); }
.progress > span.b { background: #8d877d; }

.type-breakdown {
  margin-top: 16px;
  display: grid;
  gap: 8px;
}
.type-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}
.type-row strong { color: var(--ink); font-family: var(--mono); }

.peak-list { display: grid; gap: 8px; }
.peak-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-raised);
  font-size: 14px;
}
.peak-item strong { font-family: var(--mono); }
.peak-item .tag {
  color: var(--rose);
  font-size: 12px;
  font-weight: 500;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  font-size: 14px;
}

.media-fallback {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--surface-raised);
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 13px;
  max-width: 260px;
}
.media-fallback strong {
  color: var(--ink);
  font-size: 14px;
}
.media-fallback span {
  word-break: break-all;
  font-family: var(--mono);
  font-size: 12px;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(24, 22, 20, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lightbox.hidden { display: none !important; }
.lightbox img {
  max-width: min(92vw, 1100px);
  max-height: 88vh;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.28);
  cursor: zoom-out;
  background: #161513;
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 24px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.lightbox-close:hover {
  background: rgba(255,255,255,0.22);
}
.zoomable {
  cursor: zoom-in;
}



/* Dark theme */
body[data-theme="dark"] {
  --bg: #181715;
  --surface: #211f1b;
  --surface-raised: #2a2722;
  --ink: #eee9df;
  --muted: #aaa398;
  --line: #3b3730;
  --rose: #d78a91;
  --rose-soft: #3b292c;
  --peri-soft: #302d27;
  --chart-rgb: 215, 138, 145;
}
body[data-theme="dark"] .btn-primary { color: #1f1b16; }
body[data-theme="dark"] .btn-primary:hover { background: #e5a0a5; border-color: #e5a0a5; }
body[data-theme="dark"] .drop-zone {
  background: var(--surface);
  border-color: var(--line);
}
body[data-theme="dark"] code {
  background: var(--surface-raised);
}
body[data-theme="dark"] input[type="search"],
body[data-theme="dark"] input[type="date"],
body[data-theme="dark"] select {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
body[data-theme="dark"] .chip {
  background: var(--surface);
  color: var(--muted);
  border-color: var(--line);
}
body[data-theme="dark"] .chip.active,
body[data-theme="dark"] .chip[data-speaker="a"].active {
  background: var(--rose-soft);
  color: var(--rose);
  border-color: var(--line);
}
body[data-theme="dark"] .chip[data-speaker="b"].active {
  background: var(--peri-soft);
  color: var(--ink);
  border-color: var(--line);
}
body[data-theme="dark"] .bubble {
  background: var(--surface-raised);
  color: var(--ink);
  border-color: var(--line);
}
body[data-theme="dark"] .msg-row.me .bubble,
body[data-theme="dark"] .msg-group.me .bubble {
  background: var(--rose-soft);
  color: var(--ink);
  border-color: var(--line);
}
body[data-theme="dark"] .msg-row.them .bubble,
body[data-theme="dark"] .msg-group.them .bubble {
  background: var(--surface-raised);
  color: var(--ink);
  border-color: var(--line);
}
body[data-theme="dark"] .bubble.meta {
  background: var(--surface-raised) !important;
  color: var(--muted) !important;
}
body[data-theme="dark"] .bubble.image,
body[data-theme="dark"] .bubble.video {
  background: var(--surface-raised) !important;
  color: var(--ink) !important;
  border-color: var(--line) !important;
}
body[data-theme="dark"] .stat-mini div,
body[data-theme="dark"] .peak-item,
body[data-theme="dark"] .media-fallback,
body[data-theme="dark"] .type-row {
  background: var(--surface-raised);
  border-color: var(--line);
  color: var(--ink);
}
body[data-theme="dark"] .tabs {
  background: var(--surface);
}
body[data-theme="dark"] .tab.active {
  background: var(--surface-raised);
  color: var(--ink);
}
body[data-theme="dark"] .chat-stream {
  background: var(--surface);
}
body[data-theme="dark"] .progress { background: var(--surface-raised); }
body[data-theme="dark"] .lightbox {
  background: rgba(0, 0, 0, 0.92);
}

/* Keyword mini timeline in rail */
.mini-timeline {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}
.mini-timeline .mini-row {
  display: grid;
  grid-template-columns: 64px 1fr 36px;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}
.mini-timeline .mini-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-raised);
  overflow: hidden;
}
body[data-theme="dark"] .mini-timeline .mini-bar {
  background: var(--surface-raised);
}
.mini-timeline .mini-bar > span {
  display: block;
  height: 100%;
  background: var(--rose);
  border-radius: inherit;
}

/* Rhythm cards */
.rhythm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.rhythm-card {
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
body[data-theme="dark"] .rhythm-card { background: var(--surface-raised); }
.rhythm-card .label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}
.rhythm-card .value {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.rhythm-card .sub {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted);
}

/* Infinite scroll / virtualized groups */
.msg-group {
  content-visibility: auto;
  contain-intrinsic-size: auto 120px;
}
.scroll-sentinel {
  height: 1px;
  width: 100%;
}
.chat-toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* GitHub-style contribution heatmap */
.heatmap-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.heatmap-controls select {
  width: auto;
  min-width: 96px;
  padding: 8px 12px;
}
.heatmap-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 12px;
  max-width: 100%;
}
.heatmap-graph {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 12px);
  grid-auto-columns: 12px;
  gap: 4px;
  width: max-content;
  min-width: 100%;
}
.heatmap-cell {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  background: var(--surface-raised);
}
body[data-theme="dark"] .heatmap-cell {
  background: var(--surface-raised);
}
.heatmap-cell.l1 { background: #e8cacc; }
.heatmap-cell.l2 { background: #d7aeb1; }
.heatmap-cell.l3 { background: #c58288; }
.heatmap-cell.l4 { background: var(--rose); }
body[data-theme="dark"] .heatmap-cell.l1 { background: #50383a; }
body[data-theme="dark"] .heatmap-cell.l2 { background: #694347; }
body[data-theme="dark"] .heatmap-cell.l3 { background: #925b61; }
body[data-theme="dark"] .heatmap-cell.l4 { background: var(--rose); }
.heatmap-cell:hover {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--muted);
}
.heatmap-legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 4px;
}
.heatmap-summary {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}
.heatmap-month-labels {
  display: flex;
  gap: 0;
  width: max-content;
  min-width: 100%;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--muted);
}

/* Weekday x Hour matrix */
.hourmatrix-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}
.hourmatrix {
  display: grid;
  grid-template-columns: 36px repeat(24, minmax(18px, 1fr));
  gap: 4px;
  min-width: 640px;
  font-size: 12px;
  color: var(--muted);
}
.hourmatrix .hm-label {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 4px;
  white-space: nowrap;
}
.hourmatrix .hm-cell {
  aspect-ratio: 1;
  min-height: 20px;
  border-radius: 4px;
  background: var(--surface-raised);
}
body[data-theme="dark"] .hourmatrix .hm-cell {
  background: var(--surface-raised);
}
.hourmatrix .hm-cell.l1 { background: #e8cacc; }
.hourmatrix .hm-cell.l2 { background: #d7aeb1; }
.hourmatrix .hm-cell.l3 { background: #c58288; }
.hourmatrix .hm-cell.l4 { background: var(--rose); }
body[data-theme="dark"] .hourmatrix .hm-cell.l1 { background: #50383a; }
body[data-theme="dark"] .hourmatrix .hm-cell.l2 { background: #694347; }
body[data-theme="dark"] .hourmatrix .hm-cell.l3 { background: #925b61; }
body[data-theme="dark"] .hourmatrix .hm-cell.l4 { background: var(--rose); }

@media (max-width: 1040px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .top-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .tz-toggle { justify-content: space-between; }
}

/* Mobile layout safety */
@media (max-width: 640px) {
  .topbar {
    padding: 12px 16px;
  }
  .layout {
    margin: 16px auto 40px;
    padding: 0 16px;
    gap: 16px;
  }
  .drop-zone {
    width: calc(100% - 32px);
    min-height: max(320px, calc(100svh - 220px));
    margin: 16px auto 16px;
  }
  .drop-inner {
    padding: 24px 16px;
  }
  .drop-inner p {
    overflow-wrap: anywhere;
  }
  .chat-stream {
    max-height: 65vh;
    padding: 16px;
    border-radius: 16px;
  }
  .msg-stack {
    max-width: 88%;
  }
  .bubble {
    max-width: 100%;
    font-size: 14px;
  }
  .stats-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .stats-toolbar-actions {
    width: 100%;
  }
  .stats-toolbar-actions .btn {
    flex: 1;
  }
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }
  .kpi .value {
    font-size: 20px;
  }
  .bar-chart {
    height: 152px;
  }
  .stats-toolbar .muted {
    margin-left: 0;
  }
  .chat-toolbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }
  .chat-toolbar-actions {
    width: 100%;
  }
  .chat-toolbar-actions .btn {
    flex: 1;
  }
}

@media (max-width: 400px) {
  .top-actions {
    grid-template-columns: 1fr;
  }
  .stats-toolbar-actions {
    flex-direction: column;
  }
  .stats-toolbar-actions .btn {
    width: 100%;
  }
}
