:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --sunk: #efede7;
  --ink: #1d1f1e;
  --ink-2: #4f5453;
  --ink-3: #686d6c;
  --line: #e2dfd7;
  --line-2: #cfcbc1;
  --focus: #2f5d62;

  --on: #3d6b4e;
  --on-soft: #e3ece4;
  --under: #8a5a00;
  --under-soft: #f6ead0;
  --over: #a03c28;
  --over-soft: #f6e1db;
  --none: #5d6261;
  --none-soft: #e9e8e3;

  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --serif: "Newsreader", Georgia, serif;
  --radius: 10px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--sans);
  font-variant-numeric: tabular-nums;
  caret-color: var(--focus);
  -webkit-font-smoothing: antialiased;
}
::selection { background: #cfe0dd; color: var(--ink); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
* { scrollbar-color: var(--line-2) transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Banner */
.sample-banner {
  margin: 0;
  display: flex; gap: 8px; align-items: center; justify-content: center;
  padding: 8px 16px;
  background: var(--ink);
  color: #ecebe6;
  font-size: 13px;
  text-align: center;
}
.sample-banner svg { flex: none; }
.sample-banner strong { font-weight: 600; color: #fff; }

.shell { max-width: 1120px; margin: 0 auto; padding: 0 16px 32px; }

/* Masthead */
.masthead { padding: 28px 0 20px; }
.product {
  margin: 0 0 14px;
  font-size: 13px; font-weight: 600; letter-spacing: 0.01em;
  display: flex; align-items: center; gap: 8px;
}
.product::before {
  content: ""; width: 18px; height: 18px; border-radius: 5px;
  background: var(--ink) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M4 13.5 L14 4.5' stroke='%23f6f5f1' stroke-width='1.4' stroke-dasharray='1.8 1.8'/%3E%3Cpath d='M4 13.5 L8.5 10 L14 9.5' stroke='%23f6f5f1' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 18px no-repeat;
}
h1 {
  margin: 0;
  font: 500 clamp(30px, 6.4vw, 46px)/1.08 var(--serif);
  letter-spacing: -0.015em;
  text-wrap: balance;
  max-width: 22ch;
}
h1 .count { font-variant-numeric: lining-nums tabular-nums; }
.context { margin: 10px 0 0; color: var(--ink-2); max-width: 70ch; }
.context .sep { color: var(--line-2); padding: 0 6px; }

/* Toolbar */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: end;
  padding: 16px 0 18px;
  border-top: 1px solid var(--line);
}
.field { display: grid; gap: 5px; min-width: 0; }
.field-label { font-size: 12px; font-weight: 500; color: var(--ink-2); }
.field-client { flex: 1 1 200px; max-width: 280px; }
.select-wrap { position: relative; display: block; }
.select-wrap::after {
  content: ""; position: absolute; right: 12px; top: 50%; width: 7px; height: 7px;
  border-right: 1.5px solid var(--ink-2); border-bottom: 1.5px solid var(--ink-2);
  transform: translateY(-70%) rotate(45deg); pointer-events: none;
}
select, input {
  width: 100%; height: 40px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px;
  appearance: none;
}
select { padding-right: 32px; }
input::placeholder { color: var(--ink-3); }
select:hover, input:hover { border-color: #b4afa3; }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--sunk); border-radius: 9px;
}
.segmented button {
  height: 34px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent;
  color: var(--ink-2); font-size: 14px; white-space: nowrap;
}
.segmented button[aria-checked="true"] {
  background: var(--surface); color: var(--ink); font-weight: 500;
  box-shadow: 0 1px 2px rgba(29, 31, 30, 0.12), 0 0 0 1px rgba(29, 31, 30, 0.04);
}

.stepper {
  display: inline-flex; align-items: center; height: 40px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px;
}
.stepper button {
  width: 38px; height: 100%; border: 0; background: transparent; color: var(--ink-2);
  display: grid; place-items: center;
}
.stepper button:hover { color: var(--ink); background: var(--sunk); }
.stepper button:first-child { border-radius: 7px 0 0 7px; }
.stepper button:last-child { border-radius: 0 7px 7px 0; }
.stepper output {
  min-width: 64px; text-align: center; font-weight: 500;
  border-inline: 1px solid var(--line); line-height: 38px;
}

/* Table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(29, 31, 30, 0.04);
  overflow: hidden;
}
.pacing { width: 100%; border-collapse: collapse; }
.pacing th, .pacing td { padding: 12px 14px; text-align: left; vertical-align: middle; }
.pacing thead th {
  font-size: 12px; font-weight: 500; color: var(--ink-2);
  border-bottom: 1px solid var(--line); background: #fbfaf8;
  white-space: nowrap;
}
.pacing .c-num { text-align: right; }
.pacing tbody tr.row { border-top: 1px solid var(--line); cursor: pointer; transition: background-color 120ms; }
.pacing tbody tr.row:first-child { border-top: 0; }
.pacing tbody tr.row:hover { background: #faf9f6; }
.pacing tbody tr.row[aria-expanded="true"] { background: #f7f6f2; }
.pacing tbody tr.group + tr.row { border-top: 0; }

.client-name { font-weight: 500; display: block; }
.plat-inline { display: none; }
.plat { color: var(--ink-2); }

.budget-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; background: none; border-radius: 6px;
  padding: 3px 6px; margin: -4px -7px -4px 0;
}
.budget-btn svg { color: var(--ink-3); opacity: 0.55; transition: opacity 120ms; }
.budget-btn:hover { border-color: var(--line-2); background: var(--surface); }
.budget-btn:hover svg, .budget-btn:focus-visible svg { opacity: 1; }
.budget-edit { display: inline-flex; align-items: center; gap: 6px; }
.budget-edit .money-input { width: 112px; }
.money-input { position: relative; display: block; }
.money-input > span {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none;
}
.money-input input { padding-left: 22px; }
.budget-edit input { height: 34px; text-align: right; }

/* Used: number plus a track with the expected tick */
.used { display: grid; grid-template-columns: 3.2em 1fr; align-items: center; gap: 10px; min-width: 170px; }
.used-num { text-align: right; font-weight: 500; }
.track {
  position: relative; height: 8px; border-radius: 4px; background: var(--sunk);
}
.track .fill { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: #8f948f; }
.track .tick {
  position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px;
  background: var(--ink); border-radius: 1px;
}
.track .overflow {
  position: absolute; right: -6px; top: 50%; transform: translateY(-50%);
  width: 6px; height: 10px; background: var(--over); clip-path: polygon(0 0, 100% 50%, 0 100%);
}
tr[data-status="on"] .fill { background: #8aa894; }
tr[data-status="under"] .fill { background: #d9a648; }
tr[data-status="over"] .fill { background: #c9705d; }
.used-m { display: none; }

/* Status: word + shape, colour only reinforces */
.status {
  display: inline-flex; align-items: center; gap: 7px;
  height: 28px; padding: 0 10px 0 8px; border-radius: 14px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.status svg { flex: none; }
.status .gap { font-weight: 400; opacity: 0.9; }
.status-on { color: var(--on); background: var(--on-soft); }
.status-under { color: var(--under); background: var(--under-soft); }
.status-over { color: var(--over); background: var(--over-soft); }
.status-none { color: var(--none); background: var(--none-soft); }

tr.group th {
  padding: 18px 14px 8px; background: var(--surface);
  border-top: 1px solid var(--line);
  font-size: 14px; font-weight: 600;
}
tr.group:first-child th { border-top: 0; }
tr.group .group-meta { font-weight: 400; color: var(--ink-2); margin-left: 8px; }

/* Detail */
tr.detail > td { padding: 0; border-top: 1px solid var(--line); background: #fbfaf8; }
.detail-inner { padding: 20px 20px 22px; display: grid; gap: 18px; animation: open 260ms var(--ease); }
@keyframes open { from { opacity: 0; transform: translateY(-4px); } }
.detail-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; align-items: baseline; }
.detail-head h2 { margin: 0; font: 500 22px/1.2 var(--serif); }
.detail-head h2 span { color: var(--ink-2); }
.facts { display: flex; flex-wrap: wrap; gap: 10px 28px; margin: 0; }
.facts div { display: grid; gap: 1px; }
.facts dt { font-size: 12px; color: var(--ink-2); }
.facts dd { margin: 0; font-weight: 500; font-size: 16px; }
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text {
  font-family: var(--sans); font-size: 12px; fill: var(--ink-2);
  paint-order: stroke; stroke: #fbfaf8; stroke-width: 4px; stroke-linejoin: round;
}
.chart .lbl-strong { fill: var(--ink); font-weight: 600; }
.chart .lbl-flag { fill: var(--under); font-weight: 600; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.loading { color: var(--ink-2); padding: 12px 0; }

.btn {
  height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--surface); font-weight: 500; font-size: 14px;
  display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { background: var(--sunk); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #343836; }
.btn-danger { color: var(--over); }
.btn-danger.confirm { background: var(--over); border-color: var(--over); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }
.confirm-text { color: var(--ink); font-size: 14px; }

.empty { margin: 0; padding: 32px 16px; text-align: center; color: var(--ink-2); }

/* Add */
.add { padding: 28px 0 8px; }
.add h2 { margin: 0 0 12px; font: 500 22px/1.2 var(--serif); }
.add form {
  display: grid; gap: 12px; align-items: end;
  grid-template-columns: minmax(180px, 2fr) minmax(120px, 1fr) minmax(130px, 1fr) auto;
}
.add .btn { height: 40px; padding: 0 22px; }
.form-msg { grid-column: 1 / -1; margin: 0; min-height: 1.5em; font-size: 14px; color: var(--ink-2); }
.form-msg.error { color: var(--over); }
.inline-msg { font-size: 13px; color: var(--over); }

.foot {
  margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 24px;
  font-size: 13px; color: var(--ink-2);
}
.foot p { margin: 0; max-width: 70ch; }

/* Phone: each row becomes a compact block */
@media (max-width: 760px) {
  body { font-size: 15px; }
  .masthead { padding: 22px 0 16px; }
  .toolbar { gap: 12px; }
  .field-client { flex-basis: 100%; max-width: none; }
  .field-threshold .field-label { white-space: nowrap; }

  .table-wrap { border-radius: 12px; }
  .pacing thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .pacing, .pacing tbody { display: block; }
  .pacing tbody tr.row {
    display: flex; flex-wrap: wrap; align-items: center;
    row-gap: 8px; padding: 14px 14px 12px;
  }
  .pacing tbody tr.row td { padding: 0; }
  .pacing tbody tr.row td.c-client { flex: 1 1 0; min-width: 0; padding-right: 10px; order: 1; }
  .pacing td.c-platform, .pacing td.c-month { display: none; }
  .pacing tbody tr.row td.c-status { flex: none; order: 2; }
  .pacing tbody tr.row td.c-used { flex: 0 0 100%; padding-top: 4px; order: 3; }
  .pacing tbody tr.row td.c-spent { order: 4; text-align: left; font-weight: 500; }
  .pacing tbody tr.row td.c-budget { order: 5; text-align: left; color: var(--ink-2); padding-left: 5px; }
  .detail-head h2 .plat-sub { display: block; }
  .detail-head h2 .dot { display: none; }
  .plat-inline { display: block; font-size: 13px; color: var(--ink-2); }
  .client-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .used { grid-template-columns: 1fr; gap: 6px; min-width: 0; }
  .used-num { display: none; }
  .used-m { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); }
  .used-m b { color: var(--ink); font-weight: 600; }
  .budget-btn { margin: -4px 0; padding: 3px 5px 3px 2px; }
  .m-only { display: inline; }

  tr.group, tr.detail { display: block; }
  tr.group th { display: block; padding: 16px 14px 4px; }
  tr.detail > td { display: block; }
  .detail-inner { padding: 16px 14px 18px; }

  .add form { grid-template-columns: 1fr 1fr; }
  .add form .field:first-child { grid-column: 1 / -1; }
  .add .btn { grid-column: 1 / -1; justify-content: center; }
}
@media (min-width: 761px) { .m-only { display: none; } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
