:root {
  --soil: #292319;
  --root: #5a3b25;
  --leaf: #2f6b49;
  --sprout: #7fa86b;
  --sun: #f2b84b;
  --clay: #c7653f;
  --cream: #fbf4e7;
  --paper: #fffaf0;
  --line: #dfd0bd;
  --muted: #786c5d;
  --good: #2f6b49;
  --warn: #bb6b2d;
  --bad: #a33a32;
  --shadow: 0 18px 60px rgba(41, 35, 25, 0.13);
  color: var(--soil);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--cream);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 18%, rgba(242, 184, 75, 0.2), transparent 30%),
    linear-gradient(145deg, #fff7e7, #ece2d1);
}

.login-panel {
  width: min(440px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 8px;
  padding: 28px;
}

.wordmark {
  display: flex;
  align-items: center;
  margin-bottom: 28px;
}

.brand-logo {
  display: block;
  width: 168px;
  max-width: 100%;
  height: auto;
}

.wordmark span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 5px;
}

.login-panel h1 {
  margin: 0 0 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 8vw, 3rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.login-panel p {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.45;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-form input,
.field input,
.field select,
.inline-input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  background: #fffdf7;
  color: var(--soil);
  border-radius: 6px;
  padding: 8px 10px;
}

.primary-button,
.secondary-button,
.icon-button,
.danger-button {
  min-height: 38px;
  border-radius: 6px;
  color: #fffdf7;
  background: var(--leaf);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  font-weight: 700;
}

.secondary-button {
  background: #efe3d1;
  color: var(--soil);
}

.quiet-button {
  min-height: 34px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

.danger-button,
.icon-button.danger {
  background: #e8d5cf;
  color: #8b3f31;
}

.primary-button:disabled,
.secondary-button:disabled,
.danger-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.icon-button {
  width: 38px;
  padding: 0;
}

.error {
  color: var(--bad);
  font-weight: 700;
  min-height: 20px;
}

.auth-note {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.auth-success {
  display: grid;
  gap: 4px;
  min-height: 0;
  padding: 12px 14px;
  border: 1px solid rgba(47, 107, 73, 0.24);
  border-radius: 8px;
  background: #eef7ed;
  color: var(--good);
  line-height: 1.35;
}

.auth-success strong {
  font-size: 0.95rem;
}

.auth-success span {
  color: #466344;
  font-size: 0.9rem;
}

.login-help {
  display: grid;
  gap: 10px;
  color: var(--muted);
}

.login-help summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
}

.login-help .quiet-button {
  width: 100%;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  background: #312719;
  color: #fff6e6;
  min-height: 100vh;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  align-self: start;
}

.sidebar .wordmark {
  margin-bottom: 30px;
}

.sidebar .brand-logo {
  width: 176px;
  filter: brightness(1.35) saturate(0.9);
}

.sidebar .wordmark span {
  color: #dcc8ae;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button {
  color: #fff6e6;
  background: transparent;
  border-radius: 6px;
  min-height: 40px;
  text-align: left;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav button.active,
.nav button:hover {
  background: rgba(255, 246, 230, 0.12);
}

.nav svg,
.tiny-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.main {
  padding: 22px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hidden-file {
  display: none;
}

.mode-pill {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  background: #fffdf7;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.dashboard-note {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(47, 107, 73, 0.22);
  border-left: 4px solid var(--leaf);
  border-radius: 8px;
  background: #f2f7ea;
  color: var(--soil);
}

.dashboard-note strong {
  font-size: 0.95rem;
}

.dashboard-note span {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.dashboard-note button {
  display: inline;
  min-height: 0;
  padding: 0;
  background: transparent;
  color: var(--leaf);
  font: inherit;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.compact-metrics {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  padding: 14px 16px 0;
}

.forecast-totals {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.month-notes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  padding: 14px 16px 0;
}

.month-note {
  min-height: 72px;
  border: 1px solid rgba(187, 107, 45, 0.28);
  border-left: 4px solid var(--sun);
  border-radius: 8px;
  background: #fff5d8;
  color: var(--soil);
  padding: 10px 12px;
  text-align: left;
}

.month-note:hover,
.month-note:focus-visible {
  border-color: rgba(187, 107, 45, 0.48);
  background: #fff0c2;
}

.month-note span,
.month-note small {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.month-note strong {
  display: block;
  margin: 4px 0;
  font-size: 1rem;
  line-height: 1.2;
}

.month-note.drops {
  border-left-color: var(--warn);
}

.metric {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.metric label,
.field label,
.section-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 800;
  margin-bottom: 7px;
}

.metric strong {
  display: block;
  font-size: 1.55rem;
  line-height: 1.1;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(41, 35, 25, 0.05);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin: 0;
  font-size: 1rem;
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tabs button {
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--root);
  background: #efe3d1;
  font-weight: 800;
}

.tabs button.active {
  background: var(--leaf);
  color: #fffdf7;
}

.partner-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.partner-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  position: relative;
  overflow: hidden;
}

.partner-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: var(--leaf);
}

.partner-card.warn::before {
  background: var(--warn);
}

.partner-card.bad::before {
  background: var(--bad);
}

.partner-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 5px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--good);
}

.warn .status-dot {
  background: var(--warn);
}

.bad .status-dot {
  background: var(--bad);
}

.partner-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.stat small {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

.stat strong {
  font-size: 1.05rem;
}

.table-scroll {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: middle;
  font-size: 0.9rem;
}

th {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.68rem;
  background: #f5ead9;
  position: sticky;
  top: 0;
  z-index: 1;
}

.person-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sort-button {
  width: 100%;
  min-height: 24px;
  padding: 0;
  color: inherit;
  background: transparent;
  text-align: left;
  text-transform: inherit;
  letter-spacing: inherit;
  font-size: inherit;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sort-button span {
  color: var(--leaf);
  font-size: 0.62rem;
  text-transform: lowercase;
}

.client-name {
  min-width: 240px;
  font-weight: 800;
}

.client-link {
  max-width: 100%;
  padding: 0;
  background: transparent;
  color: var(--soil);
  text-align: left;
  font-weight: 900;
  line-height: 1.25;
}

.client-link:hover span,
.client-link:focus-visible span {
  color: var(--leaf);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.client-link small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.muted {
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eadfcf;
  color: var(--root);
  font-weight: 800;
  font-size: 0.72rem;
}

.pill.active {
  background: rgba(47, 107, 73, 0.14);
  color: var(--leaf);
}

.pill.closed {
  background: #e8d5cf;
  color: #8b3f31;
}

.closed-section {
  margin-top: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(41, 35, 25, 0.05);
  overflow: hidden;
}

.closed-section summary {
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 900;
  display: flex;
  align-items: center;
  gap: 10px;
}

.closed-section summary span {
  background: #eadfcf;
  color: var(--root);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.78rem;
}

.forecast-grid {
  display: grid;
  grid-template-columns: 170px repeat(var(--forecast-months, 12), minmax(112px, 1fr));
  min-width: max(100%, calc(170px + (var(--forecast-months, 12) * 112px)));
}

.forecast-cell {
  min-height: 52px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 8px;
  background: #fffdf7;
}

.month-button,
.month-cell-button {
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0;
  border-radius: 4px;
}

.month-button {
  min-height: 28px;
  font-weight: 900;
  text-transform: uppercase;
}

.month-button.active,
.month-button:hover,
.month-cell-button:hover {
  color: var(--leaf);
}

.month-button.active {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.forecast-cell.head {
  background: #f5ead9;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.forecast-cell.name {
  font-weight: 900;
  background: var(--paper);
  position: sticky;
  left: 0;
  z-index: 2;
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: #e9d7bd;
  overflow: hidden;
  margin-top: 6px;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--leaf);
}

.over span {
  background: var(--bad);
}

.forecast-inputs {
  margin-top: 16px;
}

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(760px, 100%);
  background: var(--paper);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform 180ms ease;
  z-index: 10;
  overflow: auto;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  padding: 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.drawer-header h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  line-height: 1;
}

.drawer-body {
  padding: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.assignment-editor {
  display: grid;
  gap: 10px;
}

.assignment-header {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.assignment-row {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr 1fr 1fr 38px;
  gap: 8px;
  align-items: end;
}

.calculated-cell {
  min-height: 38px;
  border: 1px solid var(--line);
  background: #f5ead9;
  border-radius: 6px;
  padding: 9px 10px;
  font-weight: 900;
}

.mini-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.split-panel {
  border: 1px solid var(--line);
  background: #fffdf7;
  border-radius: 8px;
  padding: 12px;
  margin: 0 0 16px;
}

.split-panel p {
  margin: -2px 0 12px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.split-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 8px;
}

.split-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f5ead9;
  padding: 9px 10px;
}

.split-item.owner {
  border-color: rgba(47, 107, 73, 0.35);
  background: rgba(47, 107, 73, 0.1);
}

.split-item small {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.split-item strong {
  font-size: 1rem;
}

.save-strip {
  position: sticky;
  bottom: 0;
  padding: 14px 18px;
  background: rgba(255, 250, 240, 0.94);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.drawer-error,
.drawer-message {
  flex: 1 0 100%;
  border-radius: 6px;
  padding: 9px 10px;
  font-weight: 800;
}

.drawer-error {
  background: rgba(163, 58, 50, 0.1);
  color: var(--bad);
}

.drawer-message {
  background: rgba(47, 107, 73, 0.1);
  color: var(--good);
}

.save-spacer {
  flex: 1;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: 0;
    position: static;
  }

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

  .metric-grid,
  .partner-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .topbar {
    display: grid;
  }

  .toolbar {
    justify-content: flex-start;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 14px;
  }

  .nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .metric-grid,
  .partner-grid,
  .form-grid,
  .mini-summary,
  .split-grid {
    grid-template-columns: 1fr;
  }

  .assignment-row {
    grid-template-columns: 1fr 1fr;
  }
}

/* Forecast client matrix (hours & revenue by client) */
.matrix-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.matrix-table th, .matrix-table td { padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.matrix-table thead th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: var(--bg-soft); }
.matrix-table .row-label { text-align: left; font-weight: 500; color: var(--ink); position: sticky; left: 0; background: var(--surface); z-index: 1; }
.matrix-table thead .row-label, .matrix-table tr.matrix-divider .row-label { background: var(--bg-soft); }
.matrix-table tr.matrix-strong td, .matrix-table tr.matrix-strong .row-label { font-weight: 700; color: var(--ink); }
.matrix-table tr.matrix-muted td, .matrix-table tr.matrix-muted .row-label { color: var(--muted); font-size: 12px; }
.matrix-table tr.matrix-divider td { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: var(--bg-soft); padding-top: 10px; }
.matrix-table td.cell-warn { background: #fef3c7; color: #b45309; font-weight: 600; }
.matrix-table td.cell-over { background: #fee2e2; color: #b91c1c; font-weight: 700; }
.matrix-table tbody tr:hover td, .matrix-table tbody tr:hover .row-label { background: var(--accent-soft); }
.matrix-table .row-label .client-link { font-weight: 600; }

/* Highlight the matrix summary rows at the top for readability */
.matrix-table tr.matrix-summary td,
.matrix-table tr.matrix-summary .row-label { background: var(--accent-soft); }
.matrix-table tr.matrix-summary:hover td,
.matrix-table tr.matrix-summary:hover .row-label { background: #e4f0c4; }

/* Forecast: compact chart + month-detail side by side */
.forecast-split { display: grid; grid-template-columns: 1.35fr 1fr; gap: 18px; align-items: stretch; margin-top: 18px; }
.forecast-split > .panel { margin-top: 0; }
@media (max-width: 980px) { .forecast-split { grid-template-columns: 1fr; } }
.detail-card .card-sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.big-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 4px; }
.big-stat { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.big-stat.primary { background: var(--accent-soft); border-color: var(--accent-light); }
.big-num { font-family: var(--serif); font-weight: 400; font-size: clamp(24px, 3vw, 32px); line-height: 1; color: var(--accent-deep); letter-spacing: -0.01em; }
.big-stat.primary .big-num { color: var(--accent); }
.big-unit { font-size: 0.55em; color: var(--muted); margin-left: 1px; }
.big-label { margin-top: 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }

/* Forecast vs actuals tab */
.sync-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.actuals-stats { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 760px) { .actuals-stats { grid-template-columns: 1fr 1fr; } }
.big-stat.stat-over { background: #eef6d9; border-color: var(--accent-light); }
.big-stat.stat-over .big-num { color: var(--accent); }
.big-stat.stat-under { background: #fdeede; border-color: #e7c3a3; }
.big-stat.stat-under .big-num { color: #b45309; }
.matrix-table td.cell-good { background: #eef6d9; color: var(--accent); font-weight: 600; }

/* Actuals: needs-mapping callout */
.needs-mapping { border-color: #e7c3a3; background: #fdf6ee; }
.unmapped-list { display: flex; flex-wrap: wrap; gap: 8px; }
.unmapped-chip { display: inline-flex; align-items: center; gap: 8px; background: #fff; border: 1px solid #e7c3a3; border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.unmapped-chip strong { color: var(--ink); font-weight: 600; }
.unmapped-chip span { color: #b45309; font-variant-numeric: tabular-nums; font-size: 12px; }
