/* ==========================================================================
   Priorities (Focus) — design system
   Tokens lifted verbatim from .planning/SPEC.md §5 / the design file.
   Later sessions build on these classes — do not rename them.
   ========================================================================== */

:root {
  /* Colour */
  --bg: #FAF9F6;
  --surface: #FFFFFF;
  --surface-alt: #FEFDFB;
  --sidebar: #F3F1EA;
  --ink: #1C1B18;
  --ink-2: #3A3730;
  --ink-3: #4B4740;
  --muted: #6B675E;
  --muted-2: #8F8B7E;
  /* Session 09 a11y audit: ~2.3:1 against --bg/--surface — well below AA for
     body text. Every current usage (move-up/down arrows, hint/placeholder
     text, the unchecked task-row checkbox border) is decorative or
     secondary, per the design's own choice — keep it that way; do not use
     this for primary body text. */
  --muted-3: #B0AB9C;
  --faint: #B9B4A5;
  --line: #E4E1D8;
  --line-2: #EDEAE1;
  --hover: #EAE7DE;
  --accent: #3B5BDB;
  --danger: #B3403A;
  --danger-bg: #FBEAEA;
  --danger-line: #F0C7C4;
  --blocked-bg: #F6F2E8;
  --blocked-line: #EBDFC0;
  /* Session 09 a11y audit: the design's #8A6D3B/#A28A54 measured ~4.3:1 and
     ~3.0:1 against --blocked-bg — both below the 4.5:1 AA text threshold at
     the sizes they're actually used at (task-row__title, blocked-meta).
     Darkened within the same golden-brown hue: --blocked-ink now ~6.1:1,
     --blocked-meta ~5.2:1. */
  --blocked-ink: #6E5730;
  --blocked-icon-bg: #EFE2BC;
  --blocked-meta: #7A6238;
  --warn-bg: #FBEFE3;
  --warn-line: #EFDBB8;
  --warn-ink: #A15A1F;
  --ok: #3E8259;
  --sync-conflict: #B45309;
  /* Knowledge-base cards: same bg/line/accent trio shape as --blocked-*
     above (a distinct-state row gets a tinted background here, not a side
     bar — a left accent border reads as a generic templated-AI-UI tell, so
     this follows the app's own existing idiom instead). --kb-accent is a
     distinct hue from --accent (blue, "primary action"), used only as an
     icon stroke, never body text, so no AA contrast requirement. */
  --kb-bg: #F5F2FB;
  --kb-line: #E1D7F2;
  --kb-accent: #6D5BD0;

  /* Type */
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  /* Radii */
  --radius-xs: 6px;
  --radius-sm: 7px;
  --radius-md: 8px;
  --radius-lg: 9px;
  --radius-xl: 10px;
  --radius-2xl: 12px;
  --radius-3xl: 14px;

  /* Layout */
  --sidebar-width: 240px;
  --drawer-width: 480px;
}

/* ---- Reset --------------------------------------------------------------- */

*, *::before, *::after {
  box-sizing: border-box;
}

[x-cloak] {
  display: none !important;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 8px;
}

/* ---- Keyframes (from the design's <helmet>) ------------------------------ */

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ---- Layout ---------------------------------------------------------------- */

.app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.main {
  flex: 1;
  overflow-y: auto;
  position: relative;
}

.main-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 56px 40px 64px 40px;
}

/* ---- Sidebar nav ----------------------------------------------------------- */

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 22px 10px;
}

.sidebar-brand-mark {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  flex-shrink: 0;
}

.sidebar-brand-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  padding: 9px 12px;
  margin-bottom: 2px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
  font-family: inherit;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--hover);
}

.nav-item--active,
.nav-item--active:hover {
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(28, 27, 24, 0.06);
  color: var(--ink);
  font-weight: 600;
}

.nav-item__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: transparent;
  flex-shrink: 0;
}

.nav-item--active .nav-item__dot {
  background: var(--accent);
}

.sidebar-section-label {
  margin-top: 22px;
  padding: 0 10px 8px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--muted-2);
  text-transform: uppercase;
}

.sidebar-groups {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
}

.sidebar-sort {
  display: flex;
  gap: 4px;
  padding: 0 10px 6px 10px;
}

.sidebar-sort__btn {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 11px;
  color: var(--muted-2);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
}

.sidebar-sort__btn:hover {
  background: var(--hover);
  color: var(--ink-3);
}

.sidebar-sort__btn--active {
  background: var(--ink);
  color: #fff;
}

.sidebar-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  cursor: pointer;
  color: var(--ink-3);
  font-size: 13.5px;
  font-family: inherit;
  text-decoration: none;
}

.sidebar-group--current {
  background: var(--hover);
  color: var(--ink);
  font-weight: 600;
}

.sidebar-group__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-group__count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted-2);
}

.sidebar-spacer {
  flex: 1;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  margin-top: 8px;
}

.sidebar-user__avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  object-fit: cover;
}

.sidebar-user__name {
  font-size: 13px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Buttons ----------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-md);
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}

.btn--primary {
  background: var(--ink);
  color: #fff;
}

.btn--ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-3);
}

.btn--danger {
  background: transparent;
  border: 1px solid var(--danger-line);
  color: var(--danger);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Card / task row ---------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-2xl);
  padding: 18px 20px;
}

.task-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: grab;
}

.task-row--blocked {
  background: var(--blocked-bg);
  border-color: var(--blocked-line);
  align-items: flex-start;
}

.task-row--completed {
  background: transparent;
  border-color: var(--line-2);
  opacity: 0.55;
}

