/* AIPOS — design tokens, shell, and components.
   System fonts, hairline separators, translucent chrome, quiet motion. */

/* ---------------------------------------------------------------- tokens */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", "Segoe UI", system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #fbfbfd;
  --bg-elev: #ffffff;
  --sidebar: rgba(242, 242, 245, 0.78);
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --surface-3: #ececf0;
  --fill: rgba(120, 120, 128, 0.12);
  --fill-hover: rgba(120, 120, 128, 0.18);
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #8e8e93;
  --separator: rgba(60, 60, 67, 0.12);
  --separator-strong: rgba(60, 60, 67, 0.2);
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-tint: rgba(0, 113, 227, 0.1);
  --on-accent: #ffffff;
  --orange: #c45d00;
  --orange-tint: rgba(255, 149, 0, 0.14);
  --green: #1f9d48;
  --green-dot: #34c759;
  --red: #d70015;
  --scrim: rgba(0, 0, 0, 0.28);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 1px rgba(0, 0, 0, 0.02);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.04), 0 24px 64px rgba(0, 0, 0, 0.14);

  --glow-1: #2f7bff;
  --glow-2: #8a5cff;
  --glow-3: #ff5fa2;
  --glow-4: #ffb340;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 24px;

  --sidebar-w: 256px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e10;
    --bg-elev: #1c1c1e;
    --sidebar: rgba(28, 28, 30, 0.72);
    --surface: #1c1c1e;
    --surface-2: #232326;
    --surface-3: #2c2c2e;
    --fill: rgba(120, 120, 128, 0.22);
    --fill-hover: rgba(120, 120, 128, 0.3);
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #7c7c80;
    --separator: rgba(84, 84, 88, 0.42);
    --separator-strong: rgba(84, 84, 88, 0.65);
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --accent-tint: rgba(10, 132, 255, 0.18);
    --orange: #ffb340;
    --orange-tint: rgba(255, 159, 10, 0.16);
    --green: #30d158;
    --green-dot: #30d158;
    --red: #ff453a;
    --scrim: rgba(0, 0, 0, 0.5);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.3), 0 24px 64px rgba(0, 0, 0, 0.55);
  }
}

:root[data-theme="dark"] {
  --bg: #0e0e10;
  --bg-elev: #1c1c1e;
  --sidebar: rgba(28, 28, 30, 0.72);
  --surface: #1c1c1e;
  --surface-2: #232326;
  --surface-3: #2c2c2e;
  --fill: rgba(120, 120, 128, 0.22);
  --fill-hover: rgba(120, 120, 128, 0.3);
  --text: #f5f5f7;
  --text-2: #a1a1a6;
  --text-3: #7c7c80;
  --separator: rgba(84, 84, 88, 0.42);
  --separator-strong: rgba(84, 84, 88, 0.65);
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --accent-tint: rgba(10, 132, 255, 0.18);
  --orange: #ffb340;
  --orange-tint: rgba(255, 159, 10, 0.16);
  --green: #30d158;
  --green-dot: #30d158;
  --red: #ff453a;
  --scrim: rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.3), 0 24px 64px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.47 var(--font);
  letter-spacing: -0.009em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
button, input, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: 0.88em; }
:focus { outline: none; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; border-radius: 6px; }
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
[hidden] { display: none !important; }

.icon { width: 18px; height: 18px; flex: none; display: block; }
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 22px; height: 22px; }

/* ----------------------------------------------------------------- shell */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  position: sticky;
  top: 0;
  flex: none;
  width: var(--sidebar-w);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 18px 12px 14px;
  background: var(--sidebar);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border-right: 0.5px solid var(--separator-strong);
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cpath d='M32 14c1.6 8.6 7.4 14.4 16 16-8.6 1.6-14.4 7.4-16 16-1.6-8.6-7.4-14.4-16-16 8.6-1.6 14.4-7.4 16-16z' fill='%23fff'/%3E%3C/svg%3E") center / 22px no-repeat,
    linear-gradient(135deg, var(--glow-1), var(--glow-2) 55%, var(--glow-3));
  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.25), 0 1px 3px rgba(0, 0, 0, 0.12);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--text-2); }

