:root {
  --terracotta: #C75A2E;
  --terracotta-dk: #A8451F;
  --ink: #2B333A;
  --ink-soft: #5A636C;
  --ink-faint: #97A0A8;
  --paper: #F7F4F0;
  --surface: #FFFFFF;
  --surface-2: #FBF8F4;
  --line: #E7E0D8;
  --line-strong: #D8CFC4;
  --ok: #2F7D5B;
  --warn: #C98A1E;
  --danger: #C23B36;
  --shadow: 0 1px 2px rgba(43,51,58,.06), 0 8px 24px rgba(43,51,58,.08);
  --radius: 14px;
  --tap: 46px;
  --font: "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
  --display: "Bricolage Grotesque", var(--font);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  font-size: 16px; line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -.01em; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 16px; border-radius: 11px;
  border: 1px solid var(--line-strong); background: var(--surface);
  font-weight: 600; cursor: pointer; transition: transform .06s ease, background .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--terracotta); border-color: var(--terracotta); color: #fff; }
.btn-primary:active { background: var(--terracotta-dk); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--terracotta); }
.btn-danger { color: var(--danger); border-color: #E8C9C7; background: #FCF3F2; }
.btn-lg { width: 100%; font-size: 1.05rem; }
.btn-sm { min-height: 38px; padding: 0 12px; border-radius: 9px; font-size: .9rem; }
.btn:disabled { opacity: .5; }

/* ---------- login ---------- */
.login {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(199,90,46,.16), transparent 60%),
    var(--paper);
}
.login-card { width: 100%; max-width: 340px; text-align: center; }
.brand-mark {
  width: 76px; height: 76px; margin: 0 auto 18px; border-radius: 20px;
  display: grid; place-items: center; color: #fff; font-family: var(--display);
  font-weight: 800; font-size: 42px;
  background: linear-gradient(150deg, var(--terracotta), var(--terracotta-dk));
  box-shadow: var(--shadow);
}
.brand-word { font-size: clamp(1.3rem, 7vw, 2rem); font-weight: 800; letter-spacing: .1em; color: var(--ink); }
.brand-sub { margin: 2px 0 26px; color: var(--ink-soft); letter-spacing: .04em; }
.pin-input {
  width: 100%; text-align: center; letter-spacing: .4em; font-size: 1.5rem;
  padding: 14px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface); margin-bottom: 14px;
}
.pin-input:focus { outline: 2px solid var(--terracotta); border-color: var(--terracotta); }
.login-err { color: var(--danger); min-height: 1.2em; margin: 12px 0 0; font-size: .9rem; }

/* ---------- shell ---------- */
.shell { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar-brand { font-family: var(--display); font-weight: 800; letter-spacing: .14em; display: flex; align-items: center; gap: 8px; }
.topbar-brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--terracotta); }
.app { flex: 1; overflow-y: auto; padding: 14px 14px 96px; -webkit-overflow-scrolling: touch; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 8px; color: var(--ink-faint); font-size: .7rem; font-weight: 600;
}
.tab .ico { font-size: 1.2rem; line-height: 1; }
.tab.active { color: var(--terracotta); }

/* ---------- day view ---------- */
.day-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 12px;
}
.day-date { text-align: center; }
.day-date b { display: block; font-family: var(--display); font-size: 1.15rem; }
.day-date small { color: var(--ink-soft); }
.nav-btn {
  width: 42px; height: 42px; border-radius: 11px; border: 1px solid var(--line-strong);
  background: var(--surface); font-size: 1.3rem; display: grid; place-items: center;
}
.today-link { font-size: .82rem; color: var(--terracotta); font-weight: 600; }


