:root {
  color-scheme: light dark;
  --canvas: oklch(97.5% 0.006 95);
  --surface: oklch(99.2% 0.003 95);
  --ink: oklch(24% 0.012 120);
  --muted: oklch(52% 0.012 110);
  --faint: oklch(72% 0.009 105);
  --line: oklch(88% 0.009 95);
  --line-strong: oklch(80% 0.012 100);
  --accent: oklch(47% 0.09 155);
  --accent-strong: oklch(40% 0.085 155);
  --accent-soft: oklch(95% 0.025 150);
  --warning: oklch(54% 0.105 65);
  --danger: oklch(49% 0.14 28);
  --shadow: 0 14px 34px oklch(24% 0.012 120 / 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body { margin: 0; min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button, input, textarea, select, summary, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

button {
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: var(--surface);
  padding: 0.64rem 0.86rem;
  font-weight: 650;
  cursor: pointer;
  transition: background 160ms cubic-bezier(.16, 1, .3, 1), border-color 160ms cubic-bezier(.16, 1, .3, 1);
}
button:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid color-mix(in oklch, var(--accent) 28%, transparent); outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
.secondary-button { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.secondary-button:hover { background: var(--canvas); border-color: var(--faint); }
.text-button { padding: 0; border: 0; background: transparent; color: var(--muted); font-weight: 600; }
.text-button:hover { background: transparent; border-color: transparent; color: var(--ink); }
.icon-button { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; border-color: transparent; background: transparent; color: var(--muted); font-size: 1rem; }
.icon-button:hover { background: var(--surface); border-color: var(--line); color: var(--ink); }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  padding: 0.66rem 0.72rem;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea { min-height: 96px; resize: vertical; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 0.76rem; font-weight: 650; }

.topbar {
  height: 56px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; font-size: 0.88rem; font-weight: 720; }
.mark { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--ink); color: var(--surface); font-size: 0.76rem; font-weight: 760; }
.product-note { margin-left: 18px; padding-left: 18px; border-left: 1px solid var(--line); color: var(--muted); font-size: 0.75rem; }
.topbar #logout { margin-left: auto; }

.login { width: min(430px, calc(100% - 32px)); margin: 14vh auto 0; }
.login-mark { margin-bottom: 28px; width: 32px; height: 32px; }
.login h1 { margin: 0; font-size: 1.65rem; line-height: 1.2; letter-spacing: -0.025em; }
.login > p { margin: 9px 0 28px; color: var(--muted); font-size: 0.88rem; line-height: 1.55; }
.login-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }

#app { display: grid; grid-template-columns: 214px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.project-rail { padding: 22px 12px; border-right: 1px solid var(--line); background: color-mix(in oklch, var(--canvas) 72%, var(--surface)); }
.rail-heading { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 10px; color: var(--muted); font-size: 0.68rem; font-weight: 760; letter-spacing: 0.08em; text-transform: uppercase; }
nav { display: grid; gap: 2px; }
nav button { width: 100%; padding: 0.58rem 0.7rem; border-color: transparent; background: transparent; color: var(--muted); text-align: left; font-size: 0.8rem; font-weight: 570; }
nav button:hover { background: var(--surface); border-color: transparent; color: var(--ink); }
nav button.active { background: var(--surface); border-color: var(--line); color: var(--ink); font-weight: 670; }

#workspace { min-width: 0; padding: 40px clamp(28px, 5vw, 68px) 80px; }
#project-view { max-width: 920px; }
.empty { margin-top: 10vh; max-width: 480px; }
.empty h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.02em; }
.empty p { color: var(--muted); line-height: 1.55; }

.project-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 32px; padding-bottom: 28px; border-bottom: 1px solid var(--line); }
.project-copy { min-width: 0; }
.project-slug { display: block; margin-bottom: 7px; color: var(--muted); font: 600 0.7rem/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; }
.project-header h1 { margin: 0; font-size: 1.72rem; line-height: 1.2; letter-spacing: -0.03em; overflow-wrap: anywhere; }
.project-header p { margin: 8px 0 0; max-width: 70ch; color: var(--muted); font-size: 0.86rem; line-height: 1.55; }
.repository-context { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 13px; color: var(--muted); font-size: 0.72rem; }
.repository-context a { color: var(--muted); font-weight: 620; text-decoration: none; }
.repository-context a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.project-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 7px; }

