:root {
  color-scheme: light;
  --bg: #f6f8f3;
  --surface: #ffffff;
  --surface-muted: #eef3ea;
  --text: #1b1f1a;
  --text-muted: #5a6656;
  --border: #d9e3d3;
  --primary: #6f9642;
  --primary-dark: #5a7d34;
  --accent: #c7dd6b;
  --success: #2f8b5a;
  --shadow: 0 18px 50px rgba(31, 44, 28, 0.12);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --font-sans: "Inter", "SF Pro Text", "Segoe UI", system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1310;
  --surface: #171d16;
  --surface-muted: #232c22;
  --text: #f1f6ee;
  --text-muted: #b6c2b0;
  --border: #2b3628;
  --primary: #95b45b;
  --primary-dark: #7f9c49;
  --accent: #d3e57a;
  --success: #4dc08a;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: radial-gradient(circle at top left, rgba(91, 91, 214, 0.15), transparent 55%),
    radial-gradient(circle at bottom right, rgba(255, 153, 102, 0.15), transparent 45%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 20px clamp(16px, 4vw, 44px) 24px;
  gap: 18px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: -999px;
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  border-radius: 999px;
  z-index: 100;
}

.skip-link:focus {
  left: 24px;
  top: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
}

.brand-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.brand-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.ghost-button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, border 0.2s ease;
}

.ghost-button .icon-large {
  font-size: 1.15rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ghost-button:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
}

.chat-shell {
  display: block;
}

.chat-panel {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 68vh;
  padding: 20px;
  gap: 16px;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}


.chat-meta {
  display: flex;
  gap: 8px;
}

.meta-pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 6px;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: min(680px, 100%);
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.bubble {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  line-height: 1.5;
  background: var(--surface-muted);
  color: var(--text);
  white-space: pre-line;
}

.message.user .bubble {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
}

.message.assistant .bubble {
  border: 1px solid var(--border);
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.confidence-pill {
  background: rgba(26, 156, 110, 0.12);
  color: var(--success);
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
}


.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-reply {
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 6px 12px;
  background: var(--surface);
  cursor: pointer;
  transition: border 0.2s ease, transform 0.2s ease;
}

.quick-reply:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.composer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.composer-label-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  position: relative;
}

.composer-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.help-button {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.help-button:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

.tooltip {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 0.75rem;
  color: var(--text);
  box-shadow: var(--shadow);
  display: none;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
  z-index: 2;
}

.help-button:focus-visible + .tooltip,
.help-button:hover + .tooltip,
.help-button:focus + .tooltip {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.composer-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

textarea {
  width: 100%;
  resize: none;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 12px 14px;
  font: inherit;
  background: var(--surface);
  color: var(--text);
  min-height: 52px;
}

textarea:focus,
button:focus-visible,
.quick-reply:focus-visible,
a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.primary-button {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.primary-button:hover {
  transform: translateY(-1px);
}

.composer-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
}

.helper-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.external-link {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  padding: 4px 10px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 10px 24px rgba(31, 44, 28, 0.15);
  white-space: nowrap;
}

.external-link::after {
  content: "↗";
  font-size: 0.85em;
}

.external-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(31, 44, 28, 0.2);
}

.footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer-link {
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  padding: 10px 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 24px rgba(31, 44, 28, 0.15);
}

.footer-meta {
  color: var(--text-muted);
}

.typing-indicator {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1s infinite ease-in-out;
}

.dot:nth-child(2) {
  animation-delay: 0.15s;
}

.dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: scale(0.7);
  }
  40% {
    transform: scale(1);
  }
}

@media (max-width: 1024px) {
  .chat-shell {
    display: block;
  }
}

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .composer-row {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-panel {
    padding: 18px;
  }
}

@media (max-width: 720px) {
  .page {
    padding: 12px 12px 16px;
  }

  .chat-panel {
    gap: 12px;
  }

  .messages {
    padding-right: 0;
  }

  .quick-replies {
    flex-direction: column;
    gap: 6px;
  }

  .quick-reply {
    width: 100%;
    justify-content: flex-start;
  }

  .composer-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .helper-text {
    font-size: 0.7rem;
    line-height: 1.2;
  }
}

@media (max-width: 480px) {
  .chat-panel {
    padding: 16px;
  }

  .composer-row {
    gap: 8px;
  }

  textarea {
    min-height: 48px;
    padding: 10px 12px;
    font-size: 0.95rem;
    line-height: 1.35;
  }

  textarea::placeholder {
    font-size: 0.9rem;
    line-height: 1.35;
  }

  .composer {
    gap: 6px;
  }

  #consent-text {
    opacity: 0.85;
    max-width: 100%;
  }
}

/* ── Dashboard ─────────────────────────────────────────────── */

.dashboard-shell {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  padding: 24px 28px;
}

.panel h2 {
  margin: 0 0 16px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Stats summary cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--surface-muted);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Shared table styles */
.days-table,
.conv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.days-table th,
.conv-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.days-table td,
.conv-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.day-row,
.conv-row {
  cursor: pointer;
  transition: background 0.15s ease;
}

.day-row:hover,
.conv-row:hover {
  background: var(--surface-muted);
}

.day-row.selected,
.conv-row.selected {
  background: rgba(111, 150, 66, 0.12);
}

.day-row.selected td,
.conv-row.selected td {
  color: var(--primary-dark);
  font-weight: 600;
}

.sortable {
  cursor: pointer;
  user-select: none;
}

.sortable:hover {
  color: var(--primary);
}

.sort-arrow {
  font-size: 0.7em;
  margin-left: 2px;
  opacity: 0.6;
}

.day-cell {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.session-id-cell {
  font-family: monospace;
  font-size: 0.85rem;
}

.muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Reduced motion ────────────────────────────────────────── */

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