/* Tokens follow DESIGN.md (cream/serif system); green is an accent, not a surface. */
:root {
  --forest: #0f3e17;
  --forest-deep: #0c2f10;
  --keylime: #e1f4df;
  --cream: #fffefc;
  --stone: #f4f3ef;
  --line: #e4e2da;
  --charcoal: #222222;
  --muted: #55605a;
  --field-border: #868f88;
  --lime: #c5f06b;

  /* Chart series — validated with the dataviz palette checker against cream. */
  --series-1: #2a7a3b;
  --series-2: #c08a2e;

  --good: #2a7a3b;
  --bad: #b3261e;
  --warn-bg: #fff6e0;
  --bad-bg: #fdecea;
  --good-bg: #e8f4ea;

  --font-serif: 'Cormorant Garamond', Georgia, serif;
  --font-sans: 'Inter', 'Helvetica Neue', system-ui, sans-serif;
  --r: 14px;
  --r-sm: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--cream);
  color: var(--charcoal);
  font: 14px/1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-weight: 400; color: var(--forest); }
h1 { font: 400 34px/1.1 var(--font-serif); }
h2 { font: 600 15px/1.3 var(--font-sans); }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--forest); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px;
  border: 1px solid var(--forest); background: transparent; color: var(--forest); font-weight: 500;
}
.btn:hover { background: var(--keylime); }
.btn.primary { background: var(--forest); color: var(--cream); }
.btn.primary:hover { background: var(--forest-deep); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.block { width: 100%; }
a.btn { text-decoration: none; }
.btn:disabled { opacity: .55; cursor: wait; }
.link { background: none; border: 0; padding: 0; color: var(--forest); text-decoration: underline; text-underline-offset: 3px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border: 0; border-radius: 999px; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--stone); color: var(--forest); }
.icon-btn.danger:hover { background: var(--bad-bg); color: var(--bad); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span:first-child { font-weight: 500; font-size: 13px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--charcoal);
  background: var(--cream); border: 1px solid var(--field-border); border-radius: var(--r-sm);
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--forest); outline-offset: 2px;
}
.input-with-btn { position: relative; display: block; }
.input-with-btn input { padding-right: 44px; }
.input-with-btn .icon-btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.code-input { font-size: 26px; letter-spacing: 10px; text-align: center; font-variant-numeric: tabular-nums; }

.segmented { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--stone); border-radius: 999px; }
.segmented button { border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; color: var(--muted); font-weight: 500; }
.segmented button.on { background: var(--cream); color: var(--forest); box-shadow: 0 0 0 1px var(--line); }

.search { position: relative; flex: 1 1 260px; max-width: 380px; }
.search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 36px; border-color: var(--line); border-radius: 999px; }

.alert { padding: 10px 14px; border-radius: var(--r-sm); font-size: 13.5px; }
.alert.error { background: var(--bad-bg); color: var(--bad); }
.alert.ok { background: var(--good-bg); color: var(--forest); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--stone); }
.login-card { width: 100%; max-width: 400px; background: var(--cream); border: 1px solid var(--line); border-radius: var(--r); padding: 32px 28px; }
.login-card .brand { margin-bottom: 28px; }
.login-links { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 13px; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; color: var(--forest); font-weight: 600; line-height: 1.2; }
.brand small { color: var(--muted); font-size: 12px; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--forest); color: var(--lime); font-size: 18px; }

.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; width: 232px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 24px; padding: 22px 14px;
  background: var(--stone); border-right: 1px solid var(--line);
}
.sidebar .brand { padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--charcoal); text-align: left;
}
.nav-item i { font-size: 16px; color: var(--muted); }
.nav-item:hover { background: var(--cream); }
.nav-item.on { background: var(--keylime); color: var(--forest); font-weight: 600; }
.nav-item.on i { color: var(--forest); }
.count { margin-left: auto; min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--forest); color: var(--cream); font-size: 11.5px; font-weight: 600; text-align: center; }
.sidebar-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted); }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .icon-btn { flex-shrink: 0; }

