/* ---------------------------------------------------------------------
   Sprig — team task inbox
   Cottage-warm ledger: rows are ruled like a garden log, status is a
   staked tag, and the active filter is stitched in with a hand-drawn
   twine underline (see .stitch / --stitch-draw).
--------------------------------------------------------------------- */

:root {
  --bg: #fbf3e2;
  --paper-grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='matrix' values='0 0 0 0 0.2  0 0 0 0 0.14  0 0 0 0 0.08  0 0 0 0.05 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  --surface: #fffcf5;
  --surface-raised: #ffffff;
  --ink: #2e2116;
  --muted: #5b4a38;
  --line: #e6d5b8;
  --line-strong: #d8c19a;
  --accent: #a8542e;
  --accent-hover: #8c4423;
  --accent-ink: #fff8ef;
  --leaf: #3f5c2d;
  --leaf-bg: #dce9c9;
  --leaf-ink: #2c4419;
  --amber-bg: #f6e0a1;
  --amber-ink: #5c4008;
  --rust-bg: #f3d0bd;
  --rust-ink: #7c2e10;
  --neutral-bg: #eee2c7;
  --neutral-ink: #4a3b22;

  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;

  --shadow-panel: 0 24px 60px -20px rgba(46, 33, 22, 0.35);

  --font-display: "Lora", "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: var(--paper-grain);
  background-repeat: repeat;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  margin: 0;
  color: var(--ink);
}

p {
  margin: 0;
}

ul, dl, dd {
  margin: 0;
  padding: 0;
  list-style: none;
}

button {
  font: inherit;
  color: inherit;
}

input, select {
  font: inherit;
  color: inherit;
}

/* ---------- accessibility helpers ---------- */

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  background: var(--ink);
  color: var(--accent-ink);
  padding: 12px 18px;
  border-radius: var(--radius-s);
  z-index: 200;
  transition: top 160ms var(--ease-out);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 12px;
}

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

:focus:not(:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- layout shell ---------- */

.app-shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 32px 96px;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  padding-bottom: 24px;
  border-bottom: 2px dashed var(--line-strong);
  margin-bottom: 32px;
}

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

.brand-mark {
  color: var(--accent);
  flex: none;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1;
}

.brand-tagline {
  margin-top: 6px;
  font-size: 13.5px;
  color: var(--muted);
  font-style: italic;
}

.header-tally {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.tally-number {
  font-family: var(--font-display);
  font-size: clamp(48px, 6vw, 68px);
  font-weight: 600;
  line-height: 0.9;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.tally-label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 600;
  max-width: 8em;
}

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}

.field-search {
  flex: 1 1 320px;
}

.field-filter {
  flex: 0 0 220px;
}

.field label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--muted);
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  color: var(--muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 12px 16px 12px 40px;
  min-height: 44px;
  border-radius: var(--radius-m);
  border: 1.5px solid var(--line-strong);
  background: var(--surface-raised);
  color: var(--ink);
  transition: border-color 160ms var(--ease-out);
}

#search-input::placeholder {
  color: #9c8a72;
}

#search-input:focus {
  border-color: var(--accent);
}

@media (hover: hover) and (pointer: fine) {
  #search-input:hover {
    border-color: var(--accent-hover);
  }
}

.field-search .stitch {
  position: absolute;
  left: 0;
  bottom: -3px;
  width: 100%;
  height: 6px;
  color: var(--accent);
  pointer-events: none;
}

.field-search .stitch path {
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 6 6;
  fill: none;
  stroke-dashoffset: 220;
  opacity: 0;
  transition: none;
}

.field-search.is-active .stitch path {
  opacity: 1;
  animation: stitchDraw 420ms var(--ease-out) forwards;
}

#filter-select {
  width: 100%;
  min-height: 44px;
  padding: 12px 40px 12px 16px;
  border-radius: var(--radius-m);
  border: 1.5px solid var(--line-strong);
  background-color: var(--surface-raised);
  color: var(--ink);
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%235b4a38' stroke-width='1.8'><path d='M5 8 L10 13 L15 8' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px;
  transition: border-color 160ms var(--ease-out);
}

