:root {
  --ink: #17211c;
  --muted: #5d6d66;
  --line: #dfe6e2;
  --bg: #f4f6f5;
  --card: #ffffff;
  --green: #1b7f45;
  --green-dark: #115c32;
  --green-soft: #e6f5ec;
  --amber: #8a5a12;
  --amber-soft: #fbf4e8;
  --late: #9c342c;
  --late-soft: #fdeeee;
  --radius: 4px;
  --sans: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
  --cond: "IBM Plex Sans Condensed", "Avenir Next Condensed", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

.app { min-height: 100vh; }

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 20px;
  background: rgba(244, 246, 245, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img {
  height: 36px;
  width: auto;
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.brand-text { min-width: 0; }
.brand-text strong {
  display: block;
  font-family: var(--cond);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.brand-text span { color: var(--muted); font-size: 12px; }

.nav {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.nav button {
  border: 0;
  background: transparent;
  border-radius: 2px;
  padding: 5px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.nav button[aria-current="page"] {
  background: var(--ink);
  color: white;
}

.wrap { width: min(1080px, calc(100% - 32px)); margin: 0 auto; padding: 18px 0 32px; }

.page-head { margin-bottom: 14px; max-width: 640px; }
.kicker {
  font-family: var(--cond);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
}
h1 { font-size: 22px; line-height: 1.2; letter-spacing: -0.02em; font-weight: 600; }
.lede { margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.45; }

.stats { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.stat {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  min-width: 112px;
}
.stat strong { display: block; font-size: 16px; letter-spacing: -0.02em; }
.stat span { color: var(--muted); font-size: 12px; }

.weekbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 6px;
  align-items: center;
  margin-bottom: 14px;
}
.weekbar h2 { font-size: 13px; font-weight: 600; text-align: center; }
.icon-btn, .ghost, .primary, .quiet {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: white;
  min-height: 30px;
  font-size: 13px;
}
.icon-btn { width: 30px; font-size: 16px; line-height: 1; padding: 0; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day {
  border: 1px solid var(--line);
  background: white;
  border-radius: var(--radius);
  min-height: 52px;
  padding: 4px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}
.day span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.day strong { font-size: 13px; }
.day em { font-style: normal; font-size: 10px; color: var(--green-dark); min-height: 12px; }
.day.is-selected { background: var(--ink); color: white; border-color: var(--ink); }
.day.is-selected span, .day.is-selected em { color: rgba(255,255,255,.75); }
.day.is-today:not(.is-selected) { border-color: var(--green); }
.day:disabled { opacity: 0.4; cursor: default; }

.section { margin: 16px 0; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}
.section-head h2 { font-size: 14px; }
.section-head p { color: var(--muted); font-size: 12px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; align-items: start; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card.is-done { background: #f7fbf8; }
.card h3 { font-size: 14px; letter-spacing: -0.01em; margin-top: 1px; }
.meta { color: var(--muted); font-size: 11px; font-family: var(--cond); letter-spacing: 0.04em; text-transform: uppercase; }
.sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.card-actions { display: flex; justify-content: flex-end; flex-shrink: 0; }
.primary, .ghost, .quiet { padding: 0 10px; font-weight: 600; }
.primary { background: var(--green); color: white; border-color: var(--green); }
.primary:hover { background: var(--green-dark); }
.quiet { background: transparent; color: var(--muted); border-color: transparent; min-height: 28px; }

.callout {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--late-soft);
  border: 1px solid #f3d0cc;
  margin-bottom: 8px;
}
.callout.calm { background: var(--amber-soft); border-color: #f0e0c4; }
.callout h3 { font-size: 14px; margin-bottom: 2px; }
.callout p { color: var(--muted); font-size: 12px; }

.logged { display: flex; flex-direction: column; gap: 6px; }
.log-row, .labor-row {
  display: grid;
  grid-template-columns: 72px 1fr auto auto;
  gap: 8px;
  align-items: center;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
  font-size: 13px;
}
.log-row strong, .labor-row strong { font-weight: 600; }
.log-row span, .labor-row span { color: var(--muted); font-size: 12px; }
.code {
  font-family: var(--cond);
  letter-spacing: 0.03em;
  color: var(--muted);
  font-size: 12px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.filters input, .filters select {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 30px;
  padding: 0 8px;
  font-size: 13px;
}
.filters input { flex: 1; min-width: 160px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  border: 1px solid var(--line);
  background: white;
  border-radius: var(--radius);
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  min-height: 28px;
}
.chip[aria-pressed="true"] { background: var(--green-soft); color: var(--green-dark); border-color: #b7e0c6; font-weight: 600; }

.schedule {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 10px;
  align-items: start;
}
.list, .detail, .panel, .tile, .insight, .bar-row {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.list { padding: 4px; max-height: calc(100vh - 180px); overflow: auto; }
.task-row {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 2px;
  padding: 6px 8px;
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 6px;
  align-items: center;
  font-size: 13px;
}
.task-row small { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.task-row[aria-current="true"] { background: var(--green-soft); }
.detail { padding: 12px; position: sticky; top: 64px; }
.detail h2 { font-size: 18px; letter-spacing: -0.02em; margin: 2px 0 4px; }
.detail-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }

.bar { height: 4px; background: #e7eeea; border-radius: 2px; overflow: hidden; margin: 8px 0 4px; }
.bar span { display: block; height: 100%; background: var(--green); }
.bar.over span { background: #0f766e; }

.cal { margin-top: 12px; }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head span { text-align: center; color: var(--muted); font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; }
.cal-cell {
  border: 1px solid var(--line);
  background: #fbfcfb;
  border-radius: var(--radius);
  min-height: 46px;
  padding: 4px;
  text-align: left;
}
.cal-cell strong { font-size: 12px; }
.cal-cell em { display: block; font-style: normal; font-size: 10px; color: var(--green-dark); margin-top: 4px; }
.cal-cell.has { background: var(--green-soft); border-color: #b7e0c6; }
.cal-cell:disabled { opacity: 0; border: 0; background: transparent; }

.labor-layout { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 10px; }
.block { background: white; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.block h2 { font-size: 14px; margin-bottom: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 1.2fr) minmax(60px, 1fr) auto; gap: 8px; align-items: center; padding: 6px 8px; margin-bottom: 4px; border-radius: 2px; }
.bar-row > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.bar-row strong { white-space: nowrap; font-size: 12px; }
.bar-track { height: 4px; background: #e7eeea; border-radius: 2px; overflow: hidden; }
.bar-track span { display: block; height: 100%; background: var(--green); }
.labor-row { grid-template-columns: 1fr auto auto; margin-bottom: 6px; }

.freq-block { margin-bottom: 16px; }
.freq-block h2 { font-size: 14px; margin-bottom: 2px; }
.freq-note { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.tiles { display: grid; grid-template-columns: repeat(12, minmax(68px, 1fr)); gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.tile { padding: 8px 6px; min-width: 68px; }
.tile-m { display: block; color: var(--muted); font-size: 11px; font-family: var(--cond); letter-spacing: 0.04em; text-transform: uppercase; }
.tile strong { display: block; font-size: 15px; margin: 4px 0 1px; letter-spacing: -0.02em; }
.tile strong span { color: var(--muted); font-weight: 500; font-size: 11px; }
.tile em { font-style: normal; color: var(--muted); font-size: 11px; }
.tile.short strong { color: var(--amber); }
.tile.future { background: transparent; }
.tile.now { border-color: var(--ink); }
.tile button.as-tile {
  all: unset;
  cursor: pointer;
  display: block;
  width: 100%;
}

.insights { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.insight { padding: 10px 12px; }
.insight h3 { font-size: 13px; margin-bottom: 4px; }
.insight p { color: var(--muted); font-size: 12px; line-height: 1.4; }

.quarters { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.q {
  border-radius: var(--radius);
  padding: 6px 8px;
  background: white;
  border: 1px solid var(--line);
  min-width: 108px;
  font-size: 13px;
}
.q strong { display: block; }
.q span { color: var(--muted); font-size: 12px; }
.q.miss { background: var(--late-soft); border-color: #f3d0cc; }
.q.hit { background: var(--green-soft); border-color: #b7e0c6; }
.q.wait { opacity: 0.7; }

.foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-top: 20px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.foot button { min-height: 30px; white-space: nowrap; }
.foot a { color: var(--green-dark); }

.empty { color: var(--muted); padding: 12px; font-size: 13px; }

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(23, 33, 28, 0.46);
  z-index: 30;
  display: grid;
  align-items: end;
  justify-items: center;
  padding: 12px;
}
.panel {
  width: min(420px, 100%);
  padding: 14px;
  border-radius: var(--radius);
  max-height: min(92vh, 720px);
  overflow: auto;
}
.panel h2 { font-size: 18px; letter-spacing: -0.02em; margin: 2px 0 10px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 12px; font-weight: 600; }
.field input {
  min-height: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 0 8px;
  font-weight: 400;
  font-size: 14px;
}
.presets { display: flex; flex-wrap: wrap; gap: 4px; }
.panel-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 4px; }
.mini-logs { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.mini-logs p { color: var(--muted); font-size: 12px; margin-bottom: 2px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%) translateY(8px);
  background: var(--ink);
  color: white;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 40;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

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

@media (max-width: 900px) {
  .top { position: static; flex-direction: column; align-items: stretch; padding: 8px 12px; }
  .section-head { flex-direction: column; align-items: flex-start; }
  .callout { flex-direction: column; align-items: stretch; }
  .cal-cell { min-height: 42px; padding: 3px; }
  .cal-head, .cal-grid { gap: 3px; }
  .nav { overflow-x: auto; }
  .wrap { width: min(1080px, calc(100% - 20px)); }
  h1 { font-size: 20px; }
  .schedule, .labor-layout, .insights { grid-template-columns: 1fr; }
  .list { max-height: none; }
  .detail { position: static; order: -1; }
  .tiles { grid-template-columns: repeat(12, 72px); }
  .log-row { grid-template-columns: 64px 1fr auto; }
  .log-row .quiet { grid-column: 1 / -1; justify-self: start; }
  .foot { flex-direction: column; align-items: flex-start; }
  .days { gap: 3px; }
  .day { min-height: 48px; padding: 4px 2px; }
}
@media (min-width: 720px) {
  .scrim { align-items: center; }
}
@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}
