:root {
  --paper: #f3efe4;
  --ink: #1c1915;
  --muted: #6d6458;
  --line: #ddd4c3;
  --card: #fffdf8;
  --rust: #b8431f;
  --rust-soft: #f8ebe3;
  --pine: #1e3d34;
  --pine-soft: #e7f0ec;
  --shadow: 0 18px 50px rgba(48, 32, 14, 0.08);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #efe2cc 0%, transparent 55%),
    var(--paper);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
}

.top {
  background: var(--ink);
  color: #f6f1e6;
}

.top-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 36px 20px 32px;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
  color: #e2b08a;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(32px, 5vw, 52px);
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.lede {
  max-width: 68ch;
  margin: 14px 0 0;
  color: #d9d0c2;
}

.view-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.view-nav button {
  border: 1px solid #6a5e50;
  background: transparent;
  color: #f6f1e6;
  border-radius: 999px;
  padding: 8px 16px;
  font: inherit;
  cursor: pointer;
}

.view-nav button.on {
  background: #f6f1e6;
  color: var(--ink);
  border-color: #f6f1e6;
}

.months-wrap {
  max-width: 1100px;
  margin: -28px auto 48px;
  padding: 0 20px;
}

.months-wrap[hidden],
#calcScreen[hidden] {
  display: none !important;
}

.months-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.months-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
}

.year-switch {
  display: flex;
  gap: 8px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 8px 0 14px;
}

.stat {
  background: #f7f1e6;
  border-radius: 14px;
  padding: 12px 14px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-family: var(--serif);
  font-size: 28px;
  letter-spacing: -0.03em;
  font-weight: 600;
}

.stat em {
  font-style: normal;
  color: var(--muted);
  font-size: 13px;
}

.bulletin {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--rust-soft);
  color: var(--ink);
}

.bulletin button {
  margin-left: 8px;
}

