/* ===== Theme Variables ===== */
:root {
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --bg-nav: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --radius: 10px;

  --badge-not_started-bg: #f3f4f6;
  --badge-not_started-fg: #6b7280;
  --badge-in_progress-bg: #dbeafe;
  --badge-in_progress-fg: #1d4ed8;
  --badge-blocked-bg: #fee2e2;
  --badge-blocked-fg: #dc2626;
  --badge-done-bg: #dcfce7;
  --badge-done-fg: #16a34a;
  --badge-cancelled-bg: #f3f4f6;
  --badge-cancelled-fg: #9ca3af;
  --badge-active-bg: #dcfce7;
  --badge-active-fg: #16a34a;
  --badge-inactive-bg: #f3f4f6;
  --badge-inactive-fg: #9ca3af;
  --badge-kind-enabler-bg: #ede9fe;
  --badge-kind-enabler-fg: #6d28d9;
  --badge-kind-result-bg: #fef3c7;
  --badge-kind-result-fg: #b45309;
  --progress-bg: #e5e7eb;
  --progress-fg: var(--primary);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111827;
    --bg-card: #1f2937;
    --bg-nav: #1f2937;
    --text: #f9fafb;
    --text-muted: #9ca3af;
    --border: #374151;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);

    --badge-not_started-bg: #374151;
    --badge-not_started-fg: #9ca3af;
    --badge-in_progress-bg: #1e3a5f;
    --badge-in_progress-fg: #93c5fd;
    --badge-blocked-bg: #450a0a;
    --badge-blocked-fg: #fca5a5;
    --badge-done-bg: #052e16;
    --badge-done-fg: #86efac;
    --badge-cancelled-bg: #1f2937;
    --badge-cancelled-fg: #6b7280;
    --badge-active-bg: #052e16;
    --badge-active-fg: #86efac;
    --badge-inactive-bg: #1f2937;
    --badge-inactive-fg: #6b7280;
    --badge-kind-enabler-bg: #2e1065;
    --badge-kind-enabler-fg: #c4b5fd;
    --badge-kind-result-bg: #451a03;
    --badge-kind-result-fg: #fcd34d;
    --progress-bg: #374151;
  }
}

[data-theme="dark"] {
  --bg: #111827;
  --bg-card: #1f2937;
  --bg-nav: #1f2937;
  --text: #f9fafb;
  --text-muted: #9ca3af;
  --border: #374151;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);

  --badge-not_started-bg: #374151;
  --badge-not_started-fg: #9ca3af;
  --badge-in_progress-bg: #1e3a5f;
  --badge-in_progress-fg: #93c5fd;
  --badge-blocked-bg: #450a0a;
  --badge-blocked-fg: #fca5a5;
  --badge-done-bg: #052e16;
  --badge-done-fg: #86efac;
  --badge-cancelled-bg: #1f2937;
  --badge-cancelled-fg: #6b7280;
  --badge-active-bg: #052e16;
  --badge-active-fg: #86efac;
  --badge-inactive-bg: #1f2937;
  --badge-inactive-fg: #6b7280;
  --badge-kind-enabler-bg: #2e1065;
  --badge-kind-enabler-fg: #c4b5fd;
  --badge-kind-result-bg: #451a03;
  --badge-kind-result-fg: #fcd34d;
  --progress-bg: #374151;
}

[data-theme="light"] {
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --bg-nav: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);

  --badge-not_started-bg: #f3f4f6;
  --badge-not_started-fg: #6b7280;
  --badge-in_progress-bg: #dbeafe;
  --badge-in_progress-fg: #1d4ed8;
  --badge-blocked-bg: #fee2e2;
  --badge-blocked-fg: #dc2626;
  --badge-done-bg: #dcfce7;
  --badge-done-fg: #16a34a;
  --badge-cancelled-bg: #f3f4f6;
  --badge-cancelled-fg: #9ca3af;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}
a { color: var(--primary); }
p { margin: 0 0 0.75rem; }

