@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=Space+Grotesk:wght@500;600;700&display=swap');

/* =============================================
   Design tokens
   ============================================= */
:root {
  /* Colors */
  --bg: #f8f7f4;
  --card-bg: #ffffff;
  --text: #1b1f24;
  --muted: #5f6b72;
  --brand: #0f766e;
  --brand-weak: #e0f2f1;
  --border: #e5e7eb;
  --gray-border: #e5e7eb;
  /* Accents and surfaces (light theme) */
  --accent-border: #b5e2dd;
  --hover-step-top: #ffffff;
  --hover-step-bottom: #f0f7f6;
  --hover-sub-top: #ffffff;
  --hover-sub-bottom: #f3f9f8;
  --hover-step-open-top: #f7fbfa;
  --hover-step-open-bottom: #eef7f5;
  --link-bg: #edf7f6;
  --link-bg-hover: #e2f3f1;
  --link-border: #cdeae6;
  --link-text: #0f766e;
  /* Count high tokens (light) */
  --count-high-fg: #0f7a3a;
  --count-high-bg: #d4f4e3;
  --count-high-border: #86e1b9;
  /* Progress tokens (light) */
  --progress-low: #22c55e;
  --progress-mid: #16a34a;
  --progress-high: #0f766e;
  --progress-done: #0f5f57;

  /* Spacing (4/8 scale) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;

  /* Radius */
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 12px;

  /* Elevation */
  --elev-1: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);

  /* Durations */
  --duration-fast: 150ms;

  /* Z-index */
  --z-header: 10;
  --z-step-sticky: 9;
  --header-h: 0px; /* dynamic via JS */

  /* Extended palette for states */
  --gray-100: #f2f4f7;
  --gray-300: #d0d5dd;
  --green-50: #e8fbf0;
  --green-200: #b6f0d1;
  --green-100: #d9f7e8;
  --green-300: #8ee6bb;
  --green-700: #0f5f57;
}

/* Dark theme tokens tuned around #1b1d1e */
:root[data-theme="dark"] {
  --bg: #121414;
  --card-bg: #1a1d1e;
  --text: #e6e7e8;
  --muted: #a0a4a8;
  --brand: #5eead4;
  --brand-weak: #123534;
  --border: #2a2c2d;
  --accent-border: #345454;
  /* Grays */
  --gray-100: #242627;
  --gray-300: #3a3d3f;
  /* Greens for progress and counts */
  --green-50: #0f231a;
  --green-100: #123022;
  --green-200: #15412e;
  --green-300: #1a5a43;
  --green-700: #2dd4bf;
  /* Hovers and link surfaces */
  --hover-step-top: #26292b;
  --hover-step-bottom: #26292b;
  --hover-sub-top: #242728;
  --hover-sub-bottom: #242728;
  --link-bg: #24282a;
  --link-bg-hover: #2a2e31;
  --link-border: var(--accent-border);
  --link-text: #9ef3e9;
  /* Count high state palette */
  --count-high-fg: #8cefe2;
  --count-high-bg: #0d2a29;
  --count-high-border: #1b4f4c;
}

/* =============================================
   Base
   ============================================= */
html, body { height: 100%; }
body {
  font-family: 'IBM Plex Sans', sans-serif;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(600px 400px at 10% 10%, rgba(15, 118, 110, 0.10), transparent 60%),
    radial-gradient(500px 320px at 90% 0%, rgba(14, 159, 110, 0.12), transparent 55%),
    var(--bg);
}
.app {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: rgba(248, 247, 244, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
}
:root[data-theme="dark"] .topbar {
  background: rgba(18, 20, 20, 0.88);
}
.layout {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  gap: 24px;
  padding: 24px 28px 48px;
}
.sidebar {
  display: grid;
  gap: 18px;
  position: sticky;
  top: 84px;
  align-self: start;
}
.main {
  display: grid;
  gap: 20px;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}
.logo-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0f766e, #10b981);
  box-shadow: 0 0 0 6px rgba(15, 118, 110, 0.12);
}
.brand-title {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}
.hero-card {
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(15, 118, 110, 0.02));
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-l);
  padding: 18px;
  box-shadow: var(--elev-1);
}
.hero-card h1 {
  margin: 0 0 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 22px;
}
.hero-card p { margin: 0; }
.ghost-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
}
.ghost-btn:hover { border-color: var(--accent-border); }
.muted { color: var(--muted); font-size: 12px; }
/* Ensure progress text is readable in both themes */
.global-progress .progress-text { color: var(--text); }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Honor system theme when user hasn't toggled */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) { color-scheme: dark; }
}