.month-chart {
  display: grid;
  grid-template-columns: repeat(12, minmax(68px, 1fr));
  gap: 8px;
  align-items: end;
  min-height: 240px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.month-col {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: stretch;
  gap: 6px;
  min-height: 220px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0;
}

.month-col .stem-wrap {
  height: 150px;
  display: flex;
  align-items: flex-end;
}

.month-col .stem {
  width: 100%;
  border-radius: 8px 8px 3px 3px;
  background: #e7b199;
  min-height: 6px;
}

.month-col.on .stem { background: var(--rust); }
.month-col.missing { cursor: default; }
.month-col.missing .stem {
  height: 8px !important;
  background: repeating-linear-gradient(-45deg, #efe7da, #efe7da 4px, #e4d8c6 4px, #e4d8c6 8px);
}

.month-col small,
.month-col b {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
}

.month-col small {
  color: var(--muted);
  font-weight: 500;
}

.delta.up { color: var(--rust); }
.delta.down { color: var(--pine); }

.wrap {
  max-width: 1100px;
  margin: -28px auto 48px;
  padding: 0 20px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 16px;
}

.panel,
.result-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.result-card {
  background:
    linear-gradient(180deg, #fffdf8 0%, #fbf6ee 100%);
}

.wide { grid-column: 1 / -1; }

h2 {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

h3 {
  margin: 18px 0 8px;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
}

.hint, .preview, .empty, .toast {
  color: var(--muted);
  margin: 0 0 14px;
  font-size: 14px;
}

.ratio-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.agreement-chip {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 14px;
}

#ratioSum.bad { color: var(--rust); }
#ratioSum.ok { color: var(--pine); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: #f6f1e6;
  z-index: 5;
  box-shadow: var(--shadow);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

.field small {
  color: var(--rust);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

.input-suffix {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}

.input-suffix em {
  font-style: normal;
  color: var(--muted);
  padding-right: 12px;
  font-size: 13px;
}

input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 12px;
  font: inherit;
  font-size: 16px;
}

.input-suffix input {
  border: 0;
  border-radius: 0;
}

input:focus {
  outline: 2px solid #e2b08a;
  outline-offset: 1px;
}

.result-head {
  display: flex;
  gap: 12px;
  align-items: end;
}

.result-head .grow { flex: 1; min-width: 0; }

.trips { width: 120px; }

.result-kicker {
  margin: 8px 0 0;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 12px;
}

.result-total {
  margin: 4px 0 0;
  font-family: var(--serif);
  font-size: clamp(42px, 6vw, 68px);
  letter-spacing: -0.04em;
  line-height: 0.95;
}

.result-diff {
  margin: 8px 0 16px;
  font-size: 18px;
}

.result-diff.up { color: var(--rust); }
.result-diff.down { color: var(--pine); }

.formula {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
  display: grid;
  gap: 8px;
}

.formula li {
  background: var(--pine-soft);
  border-radius: 12px;
  padding: 10px 12px;
  font-variant-numeric: tabular-nums;
}

.formula strong { font-weight: 650; }

.breakdown {
  list-style: none;
  padding: 0;
  margin: 0 0 16px;
  display: grid;
  gap: 8px;
}

.breakdown li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  align-items: end;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.breakdown .bar {
  height: 8px;
  width: 100%;
  border-radius: 99px;
  background: #efe7da;
  margin-top: 6px;
  overflow: hidden;
}

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

.breakdown .bar.vehicle span { background: #8d6a43; }
.breakdown .bar.driver span { background: var(--pine); }

.result-actions, .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
}

.btn.primary {
  background: var(--ink);
  color: #f6f1e6;
  border-color: var(--ink);
}

.btn.ghost { background: transparent; }
.btn.block { width: 100%; margin-bottom: 8px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.shares {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.fixed-defs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  margin: 0 0 14px;
}

.fixed-defs div {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7f1e6;
}

.fixed-defs dt {
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.fixed-defs dd {
  margin: 2px 0 0;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.liter-lock {
  margin: 4px 0 0;
  padding: 12px;
  border-radius: 12px;
  background: var(--rust-soft);
  color: var(--rust);
  font-weight: 650;
}

.log {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 6px;
}

.log li {
  font-size: 14px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

th, td {
  text-align: right;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th:first-child, td:first-child { text-align: left; }

#monthlyLog tr { cursor: pointer; }
#monthlyLog tr:hover { background: #fbf6ee; }

select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  font-size: 16px;
}

.year-field { width: 140px; flex: 0 0 140px; }

.month-picks {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin: 4px 0 8px;
}

.month-picks button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 0;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.month-picks button.on {
  background: var(--ink);
  color: #f6f1e6;
  border-color: var(--ink);
}

.month-picks button.saved:not(.on) {
  border-color: #e2b08a;
}

.month-picks button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.legend {
  display: flex;
  gap: 14px;
  margin: 8px 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.legend span::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
}

.legend .on::before { background: #1e3d34; }
.legend .half::before { background: #e2b08a; }
.legend .off::before { background: #cfc6b8; }

.day-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.day-grid .dow {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding-bottom: 4px;
}

.day {
  border: 1px solid var(--line);
  background: #f6f3ee;
  color: var(--muted);
  border-radius: 12px;
  min-height: 72px;
  padding: 6px;
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.day b { display: block; font-size: 16px; color: var(--ink); }
.day small { display: block; font-size: 11px; line-height: 1.25; }

.day.on {
  background: var(--pine-soft);
  border-color: #8eaea4;
  color: var(--pine);
}

.day.half {
  background: #f8efe0;
  border-color: #e2b08a;
  color: #7a4e12;
}

.day.empty { visibility: hidden; }

.invoice {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 8px 0 14px;
}

.bill-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: start;
}

.bill-kicker {
  margin: 0 0 6px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--rust);
}

.bill-meta {
  margin: 0;
  min-width: 240px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7f1e6;
}

.bill-meta div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 3px 0;
}

.bill-meta dt { color: var(--muted); }
.bill-meta dd { margin: 0; font-weight: 600; text-align: right; }

.bill-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 16px 0;
}

.bill-parties > div {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}

.bill-parties h3 { margin-top: 0; }
.bill-parties p { margin: 0 0 8px; }

.bill-lines { font-variant-numeric: tabular-nums; }
.bill-lines td, .bill-lines th { white-space: nowrap; }

.bill-foot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 16px;
  align-items: end;
  margin-top: 16px;
}

.bill-reason {
  margin: 0;
  padding: 12px 14px;
  background: #f7f1e6;
  border-radius: 12px;
}

.bill-totals {
  width: 100%;
  border-collapse: collapse;
}

.bill-totals td {
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}

.bill-totals td:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bill-totals tr.pay td {
  font-weight: 700;
  font-size: 18px;
  border-bottom: 0;
  padding-top: 10px;
}

#workTable tr { cursor: pointer; }
#workTable tr.on { background: var(--pine-soft); }

@media (max-width: 860px) {
  .invoice { grid-template-columns: 1fr 1fr; }
  .day { min-height: 58px; padding: 4px; }
  .day small { display: none; }
  .day.on small, .day.half small { display: block; }
}
#monthTable tr.on { background: var(--rust-soft); }
#kutahyaDays tr.on { background: var(--rust-soft); }

.linkish {
  border: 0;
  background: transparent;
  color: var(--rust);
  cursor: pointer;
  font: inherit;
}

.note p { max-width: 75ch; }

.example {
  padding: 12px 14px;
  background: #f7f1e6;
  border-radius: 12px;
  font-variant-numeric: tabular-nums;
}

.toast:empty { display: none; }
.toast.show { color: #f6f1e6; }

@media (max-width: 860px) {
  .wrap { grid-template-columns: minmax(0, 1fr); margin-top: 16px; }
  .months-wrap { margin-top: 16px; }
  .months-head, .stat-row, .ratio-row, .fixed-defs { display: grid; grid-template-columns: 1fr; }
  .stat strong { font-size: 24px; }
  .result-card { grid-row: auto; }
  .row { grid-template-columns: 1fr; }
  .result-head { flex-direction: column; align-items: stretch; }
  .trips, .year-field { width: auto; flex: 1 1 auto; }
  .month-picks { grid-template-columns: repeat(4, 1fr); }
  .bill-head, .bill-parties, .bill-foot { display: grid; grid-template-columns: 1fr; }
  .bill-meta { min-width: 0; }
}

@media print {
  .top, .result-actions, .btn, .panel:not(.note) { display: none !important; }
  .wrap { display: block; margin: 0; }
  .result-card, .note { display: block !important; box-shadow: none; }
  .note .btn { display: none !important; }
}