#filter-select:focus {
  border-color: var(--accent);
}

@media (hover: hover) and (pointer: fine) {
  #filter-select:hover {
    border-color: var(--accent-hover);
  }
}

/* ---------- quick chips ---------- */

.chip-row {
  margin-bottom: 28px;
}

.chip-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 24px 10px 2px;
  scrollbar-width: thin;
}

.chip {
  position: relative;
  flex: none;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1.5px solid var(--line-strong);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 160ms var(--ease-out), color 160ms var(--ease-out), border-color 160ms var(--ease-out), transform 160ms var(--ease-out);
}

.chip .stitch {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 4px;
  height: 4px;
  color: var(--accent-ink);
  pointer-events: none;
}

.chip .stitch path {
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-dasharray: 5 5;
  fill: none;
  stroke-dashoffset: 160;
  opacity: 0;
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.chip[aria-pressed="true"] .stitch path {
  opacity: 0.9;
  animation: stitchDraw 380ms var(--ease-out) forwards;
}

.chip:active {
  transform: scale(0.97);
}

@media (hover: hover) and (pointer: fine) {
  .chip:hover {
    border-color: var(--accent-hover);
    color: var(--accent-hover);
  }
  .chip[aria-pressed="true"]:hover {
    color: var(--accent-ink);
  }
}

@keyframes stitchDraw {
  to {
    stroke-dashoffset: 0;
  }
}

/* ---------- task list (ledger) ---------- */

.task-main {
  position: relative;
}

.task-list {
  border-top: 1.5px solid var(--line-strong);
}

.task-row {
  border-bottom: 1.5px solid var(--line);
}

.task-row-button {
  width: 100%;
  display: grid;
  grid-template-columns: 132px 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 16px 12px;
  min-height: 64px;
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-s);
  transition: background 160ms var(--ease-out);
}

.task-row-button:hover {
  background: rgba(168, 84, 46, 0.06);
}

.task-row-button:active {
  transform: scale(0.995);
}

.status-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: var(--radius-s) var(--radius-s) var(--radius-s) 2px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  position: relative;
}

.status-tag::after {
  content: "";
  position: absolute;
  top: -4px;
  left: 10px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--surface-raised);
  border: 1.5px solid currentColor;
}

.status-tag[data-status="todo"] {
  background: var(--neutral-bg);
  color: var(--neutral-ink);
}

.status-tag[data-status="in-progress"] {
  background: var(--amber-bg);
  color: var(--amber-ink);
}

.status-tag[data-status="blocked"] {
  background: var(--rust-bg);
  color: var(--rust-ink);
}

.status-tag[data-status="done"] {
  background: var(--leaf-bg);
  color: var(--leaf-ink);
}

.task-title-wrap {
  min-width: 0;
}

.task-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.task-meta {
  margin-top: 4px;
  font-size: 13.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-meta .overdue {
  color: var(--rust-ink);
  font-weight: 700;
}

.task-side {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: nowrap;
}

.priority-meter {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

.priority-meter span {
  width: 4px;
  border-radius: 1px;
  background: var(--line-strong);
}

.priority-meter span:nth-child(1) { height: 5px; }
.priority-meter span:nth-child(2) { height: 9px; }
.priority-meter span:nth-child(3) { height: 14px; }

.priority-meter.p-low span:nth-child(1) { background: var(--accent); }
.priority-meter.p-medium span:nth-child(1),
.priority-meter.p-medium span:nth-child(2) { background: var(--accent); }
.priority-meter.p-high span { background: var(--accent); }

.task-comments {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--muted);
}

.task-comments svg {
  flex: none;
}

/* ---------- empty state ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 72px 24px;
  color: var(--muted);
}

.empty-state svg {
  color: var(--line-strong);
  margin-bottom: 8px;
}

.empty-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
}

.empty-copy {
  max-width: 42ch;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 11px 22px;
  border-radius: var(--radius-m);
  border: 1.5px solid transparent;
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  transition: background 160ms var(--ease-out), border-color 160ms var(--ease-out), transform 160ms var(--ease-out);
}

.btn-secondary {
  background: var(--surface-raised);
  border-color: var(--line-strong);
  color: var(--ink);
  margin-top: 8px;
}

.btn-secondary:hover {
  border-color: var(--accent-hover);
  color: var(--accent-hover);
}

.btn:active {
  transform: scale(0.97);
}

/* ---------- detail overlay + panel ---------- */

.detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(46, 33, 22, 0.38);
  z-index: 90;
  opacity: 0;
  animation: overlayIn 220ms var(--ease-out) forwards;
}

