:root {
  --ink: #172133;
  --muted: #657187;
  --paper: #f7f9fc;
  --surface: #ffffff;
  --line: #dce3ee;
  --line-strong: #b8c4d6;
  --cobalt: #2457d6;
  --cobalt-dark: #183d9b;
  --aqua: #168b89;
  --coral: #d95748;
  --sun: #e8a91c;
  --success: #16845b;
  --danger: #bd3f39;
  --shadow: 0 18px 48px rgba(31, 48, 78, 0.10);
  --display: "Avenir Next", Avenir, "Helvetica Neue", sans-serif;
  --body: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --data: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--paper); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: var(--body);
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(36, 87, 214, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(36, 87, 214, 0.045) 1px, transparent 1px);
  background-size: 24px 24px;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 3px solid rgba(36, 87, 214, 0.3);
  outline-offset: 2px;
}

h1, h2, p { margin-top: 0; }
h1, h2 { font-family: var(--display); letter-spacing: -0.035em; }
h1 { margin-bottom: 0; font-size: clamp(1.8rem, 3vw, 3rem); line-height: 1; }
h2 { margin-bottom: 0.55rem; font-size: 1.45rem; }

.eyebrow {
  margin-bottom: 0.45rem;
  color: var(--cobalt);
  font-family: var(--data);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lede { color: var(--muted); line-height: 1.6; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.auth-card {
  width: min(100%, 480px);
  position: relative;
  overflow: hidden;
  padding: clamp(2rem, 6vw, 3.6rem);
  border: 1px solid var(--line);
  border-radius: 28px 8px 28px 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.brand-mark {
  position: absolute;
  top: -1.5rem;
  right: 1rem;
  color: rgba(36, 87, 214, 0.09);
  font-family: Georgia, serif;
  font-size: 10rem;
  line-height: 1;
  transform: rotate(-7deg);
  user-select: none;
}

.stack-form { display: grid; gap: 1rem; margin-top: 1.75rem; }
.stack-form.compact { margin-top: 1.2rem; gap: 0.75rem; }

label {
  display: grid;
  gap: 0.42rem;
  color: #344057;
  font-size: 0.82rem;
  font-weight: 700;
}

label span { color: var(--muted); font-weight: 500; }

input, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0.66rem 0.75rem;
  color: var(--ink);
  background: var(--surface);
}

input:hover, select:hover { border-color: #8998b1; }

.button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0.72rem 1rem;
  font-weight: 800;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: 0.45; }
.button.primary { color: white; background: var(--cobalt); box-shadow: 0 7px 18px rgba(36, 87, 214, 0.22); }
.button.primary:hover:not(:disabled) { background: var(--cobalt-dark); }
.button.secondary { color: var(--cobalt-dark); background: #e8eeff; }
.button.small { min-height: 34px; padding: 0.45rem 0.72rem; font-size: 0.78rem; }

.notice { padding: 0.8rem 0.9rem; border-radius: 8px; font-size: 0.87rem; line-height: 1.45; }
.notice.error { color: #822d2d; border: 1px solid #efb9b3; background: #fff0ee; }
.notice.success { color: #166140; border: 1px solid #a7ddc4; background: #ecfaf4; }
.page-notice { margin: 1rem 0; }

.app-shell { width: min(100% - 36px, 1500px); margin: 0 auto; padding: 2rem 0 7rem; }

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  padding: 1rem 0 1.6rem;
}

.user-menu { display: flex; align-items: center; gap: 0.8rem; color: var(--muted); font-size: 0.86rem; }
.user-menu form { margin: 0; }
.text-button { border: 0; padding: 0; color: var(--cobalt); background: transparent; font-weight: 800; }

.tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  border-bottom: 1px solid var(--line-strong);
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 0.9rem 1rem 0.75rem;
  color: var(--muted);
  background: transparent;
  font-weight: 750;
  white-space: nowrap;
}

.tab.active { color: var(--ink); border-bottom-color: var(--cobalt); }
.count-badge { display: inline-grid; place-items: center; min-width: 24px; height: 20px; margin-left: 0.35rem; border-radius: 99px; padding: 0 0.4rem; color: #fff; background: var(--coral); font: 700 0.68rem var(--data); }

.panel { display: none; padding-top: 1.5rem; }
.panel.active { display: block; }

.month-rail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 1rem;
}

.month-control { display: flex; align-items: center; gap: 0.4rem; }
.month-control input { width: 164px; font-family: var(--data); font-weight: 700; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--cobalt); background: var(--surface); font-weight: 900; }

.equation-key { display: flex; align-items: center; gap: 0.8rem; max-width: 490px; }
.equation-key .sigma { color: var(--cobalt); font-family: Georgia, serif; font-size: 3.3rem; line-height: 1; }
.equation-key strong, .equation-key small { display: block; }
.equation-key small { margin-top: 0.15rem; color: var(--muted); line-height: 1.35; }

.table-card { position: relative; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.table-scroller { overflow: auto; max-height: calc(100vh - 330px); min-height: 340px; border-radius: inherit; }
.allocation-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.8rem; }
.allocation-table th, .allocation-table td { border-right: 1px solid #e8edf4; border-bottom: 1px solid #e8edf4; padding: 0.55rem; text-align: center; }
.allocation-table th { position: sticky; top: 0; z-index: 4; min-width: 105px; color: #4e5a70; background: #f1f5fb; font: 700 0.68rem var(--data); letter-spacing: 0.025em; text-transform: uppercase; }
.allocation-table th:first-child, .allocation-table td:first-child { position: sticky; left: 0; z-index: 3; min-width: 220px; text-align: left; background: var(--surface); }
.allocation-table th:first-child { z-index: 5; background: #edf2fb; }
.allocation-table tr:last-child td { border-bottom: 0; }
.allocation-table tr.changed td { background-color: #fbfcff; }
.allocation-table tr.changed td:first-child { background-color: #f2f6ff; box-shadow: inset 4px 0 0 var(--cobalt); }
.allocation-table tr.invalid td:first-child { box-shadow: inset 4px 0 0 var(--coral); }
.contractor-name { display: block; font-weight: 800; font-size: 0.85rem; }
.plan-meta { display: block; margin-top: 0.2rem; color: var(--muted); font: 0.65rem var(--data); }
.allocation-input { min-width: 86px; min-height: 36px; padding: 0.42rem; text-align: right; font: 700 0.78rem var(--data); }
.percent-wrap { position: relative; }
.percent-wrap::after { content: "%"; position: absolute; right: 0.45rem; top: 50%; transform: translateY(-50%); color: #8793a7; pointer-events: none; }
.percent-wrap input { padding-right: 1.3rem; }
.total-cell { min-width: 88px; }
.total-pill { display: inline-flex; align-items: center; justify-content: center; min-width: 68px; padding: 0.45rem; border-radius: 99px; color: var(--success); background: #e8f7f0; font: 800 0.75rem var(--data); }
.total-pill.bad { color: var(--danger); background: #ffedeb; }
.loading-state { position: absolute; inset: 0; display: grid; place-items: center; border-radius: inherit; color: var(--muted); background: rgba(255, 255, 255, 0.86); }
.loading-state.hidden { display: none; }

.save-dock {
  position: sticky;
  bottom: 1rem;
  z-index: 8;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  width: min(100% - 2rem, 900px);
  margin: 1rem auto 0;
  padding: 0.85rem;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 35px rgba(31, 48, 78, 0.18);
  backdrop-filter: blur(12px);
}
.note-field { flex: 1; }
.note-field input { min-height: 38px; }
.save-summary { display: flex; align-items: center; gap: 1rem; }
.save-summary span { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 2rem; margin: 0.6rem 0 1rem; }
.section-heading > p { max-width: 600px; margin-bottom: 0.2rem; color: var(--muted); line-height: 1.5; }
.card-list { display: grid; gap: 0.7rem; }
.vendor-card { display: grid; grid-template-columns: minmax(220px, 1fr) auto minmax(230px, 0.8fr); align-items: center; gap: 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.vendor-card h3 { margin: 0 0 0.25rem; font-size: 0.95rem; }
.vendor-card p { margin: 0; color: var(--muted); font-size: 0.75rem; }
.vendor-amount { color: var(--coral); font: 800 0.92rem var(--data); }
.map-controls { display: flex; gap: 0.5rem; }
.map-controls select { min-height: 36px; padding: 0.45rem; }
.empty-card { padding: 2rem; border: 1px dashed var(--line-strong); border-radius: 10px; color: var(--muted); text-align: center; background: rgba(255,255,255,.65); }

.people-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.form-card { padding: 1.25rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.roster-heading { margin-top: 2rem; }
.user-list { overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.85rem 1rem; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: 0; }
.user-row strong, .user-row small { display: block; }
.user-row small { margin-top: 0.2rem; color: var(--muted); font-family: var(--data); }
.status-dot { color: var(--success); font-size: 0.75rem; }

.toast { position: fixed; right: 1.5rem; bottom: 1.5rem; z-index: 20; max-width: 430px; transform: translateY(140%); padding: 0.9rem 1rem; border-radius: 9px; color: white; background: var(--ink); box-shadow: var(--shadow); transition: transform 180ms ease; }
.toast.show { transform: translateY(0); }
.toast.error { background: #8c302d; }

@media (max-width: 900px) {
  .month-rail, .section-heading { align-items: flex-start; flex-direction: column; gap: 1rem; }
  .people-grid { grid-template-columns: 1fr; }
  .vendor-card { grid-template-columns: 1fr; }
  .save-dock { width: 100%; }
}

@media (max-width: 620px) {
  .app-shell { width: min(100% - 20px, 1500px); padding-top: 1rem; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 0.8rem; }
  .equation-key { display: none; }
  .save-dock { align-items: stretch; flex-direction: column; bottom: 0.5rem; }
  .save-summary { justify-content: space-between; }
  .save-summary span { white-space: normal; }
  .auth-shell { padding: 1rem; }
  .auth-card { padding: 1.6rem; }
}

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