/* ===== Navbar ===== */
.navbar {
  background: var(--bg-nav);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.navbar .brand {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary);
  text-decoration: none;
  letter-spacing: -0.5px;
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.nav-link {
  color: var(--text);
  text-decoration: none;
  padding: 0.4rem 0.65rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  background: none;
  cursor: pointer;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}
.nav-link:hover { background: var(--bg); }

/* ===== Container ===== */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* ===== Page Header ===== */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
}
.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0.2rem 0 0;
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
}
.card-title a {
  color: var(--text);
  text-decoration: none;
}
.card-title a:hover { color: var(--primary); text-decoration: underline; }

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 0.2em 0.7em;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.4;
}
.badge-not_started  { background: var(--badge-not_started-bg); color: var(--badge-not_started-fg); }
.badge-in_progress  { background: var(--badge-in_progress-bg); color: var(--badge-in_progress-fg); }
.badge-blocked      { background: var(--badge-blocked-bg);     color: var(--badge-blocked-fg); }
.badge-done         { background: var(--badge-done-bg);        color: var(--badge-done-fg); }
.badge-cancelled    { background: var(--badge-cancelled-bg);   color: var(--badge-cancelled-fg); }
.badge-active       { background: var(--badge-active-bg);      color: var(--badge-active-fg); }
.badge-inactive     { background: var(--badge-inactive-bg);    color: var(--badge-inactive-fg); }
.badge-kind-enabler { background: var(--badge-kind-enabler-bg); color: var(--badge-kind-enabler-fg); }
.badge-kind-result  { background: var(--badge-kind-result-bg);  color: var(--badge-kind-result-fg); }
.badge-direction    { background: var(--badge-not_started-bg); color: var(--badge-not_started-fg); }
.badge-nba {
  background: var(--primary);
  color: white;
  font-size: 0.65rem;
  padding: 0.15em 0.6em;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  min-height: 44px;
  line-height: 1;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { opacity: 0.75; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); }
.btn-outline-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1.25rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  min-height: 44px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn-outline-danger:hover {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger);
}
.btn-sm {
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  min-height: 36px;
  border-radius: 6px;
}
.btn-xs {
  padding: 0.15rem 0.5rem;
  font-size: 0.72rem;
  min-height: 26px;
  border-radius: 5px;
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* ===== Forms ===== */
.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.form-group { margin-bottom: 1.25rem; }
label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="tel"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg-card);
  min-height: 44px;
  transition: border-color 0.15s, outline 0.15s;
  -webkit-appearance: auto;
}
textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; -webkit-appearance: none; font-family: inherit; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 0;
  border-color: var(--primary);
}
.form-check {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
}
.form-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: unset;
  cursor: pointer;
}
.form-check label { margin: 0; font-weight: 500; cursor: pointer; }
.errorlist {
  list-style: none;
  padding: 0;
  margin: 0.3rem 0 0;
  color: var(--danger);
  font-size: 0.85rem;
}
.form-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

/* ===== Alerts / Messages ===== */
.messages { margin-bottom: 1rem; }
.alert {
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}
.alert-success { background: var(--badge-done-bg); color: var(--badge-done-fg); }
.alert-error, .alert-warning { background: var(--badge-blocked-bg); color: var(--badge-blocked-fg); }
.alert-info { background: var(--badge-in_progress-bg); color: var(--badge-in_progress-fg); }

/* ===== Meta info row ===== */
.meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.4rem;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state p { margin-bottom: 1.25rem; font-size: 1rem; }

/* ===== Filter bar ===== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.filter-btn {
  padding: 0.3rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}
.filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.filter-select {
  width: auto;
  min-height: 32px;
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  border-radius: 6px;
}

/* ===== Login page ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow);
}
.login-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  margin: 0 0 0.25rem;
  text-align: center;
}
.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.75rem;
}

/* ===== Progress bar ===== */
.progress-bar {
  height: 8px;
  border-radius: 100px;
  background: var(--progress-bg);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 100px;
  background: var(--progress-fg);
  transition: width 0.3s ease;
}

/* ===== Hamburger ===== */
.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text);
  min-height: 44px;
  padding: 0 0.5rem;
  line-height: 1;
}

/* ===== Back link ===== */
.back-link {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}
.back-link:hover { color: var(--primary); }