.task-row__title {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-row--blocked .task-row__title {
  color: var(--blocked-ink);
  margin-bottom: 4px;
}

.task-row--completed .task-row__title {
  text-decoration: line-through;
  color: var(--muted);
  font-weight: 400;
}

.blocked-icon {
  margin-top: 2px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-xs);
  background: var(--blocked-icon-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.blocked-meta {
  font-size: 12.5px;
  color: var(--blocked-meta);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ---- Knowledge base -------------------------------------------------------
   Cards get a tinted background + small note icon, same shape as
   .task-row--blocked's own bg/line/ink treatment above — not a left accent
   bar (a generic templated-AI-UI tell) — so a list of them reads as
   reference material, not a broken task list. */

.kb-card {
  background: var(--kb-bg);
  border: 1px solid var(--kb-line);
  border-radius: var(--radius-xl);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}

.kb-card__title {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
}

.kb-card__excerpt {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ---- Pills / chips / badges ---------------------------------------------- */

.pill {
  font-size: 11.5px;
  font-weight: 500;
  border-radius: var(--radius-xs);
  padding: 3px 8px;
  background: var(--pill-bg, var(--line-2));
  color: var(--pill-fg, var(--ink-3));
}

.chip {
  background: #fff;
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 6px 13px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
}

.chip--active {
  background: var(--ink);
  color: #fff;
  border-color: transparent;
}

.badge--sync-synced {
  color: var(--ok);
}

.badge--sync-syncing {
  color: var(--muted);
}

.badge--sync-conflict {
  color: var(--sync-conflict);
}

.num {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--faint);
}

/* ---- Fields --------------------------------------------------------------- */

.field {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}

.field:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* ---- Overlays: drawer / modal / toast -------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 27, 24, 0.4);
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: var(--drawer-width);
  max-width: 92vw;
  background: var(--surface-alt);
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.12);
  z-index: 71;
  overflow-y: auto;
  animation: slideIn 0.2s ease;
  padding: 28px 30px 60px 30px;
}

.task-desc {
  overflow-wrap: break-word;
  word-break: break-word;
}

.task-desc pre {
  overflow-x: auto;
  max-width: 100%;
}

.task-desc img,
.task-desc table {
  max-width: 100%;
}

.task-desc table {
  display: block;
  overflow-x: auto;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-3xl);
  max-width: 480px;
  width: 92vw;
  padding: 24px 26px;
  max-height: 86vh;
  overflow-y: auto;
}

/* Session 09 — real bug found live: #modal-shell's own ".overlay" (shared
   class with #drawer-shell/#notifications-shell's backdrop, z-index 70)
   establishes its own stacking context, so ".modal" being a *child* of it
   never actually competed against ".drawer" (z-index 71) the way the flat
   numbers suggest — the drawer's own stacking context (71 > 70) painted
   (and intercepted clicks) OVER the modal whenever both were open at once.
   This is a real, reachable case, not just a test artifact: the sync-
   conflict modal (SPEC.md §5.2) deliberately opens while the edit drawer
   stays visible behind it, so "Keep ours"/"Keep theirs" were unclickable
   the moment a real conflict fired with the edit form open — caught live by
   this session's tests/e2e/test_smoke.py conflict-flow test, a scenario no
   prior HTMX-era test ever drove with a real click. Scoped to #modal-shell
   only (not a blanket ".overlay" bump) so the drawer's own overlay-vs-panel
   relationship, and notifications' identical "drawer" class, stay
   unchanged. */
#modal-shell .overlay {
  z-index: 90;
}

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  animation: toastIn 0.2s ease;
  z-index: 80;
}

/* ---- Empty state ------------------------------------------------------------ */

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

/* ---- Global loading indicator (session 09) --------------------------------
   Driven by htmx:beforeRequest/afterRequest (static/js/app.js) rather than a
   per-template hx-indicator on every request — htmx fires those two events
   for literally every hx-* request in the app (including hx-boosted
   navigation), so one global bar covers every "can be slow" request without
   annotating dozens of templates individually. Not duplicated in Alpine. */

#htmx-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 100%;
  background: var(--accent);
  z-index: 100;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.2s ease, opacity 0.2s ease;
  opacity: 0;
  pointer-events: none;
}

#htmx-progress.htmx-progress--active {
  opacity: 1;
  transform: scaleX(0.7);
}

/* ---- Inline loading spinner (e.g. Attention's progressive repo fetch) ----- */

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 1.5px solid var(--muted-3);
  border-top-color: var(--muted-2);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ---- Responsive (session 09) ----------------------------------------------- */

/* ---- Mobile nav toggle (session 14) ----------------------------------------
   Hidden above the breakpoint; below it the hamburger is the only way to
   reach the sidebar, which becomes an off-canvas panel (see the max-width:
   840px block below). Reuses the shared .overlay backdrop class (drawer/
   modal/notifications) rather than inventing a new one, scoped to its own
   z-index the same way #modal-shell's overlay already is. */
.nav-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 96;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(28, 27, 24, 0.12);
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.nav-toggle span {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--ink-2);
  border-radius: 1px;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.nav-toggle--open span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.nav-toggle--open span:nth-child(2) {
  opacity: 0;
}

.nav-toggle--open span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.nav-overlay {
  z-index: 85;
}

@media (max-width: 840px) {
  .nav-toggle {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: min(280px, 82vw);
    z-index: 86;
    padding-top: 64px;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.14);
  }

  .sidebar--open {
    transform: translateX(0);
  }

  .main-inner {
    padding-top: 72px;
  }
}

@media (max-width: 600px) {
  .drawer {
    width: 100%;
    max-width: 100vw;
  }

  .main-inner {
    padding: 72px 18px 48px 18px;
  }
}