/* Legend removed */

/* =============================================
   Header (Type Scale)
   28/20/16/14/12
   ============================================= */
h1 {
  margin: 0 0 16px;
  font-size: 28px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.01em;
}
h2 {
  margin: 0 0 6px;
  font-size: 20px;
  line-height: 1.3;
  font-weight: 700;
  font-family: 'Space Grotesk', sans-serif;
}
h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: 'Space Grotesk', sans-serif;
}
.total-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--brand);
  background: var(--brand-weak);
  border: 1px solid var(--accent-border);
  border-radius: 999px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 14px 16px;
  box-shadow: var(--elev-1);
}
.total-pill { display: none; }

/* Global progress */
.global-progress {
  display: grid;
  gap: var(--space-2);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 12px 12px 10px;
  box-shadow: var(--elev-1);
}
.progress { position: relative; height: 10px; background: var(--gray-100); border-radius: 999px; overflow: hidden; border: 1px solid var(--gray-border); }
.progress .bar { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; border: 0; border-radius: inherit; transition: width var(--duration-fast) ease, background var(--duration-fast) ease; }
.progress.is-neutral .bar { background: var(--gray-300); }
.progress.is-low .bar { background: var(--progress-low); }
.progress.is-mid .bar { background: var(--progress-mid); }
.progress.is-high .bar { background: var(--progress-high); }
.progress.is-done .bar { background: var(--progress-done); }
:root[data-theme="dark"] .progress { background: #ffffff; border: 0; }
.progress-text { font-size: 12px; }

/* =============================================
   Filters
   ============================================= */
.filters {
  display: grid;
  gap: var(--space-2);
  margin: 0;
}
.nav-label {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.filter-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--duration-fast) ease, border-color var(--duration-fast) ease, color var(--duration-fast) ease;
}
.filter-btn:hover { background: var(--link-bg); border-color: var(--accent-border); }
.filter-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.filter-btn.active { background: var(--brand-weak); border-color: var(--accent-border); color: var(--brand); }
.quick-links { display: grid; gap: 8px; }
.nav-link {
  appearance: none;
  text-decoration: none;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.nav-link:hover { border-color: var(--accent-border); background: var(--link-bg); }
.nav-link.is-active {
  background: var(--brand-weak);
  color: var(--brand);
  border-color: var(--accent-border);
}

.view-panel.is-hidden { display: none; }
.is-hidden { display: none !important; }

/* =============================================
   Reviser
   ============================================= */
.reviser {
  display: grid;
  gap: var(--space-3);
}
.reviser-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 6px 2px;
}
.reviser-today {
  display: grid;
  gap: 2px;
  text-align: right;
  font-size: 12px;
}
.reviser-today strong {
  font-size: 20px;
  color: var(--brand);
}
.reviser-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}
.heatmap-card { padding: var(--space-2) var(--space-3) var(--space-3); }
.heatmap-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: var(--space-3);
  box-shadow: var(--elev-1);
  animation: float-in 420ms ease both;
}

@keyframes float-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.reviser-heatmap {
  display: block;
  overflow: hidden;
  padding-bottom: 4px;
  width: 100%;
  min-height: 22px;
  position: relative;
}
.reviser-heatmap svg { display: block; }

.reviser-due,
.reviser-upcoming {
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-2);
  max-height: 220px;
  overflow: auto;
  padding-right: 4px;
}

.reviser-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: var(--space-2);
  display: grid;
  gap: 6px;
  background: var(--bg);
}
.reviser-item-title { font-weight: 600; }
.reviser-item-meta { font-size: 12px; color: var(--muted); }
.reviser-item-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.item-row.is-highlight {
  outline: 2px solid var(--brand);
  box-shadow: 0 0 0 4px rgba(11, 105, 199, 0.15);
  transition: box-shadow 0.6s ease, outline-color 0.6s ease;
}
.reviser-item-actions a {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--link-border);
  background: var(--link-bg);
  color: var(--link-text);
  font-weight: 600;
}

