/* App shell: tokens, sidebar, header, chat panel, mobile tab bar, toasts.
   Component classes (.btn, .chip, .card, .menu, .page-head) are in
   components.css and build on the tokens defined here. */
:root {
  /* Surfaces: near-white canvas, white cards, one delineator (a faint border) */
  --canvas: #f7f7f6;
  --surface: #f1f2f1;
  --surface-card: #ffffff;
  --surface-tint: #edf3ef;
  --surface-highlight: #cfe3d6;
  /* One accent, three jobs: primary action, active nav, success */
  --accent: #1f7a4d;
  --accent-hover: #186540;
  --accent-soft: rgba(31, 122, 77, 0.10);
  --green-deep: var(--accent);
  /* Text: neutral, high contrast. --anchor stays as an alias for headings. */
  --text: #16201b;
  --text-soft: #5b6660;
  --text-faint: #8a948f;
  --text-inverse: #ffffff;
  --anchor: var(--text);
  /* Semantic colours, used sparingly and never as outline buttons */
  --danger: #b42318;
  --danger-hover: #912018;
  --danger-soft: rgba(180, 35, 24, 0.08);
  --warning: #b45309;
  --warning-soft: rgba(180, 83, 9, 0.10);
  --info: #1d4ed8;
  --info-soft: rgba(29, 78, 216, 0.08);
  --success: var(--accent);
  --success-soft: var(--accent-soft);
  /* Structure */
  --border: rgba(22, 32, 27, 0.10);
  --border-strong: rgba(22, 32, 27, 0.18);
  --shadow: 0 1px 2px rgba(22, 32, 27, 0.04);
  --shadow-float: 0 8px 24px rgba(22, 32, 27, 0.12), 0 1px 3px rgba(22, 32, 27, 0.08);
  --shadow-drawer: var(--shadow-float);
  --overlay: rgba(22, 32, 27, 0.42);
  --focus-ring: 0 0 0 3px rgba(31, 122, 77, 0.28);
  /* Sender avatars: eight fixed tint pairs, picked by hashing the address. */
  --avatar-1-bg: #d7ebdf;
  --avatar-1-fg: #17583a;
  --avatar-2-bg: #dbe7fb;
  --avatar-2-fg: #1e3f8a;
  --avatar-3-bg: #f8e6c8;
  --avatar-3-fg: #7a4306;
  --avatar-4-bg: #f9dcdc;
  --avatar-4-fg: #8a1f1f;
  --avatar-5-bg: #e6defa;
  --avatar-5-fg: #4b2a8f;
  --avatar-6-bg: #d2ece9;
  --avatar-6-fg: #115e59;
  --avatar-7-bg: #e0e4e8;
  --avatar-7-fg: #2f3a45;
  --avatar-8-bg: #fbe0d0;
  --avatar-8-fg: #8a3a10;
  /* Radius scale by role: chips, controls, cards, dialogs */
  --r-1: 6px;
  --r-2: 8px;
  --r-3: 12px;
  --r-4: 16px;
  --radius: var(--r-3);
  --radius-sm: var(--r-2);
  /* Type scale; nothing below 12px */
  --fs-title: 1.625rem;
  --fs-h2: 1.0625rem;
  --fs-body: 0.9375rem;
  --fs-sm: 0.8125rem;
  --fs-xs: 0.75rem;
  /* Control heights */
  --h-sm: 2rem;
  --h-md: 2.25rem;
  --h-lg: 2.5rem;
  --toolbar-control-h: var(--h-sm);
  /* Shell geometry */
  --sidebar-bg: var(--canvas);
  --sidebar-border: var(--border);
  --sidebar-rail: 3.5rem;
  --sidebar-expanded: 15rem;
  --sidebar-w: var(--sidebar-expanded);
  --chatbar-rail: 0rem;
  --chatbar-expanded: 22rem;
  --chatbar-gap: 0rem;
  --mobile-header-h: 3.25rem;
  --tabbar-h: 3.5rem;
  /* Clearance under the tab icons so the iOS home indicator swipe zone doesn't catch taps. */
  --tabbar-inset-b: calc(env(safe-area-inset-bottom, 0px) + 0.6rem);
  --font: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #121614;
    --surface: #1b211e;
    --surface-card: #171d1a;
    --surface-tint: #1f2a24;
    --surface-highlight: #244634;
    --accent: #4fb57f;
    --accent-hover: #67c592;
    --accent-soft: rgba(79, 181, 127, 0.16);
    --text: #e6ebe8;
    --text-soft: #9ba59f;
    --text-faint: #6f7a74;
    --text-inverse: #0f1512;
    --danger: #f28b82;
    --danger-hover: #f5a39c;
    --danger-soft: rgba(242, 139, 130, 0.14);
    --warning: #f0a04b;
    --warning-soft: rgba(240, 160, 75, 0.14);
    --info: #7aa2f7;
    --info-soft: rgba(122, 162, 247, 0.14);
    --border: rgba(230, 235, 232, 0.10);
    --border-strong: rgba(230, 235, 232, 0.20);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.30);
    --shadow-float: 0 8px 24px rgba(0, 0, 0, 0.50), 0 1px 3px rgba(0, 0, 0, 0.40);
    --overlay: rgba(0, 0, 0, 0.55);
    --focus-ring: 0 0 0 3px rgba(79, 181, 127, 0.35);
    --avatar-1-bg: #1f3a2d;
    --avatar-1-fg: #9fd8b6;
    --avatar-2-bg: #1f2e4d;
    --avatar-2-fg: #a9c4f5;
    --avatar-3-bg: #46341a;
    --avatar-3-fg: #f0c98a;
    --avatar-4-bg: #4a2323;
    --avatar-4-fg: #f4b4b0;
    --avatar-5-bg: #35295a;
    --avatar-5-fg: #cdbff5;
    --avatar-6-bg: #1a3b39;
    --avatar-6-fg: #96d6cf;
    --avatar-7-bg: #2c333a;
    --avatar-7-fg: #c3cbd3;
    --avatar-8-bg: #4a2c1a;
    --avatar-8-fg: #f2bf9f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --canvas: #121614;
  --surface: #1b211e;
  --surface-card: #171d1a;
  --surface-tint: #1f2a24;
  --surface-highlight: #244634;
  --accent: #4fb57f;
  --accent-hover: #67c592;
  --accent-soft: rgba(79, 181, 127, 0.16);
  --text: #e6ebe8;
  --text-soft: #9ba59f;
  --text-faint: #6f7a74;
  --text-inverse: #0f1512;
  --danger: #f28b82;
  --danger-hover: #f5a39c;
  --danger-soft: rgba(242, 139, 130, 0.14);
  --warning: #f0a04b;
  --warning-soft: rgba(240, 160, 75, 0.14);
  --info: #7aa2f7;
  --info-soft: rgba(122, 162, 247, 0.14);
  --border: rgba(230, 235, 232, 0.10);
  --border-strong: rgba(230, 235, 232, 0.20);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.30);
  --shadow-float: 0 8px 24px rgba(0, 0, 0, 0.50), 0 1px 3px rgba(0, 0, 0, 0.40);
  --overlay: rgba(0, 0, 0, 0.55);
  --focus-ring: 0 0 0 3px rgba(79, 181, 127, 0.35);
  --avatar-1-bg: #1f3a2d;
  --avatar-1-fg: #9fd8b6;
  --avatar-2-bg: #1f2e4d;
  --avatar-2-fg: #a9c4f5;
  --avatar-3-bg: #46341a;
  --avatar-3-fg: #f0c98a;
  --avatar-4-bg: #4a2323;
  --avatar-4-fg: #f4b4b0;
  --avatar-5-bg: #35295a;
  --avatar-5-fg: #cdbff5;
  --avatar-6-bg: #1a3b39;
  --avatar-6-fg: #96d6cf;
  --avatar-7-bg: #2c333a;
  --avatar-7-fg: #c3cbd3;
  --avatar-8-bg: #4a2c1a;
  --avatar-8-fg: #f2bf9f;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}