@keyframes overlayIn {
  to { opacity: 1; }
}

.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(480px, 100%);
  background: var(--surface);
  box-shadow: var(--shadow-panel);
  z-index: 100;
  overflow-y: auto;
  transform: translateX(24px);
  opacity: 0;
  animation: panelIn 260ms var(--ease-out) forwards;
  border-left: 2px dashed var(--line-strong);
}

@keyframes panelIn {
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.detail-panel-inner {
  padding: 32px 32px 64px;
  position: relative;
}

.detail-close {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px 8px 10px;
  margin-bottom: 24px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-m);
  background: var(--surface-raised);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 160ms var(--ease-out), color 160ms var(--ease-out);
}

.detail-close:hover {
  border-color: var(--accent-hover);
  color: var(--accent-hover);
}

.detail-close:active {
  transform: scale(0.97);
}

.detail-eyebrow {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

.detail-title {
  font-size: clamp(24px, 3vw, 30px);
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 24px;
}

.detail-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 20px;
  padding: 20px;
  background: var(--surface-raised);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-m);
  margin-bottom: 20px;
}

.detail-meta-item dt {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 4px;
}

.detail-meta-item dd {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 28px;
}

.detail-tags li {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--neutral-bg);
  color: var(--neutral-ink);
  font-size: 12.5px;
  font-weight: 600;
}

.detail-status {
  padding: 20px;
  background: var(--surface-raised);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-m);
  margin-bottom: 28px;
}

.detail-status label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}

#status-control {
  width: 100%;
  min-height: 44px;
  padding: 11px 40px 11px 14px;
  border-radius: var(--radius-m);
  border: 1.5px solid var(--line-strong);
  background-color: var(--bg);
  color: var(--ink);
  font-weight: 600;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%235b4a38' stroke-width='1.8'><path d='M5 8 L10 13 L15 8' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px;
  transition: border-color 160ms var(--ease-out);
}

#status-control:focus {
  border-color: var(--accent);
}

@media (hover: hover) and (pointer: fine) {
  #status-control:hover {
    border-color: var(--accent-hover);
  }
}

.status-feedback {
  margin-top: 12px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--leaf-ink);
  min-height: 1.2em;
  opacity: 0;
}

.status-feedback.is-visible {
  animation: feedbackPop 260ms var(--ease-out) forwards;
}

@keyframes feedbackPop {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.detail-body h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 10px;
}

.detail-body p {
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink);
  margin-bottom: 14px;
  max-width: 60ch;
}

.detail-body p:last-child {
  margin-bottom: 0;
}

/* ---------- responsive ---------- */

@media (max-width: 780px) {
  .app-shell {
    padding: 24px 20px 96px;
  }

  .app-header {
    align-items: flex-start;
  }

  .toolbar {
    flex-direction: column;
    gap: 16px;
  }

  .field-search,
  .field-filter {
    flex: none;
    width: 100%;
  }

  .chip-scroll {
    padding-inline-end: 28px;
  }

  .task-row-button {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 16px 8px;
  }

  .task-row-button .status-tag {
    justify-self: start;
    width: fit-content;
  }

  .task-side {
    justify-content: space-between;
  }

  .detail-panel {
    width: 100%;
    border-left: none;
  }

  .detail-panel-inner {
    padding: 24px 20px 64px;
  }

  .detail-meta {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 420px) {
  .brand-name {
    font-size: 26px;
  }

  .tally-number {
    font-size: 44px;
  }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  .field-search.is-active .stitch path,
  .chip[aria-pressed="true"] .stitch path {
    opacity: 1;
    stroke-dashoffset: 0;
  }

  .detail-panel {
    transform: none;
    opacity: 1;
  }

  .detail-overlay {
    opacity: 1;
  }
}