.reviser-btn {
  appearance: none;
  border: 1px solid var(--accent-border);
  background: var(--brand-weak);
  color: var(--brand);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--duration-fast) ease, border-color var(--duration-fast) ease, color var(--duration-fast) ease;
}
.reviser-btn:hover { background: var(--link-bg); }
.reviser-btn.ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.reviser-btn.ghost:hover { color: var(--text); }

.reviser-empty {
  font-size: 12px;
  color: var(--muted);
  padding: var(--space-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-s);
  background: var(--bg);
}

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .sidebar { position: relative; top: 0; }
  .topbar { padding: 14px 16px; }
  .reviser-grid { grid-template-columns: 1fr; }
  .reviser-today { text-align: left; }
}

/* =============================================
   Details (Steps/Substeps)
   ============================================= */
details { margin: 8px 0; }
summary {
  cursor: pointer;
  list-style: none;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: var(--space-3) var(--space-4) var(--space-3) 32px;
  box-shadow: var(--elev-1);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 16px;
}
summary::-webkit-details-marker { display: none; }
summary { position: relative; }
summary::before {
  content: '';
  position: absolute;
  left: 12px;
  top: 50%;
  width: 7px;
  height: 7px;
  margin-top: -6px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.18s ease;
}
details[open] > summary::before { transform: rotate(45deg); }
details[open] > summary {
  border-color: #c8daff;
  background: #f8fbff;
}
/* Dark theme: keep open summaries on card background */
:root[data-theme="dark"] details[open] > summary {
  border-color: var(--accent-border);
  background: var(--card-bg);
}
summary:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Sticky Step Header */
#content > details > summary {
  position: sticky;
  top: var(--header-h);
  z-index: var(--z-step-sticky);
  background: var(--card-bg);
}

/* Emphasis on hover: steps and substeps */
#content > details > summary,
#content > details > details > summary {
  transition: background var(--duration-fast) ease, border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease, transform var(--duration-fast) ease;
}

/* Step hover */
#content > details > summary:hover,
details[open] > summary:hover {
  background: linear-gradient(180deg, var(--hover-step-top), var(--hover-step-bottom));
  border-color: var(--accent-border);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(16, 24, 40, 0.12), 0 2px 6px rgba(16, 24, 40, 0.08);
}

/* Substep hover */
#content > details > details summary { box-shadow: none; }
#content > details > details summary:hover,
#content > details > details[open] > summary:hover {
  background: linear-gradient(180deg, var(--hover-sub-top), var(--hover-sub-bottom));
  border-color: var(--accent-border);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(16, 24, 40, 0.10), 0 1px 4px rgba(16, 24, 40, 0.06);
}

/* Dark theme hover uses tokens already; no extra overrides needed */

/* =============================================
   Badges & Counts
   ============================================= */
.badge {
  display: inline-block;
  background: var(--brand-weak);
  border: 1px solid var(--accent-border);
  color: var(--brand);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  line-height: 1;
  vertical-align: baseline;
}
.small { font-size: 12px; }

.counts {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
  background: var(--brand-weak);
  border: 1px solid var(--accent-border);
  box-shadow: 0 0 0 1px var(--accent-border) inset; /* reinforce border visibility on dark */
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 600;
  font-size: 14px;
}
.counts[data-scope="step"] { font-size: 14px; }
.counts[data-scope="sub"] { font-size: 12px; }

/* Count pill states (positive-only scale) */
.counts.is-neutral { color: var(--text); background: var(--gray-100); border-color: var(--border); }
.counts.is-low { color: var(--green-700); background: var(--green-50); border-color: var(--green-200); }
.counts.is-mid { color: var(--green-700); background: var(--green-100); border-color: var(--green-300); }
.counts.is-high { color: var(--count-high-fg); background: var(--count-high-bg); border-color: var(--count-high-border); }
.counts.is-done { color: var(--green-700); background: var(--green-100); border-color: var(--green-300); }

/* (Removed unused .section-progress styles) */

/* Step & Substep summary progress alignment (keep bar at far right) */
#content > details > summary .progress.step,
#content > details > details > summary .progress.sub {
  width: 160px;
  height: 8px;
  margin-left: var(--space-2);
  flex: 0 0 auto;
}
@media (max-width: 680px) {
  #content > details > summary,
  #content > details > details > summary { flex-wrap: wrap; row-gap: 6px; }
  #content > details > summary .progress.step,
  #content > details > details > summary .progress.sub {
    order: 10;
    width: 100%;
  }
}

