/* ===== 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; }

/* ===== NBA Section ===== */
.nba-box {
  margin-top: 0.875rem;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  font-size: 0.9rem;
}
.nba-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  margin-bottom: 0.2rem;
}
.nba-name { font-weight: 500; }
.no-nba {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== 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;
}

/* ===== Action list in goal detail ===== */
.action-list { list-style: none; padding: 0; margin: 0; }
.action-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.action-item:last-child { border-bottom: none; }
.action-item.is-nba {
  background: color-mix(in srgb, var(--primary) 6%, var(--bg-card));
}
.action-info { flex: 1; min-width: 0; }
.action-name {
  font-weight: 500;
  font-size: 0.95rem;
  word-break: break-word;
}

/* ===== 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;
}

/* ===== Navbar search ===== */
.nav-search { margin: 0; }
.nav-search-input {
  width: 160px;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg);
  min-height: 32px;
  transition: border-color 0.15s, width 0.2s;
}
.nav-search-input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 0;
  border-color: var(--primary);
  width: 220px;
}

/* ===== 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;
}

/* ===== Tag picker (checkbox multi-select) ===== */
.tag-picker ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tag-picker li { display: contents; }
.tag-picker label {
  display: inline-flex;
  align-items: center;
  padding: 0.25em 0.75em;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.tag-picker label:hover { border-color: var(--primary); color: var(--primary); }
.tag-picker label:has(input:checked) {
  background: color-mix(in srgb, var(--primary) 12%, var(--bg-card));
  border-color: var(--primary);
  color: var(--primary);
}
.tag-picker input[type="checkbox"] { display: none; }

/* ===== Tags ===== */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.tag {
  display: inline-flex;
  align-items: center;
  padding: 0.15em 0.6em;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 500;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}
a.tag:hover { border-color: var(--primary); color: var(--primary); }
.tag-active {
  background: color-mix(in srgb, var(--primary) 12%, var(--bg-card));
  border-color: var(--primary);
  color: var(--primary);
}

/* ===== 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; }

  .nav-search { width: 100%; }
  .nav-search-input,
  .nav-search-input:focus { width: 100%; }
}

@media (max-width: 480px) {
  .page-header { flex-direction: column; }
  .card-header { flex-direction: column; }
  .action-item { 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; }
}

/* ── Calendar ──────────────────────────────────────────────────────────── */

.cal-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.4rem;
  margin: 0 0 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.cal-toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}