.nav { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.nav-section + .nav-section { margin-top: 18px; }
.nav-heading {
  margin: 0 0 4px; padding: 0 10px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  color: var(--text-3);
}
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  height: 32px; padding: 0 10px;
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 13.5px; font-weight: 500;
  transition: background-color 0.15s ease;
}
.nav-link:hover { background: var(--fill); text-decoration: none; }
.nav-link .icon { color: var(--accent); width: 17px; height: 17px; }
.nav-link[aria-current="page"] { background: var(--fill-hover); }
.nav-link .badge { margin-left: auto; }

.sidebar-foot { display: grid; gap: 10px; padding-top: 12px; border-top: 0.5px solid var(--separator); }
.repo-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--text); min-width: 0;
}
.repo-chip:hover { background: var(--fill); text-decoration: none; }
.repo-chip .dot {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--green-dot);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green-dot) 22%, transparent);
}
.repo-chip.is-error .dot { background: #ff453a; box-shadow: 0 0 0 3px rgba(255, 69, 58, 0.22); }
.repo-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.repo-name { font-size: 12.5px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.repo-meta { font-size: 11.5px; color: var(--text-2); font-family: var(--mono); }

.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 2px; border-radius: 9px; background: var(--fill);
}
.segmented button {
  display: flex; align-items: center; justify-content: center; gap: 5px;
  height: 26px; border: 0; border-radius: 7px; background: transparent;
  color: var(--text-2); font-size: 12px; font-weight: 500;
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.segmented button[aria-checked="true"] {
  background: var(--bg-elev); color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 0.5px var(--separator);
}
.segmented .icon { width: 14px; height: 14px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.view:focus { outline: none; }
.view-root > * { animation: view-in 0.42s var(--ease-out) both; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text);
}
.icon-btn:hover { background: var(--fill); }

/* ------------------------------------------------------- shared primitives */
.page { width: 100%; max-width: 1040px; margin: 0 auto; padding: 56px 48px 96px; }
.eyebrow { margin: 0 0 6px; font-size: 13px; font-weight: 600; color: var(--text-2); letter-spacing: 0; }
.large-title {
  margin: 0;
  font: 700 40px/1.08 var(--font-display);
  letter-spacing: -0.028em;
}
.lede { margin: 10px 0 0; max-width: 620px; font-size: 17px; line-height: 1.5; color: var(--text-2); letter-spacing: -0.016em; }
.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 16px; font-size: 13px; color: var(--text-2); }
.meta-row .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--text-3); }

.section { margin-top: 48px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-title { margin: 0; font: 650 22px/1.2 var(--font-display); letter-spacing: -0.02em; }
.section-note { font-size: 13px; color: var(--text-2); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--fill); color: var(--text-2);
}
.badge-orange { background: var(--orange-tint); color: var(--orange); }
.badge-accent { background: var(--accent-tint); color: var(--accent); }
.badge-green { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }

.tag {
  display: inline-flex; align-items: center; height: 24px; padding: 0 9px;
  border-radius: 7px; background: var(--surface-2);
  font-size: 12px; color: var(--text-2); white-space: nowrap;
}

.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm), inset 0 0 0 0.5px var(--separator);
}