.action-menu { position: relative; }
.action-menu summary { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--surface); color: var(--muted); cursor: pointer; list-style: none; letter-spacing: 0.08em; }
.action-menu summary::-webkit-details-marker { display: none; }
.action-menu summary:hover { color: var(--ink); border-color: var(--faint); }
.menu { position: absolute; top: calc(100% + 7px); right: 0; z-index: 15; width: 220px; padding: 6px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); box-shadow: var(--shadow); }
.menu button { width: 100%; padding: 0.62rem 0.7rem; border: 0; background: transparent; color: var(--ink); text-align: left; font-size: 0.78rem; font-weight: 560; }
.menu button:hover { background: var(--canvas); }

.log-section { padding-top: 32px; }
.log-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 17px; }
.log-heading > div { display: flex; align-items: baseline; gap: 10px; }
.log-heading h2 { margin: 0; font-size: 1rem; font-weight: 690; letter-spacing: -0.01em; }
#log-count { color: var(--muted); font-size: 0.72rem; }
.log-controls { display: grid; grid-template-columns: minmax(240px, 1fr) auto auto; gap: 8px; margin-bottom: 20px; }
.log-controls select { min-width: 130px; color: var(--muted); font-size: 0.77rem; }
.search-field { position: relative; display: block; }
.search-field input { padding-left: 2.05rem; font-size: 0.8rem; }
.search-icon { position: absolute; left: 0.74rem; top: 50%; transform: translateY(-53%); color: var(--faint); font-size: 1rem; pointer-events: none; }