.timeline { display: flex; gap: 6px; }
.time-gutter { width: 44px; position: relative; flex: none; }
.time-gutter .t {
  position: absolute; right: 6px; transform: translateY(-50%);
  font-size: .72rem; color: var(--ink-faint); font-variant-numeric: tabular-nums;
}
.lanes {
  flex: 1; display: flex; gap: 6px; min-width: 0;
  overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
  scrollbar-width: thin;
}
.lane {
  /* show 3 lanes across the viewport, then horizontal-scroll the rest.
     grow:1 so 1–3 lanes still fill the width; shrink:0 so a 4th overflows instead of squeezing. */
  flex: 1 0 calc((100% - 12px) / 3);
  min-width: 0; position: relative; border-radius: 10px;
  /* --row = one 30-min slot. Layered top→bottom:
     1) solid line at each full hour (painted on top → stays solid),
     2) "chopper": surface-coloured vertical stripes that break the layer below into dashes,
     3) thin line at each half-hour mark (chopped by layer 2 → dashed),
     4) surface base. */
  background:
    repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--row) * 2 - 1px),
      var(--line-strong) calc(var(--row) * 2 - 1px), var(--line-strong) calc(var(--row) * 2)),
    repeating-linear-gradient(to right, var(--surface-2) 0 4px, transparent 4px 10px),
    repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--row) - 1px),
      var(--line) calc(var(--row) - 1px), var(--line) var(--row)),
    var(--surface-2);
  border: 1px solid var(--line);
}
.lane.closed { background: repeating-linear-gradient(45deg, #F1ECE5 0 8px, #ece6dd 8px 16px); }

.block {
  position: absolute; left: 3px; right: 3px; border-radius: 8px; overflow: hidden;
  padding: 5px 6px; color: #fff; font-size: .72rem; line-height: 1.15;
  box-shadow: 0 1px 2px rgba(0,0,0,.12); cursor: pointer;
  border-left: 3px solid rgba(255,255,255,.55);
}
.block b { font-weight: 700; display: block; font-size: .76rem; }
.block .m { opacity: .92; }
.block.cancelled { opacity: .4; text-decoration: line-through; }
.block.done::after { content: "✓"; position: absolute; top: 3px; right: 5px; font-size: .7rem; }

/* red dot = individual therapy (needs the therapist's full attention) */
.ind-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: #e5484d; box-shadow: 0 0 0 1.5px rgba(255,255,255,.85);
  flex: none; vertical-align: middle;
}
.block .ind-dot { position: absolute; top: 5px; right: 6px; }
.block.done.ind::after { right: 18px; } /* nudge the ✓ left so it clears the dot */
.ind-dot-inline { width: 8px; height: 8px; box-shadow: none; margin-right: 2px; }

.empty-note { color: var(--ink-faint); text-align: center; padding: 30px 0; }

/* ---------- cards / lists ---------- */
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); margin: 18px 2px 8px; font-weight: 700; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.row:last-child { border-bottom: none; }
.row:active { background: var(--surface-2); }
.avatar {
  width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center;
  font-weight: 700; color: #fff; font-family: var(--display);
  background: linear-gradient(150deg, var(--terracotta), var(--terracotta-dk));
}
.row-main { flex: 1; min-width: 0; }
.row-main b { display: block; }
.row-main small { color: var(--ink-soft); }
.row-meta { color: var(--ink-faint); font-size: .85rem; text-align: right; }
.chev { color: var(--ink-faint); }

.search {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface); margin-bottom: 12px;
}
.search:focus { outline: 2px solid var(--terracotta); border-color: var(--terracotta); }

.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600; }
.pill.active { background: #EAF4EE; color: var(--ok); }
.pill.finished { background: #EFEAF4; color: #6b4f9e; }
.pill.warn { background: #FBF1DD; color: var(--warn); }

.fab {
  position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 6;
  width: 58px; height: 58px; border-radius: 18px; border: none; color: #fff; font-size: 1.8rem;
  background: linear-gradient(150deg, var(--terracotta), var(--terracotta-dk));
  /* white ring keeps the button distinct even when a same-color block sits behind it */
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.08), 0 6px 18px rgba(168,69,31,.45); display: grid; place-items: center;
}

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 13px; border-radius: 11px; border: 1px solid var(--line-strong);
  background: var(--surface);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--terracotta); border-color: var(--terracotta); }
.field textarea { min-height: 72px; resize: vertical; }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }
.check-row { display: flex; gap: 10px; align-items: center; margin: 8px 0 4px; }
.check-row input { width: 20px; height: 20px; flex: none; }

.item-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.item-row select { flex: 2; }
.item-row input { flex: 1; }
.icon-btn { width: 42px; height: 42px; border-radius: 11px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 1.1rem; flex: none; }

.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1; min-height: 40px; border: none; background: transparent; border-radius: 9px; font-weight: 600; color: var(--ink-soft); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- sheet / modal ---------- */
.sheet-host { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(43,51,58,.45); }
.sheet {
  position: relative; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--paper); border-radius: 22px 22px 0 0; padding: 8px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0,0,0,.2); animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 6px auto 14px; }
.sheet h2 { font-size: 1.3rem; margin-bottom: 4px; }
.sheet .sub { color: var(--ink-soft); margin: 0 0 16px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet-actions .btn { flex: 1; }

.conflict { border-radius: 11px; padding: 10px 12px; margin: 4px 0; font-size: .86rem; }
.conflict.hard { background: #FCF3F2; color: var(--danger); border: 1px solid #E8C9C7; }
.conflict.warn { background: #FBF1DD; color: #8a6310; border: 1px solid #EBD8AE; }

.kv { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border: none; }
.kv span { color: var(--ink-soft); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 40;
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: .9rem; box-shadow: var(--shadow); animation: rise .2s ease;
}
.toast.err { background: var(--danger); }

/* global error popup */
.errpop { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.errpop-backdrop { position: absolute; inset: 0; background: rgba(43,51,58,.55); }
.errpop-card {
  position: relative; width: 100%; max-width: 420px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 22px; box-shadow: var(--shadow); animation: rise .2s ease;
}
.errpop-icon { font-size: 2rem; line-height: 1; color: var(--danger); }
.errpop-title { font-size: 1.3rem; margin: 8px 0 4px; }
.errpop-msg { color: var(--ink-soft); margin: 0 0 12px; word-break: break-word; }
.errpop-detail {
  display: none; text-align: left; margin: 0 0 14px; padding: 10px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  font-size: .76rem; line-height: 1.45; color: var(--ink);
  white-space: pre-wrap; word-break: break-word; max-height: 180px; overflow: auto;
}
.errpop-detail.show { display: block; }
.errpop-actions { display: flex; gap: 10px; }
.errpop-actions .btn { flex: 1; }