.skeleton {
  border-radius: var(--r-lg);
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.empty-state {
  display: grid; place-items: center; gap: 8px; text-align: center;
  padding: 48px 24px; color: var(--text-2);
}
.empty-state h2 { margin: 0; color: var(--text); font-size: 19px; letter-spacing: -0.015em; }
.empty-state p { margin: 0; max-width: 420px; }

/* ------------------------------------------------------------------ home */
.home { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.home-glow {
  position: absolute; inset: 0 0 auto; height: 520px; pointer-events: none; overflow: hidden;
  mask-image: linear-gradient(to bottom, #000 30%, transparent);
  -webkit-mask-image: linear-gradient(to bottom, #000 30%, transparent);
}
.home-glow::before {
  content: ""; position: absolute; left: 50%; top: -260px; width: 900px; height: 620px;
  transform: translateX(-50%);
  background:
    radial-gradient(closest-side, color-mix(in srgb, var(--glow-1) 22%, transparent), transparent) -120px 60px / 560px 420px no-repeat,
    radial-gradient(closest-side, color-mix(in srgb, var(--glow-2) 20%, transparent), transparent) 200px 0 / 560px 440px no-repeat,
    radial-gradient(closest-side, color-mix(in srgb, var(--glow-3) 14%, transparent), transparent) 420px 120px / 520px 380px no-repeat;
  filter: blur(20px);
  opacity: 0.9;
}

.home-inner {
  position: relative; flex: 1; display: flex; flex-direction: column;
  width: 100%; max-width: 760px; margin: 0 auto; padding: 0 32px;
}

.hero { padding: 18vh 0 28px; text-align: center; }
.orb {
  position: relative; width: 56px; height: 56px; margin: 0 auto 22px; border-radius: 50%;
  background: conic-gradient(from 210deg, var(--glow-1), var(--glow-2), var(--glow-3), var(--glow-4), var(--glow-1));
  box-shadow: 0 10px 40px color-mix(in srgb, var(--glow-2) 40%, transparent);
  animation: orb-spin 14s linear infinite;
}
.orb::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0) 46%);
}
@keyframes orb-spin { to { transform: rotate(360deg); } }
.hero h1 { margin: 0; font: 700 38px/1.1 var(--font-display); letter-spacing: -0.03em; }
.hero p { margin: 10px auto 0; max-width: 520px; font-size: 17px; color: var(--text-2); letter-spacing: -0.016em; text-wrap: balance; }
.lede, .priority h3, .section-title, .empty-state p { text-wrap: pretty; }

/* thread */
.thread { display: none; flex-direction: column; gap: 22px; padding: 40px 0 24px; }
.msg { display: flex; gap: 12px; max-width: 100%; animation: msg-in 0.36s var(--ease-out) both; }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px) scale(0.99); } }
.msg-user { justify-content: flex-end; }
.msg-user .bubble {
  max-width: 78%; padding: 10px 15px; border-radius: 20px 20px 6px 20px;
  background: var(--accent); color: var(--on-accent);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-assistant .avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none; margin-top: 1px;
  background: conic-gradient(from 210deg, var(--glow-1), var(--glow-2), var(--glow-3), var(--glow-4), var(--glow-1));
}
.msg-assistant .bubble { min-width: 0; padding-top: 3px; overflow-wrap: anywhere; }
.msg-assistant .bubble > :first-child { margin-top: 0; }
.msg-assistant .bubble > :last-child { margin-bottom: 0; }
.msg-assistant .note { margin-top: 8px; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); }
.msg-error .bubble { color: #ff453a; }
.typing { display: inline-flex; gap: 4px; padding: 10px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-3);
  animation: blink 1.2s infinite ease-in-out both;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); } 40% { opacity: 1; transform: scale(1); } }