body.nav-open,
body.chat-open {
  overflow: hidden;
}
@media (min-width: 721px) {
  body.chat-open {
    overflow: auto;
  }
}
.mobile-header,
.pwa-nav-controls,
.nav-backdrop,
.chat-backdrop,
.tabbar {
  display: none;
}
.app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Desktop sidebar: persistent and labelled; collapses to a rail on request
   (html.sidebar-collapsed, remembered per browser). */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 40;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  overflow: hidden;
  transition: width 0.2s ease;
}
html.sidebar-collapsed {
  --sidebar-w: var(--sidebar-rail);
}
.sidebar-inner {
  width: var(--sidebar-expanded);
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0.85rem 0.6rem 0.85rem;
}
html.sidebar-collapsed .sidebar-inner {
  width: var(--sidebar-rail);
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}
.sidebar-icon {
  flex-shrink: 0;
  width: 1.2rem;
  height: 1.2rem;
  color: var(--text-soft);
  display: block;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.sidebar a.active .sidebar-icon {
  color: var(--accent);
}
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  margin-bottom: 1rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.03em;
  color: var(--text);
  text-decoration: none;
  padding: 0.4rem 0.5rem;
  border-radius: var(--r-2);
}
.brand .sidebar-icon {
  color: var(--accent);
  width: 1.4rem;
  height: 1.4rem;
}
.brand:hover {
  background: var(--surface-tint);
}
.brand-text {
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-collapse {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 0;
  border-radius: var(--r-1);
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-collapse:hover {
  background: var(--surface-tint);
  color: var(--text);
}
.sidebar-collapse svg {
  width: 1rem;
  height: 1rem;
  transition: transform 0.2s ease;
}
html.sidebar-collapsed .sidebar-collapse svg {
  transform: rotate(180deg);
}
html.sidebar-collapsed .sidebar-top {
  flex-direction: column;
  gap: 0.35rem;
}
html.sidebar-collapsed .brand {
  padding: 0.35rem;
}
html.sidebar-collapsed .brand-text,
html.sidebar-collapsed .nav-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.nav {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.nav-group {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
/* Every separator in the sidebar (between groups, and the hairlines inside
   a group) leaves the same room above and below its line. */
.nav-group + .nav-group {
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
}
.nav a,
.logout-form button {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0 0.5rem;
  min-height: 2.25rem;
  position: relative;
  border-radius: var(--r-2);
  border: 1px solid transparent;
  background: transparent;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-soft);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav a:hover,
.logout-form button:hover {
  background: var(--surface-tint);
  color: var(--text);
}
.nav a:hover .sidebar-icon,
.logout-form button:hover .sidebar-icon {
  color: var(--text);
}
.nav a.active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}
.nav a:focus-visible,
.logout-form button:focus-visible,
.sidebar-collapse:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
/* Kept for the group boundary the tests expect; spacing now comes from
   .nav-group gap, so this only adds a hairline. */
.nav a.nav-divider-after {
  margin-bottom: 0.9rem;
}
.nav a.nav-divider-after::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.5rem;
  border-bottom: 1px solid var(--border);
  pointer-events: none;
}
.nav-label {
  display: block;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
}
.nav-icon-slot {
  width: 1.5rem;
  height: 1.5rem;
  flex: 0 0 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.nav-icon-slot .sidebar-icon {
  margin: 0;
}
.sidebar-foot {
  margin-top: auto;
  padding-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.logout-form { margin: 0; }
.logout-form .sidebar-icon {
  flex-shrink: 0;
}

/* Main column */
.main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  margin-right: 0;
  padding: 1.5rem 2rem 4rem;
  position: relative;
  transition: margin-left 0.2s ease;
}
/* The header row keeps the toolbar beside the title; banners sit below both,
   so nothing slides under the Add task button any more. */
.main-toolbar-cluster {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}
button.subtle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: var(--h-sm);
  padding: 0 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-2);
  background: var(--surface-card);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
button.subtle:hover {
  background: var(--surface);
}
/* Add task: the one filled primary control in the header. */
.add-manual-task-toggle {
  appearance: none;
  margin: 0;
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 0 0.75rem;
  border: 1px solid transparent;
  border-radius: var(--r-2);
  background: var(--accent);
  color: var(--text-inverse);
  cursor: pointer;
  line-height: 1;
  box-sizing: border-box;
  height: var(--toolbar-control-h);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  text-decoration: none;
  transition: background 0.15s ease;
}
.add-manual-task-toggle:hover {
  background: var(--accent-hover);
  color: var(--text-inverse);
  text-decoration: none;
}
.add-manual-task-toggle:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.add-manual-task-toggle-icon {
  flex-shrink: 0;
  display: block;
}
.add-manual-task-wrap {
  position: relative;
}
.add-manual-task-wrap--split {
  display: inline-flex;
}
.add-manual-task-wrap--split > .add-manual-task-toggle:first-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.add-manual-task-more {
  border-left: 1px solid color-mix(in srgb, var(--text-inverse) 25%, transparent);
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  padding: 0 0.45rem;
}
.add-manual-task-more[aria-expanded="true"] .add-manual-task-toggle-icon {
  transform: rotate(180deg);
}
.quick-add-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 60;
  min-width: 13rem;
  margin: 0;
  padding: 0.3rem;
  display: flex;
  flex-direction: column;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-float);
  animation: mm-pop-in 0.14s ease both;
}
.quick-add-menu[hidden] {
  display: none;
}
.quick-add-menu__item {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  margin: 0;
  padding: 0.5rem 0.65rem;
  border: 0;
  border-radius: var(--r-2);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.quick-add-menu__item:hover,
.quick-add-menu__item:focus-visible {
  background: var(--surface-tint);
  outline: none;
}
.quick-add-menu__item .icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-soft);
}
.mobile-header-toolbar {
  display: none;
}