.cal-toolbar-btn:hover { background: var(--bg); color: var(--primary); }
.cal-toolbar-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  min-width: 0;
}
.cal-toolbar-label {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.cal-toolbar-today {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
  text-decoration: none;
  padding: 0.2rem 0.55rem;
  border: 1px solid currentColor;
  border-radius: 100px;
  line-height: 1.4;
}
.cal-toolbar-today:hover { background: var(--primary); color: #fff; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.cal-weekday {
  padding: 0.55rem 0.65rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  text-align: right;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.cal-cell {
  min-height: 120px;
  padding: 0.4rem 0.4rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: relative;
}
.cal-cell:nth-child(7n+7) { border-right: none; }
.cal-grid > .cal-cell:nth-last-child(-n+7) { border-bottom: none; }
.cal-cell-weekend { background: color-mix(in srgb, var(--bg) 40%, var(--bg-card)); }
.cal-cell-muted { background: color-mix(in srgb, var(--bg) 70%, var(--bg-card)); }
.cal-cell-muted .cal-cell-date { color: var(--text-muted); opacity: 0.55; }
.cal-cell-muted .cal-chip { opacity: 0.6; }
.cal-cell-head {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-height: 1.6rem;
}
.cal-cell-date {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1;
  padding: 0.3rem 0.45rem;
}
.cal-cell-today .cal-cell-date {
  background: var(--primary);
  color: #fff;
  border-radius: 100px;
  min-width: 1.55rem;
  text-align: center;
}
.cal-actions {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.cal-chip {
  --chip-color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.18rem 0.4rem 0.18rem 0.35rem;
  border-radius: 4px;
  font-size: 0.76rem;
  line-height: 1.35;
  color: var(--text);
  background: transparent;
  text-decoration: none;
  overflow: hidden;
  min-width: 0;
  transition: background 0.12s ease;
}
.cal-chip::before {
  content: "";
  flex: 0 0 auto;
  width: 3px;
  align-self: stretch;
  min-height: 0.95em;
  border-radius: 2px;
  background: var(--chip-color);
}
.cal-chip:hover { background: var(--bg); }
.cal-chip-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-chip-metric {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-chip-not_started { --chip-color: var(--badge-not_started-fg); }
.cal-chip-in_progress { --chip-color: var(--badge-in_progress-fg); }
.cal-chip-blocked     { --chip-color: var(--badge-blocked-fg); }
.cal-chip-done        { --chip-color: var(--badge-done-fg); }
.cal-chip-cancelled   { --chip-color: var(--badge-cancelled-fg); }
.cal-chip-done .cal-chip-name,
.cal-chip-cancelled .cal-chip-name {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* Mobile list view (hidden on desktop) */
.cal-list { display: none; }

@media (max-width: 640px) {
  .cal-grid { display: none; }
  .cal-toolbar { margin-bottom: 0.75rem; }
  .cal-toolbar-label { font-size: 1rem; }
  .cal-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  .cal-list-day {
    display: flex;
    gap: 0.9rem;
    padding: 0.75rem 0.9rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  .cal-list-day-today { border-color: var(--primary); }
  .cal-list-date {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    padding-right: 0.8rem;
    border-right: 1px solid var(--border);
    line-height: 1.1;
  }
  .cal-list-dow {
    font-size: 0.66rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
  }
  .cal-list-daynum {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin-top: 0.1rem;
  }
  .cal-list-day-today .cal-list-daynum { color: var(--primary); }
  .cal-list-actions {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
    justify-content: center;
  }
  .cal-list-actions .cal-chip {
    font-size: 0.88rem;
    padding: 0.35rem 0.5rem 0.35rem 0.45rem;
    flex-wrap: wrap;
    row-gap: 0.1rem;
  }
  .cal-list-actions .cal-chip-name {
    white-space: normal;
    flex: 1 1 auto;
  }
  .cal-list-actions .cal-chip::before {
    width: 3px;
    min-height: 1.4em;
  }
  .cal-list-empty {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
    align-self: center;
  }
}

/* ===== 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; }

/* ===== Rating chips (inline on people list) ===== */
.rating {
  display: inline-block;
  padding: 0.15em 0.55em;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid currentColor;
}
.rating-high   { color: var(--badge-active-fg);    background: var(--badge-active-bg); border-color: transparent; }
.rating-medium { color: var(--badge-in_progress-fg); background: var(--badge-in_progress-bg); border-color: transparent; }
.rating-low    { color: var(--badge-blocked-fg);   background: var(--badge-blocked-bg);   border-color: transparent; }

/* ===== Skill/Will matrix ===== */
.skill-matrix {
  display: flex;
  gap: 0.65rem;
  align-items: stretch;
}
.skill-axis-y {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  align-self: center;
  padding: 0 0.2rem;
}
.skill-grid-wrap {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.skill-axis-x {
  display: grid;
  grid-template-columns: 6rem repeat(3, 1fr);
  background: var(--bg);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.skill-axis-x > span {
  padding: 0.55rem 0.7rem;
  border-right: 1px solid var(--border);
}
.skill-axis-x > span:last-child { border-right: none; }
.skill-axis-x > span:first-child { background: var(--bg-card); }
.skill-row {
  display: grid;
  grid-template-columns: 6rem repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
}
.skill-row:last-child { border-bottom: none; }
.skill-row-label {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.65rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
  background: var(--bg);
}
.skill-cell {
  min-height: 110px;
  padding: 0.55rem 0.7rem 0.7rem;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.skill-cell:last-child { border-right: none; }
.skill-cell-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.skill-cell-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.88rem;
}
.skill-cell-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
}
.skill-cell-list .skill-cell-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tint the strongest quadrants for visual orientation */
.skill-cell-high-high { background: color-mix(in srgb, var(--badge-active-bg) 60%, transparent); }
.skill-cell-low-low   { background: color-mix(in srgb, var(--badge-blocked-bg) 50%, transparent); }

@media (max-width: 720px) {
  .skill-axis-y { display: none; }
  .skill-axis-x { grid-template-columns: 4.5rem repeat(3, 1fr); font-size: 0.62rem; }
  .skill-row { grid-template-columns: 4.5rem repeat(3, 1fr); }
  .skill-row-label { padding: 0.5rem 0.4rem; font-size: 0.68rem; }
  .skill-cell { min-height: 90px; padding: 0.4rem 0.45rem 0.55rem; }
  .skill-cell-label { font-size: 0.64rem; }
  .skill-cell-list { font-size: 0.82rem; }
}