/* composer */
.dock { position: relative; padding-bottom: 28px; }
.composer {
  position: relative;
  isolation: isolate;
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.25s var(--ease);
}
.composer::before {
  /* Gradient ring that blooms on focus. */
  content: ""; position: absolute; inset: -1.5px; z-index: -1; border-radius: inherit;
  background: conic-gradient(from var(--angle, 0deg), var(--glow-1), var(--glow-2), var(--glow-3), var(--glow-4), var(--glow-1));
  opacity: 0; filter: blur(0.5px);
  transition: opacity 0.35s var(--ease);
}
.composer::after {
  content: ""; position: absolute; inset: 6px; z-index: -2; border-radius: inherit;
  background: conic-gradient(from var(--angle, 0deg), var(--glow-1), var(--glow-2), var(--glow-3), var(--glow-4), var(--glow-1));
  filter: blur(26px); opacity: 0;
  transition: opacity 0.4s var(--ease);
}
.composer:focus-within { box-shadow: var(--shadow-lg); }
.composer:focus-within::before { opacity: 1; }
.composer:focus-within::after { opacity: 0.32; }
@property --angle { syntax: "<angle>"; initial-value: 0deg; inherits: false; }
.composer::before, .composer::after { animation: angle 6s linear infinite; }
@keyframes angle { to { --angle: 360deg; } }
.composer-field {
  position: relative; z-index: 1; border-radius: inherit; background: var(--bg-elev);
  box-shadow: inset 0 0 0 0.5px var(--separator-strong);
}
.composer:focus-within .composer-field { box-shadow: none; }
.composer textarea {
  display: block; width: 100%; min-height: 60px; max-height: 220px; resize: none;
  padding: 18px 20px 6px; border: 0; background: transparent;
  font-size: 16px; line-height: 1.5; letter-spacing: -0.012em;
}
.composer textarea::placeholder { color: var(--text-3); }
.composer textarea:focus-visible { outline: none; }
.composer-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px 10px 14px; }
.context-pill {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0;
  height: 28px; padding: 0 10px; border-radius: 999px;
  background: var(--fill); color: var(--text-2); font-size: 12.5px; font-weight: 500;
}
.context-pill span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-bar .grow { flex: 1; }
.kbd-hint { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.send-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  transition: transform 0.18s var(--ease), background-color 0.2s ease, opacity 0.2s ease;
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:active:not(:disabled) { transform: scale(0.92); }
.send-btn:disabled { background: var(--fill-hover); color: var(--text-3); cursor: default; }
.send-btn .icon { width: 17px; height: 17px; }

.status-line {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin: 12px 0 0; font-size: 12px; color: var(--text-3);
}
.status-line .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); }

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 18px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 14px; border-radius: 999px;
  border: 0; background: var(--surface);
  box-shadow: var(--shadow-sm), inset 0 0 0 0.5px var(--separator-strong);
  font-size: 13.5px; color: var(--text);
  transition: transform 0.18s var(--ease), box-shadow 0.2s ease, background-color 0.2s ease;
}
.chip:hover { background: var(--surface-2); }
.chip:active { transform: scale(0.97); }
.chip .icon { width: 15px; height: 15px; color: var(--text-2); }

.glance { margin: 56px 0 72px; }
.glance-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.glance-head h2 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-2); }
.glance-head a { font-size: 13px; }
.priority-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.priority { padding: 16px 16px 18px; }
.priority-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 7px; margin-bottom: 12px;
  background: var(--accent-tint); color: var(--accent);
  font-size: 12px; font-weight: 700;
}
.priority h3 { margin: 0 0 6px; font-size: 14.5px; line-height: 1.3; font-weight: 600; letter-spacing: -0.012em; }
.priority p { margin: 0; font-size: 13px; line-height: 1.45; color: var(--text-2); }

/* thread mode: composer docks to the bottom */
.home.is-thread .hero, .home.is-thread .chips, .home.is-thread .glance { display: none; }
.home.is-thread .thread { display: flex; flex: 1; }
.home.is-thread .dock {
  position: sticky; bottom: 0; padding-top: 18px;
  background: linear-gradient(to bottom, transparent, var(--bg) 22px);
}

/* --------------------------------------------------------------- report */
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-top: 36px; }
.stat { padding: 16px 18px 18px; }
.stat-label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.stat-label .icon { width: 15px; height: 15px; }
.stat-value { margin-top: 8px; font: 650 30px/1 var(--font-display); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 17px; font-weight: 600; color: var(--text-3); letter-spacing: -0.01em; }
.stat-foot { margin-top: 6px; font-size: 12px; color: var(--text-3); }