/* Chat: a floating button opens a panel in the bottom-right corner. */
.chat-fab {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 36;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 2.75rem;
  padding: 0 1rem 0 0.85rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--text-inverse);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  box-shadow: var(--shadow-float);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.chat-fab:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}
.chat-fab:focus-visible {
  outline: none;
  box-shadow: var(--shadow-float), var(--focus-ring);
}
.chat-fab .sidebar-icon {
  color: inherit;
  width: 1.15rem;
  height: 1.15rem;
}
body.chat-open .chat-fab {
  display: none;
}
.chatbar {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 37;
  width: var(--chatbar-expanded);
  max-width: calc(100vw - 3rem);
  height: min(34rem, calc(100vh - 3rem));
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--r-4);
  box-shadow: var(--shadow-float);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px) scale(0.98);
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
}
body.chat-open .chatbar {
  opacity: 1;
  visibility: visible;
  transform: none;
}
.chatbar-expanded-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chatbar-inner {
  width: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0.9rem 1rem 1rem;
  min-width: 0;
}
.chatbar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.chatbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}
.chatbar-brand .sidebar-icon {
  flex-shrink: 0;
  color: var(--accent);
}
.chatbar-brand .brand-text {
  font-weight: 600;
  font-size: var(--fs-body);
  color: var(--text);
}
.chatbar-close-mobile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 0;
  border-radius: var(--r-1);
  background: transparent;
  color: var(--text-soft);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.chatbar-close-mobile:hover {
  background: var(--surface-tint);
  color: var(--text);
}
.chat-history {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0 -0.15rem 0.65rem 0;
  padding-right: 0.25rem;
  font-size: var(--fs-sm);
}
.chat-line {
  margin-bottom: 0.65rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--r-3);
  background: var(--surface);
}
.chat-line-text {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}
.chat-line-meta {
  margin-top: 0.3rem;
  font-size: var(--fs-xs);
  color: var(--text-soft);
}
.chat-outcome--ok { color: var(--accent); font-weight: 500; }
.chat-outcome--err { color: var(--danger); }
.chat-outcome--pending { font-style: italic; }
/* A question's line carries no outcome label: the answer follows it. */
.chat-line--asked .chat-line-meta { display: none; }
.chat-answer {
  margin: -0.35rem 0 0.65rem 1.25rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--r-3);
  background: var(--surface-tint);
  color: var(--text);
}
.chat-answer--failed { background: var(--surface); color: var(--text-soft); }
.chat-answer-text {
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-answer-sources {
  margin: 0.45rem 0 0;
  font-size: var(--fs-xs);
  color: var(--text-soft);
}
.chat-answer-sources summary {
  cursor: pointer;
  width: fit-content;
}
.chat-answer-sources summary:hover { color: var(--accent); }
.chat-answer-sources ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
.chat-answer-sources li {
  margin-top: 0.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-answer-sources a { color: var(--text-soft); }
.chat-answer-sources a:hover { color: var(--accent); }
.chat-answer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}
.chat-answer-actions button {
  max-width: 100%;
  min-height: 1.75rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-2);
  background: var(--surface-card);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-xs);
  text-align: left;
  cursor: pointer;
}
.chat-answer-actions .chat-answer-task {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}
.chat-answer-actions button:hover { background: var(--surface-highlight); }
.chat-answer-actions button:disabled { opacity: 0.55; cursor: default; }
.chat-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: auto;
}
.chat-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 4rem;
  max-height: 10rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-2);
  font: inherit;
  font-size: var(--fs-sm);
  background: var(--surface-card);
  color: var(--text);
}
.chat-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
.chat-send {
  align-self: flex-end;
  height: var(--h-sm);
  padding: 0 1rem;
  border-radius: var(--r-2);
  border: 0;
  background: var(--accent);
  color: var(--text-inverse);
  font: inherit;
  font-weight: 600;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.chat-send:hover {
  background: var(--accent-hover);
}
.chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .main, .chatbar, .chat-fab, .quick-add-menu { transition: none; animation: none; }
}