/* =============================================
   Structure
   ============================================= */
#content > details { margin: var(--space-3) 0; }
#content > details > details { margin: 8px 0 8px 16px; padding-left: 12px; border-left: 2px solid var(--border); }
#content > details > details > ul { margin-left: var(--space-3); }
#content > details[style*="display: none"],
#content > details > details[style*="display: none"],
#content li[style*="display: none"] { display: none !important; }
#content > details > details summary { box-shadow: none; font-weight: 700; }
#content > details > summary { font-weight: 700; }

/* =============================================
   Items
   ============================================= */
ul { padding-left: 0; margin: var(--space-2) 0 0; }
li { list-style: none; margin: 8px 0; line-height: 1.3; }

/* Loading state */
.loading {
  margin: 12px 0;
  padding: 12px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  color: var(--muted);
  font-weight: 600;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr repeat(4, minmax(84px, 120px));
  column-gap: var(--space-2);
  row-gap: var(--space-2);
  align-items: center;
  padding: var(--space-3);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  transition: background var(--duration-fast) ease, border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease, transform var(--duration-fast) ease;
}

/* Problem row hover emphasis */
.item-row:hover {
  background: var(--card-bg);
  border-color: var(--accent-border);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(16, 24, 40, 0.12), 0 2px 6px rgba(16, 24, 40, 0.08);
}

/* Reduced motion: keep emphasis without movement */
@media (prefers-reduced-motion: reduce) {
  #content > details > summary:hover,
  details[open] > summary:hover,
  #content > details > details summary:hover,
  #content > details > details[open] > summary:hover,
  .item-row:hover {
    transform: none;
  }
  .card { animation: none; }
}

.title-cell {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.title-cell input[type="checkbox"] {
  /* Custom light-weight checkbox to keep unchecked state light in light mode */
  appearance: none;
  margin-top: 3px;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 2px solid var(--gray-border);
  background: var(--card-bg);
  display: inline-block;
  position: relative;
  cursor: pointer;
}
.title-cell input[type="checkbox"]:hover { border-color: var(--accent-border); }
.title-cell input[type="checkbox"]:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.title-cell input[type="checkbox"]:checked {
  background: var(--brand);
  border-color: var(--brand);
}
.title-cell input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 9px;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: translate(-50%, -60%) rotate(45deg);
}
/* Dark theme: soften unchecked border/background */
:root[data-theme="dark"] .title-cell input[type="checkbox"] {
  border-color: #e5e7eb; /* light border for contrast on dark bg */
  background: #ffffff;   /* keep box white in dark mode */
}
:root[data-theme="dark"] .title-cell input[type="checkbox"]:hover {
  border-color: #d0d5dd;
}
/* Dark mode: when checked, keep white box and use brand-colored tick */
:root[data-theme="dark"] .title-cell input[type="checkbox"]:checked {
  background: var(--green-300);
  border-color: var(--green-300);
}
:root[data-theme="dark"] .title-cell input[type="checkbox"]:checked::after {
  border-right-color: #ffffff;
  border-bottom-color: #ffffff;
}
.item-title {
  font-weight: 600;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
}

.links { display: flex; justify-content: center; }
.link-col a {
  display: inline-block;
  margin: 0;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--link-bg);
  border: 1px solid var(--link-border);
  color: var(--link-text);
  font-weight: 600;
}
.link-col a:hover { background: var(--link-bg-hover); text-decoration: none; }
.link-col a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Dark theme links inherit --link-* tokens */

/* Item row focus ring when any child is focused */
.item-row:focus-within { box-shadow: 0 0 0 2px #cfe0ff, var(--elev-1); border-color: #cfe0ff; }

/* Responsive */
@media (max-width: 960px) {
  .item-row { grid-template-columns: 1fr repeat(2, minmax(92px, 1fr)); }
}
@media (max-width: 680px) {
  h1 { font-size: 24px; }
  .item-row { grid-template-columns: 1fr; }
  .links { justify-content: flex-start; }
}
/* (Removed unused text utilities) */
/* Ensure dark mode progress track has no border and white unfilled background */
:root[data-theme="dark"] .progress { background: #ffffff !important; border: 0 !important; }