/* ===== Notes ===== */
.notes {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
  white-space: pre-wrap;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .hamburger { display: flex; align-items: center; }

  .nav-links {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    background: var(--bg-nav);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 0.5rem;
    gap: 0.25rem;
    z-index: 99;
  }
  .nav-links.nav-open { display: flex; }

  .nav-link { width: 100%; justify-content: flex-start; }
}

@media (max-width: 480px) {
  .page-header { flex-direction: column; }
  .card-header { flex-direction: column; }
  .btn-row { width: 100%; flex-wrap: wrap; }
  .btn-row .btn { flex: 1; min-width: 80px; }
}

/* ===== Conversation list ===== */
.conv-group { margin-bottom: 1.5rem; }
.conv-group:last-child { margin-bottom: 0; }
.conv-group-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 0.6rem 0.25rem;
}
.conv-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.95rem 1.15rem;
  margin-bottom: 0.6rem;
  color: var(--text);
  box-shadow: var(--shadow);
}
.conv-card-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-card-preview {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0 0 0.4rem;
}
.conv-card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== Chat layout ===== */
.chat-main {
  height: calc(100vh - 56px);
  height: calc(100dvh - 56px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

/* Chat header — matches page-header look */
.chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-nav);
  flex-shrink: 0;
}
.chat-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.chat-back:hover { background: var(--bg); color: var(--primary); }
.chat-back svg { width: 20px; height: 20px; }
.chat-header-titles { flex: 1; min-width: 0; }
.chat-header-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  align-items: center;
}
/* Smaller danger button so it lines up with the outline btn-sm */
.chat-header-actions .btn-outline-danger {
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  min-height: 36px;
  border-radius: 6px;
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Empty state — onboarding */
.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 1rem;
  max-width: 520px;
  width: 100%;
}
.chat-empty-title {
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0 0 0.4rem;
}
.chat-empty-sub {
  font-size: 0.9rem;
  margin: 0 0 1.5rem;
}
.chat-empty-prompts {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chat-empty-prompt {
  text-align: left;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.95rem;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  line-height: 1.4;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.chat-empty-prompt:hover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 6%, var(--bg-card));
  color: var(--primary);
}

/* Message rows */
.chat-msg {
  display: flex;
  max-width: 84%;
}
.chat-msg--user {
  align-self: flex-end;
  justify-content: flex-end;
}
.chat-msg--assistant {
  align-self: flex-start;
}
/* Group consecutive same-role bubbles tighter */
.chat-msg--user + .chat-msg--user,
.chat-msg--assistant + .chat-msg--assistant {
  margin-top: -0.4rem;
}
/* Soften inner corners on grouped bubbles */
.chat-msg--user + .chat-msg--user .chat-bubble--user {
  border-top-right-radius: 4px;
}
.chat-msg--assistant + .chat-msg--assistant .chat-bubble--assistant {
  border-top-left-radius: 4px;
}
/* Hide timestamps on all but last in a group */
.chat-msg--user + .chat-msg--user .chat-timestamp,
.chat-msg--assistant + .chat-msg--assistant .chat-timestamp {
  display: none;
}
/* Re-show timestamp on the final bubble in the group (not followed by same role) */
.chat-msg--user:has(+ :not(.chat-msg--user)) .chat-timestamp,
.chat-msg--user:last-child .chat-timestamp,
.chat-msg--assistant:has(+ :not(.chat-msg--assistant)) .chat-timestamp,
.chat-msg--assistant:last-child .chat-timestamp {
  display: block;
}
/* Also soften the bottom corner on non-last user bubbles in a group */
.chat-msg--user:has(+ .chat-msg--user) .chat-bubble--user {
  border-bottom-right-radius: 4px;
}
.chat-msg--assistant:has(+ .chat-msg--assistant) .chat-bubble--assistant {
  border-bottom-left-radius: 4px;
}

/* Hover timestamps */
.chat-msg-wrap {
  display: flex;
  flex-direction: column;
}
.chat-msg-wrap--user { align-items: flex-end; }
.chat-msg-wrap--assistant { align-items: flex-start; }
.chat-timestamp {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  padding: 0 0.4rem;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
  user-select: none;
}
.chat-msg:hover .chat-timestamp { opacity: 1; }