/* Toasts and inline alerts */
.toast-region {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 170;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  /* Size to the message: left: 50% alone would cap it at half the screen. */
  width: max-content;
  max-width: min(24rem, calc(100vw - 2rem));
  pointer-events: none;
}
.toast-region .toast {
  pointer-events: auto;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.65rem 0.8rem;
  border-radius: var(--r-3);
  border: 1px solid var(--border);
  background: var(--surface-card);
  box-shadow: var(--shadow-float);
  font-size: var(--fs-sm);
  line-height: 1.45;
  color: var(--text);
  outline: none;
  animation: mm-pop-in 0.2s ease both;
}
.toast:focus-visible {
  box-shadow: var(--shadow-float), var(--focus-ring);
}
.toast--success {
  border-color: color-mix(in srgb, var(--success) 35%, var(--border));
}
.toast--success::before,
.toast--info::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  margin-top: 0.4rem;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}
.toast--info::before {
  background: var(--info);
}
.toast__msg {
  flex: 1;
  min-width: 0;
}
.toast__undo-form {
  flex-shrink: 0;
  margin: -0.2rem 0;
}
.toast__undo {
  padding: 0.2rem 0.55rem;
  border: none;
  border-radius: var(--r-1);
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.toast__undo:hover {
  background: var(--surface-tint);
}
.toast__undo:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
@media (pointer: coarse) {
  .toast__undo {
    min-height: 2.75rem;
    padding-inline: 0.75rem;
  }
}
.toast__close,
.alerts__close {
  flex-shrink: 0;
  margin: -0.15rem -0.1rem -0.15rem 0;
  padding: 0.1rem 0.35rem;
  border: none;
  border-radius: var(--r-1);
  background: transparent;
  color: var(--text-soft);
  font: inherit;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}
.toast__close:hover,
.alerts__close:hover {
  color: var(--text);
  background: var(--surface-tint);
}
.toast--leaving {
  opacity: 0;
  transition: opacity 0.22s ease;
}
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  .toast--leaving { transition: none; }
}
.alerts {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}
.alerts__item,
.global-ingest-alert,
.push-prompt {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  margin: 0 0 0.5rem;
  border-radius: var(--r-3);
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.45;
}
.alerts__item:last-child {
  margin-bottom: 0;
}
.alerts__item--error,
.global-ingest-alert {
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
  background: var(--danger-soft);
}
.alerts__item--warning {
  border-color: color-mix(in srgb, var(--warning) 40%, var(--border));
  background: var(--warning-soft);
}
.alerts__text {
  flex: 1;
  min-width: 0;
}
.global-ingest-alert {
  margin-bottom: 1rem;
}
.global-ingest-alert a {
  color: var(--text);
  font-weight: 600;
}
.push-prompt {
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
  background: var(--accent-soft);
}
.push-prompt[hidden] {
  display: none;
}
.push-prompt__text {
  flex: 1 1 14rem;
  min-width: 0;
}
.push-prompt__actions {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}
.push-prompt__enable {
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  height: var(--h-sm);
  padding: 0 0.9rem;
  border-radius: var(--r-2);
  border: 0;
  background: var(--accent);
  color: var(--text-inverse);
  cursor: pointer;
}
.push-prompt__enable:hover {
  background: var(--accent-hover);
}
a.push-prompt__enable {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.push-prompt [hidden] {
  display: none;
}
.push-prompt__dismiss {
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
  height: var(--h-sm);
  padding: 0 0.75rem;
  border-radius: var(--r-2);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
}
.push-prompt__dismiss:hover {
  color: var(--text);
  background: var(--surface-tint);
}

/* Phone: header with the wordmark and Add task, a bottom tab bar, the
   sidebar as a drawer, and chat as a bottom sheet. */
@media (max-width: 720px) {
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    min-height: var(--mobile-header-h);
    padding: 0.5rem 0.9rem;
    padding-top: max(0.5rem, env(safe-area-inset-top));
    padding-left: max(0.9rem, env(safe-area-inset-left));
    padding-right: max(0.9rem, env(safe-area-inset-right));
    background: var(--canvas);
    border-bottom: 1px solid var(--border);
  }
  .toast-region {
    top: calc(var(--mobile-header-h) + env(safe-area-inset-top, 0px) + 1rem);
  }
  .mobile-header-lead {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
  }
  body.is-standalone .pwa-nav-controls {
    display: flex;
    align-items: center;
    gap: 0;
    flex-shrink: 0;
  }
  /* The installed app adds back/forward/refresh, so the wordmark text yields
     to keep the toolbar from colliding with them. */
  body.is-standalone .mobile-header-title > span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .pwa-nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.85rem;
    height: 2rem;
    padding: 0;
    border: 0;
    border-radius: var(--r-1);
    background: transparent;
    color: var(--text-soft);
    cursor: pointer;
  }
  .pwa-nav-btn:hover {
    background: var(--surface-tint);
    color: var(--text);
  }
  .pwa-nav-btn svg {
    width: 1.1rem;
    height: 1.1rem;
  }
  .mobile-header-title {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.03em;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
  }
  .mobile-header-title .sidebar-icon {
    color: var(--accent);
    width: 1.35rem;
    height: 1.35rem;
  }
  .mobile-header-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.45rem;
    /* Takes whatever the wordmark and the installed app's nav buttons leave,
       so the container queries below can drop labels when that runs short. */
    flex: 1 1 auto;
    min-width: 0;
    container: mobile-toolbar / inline-size;
  }
  .mobile-header-toolbar .add-manual-task-toggle {
    white-space: nowrap;
  }
  .mobile-header-toolbar .quick-add-menu {
    right: 0;
    left: auto;
  }
  @container mobile-toolbar (max-width: 7rem) {
    .add-manual-task-toggle > span {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip: rect(0 0 0 0);
      white-space: nowrap;
    }
  }
  .nav-backdrop,
  .chat-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 150;
    background: var(--overlay);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.22s ease, visibility 0.22s ease;
  }
  .chat-backdrop {
    z-index: 154;
  }
  body.nav-open .nav-backdrop,
  body.chat-open .chat-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }
  .sidebar {
    z-index: 160;
    top: 0;
    bottom: 0;
    width: min(17.5rem, 86vw);
    max-width: 100%;
    height: auto;
    border-right: 1px solid var(--sidebar-border);
    box-shadow: var(--shadow-float);
    transform: translateX(-100%);
    transition: transform 0.24s ease;
  }
  html.sidebar-collapsed .sidebar {
    width: min(17.5rem, 86vw);
  }
  body.nav-open .sidebar {
    transform: translateX(0);
  }
  .sidebar-inner,
  html.sidebar-collapsed .sidebar-inner {
    width: 100%;
    min-height: 100%;
    padding: max(1rem, env(safe-area-inset-top)) 0.75rem max(1rem, env(safe-area-inset-bottom));
  }
  html.sidebar-collapsed .brand-text,
  html.sidebar-collapsed .nav-label {
    position: static;
    width: auto;
    height: auto;
    clip: auto;
    overflow: hidden;
  }
  .sidebar-collapse {
    display: none;
  }
  .main {
    margin-left: 0;
    margin-right: 0;
    padding-top: calc(var(--mobile-header-h) + max(0.75rem, env(safe-area-inset-top)) + 0.5rem);
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: calc(var(--tabbar-h) + var(--tabbar-inset-b) + 1.5rem);
  }
  .page-head .main-toolbar-cluster {
    display: none;
  }
  .chat-fab {
    display: none;
  }
  .chatbar {
    z-index: 160;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: min(80vh, 36rem);
    max-height: min(80dvh, 36rem);
    border-radius: var(--r-4) var(--r-4) 0 0;
    border-bottom: 0;
    opacity: 1;
    visibility: hidden;
    transform: translateY(100%);
    transition: transform 0.24s ease, visibility 0.24s ease;
  }
  body.chat-open .chatbar {
    visibility: visible;
    transform: translateY(0);
  }
  .chatbar-inner {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    min-height: 12rem;
  }
  .tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 140;
    height: calc(var(--tabbar-h) + var(--tabbar-inset-b));
    padding: 0 max(0.25rem, env(safe-area-inset-left)) var(--tabbar-inset-b) max(0.25rem, env(safe-area-inset-right));
    margin: 0;
    background: var(--surface-card);
    border-top: 1px solid var(--border);
  }
  .tabbar__item {
    appearance: none;
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    margin: 0;
    padding: 0.35rem 0.25rem;
    border: 0;
    background: transparent;
    color: var(--text-soft);
    font: inherit;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    text-decoration: none;
    cursor: pointer;
  }
  .tabbar__item .sidebar-icon {
    width: 1.35rem;
    height: 1.35rem;
    color: inherit;
  }
  .tabbar__item.active {
    color: var(--accent);
  }
  .tabbar__item:focus-visible {
    outline: none;
    box-shadow: inset var(--focus-ring);
    border-radius: var(--r-2);
  }
  /* iOS Safari zooms the page when focused inputs are below 16px. */
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]),
  textarea,
  select {
    font-size: 1rem !important;
  }
}