.project-log { border-top: 1px solid var(--line-strong); }
.log-entry { display: grid; grid-template-columns: 98px minmax(0, 1fr); gap: 24px; padding: 25px 0 27px; border-bottom: 1px solid var(--line); }
.log-entry > time { padding-top: 1px; color: var(--muted); font-size: 0.7rem; line-height: 1.4; }
.log-entry > time strong, .log-entry > time span { display: block; }
.log-entry > time strong { color: var(--ink); font-weight: 620; }
.entry-body { min-width: 0; }
.entry-labels { display: flex; align-items: center; min-height: 18px; gap: 8px; color: var(--muted); font-size: 0.66rem; line-height: 1.3; }
.entry-kind { color: var(--accent); font-weight: 760; letter-spacing: 0.065em; text-transform: uppercase; }
.entry-status { text-transform: lowercase; }
.entry-status::before { content: "·"; margin-right: 8px; color: var(--faint); }
.supersede { margin-left: auto; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 0.68rem; font-weight: 570; }
.supersede:hover { background: transparent; border-color: transparent; color: var(--danger); }
.entry-body h3 { margin: 5px 0 7px; font-size: 0.98rem; line-height: 1.4; font-weight: 650; letter-spacing: -0.008em; }
.entry-summary, .entry-rationale { max-width: 72ch; margin: 0; font-size: 0.86rem; line-height: 1.55; }
.entry-summary { color: var(--ink); }
.entry-rationale { margin-top: 8px; color: var(--muted); }
.entry-rationale strong { color: var(--ink); font-weight: 620; }
.entry-provenance { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 7px; margin-top: 13px; color: var(--muted); font-size: 0.68rem; line-height: 1.45; }
.entry-provenance > span:not(:first-child)::before { content: "·"; margin-right: 7px; color: var(--faint); }
.entry-provenance .actor { color: var(--ink); font-weight: 560; }
.entry-evidence { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 8px 14px; margin-top: 11px; }
.entry-paths { display: flex; flex-wrap: wrap; gap: 5px; }
.entry-paths code, .log-empty code { padding: 3px 6px; border-radius: 5px; background: var(--canvas); color: var(--muted); font: 550 0.65rem/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.entry-evidence a, .entry-evidence > span { color: var(--muted); font-size: 0.68rem; font-weight: 590; text-decoration: none; }
.entry-evidence a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.log-entry.historical .entry-kind { color: var(--muted); }
.log-entry.historical .entry-body h3, .log-entry.historical .entry-summary { color: var(--muted); }
.log-entry.historical .entry-status { color: var(--warning); }

.log-empty { padding: 46px 0; border-bottom: 1px solid var(--line); }
.log-empty strong { font-size: 0.88rem; }
.log-empty p { max-width: 62ch; margin: 7px 0 12px; color: var(--muted); font-size: 0.82rem; line-height: 1.55; }
.log-empty .text-button { color: var(--accent); }
.advisory { margin: 18px 0 0; color: var(--muted); font-size: 0.68rem; }

dialog { width: min(540px, calc(100% - 28px)); padding: 23px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: oklch(20% 0.01 120 / 0.48); }
#dialog-fields { display: grid; gap: 14px; }
#dialog-fields h2 { margin: 0 0 2px; font-size: 1.12rem; letter-spacing: -0.015em; }
#dialog-fields > p { margin: 0; max-width: 65ch; color: var(--muted); font-size: 0.82rem; line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
#toast { position: fixed; right: 18px; bottom: 18px; z-index: 40; padding: 10px 13px; border-radius: 7px; background: var(--ink); color: var(--surface); box-shadow: var(--shadow); font-size: 0.76rem; opacity: 0; transform: translateY(7px); transition: opacity 160ms cubic-bezier(.16, 1, .3, 1), transform 160ms cubic-bezier(.16, 1, .3, 1); pointer-events: none; }
#toast.show { opacity: 1; transform: none; }

@media (max-width: 760px) {
  .product-note { display: none; }
  #app { grid-template-columns: 1fr; }
  .project-rail { padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .rail-heading { padding: 0 2px 6px; }
  nav { display: flex; overflow-x: auto; gap: 4px; }
  nav button { width: auto; flex: 0 0 auto; }
  #workspace { padding: 28px 18px 60px; }
  .project-header { gap: 18px; }
  .project-header h1 { font-size: 1.5rem; }
  .log-controls { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .log-entry { grid-template-columns: 76px minmax(0, 1fr); gap: 16px; }
}

@media (max-width: 500px) {
  .topbar { padding: 0 15px; }
  .login-row { grid-template-columns: 1fr; }
  .project-header { display: block; }
  .project-actions { margin-top: 18px; }
  .action-menu { margin-left: auto; }
  .log-controls { grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
  .log-entry { grid-template-columns: 1fr; gap: 7px; padding: 22px 0 24px; }
  .log-entry > time { display: flex; gap: 5px; }
  .log-entry > time strong, .log-entry > time span { display: inline; }
  .entry-provenance { display: block; }
  .entry-provenance > span { display: block; margin-top: 3px; }
  .entry-provenance > span:not(:first-child)::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: oklch(17% 0.009 120);
    --surface: oklch(20.5% 0.011 120);
    --ink: oklch(92% 0.009 100);
    --muted: oklch(69% 0.011 110);
    --faint: oklch(47% 0.01 110);
    --line: oklch(29% 0.011 115);
    --line-strong: oklch(35% 0.013 115);
    --accent: oklch(75% 0.09 153);
    --accent-strong: oklch(68% 0.085 153);
    --accent-soft: oklch(27% 0.035 153);
    --warning: oklch(74% 0.1 70);
    --danger: oklch(70% 0.13 28);
    --shadow: 0 16px 38px oklch(5% 0.01 120 / 0.32);
  }
}