/* Bubbles */
.chat-bubble {
  padding: 0.7rem 1rem;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.chat-bubble--user {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.chat-bubble--assistant {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}

/* Markdown inside assistant bubble */
.chat-bubble--assistant > :first-child { margin-top: 0; }
.chat-bubble--assistant > :last-child { margin-bottom: 0; }
.chat-bubble--assistant p { margin: 0 0 0.6rem; }
.chat-bubble--assistant h1,
.chat-bubble--assistant h2,
.chat-bubble--assistant h3 {
  margin: 0.85rem 0 0.4rem;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}
.chat-bubble--assistant ul,
.chat-bubble--assistant ol {
  margin: 0.4rem 0 0.6rem 1.2rem;
  padding: 0;
}
.chat-bubble--assistant li { margin-bottom: 0.2rem; }
.chat-bubble--assistant code {
  background: color-mix(in srgb, var(--primary) 10%, var(--bg));
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-size: 0.88em;
  font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, monospace;
}
.chat-bubble--assistant pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.875rem 1rem;
  overflow-x: auto;
  margin: 0.5rem 0;
}
.chat-bubble--assistant pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85em;
}
.chat-bubble--assistant strong { font-weight: 700; }
.chat-bubble--assistant em { font-style: italic; }

/* Tool indicators — collapsible details element */
/* Compact tool-call chips — dim and unobtrusive */
.chat-tool-strip {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-width: 100%;
  margin: -0.2rem 0;
}
.chat-tool {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.72rem;
  color: var(--text-muted);
  max-width: 100%;
  overflow: hidden;
}
.chat-tool[open] {
  border-radius: 10px;
  background: var(--bg-card);
}
.chat-tool-header {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.65rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  min-height: 22px;
}
.chat-tool-header::-webkit-details-marker { display: none; }
.chat-tool-header::marker { content: ''; }
.chat-tool-header:hover { color: var(--text); }
.chat-tool-name {
  font-weight: 500;
  color: inherit;
  font-family: ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace;
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}
.chat-tool-status {
  font-size: 0.68rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
  opacity: 0.75;
}
.chat-tool-status--ok { color: var(--badge-done-fg); }
.chat-tool-status--err { color: var(--danger); }
.chat-tool-body {
  padding: 0.55rem 0.75rem 0.7rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
  max-width: 560px;
}
.chat-tool-body pre {
  margin: 0;
  font-family: ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace;
  font-size: 0.74rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  max-height: 240px;
  overflow: auto;
}

/* Approval card — shown when a write tool is pending human decision */
.chat-approval {
  align-self: stretch;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
  background: color-mix(in srgb, var(--danger) 6%, var(--bg-card));
  border-radius: 12px;
  padding: 0.9rem 1rem 0.85rem;
  box-shadow: var(--shadow);
  max-width: 640px;
}
.chat-approval-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--danger);
  font-size: 0.92rem;
  margin-bottom: 0.35rem;
}
.chat-approval-header svg { width: 18px; height: 18px; flex-shrink: 0; }
.chat-approval-sub {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.chat-approval-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chat-approval-list li {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
}
.chat-approval-summary {
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text);
}
.chat-approval-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Spinner used inside tool status */
.chat-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid color-mix(in srgb, var(--text-muted) 35%, transparent);
  border-top-color: var(--text-muted);
  border-radius: 50%;
  animation: chat-spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes chat-spin { to { transform: rotate(360deg); } }

/* Typing dots */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 2px 0;
}
.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
  animation: dot-bounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Chat input area */
.chat-input-area {
  flex-shrink: 0;
  padding: 0.75rem 1.25rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-nav);
}
.chat-input-inner {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input-inner:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}
.chat-textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  min-height: 24px;
  max-height: 180px;
  padding: 0.25rem 0;
  outline: none;
  font-family: inherit;
  overflow-y: auto;
}
.chat-textarea:focus,
.chat-textarea:focus-visible {
  outline: none;
  box-shadow: none;
}
.chat-textarea::placeholder { color: var(--text-muted); }
.chat-send-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
}
.chat-send-btn:hover:not(:disabled) { background: var(--primary-hover); }
.chat-send-btn:active:not(:disabled) { transform: scale(0.96); }
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
  margin: 0.45rem 0 0;
}