/* Task priority: two semantic colours for the urgent levels, neutral for the
   rest. The signal-bars icon carries the full scale. */
.task-priority-level-1 { color: var(--text-faint); }
.task-priority-level-2 { color: var(--text-soft); }
.task-priority-level-3 { color: var(--text); }
.task-priority-level-4 { color: var(--warning); }
.task-priority-level-5 { color: var(--danger); }

/* Icon buttons (dashboard detail, task list, recurring list, etc.) */
.icon-button {
  appearance: none;
  background: transparent;
  border: none;
  padding: 0.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  cursor: pointer;
  opacity: 0.7;
  border-radius: var(--r-1);
  flex-shrink: 0;
  transition: opacity 120ms ease, background-color 120ms ease, color 120ms ease;
}
.icon-button svg {
  width: 1rem;
  height: 1rem;
}
.icon-button:hover:not(:disabled),
.icon-button:focus-visible:not(:disabled) {
  opacity: 1;
  color: var(--text);
  background: var(--surface-tint);
}
.icon-button--done:hover:not(:disabled),
.icon-button--done:focus-visible:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent);
}
.icon-button--danger:hover:not(:disabled),
.icon-button--danger:focus-visible:not(:disabled) {
  background: var(--danger-soft);
  color: var(--danger);
}
.icon-button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.task-list-row-actions .icon-button,
.recurring-actions .icon-button {
  line-height: 0;
}

/* Project completion bar */
.proj-progress {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}
.proj-progress-track {
  display: block;
  width: 5rem;
  height: 0.35rem;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in srgb, var(--text) 12%, transparent);
}
.proj-progress-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 160ms ease;
}
.proj-progress-count {
  font-size: var(--fs-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-soft);
  white-space: nowrap;
}

.card-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0 0 0.8rem;
}
.card-heading-row h2 {
  margin: 0;
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}
.creation-trail-help-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0.2rem;
  border-radius: var(--r-1);
  color: var(--text-soft);
  opacity: 0.7;
  text-decoration: none;
  transition: opacity 120ms ease, background-color 120ms ease, color 120ms ease;
}
.creation-trail-help-link svg {
  width: 1rem;
  height: 1rem;
}
.creation-trail-help-link:hover,
.creation-trail-help-link:focus-visible {
  opacity: 1;
  color: var(--text);
  background: var(--surface-tint);
}