.context-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.context-card {
  display: flex; flex-direction: column; gap: 12px; text-align: left;
  padding: 18px 18px 16px; border: 0; color: inherit;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
}
.context-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md), inset 0 0 0 0.5px var(--separator); }
.context-card:active { transform: translateY(0) scale(0.99); }
.context-card-head { display: flex; align-items: flex-start; gap: 12px; }
.tile-icon {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent-tint); color: var(--accent);
}
.context-card h3 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.015em; }
.context-card .path { margin-top: 2px; font-family: var(--mono); font-size: 11.5px; color: var(--text-3); }
.context-card .summary {
  margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--text-2);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.context-card-foot {
  display: flex; align-items: center; gap: 8px; margin-top: auto; padding-top: 12px;
  border-top: 0.5px solid var(--separator); font-size: 12px; color: var(--text-3);
}
.context-card-foot > span { white-space: nowrap; }
.context-card-foot .grow { flex: 1; }
.context-card-foot .chev { color: var(--text-3); width: 14px; height: 14px; }

.list { overflow: hidden; }
.list-row { border-top: 0.5px solid var(--separator); }
.list-row:first-child { border-top: 0; }
.skill-btn {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px;
  width: 100%; padding: 14px 18px; border: 0; background: transparent; text-align: left;
  transition: background-color 0.15s ease;
}
.skill-btn:hover { background: var(--surface-2); }
.skill-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--glow-2), var(--glow-1)); color: #fff;
}
.skill-main { min-width: 0; }
.skill-title { display: flex; align-items: center; gap: 8px; }
.skill-cmd { font-family: var(--mono); font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.skill-desc {
  margin-top: 2px; font-size: 13px; color: var(--text-2); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}
.skill-side { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 12.5px; }
.skill-side .chev { width: 14px; height: 14px; transition: transform 0.3s var(--ease); }
.list-row.is-open .skill-side .chev { transform: rotate(90deg); }
.list-row.is-open .skill-desc { -webkit-line-clamp: unset; }
.skill-detail {
  display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.35s var(--ease);
}
.list-row.is-open .skill-detail { grid-template-rows: 1fr; }
.skill-detail > div { overflow: hidden; }
.skill-detail dl {
  display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px;
  margin: 0; padding: 0 18px 16px 64px; font-size: 13px;
}
.skill-detail dt { color: var(--text-3); }
.skill-detail dd { margin: 0; color: var(--text-2); overflow-wrap: anywhere; }
.skill-detail dd code { color: var(--text); }

.open-list { list-style: none; margin: 0; padding: 0; }
.open-item { display: flex; gap: 14px; align-items: flex-start; padding: 14px 18px; border-top: 0.5px solid var(--separator); }
.open-item:first-child { border-top: 0; }
.open-mark {
  flex: none; width: 18px; height: 18px; margin-top: 2px; border-radius: 50%;
  border: 1.5px solid var(--orange); opacity: 0.85;
}
.open-text { flex: 1; min-width: 0; font-size: 14px; line-height: 1.45; }
.open-src { flex: none; font-size: 12px; color: var(--text-3); padding-top: 2px; }

/* ---------------------------------------------------------------- ideas */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-actions { display: flex; gap: 8px; padding-bottom: 4px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px; border: 0; border-radius: 999px;
  background: var(--fill); color: var(--text);
  font-size: 13.5px; font-weight: 550; white-space: nowrap;
  transition: background-color 0.2s ease, transform 0.18s var(--ease);
}
.btn:hover { background: var(--fill-hover); text-decoration: none; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn.is-busy .icon { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 36px 0 14px; }
.segmented-wide { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: auto; }
.segmented-wide button, .toolbar .segmented button { padding: 0 12px; font-size: 13px; height: 28px; white-space: nowrap; }
.toolbar .segmented-wide { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.toolbar .segmented { grid-template-columns: none; grid-auto-flow: column; }
.segmented .count {
  margin-left: 2px; min-width: 18px; padding: 0 5px; border-radius: 999px;
  font-size: 11px; font-weight: 600; line-height: 16px; color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.segmented button[aria-checked="true"] .count { color: var(--text-2); }

.idea-list { list-style: none; margin: 0; padding: 0; overflow: hidden; }
.idea-list > li + li { border-top: 0.5px solid var(--separator); }
.idea-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 16px; align-items: start;
  padding: 18px 20px; color: inherit;
  transition: background-color 0.15s ease;
}
.idea-row:hover { background: var(--surface-2); text-decoration: none; }

.fit-ring { position: relative; width: 48px; height: 48px; flex: none; }
.fit-ring svg { width: 48px; height: 48px; display: block; }
.fit-ring circle { fill: none; stroke-width: 4; }
.ring-track { stroke: var(--fill); }
.ring-value { stroke-linecap: round; transition: stroke-dasharray 0.6s var(--ease-out); }
.tone-high .ring-value { stroke: var(--green-dot); }
.tone-mid .ring-value { stroke: #ffcc00; }
.tone-low .ring-value { stroke: #ff9500; }
.tone-none .ring-track { stroke-dasharray: 3 4; stroke: var(--separator-strong); }
.fit-num {
  position: absolute; inset: 0; display: grid; place-items: center;
  font: 650 17px/1 var(--font-display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
}
.tone-none .fit-num { color: var(--text-3); font-weight: 500; }

.idea-main { min-width: 0; }
.idea-title { font-size: 16px; font-weight: 600; letter-spacing: -0.015em; line-height: 1.3; }
.idea-pitch {
  margin: 4px 0 0; font-size: 13.5px; line-height: 1.5; color: var(--text-2);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.idea-verdict {
  display: flex; align-items: baseline; gap: 6px; margin: 8px 0 0;
  font-size: 13px; line-height: 1.45; color: var(--text);
}
.idea-verdict .icon { color: var(--glow-2); flex: none; position: relative; top: 2px; }
.idea-conf { flex: none; margin-left: 4px; font-size: 12px; color: var(--text-3); }
.idea-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.idea-meta .tag { height: 20px; font-size: 11.5px; padding: 0 7px; border-radius: 6px; }
.idea-meta .tag-board { gap: 4px; background: transparent; box-shadow: inset 0 0 0 0.5px var(--separator-strong); }
.idea-meta .tag-board .icon { width: 12px; height: 12px; }
.idea-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; padding-top: 2px; }
.idea-ref { font-family: var(--mono); font-size: 12px; color: var(--text-2); }
.idea-date { font-size: 12px; color: var(--text-3); }

.status {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.stage-validated, .stage-open { background: var(--accent-tint); color: var(--accent); }
.stage-prototyping, .stage-prototype-ready, .stage-closed {
  background: color-mix(in srgb, var(--glow-2) 14%, transparent);
  color: color-mix(in srgb, var(--glow-2) 75%, var(--text));
}
.stage-ordered { background: var(--orange-tint); color: var(--orange); }
.stage-live { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }
.stage-parked { background: var(--fill); color: var(--text-2); }
.stage-dropped { background: var(--fill); color: var(--text-3); }

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  margin-top: 28px; padding: 12px 14px; border-radius: var(--r-md);
  background: var(--accent-tint); font-size: 13.5px; line-height: 1.5; color: var(--text);
}
.notice .icon { color: var(--accent); margin-top: 2px; }
.notice + .stats { margin-top: 16px; }

.footnote { margin: 14px 4px 0; font-size: 12.5px; color: var(--text-3); }
.footnote code { color: var(--text-2); }

/* Status columns on the Factory Ideas board */
.stage-ready-to-prototype { background: var(--accent-tint); color: var(--accent); }
.stage-idea-prototypes-in-progress {
  background: color-mix(in srgb, var(--glow-2) 14%, transparent);
  color: color-mix(in srgb, var(--glow-2) 75%, var(--text));
}
.stage-ready-to-order { background: var(--orange-tint); color: var(--orange); }
.stage-orders-sent { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }

.idea-actions { display: flex; align-items: center; gap: 12px; padding: 0 20px 16px 84px; margin-top: -6px; }
.idea-actions-note { font-size: 12.5px; color: var(--text-3); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; }

/* ------------------------------------------------------- create order */
.order-form { display: flex; flex-direction: column; gap: 16px; padding-top: 14px; }
.order-lede { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--text-2); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 12px; line-height: 1.4; color: var(--text-3); }
.input {
  width: 100%; min-height: 36px; padding: 7px 11px; border: 0; border-radius: var(--r-sm);
  background: var(--fill); font-size: 14px; line-height: 1.4;
  box-shadow: inset 0 0 0 0.5px var(--separator);
}
textarea.input { resize: vertical; }
.input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.input::placeholder { color: var(--text-3); }
.order-form .segmented-wide { align-self: flex-start; }
.order-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 4px; }
.order-results:empty { display: none; }
.order-verdict {
  display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r-md);
  font-size: 13.5px; line-height: 1.45;
}
.order-verdict .icon { flex: none; margin-top: 2px; }
.order-verdict.is-ok { background: color-mix(in srgb, var(--green) 12%, transparent); }
.order-verdict.is-ok .icon { color: var(--green); }
.order-verdict.is-blocked { background: color-mix(in srgb, var(--red) 10%, transparent); }
.order-verdict.is-blocked .icon { color: var(--red); }
.check-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.check-list li { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 10px; font-size: 13.5px; line-height: 1.4; }
.check-mark { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; }
.check-mark .icon { width: 13px; height: 13px; stroke-width: 2.5; }
.check-pass .check-mark { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.check-warn .check-mark { background: var(--orange-tint); color: var(--orange); }
.check-fail .check-mark { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.check-detail { margin-top: 2px; font-size: 12.5px; color: var(--text-2); overflow-wrap: anywhere; }
.order-preview { margin-top: 16px; padding: 10px 14px; border-radius: var(--r-md); background: var(--surface-2); }
.order-preview summary { cursor: pointer; font-size: 13px; font-weight: 600; }
.order-approver { margin-left: 8px; font-weight: 500; color: var(--text-3); }
.order-title { margin: 10px 0 6px; font-size: 13px; font-weight: 600; }
.order-preview pre {
  margin: 0; max-height: 420px; overflow: auto;
  font: 12px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
}
.stale-note { display: none; margin: 10px 0 0; font-size: 12.5px; color: var(--orange); }
.order-results.is-stale .stale-note { display: block; }
.order-results.is-stale .check-list, .order-results.is-stale .order-verdict { opacity: 0.55; }
.order-next { margin: 10px 0 12px; font-size: 13.5px; line-height: 1.5; color: var(--text-2); }
@media (max-width: 600px) {
  .field-row { grid-template-columns: 1fr; }
  .idea-actions { flex-wrap: wrap; padding-left: 20px; }
}

/* ---------------------------------------------------------------- sheet */
.sheet-scrim {
  position: fixed; inset: 0; z-index: 60; background: var(--scrim);
  opacity: 0; transition: opacity 0.3s var(--ease);
}
.sheet {
  position: fixed; top: 10px; right: 10px; bottom: 10px; z-index: 61;
  width: min(620px, calc(100vw - 20px));
  display: flex; flex-direction: column;
  border-radius: 20px; background: var(--bg-elev);
  box-shadow: var(--shadow-lg), inset 0 0 0 0.5px var(--separator-strong);
  transform: translateX(calc(100% + 24px));
  transition: transform 0.45s var(--ease);
}
.sheet.is-open { transform: none; }
.sheet-scrim.is-open { opacity: 1; }
.sheet-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 14px 14px 22px; border-bottom: 0.5px solid var(--separator);
}
.sheet-head .titles { flex: 1; min-width: 0; }
.sheet-head h2 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.015em; }
.sheet-head .path { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); }
.sheet-body { flex: 1; overflow-y: auto; padding: 8px 28px 40px; overscroll-behavior: contain; }

/* ------------------------------------------------------------- markdown */
.md { font-size: 15px; line-height: 1.6; }
.md h1 { font: 700 26px/1.2 var(--font-display); letter-spacing: -0.025em; margin: 24px 0 12px; }
.md h2 { font: 650 19px/1.3 var(--font-display); letter-spacing: -0.018em; margin: 28px 0 8px; }
.md h3, .md h4 { font-size: 15px; font-weight: 650; margin: 20px 0 6px; }
.md p { margin: 0 0 12px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--text-3); }
.md strong { font-weight: 620; }
.md code { padding: 1px 5px; border-radius: 5px; background: var(--fill); font-size: 0.86em; }
.md pre { margin: 0 0 14px; padding: 14px 16px; border-radius: 12px; background: var(--surface-2); overflow-x: auto; }
.md pre code { padding: 0; background: none; font-size: 13px; line-height: 1.55; }
.md blockquote { margin: 0 0 12px; padding: 2px 0 2px 14px; border-left: 3px solid var(--separator-strong); color: var(--text-2); }
.md hr { border: 0; border-top: 0.5px solid var(--separator-strong); margin: 22px 0; }
.md table { width: 100%; border-collapse: collapse; margin: 0 0 14px; font-size: 13px; display: block; overflow-x: auto; }
.md th, .md td { padding: 8px 10px; border-bottom: 0.5px solid var(--separator); text-align: left; vertical-align: top; }
.md th { font-weight: 600; color: var(--text-2); }
.md td code { overflow-wrap: anywhere; } /* long paths wrap instead of pushing columns past the sheet */

/* ------------------------------------------------------------ responsive */
@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.4s var(--ease), box-shadow 0.4s var(--ease);
    background: var(--bg-elev);
  }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .scrim { position: fixed; inset: 0; z-index: 25; background: var(--scrim); }
  .topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 8px;
    height: 52px; padding: 0 8px;
    background: color-mix(in srgb, var(--bg) 78%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid var(--separator);
  }
  .topbar-title { font-size: 16px; font-weight: 600; letter-spacing: -0.015em; }
  .topbar-spacer { flex: 1; }
  .home { min-height: calc(100dvh - 52px); }
  .hero { padding-top: 10vh; }
  .page { padding: 28px 16px 72px; }
  .home-inner { padding: 0 16px; }
  .large-title { font-size: 32px; }
  .hero h1 { font-size: 30px; }
  .priority-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-head { flex-wrap: wrap; align-items: flex-start; }
  .toolbar { overflow-x: auto; flex-wrap: nowrap; margin-left: -16px; margin-right: -16px; padding: 2px 16px; }
  .toolbar .segmented { flex: none; }
  .idea-row { grid-template-columns: auto minmax(0, 1fr); padding: 16px; gap: 14px; }
  .idea-side { grid-column: 2; flex-direction: row; align-items: center; gap: 10px; }
  .kbd-hint { display: none; }
  .skill-detail dl { padding-left: 18px; }
  .open-item { flex-wrap: wrap; }
  .open-src { width: 100%; padding-left: 32px; padding-top: 0; }
  .sheet { top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: 88dvh; border-radius: 20px 20px 0 0; transform: translateY(100%); }
  .sheet-body { padding: 4px 18px 32px; }
}
@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 26px; }
  .msg-user .bubble { max-width: 88%; }
}

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