/* Responsive chat */
@media (max-width: 640px) {
  .chat-messages { padding: 1rem 0.875rem; gap: 0.6rem; }
  .chat-input-area { padding: 0.6rem 0.875rem 0.85rem; }
  .chat-header { padding: 0.7rem 0.875rem; }
  .chat-msg { max-width: 92%; }
  .chat-tool { max-width: 92%; }
  .chat-header-actions .btn,
  .chat-header-actions .btn-outline-danger {
    padding: 0.3rem 0.7rem;
    font-size: 0.78rem;
    min-height: 32px;
  }
  .chat-hint { display: none; }
}

/* ===== Form rows (side-by-side fields) ===== */
.form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.form-row > .form-group { flex: 1 1 180px; min-width: 0; }


/* ===== Categories (Family / Health / Wealth) ===== */
:root {
  --family: #db2777;   /* pink */
  --health: #16a34a;   /* green */
  --wealth: #2563eb;   /* blue */
}
.cat-family { --cat: var(--family); }
.cat-health { --cat: var(--health); }
.cat-wealth { --cat: var(--wealth); }

/* Category badge — colour + always-visible text label (not colour alone) */
.cat-badge {
  display: inline-block;
  padding: 0.15em 0.7em;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--cat, var(--text-muted));
  white-space: nowrap;
}

/* Points-by-category cards on the dashboard / history */
.score-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.score-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--cat, var(--primary));
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
  text-align: left;
}
.score-card-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--cat, var(--text-muted));
}
.score-card-points {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text);
}
.score-card-unit { font-size: 0.7rem; color: var(--text-muted); }

@media (max-width: 480px) {
  .score-card-points { font-size: 1.3rem; }
  .score-card { padding: 0.7rem 0.5rem; }
}

/* History trend charts — stacked-by-category bars */
.trend-charts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}
.trend-chart-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 0.7rem;
}
.chart-track {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
}
.chart-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.chart-bar-area {
  width: 100%;
  height: 140px;
  display: flex;
  align-items: flex-end;
}
.chart-bar {
  width: 100%;
  min-height: 2px;
  display: flex;
  flex-direction: column-reverse;
  border-radius: 4px 4px 0 0;
  overflow: hidden;
  background: var(--border);
}
.chart-seg {
  width: 100%;
  background: var(--cat, var(--text-muted));
}
.chart-col-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.1rem;
  margin-top: 1.1rem;
}
.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.chart-legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--cat, var(--text-muted));
}
@media (max-width: 640px) {
  .trend-charts { grid-template-columns: 1fr; gap: 1.75rem; }
}

/* Effort pips on task cards */
.effort {
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
}

/* Wiki content rendered from markdown */
.wiki-body { font-size: 0.97rem; line-height: 1.65; }
.wiki-body h1, .wiki-body h2, .wiki-body h3 { margin: 1.2rem 0 0.5rem; line-height: 1.3; }
.wiki-body ul, .wiki-body ol { margin: 0.4rem 0 0.8rem 1.3rem; }
.wiki-body code {
  background: color-mix(in srgb, var(--primary) 10%, var(--bg));
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-size: 0.88em;
}
.wiki-body pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.875rem 1rem;
  overflow-x: auto;
}
.wiki-link {
  font-weight: 500;
  text-decoration: none;
  border-bottom: 1px dotted var(--primary);
}
.wiki-link--missing { color: var(--danger); border-bottom-style: dashed; }

/* Simple two-column list rows (tasks, runs, wiki pages) */
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
  box-shadow: var(--shadow);
}
.list-row-main { min-width: 0; flex: 1; }
.list-row-title { font-weight: 600; font-size: 0.97rem; word-break: break-word; }
.list-row-title a { color: var(--text); text-decoration: none; }
.list-row-title a:hover { color: var(--primary); }
.list-row-note {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Stack list rows on mobile. Must come AFTER the base .list-row above so its
   align-items: stretch beats the base align-items: center — media queries add
   no specificity, so source order decides. Otherwise single-line rows shrink-
   wrap and centre while multiline ones fill the width and look left-aligned. */
@media (max-width: 640px) {
  .list-row { flex-direction: column; align-items: stretch; }
  .list-row .btn-row { width: 100%; }
  .list-row .btn-row .btn { flex: 1; }
}