.main { flex: 1; min-width: 0; padding: 28px clamp(16px, 3vw, 40px) 64px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page { display: flex; flex-direction: column; gap: 20px; }

.card { background: var(--cream); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; }
.card.pad { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-head .sub { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.card-body { padding: 16px 20px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 20px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 12px; }
#analytics-body { display: flex; flex-direction: column; gap: 20px; }
.tile { padding: 16px 18px; background: var(--cream); border: 1px solid var(--line); border-radius: var(--r); }
.tile .label { color: var(--muted); font-size: 12.5px; }
.tile .value { margin-top: 4px; font-size: 28px; font-weight: 600; color: var(--forest); line-height: 1.15; }
.tile .delta { margin-top: 4px; font-size: 12px; color: var(--muted); }
.tile .delta.up { color: var(--good); }
.tile .delta.down { color: var(--bad); }
.tile.attention { background: var(--keylime); border-color: transparent; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 10px 20px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 20px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--stone); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-sub { display: block; color: var(--muted); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.clip { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; border: 1px solid var(--line); white-space: nowrap; }
.pill.New { background: var(--keylime); border-color: transparent; color: var(--forest); }
.pill.Confirmed, .pill.Replied { background: var(--forest); border-color: transparent; color: var(--cream); }
.pill.Cancelled { background: var(--bad-bg); border-color: transparent; color: var(--bad); }
.pill.returning { background: var(--warn-bg); border-color: transparent; color: #7a4f00; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.pager span { margin-right: auto; }
.pager .btn { padding: 6px 14px; }

.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty i { display: block; font-size: 26px; margin-bottom: 6px; }
.loading { opacity: .5; transition: opacity .2s; }

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(34, 34, 34, .35); }
.modal-box { width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--cream); border-radius: var(--r); }
.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: space-between; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.modal-foot .right { display: flex; gap: 10px; }
.details { display: grid; grid-template-columns: 120px 1fr; gap: 8px 16px; margin: 0; }
.details dt { color: var(--muted); font-size: 13px; }
.details dd { margin: 0; overflow-wrap: anywhere; }
.message { padding: 12px 14px; background: var(--stone); border-radius: var(--r-sm); white-space: pre-wrap; overflow-wrap: anywhere; }
.contact-links { display: flex; gap: 8px; flex-wrap: wrap; }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 16px; border-radius: var(--r-sm); background: var(--charcoal); color: var(--cream); font-size: 13.5px; }
.toast.error { background: var(--bad); }

.filters { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.chart { position: relative; padding: 8px 20px 16px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font: 11px var(--font-sans); fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.legend { display: flex; gap: 16px; padding: 12px 20px 0; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
details.table-view { padding: 0 20px 14px; }
details.table-view summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
details.table-view .table-wrap { max-height: 280px; overflow-y: auto; margin-top: 8px; }
details.table-view td, details.table-view th { padding: 6px 10px; }

.bars td { padding-top: 9px; padding-bottom: 9px; }
.bar-cell { width: 40%; min-width: 90px; }
.funnel .bar-cell { width: 20%; min-width: 50px; }
.funnel .clip { max-width: 170px; }
/* Half-width cards on the overview: keep date, customer, service and status. */
.compact td:nth-child(n+4):not(:last-child), .compact th:nth-child(n+4):not(:last-child) { display: none; }
.compact .clip { max-width: 150px; }
.compact .cell-sub { white-space: nowrap; }
.bar { height: 8px; border-radius: 0 4px 4px 0; background: var(--series-1); min-width: 2px; }
.rate { color: var(--muted); font-size: 12px; }

.heat { display: grid; grid-template-columns: 34px repeat(24, minmax(10px, 1fr)); gap: 2px; padding: 8px 20px 18px; font-size: 11px; color: var(--muted); }
.heat .cell { aspect-ratio: 1; border-radius: 3px; background: var(--stone); }
.heat .hour { text-align: center; }

.pivot td.cell { text-align: center; font-variant-numeric: tabular-nums; min-width: 56px; }
.pivot th.svc { white-space: normal; min-width: 90px; text-align: center; }
.note { padding: 0 20px 16px; color: var(--muted); font-size: 12.5px; }

.tooltip {
  position: fixed; z-index: 70; pointer-events: none; padding: 8px 12px; min-width: 120px;
  background: var(--cream); border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: 0 6px 20px rgba(12, 47, 16, .12); font-size: 12.5px;
}
.tooltip .t-head { color: var(--muted); margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; }
.tooltip .t-row b { font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip .key { width: 12px; height: 2px; border-radius: 2px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { position: sticky; z-index: 20; height: auto; width: 100%; flex-direction: row; align-items: center; gap: 8px; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar .brand span:last-child, .who span, .nav-item span:not(.count) { display: none; }
  .nav { flex-direction: row; justify-content: center; }
  .nav-item { width: auto; padding: 10px; position: relative; }
  .nav-item .count { position: absolute; top: 0; right: -4px; min-width: 18px; padding: 0 5px; }
  .sidebar-foot { border: 0; padding: 0; }
  .main { padding-top: 20px; }
  h1 { font-size: 28px; }
  .details { grid-template-columns: 1fr; gap: 2px; }
  .details dd { margin-bottom: 8px; }
  .heat { grid-template-columns: 30px repeat(24, 1fr); gap: 1px; padding: 8px 16px 16px; }
}
