/* Dental Tourism Sales Assistant - mobile-first shell.
   Designed for one-handed use on a phone: 44pt minimum touch targets,
   bottom navigation, safe-area padding for iPhone notch/home indicator. */

:root {
  --teal-900: #0d4f57;
  --teal-700: #0f7a80;
  --teal-500: #108a8a;
  --teal-100: #d9f0ef;
  --gold: #c9973f;
  --ink: #12212a;
  --ink-2: #48606d;
  --ink-3: #7d95a1;
  --line: #dbe6ea;
  --bg: #f4f8f9;
  --card: #ffffff;
  --red: #c0392b;
  --amber: #d98324;
  --green: #1e8a5f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(18, 33, 42, .06), 0 6px 20px rgba(18, 33, 42, .07);
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overscroll-behavior-y: none;
}

body { display: flex; flex-direction: column; }

/* ---------------------------------------------------------------- app bar */
.appbar {
  background: linear-gradient(160deg, var(--teal-900), var(--teal-700));
  color: #fff;
  padding: calc(var(--safe-t) + 12px) 16px 12px;
  position: sticky; top: 0; z-index: 30;
}
.appbar h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: .2px; }
.appbar .sub { font-size: 12px; opacity: .78; margin-top: 2px; }
.appbar-row { display: flex; align-items: center; gap: 12px; }
.appbar-row .grow { flex: 1; min-width: 0; }

.search {
  margin-top: 12px; display: flex; gap: 8px;
}
.search input {
  flex: 1; min-width: 0; height: 40px; border-radius: 10px; border: 0;
  padding: 0 12px; font-size: 15px; background: rgba(255,255,255,.16); color: #fff;
}
.search input::placeholder { color: rgba(255,255,255,.65); }
.appbar-btn { background: rgba(255,255,255,.16); border: 0; color: #fff; flex: 0 0 auto; }

/* ------------------------------------------------------------ money ledger */
.money-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.money-tile {
  background: var(--card); border-radius: var(--radius); padding: 12px 13px; box-shadow: var(--shadow);
}
.money-tile .k {
  font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 4px;
}
.money-tile .v { font-size: 17px; font-weight: 750; font-variant-numeric: tabular-nums; }
.money-tile .sub { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.money-tile.wide { grid-column: 1 / -1; }
.money-tile.pos .v { color: var(--green); }
.money-tile.neg .v { color: var(--red); }
.money-tile.accent { background: var(--teal-900); color: #fff; }
.money-tile.accent .k, .money-tile.accent .sub { color: rgba(255,255,255,.72); }

.entry {
  display: flex; gap: 11px; align-items: flex-start; background: var(--card);
  border-radius: 12px; padding: 12px; margin-bottom: 8px; box-shadow: var(--shadow);
  width: 100%; text-align: left; border: 0; min-height: 0;
}
.entry .dir {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 800;
}
.entry .dir.in { background: #e7f5ee; color: var(--green); }
.entry .dir.out { background: #fdecea; color: var(--red); }
.entry .grow { flex: 1; min-width: 0; }
.entry .cat { font-weight: 640; font-size: 14px; }
.entry .meta { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.entry .amt { font-weight: 750; font-size: 14.5px; white-space: nowrap; text-align: right; }
.entry .amt small { display: block; font-weight: 500; color: var(--ink-3); font-size: 11px; }

/* ------------------------------------------------------------------ chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px; scrollbar-width: none; }
.chips.flush { padding-left: 0; padding-right: 0; }
.chips.on-teal { background: var(--teal-700); margin-top: -1px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; height: 34px; padding: 0 14px; border-radius: 17px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink-2);
  font-size: 13px; font-weight: 550; display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { background: var(--teal-900); border-color: var(--teal-900); color: #fff; }
.chips.on-teal .chip { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.22); color: #eaf6f6; }
.chips.on-teal .chip.active { background: #fff; color: var(--teal-900); border-color: #fff; }

/* ------------------------------------------------------------------ main */
main {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(var(--nav-h) + var(--safe-b) + 24px);
}
.screen { display: none; }
.screen.active { display: block; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; font-size: 15px; font-weight: 650; }
.muted { color: var(--ink-3); font-size: 13px; }
.section-title {
  font-size: 12px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--ink-3); margin: 18px 0 8px;
}

/* --------------------------------------------------------- patient cards */
.patient-card { display: flex; gap: 12px; align-items: flex-start; }
.flag { font-size: 26px; line-height: 1; margin-top: 2px; }
.patient-name { font-weight: 650; font-size: 15.5px; }
.patient-meta { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge {
  font-size: 11.5px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: var(--teal-100); color: var(--teal-900);
}
.badge.status { background: #eef2f5; color: var(--ink-2); }
.badge.warn { background: #fdece5; color: var(--red); }
.badge.clock { background: #f2f0e6; color: #7a6428; }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* --------------------------------------------------------------- buttons */
button, .btn {
  min-height: 44px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 14px; font-weight: 600;
  padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  cursor: pointer; font-family: inherit;
}
button:active { transform: scale(.985); }
.btn-primary { background: var(--teal-900); border-color: var(--teal-900); color: #fff; }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #241a05; }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 36px; font-size: 13px; padding: 0 11px; border-radius: 9px; }
.btn-block { width: 100%; }
button[disabled] { opacity: .45; }

/* ----------------------------------------------------------------- forms */
label.field { display: block; margin-bottom: 12px; }
label.field > span {
  display: block; font-size: 12px; font-weight: 650; color: var(--ink-2);
  margin-bottom: 5px; letter-spacing: .2px;
}
input, select, textarea {
  width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 11px;
  padding: 10px 12px; font-size: 16px; /* 16px stops iOS auto-zoom on focus */
  font-family: inherit; background: #fff; color: var(--ink); -webkit-appearance: none;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ----------------------------------------------------- FDI dental chart */
.chart { background: var(--card); border-radius: var(--radius); padding: 14px 10px; box-shadow: var(--shadow); }
.arch-label {
  font-size: 11px; font-weight: 700; letter-spacing: .8px; color: var(--ink-3);
  text-transform: uppercase; text-align: center; margin: 4px 0 8px;
}
.arch { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.arch + .arch { margin-top: 5px; }
.tooth {
  position: relative; min-height: 46px; padding: 4px 2px;
  border: 1.5px solid var(--line); border-radius: 9px; background: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 650; color: var(--ink-2); transition: transform .09s, background .12s;
}
.tooth .fdi { font-size: 12.5px; }
.tooth .mat {
  font-size: 8.5px; font-weight: 700; letter-spacing: .2px; margin-top: 2px;
  text-transform: uppercase; opacity: .95;
}
.tooth.selected {
  background: var(--teal-500); border-color: var(--teal-500); color: #fff;
  box-shadow: 0 0 0 3px rgba(16,138,138,.18);
}
.tooth.assigned { background: var(--teal-900); border-color: var(--teal-900); color: #fff; }
.tooth.assigned.selected { box-shadow: 0 0 0 3px rgba(201,151,63,.4); border-color: var(--gold); }
.midline { grid-column: 1 / -1; height: 1px; background: var(--line); margin: 3px 0; }

/* ------------------------------------------------------------ summary bar */
.summary-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b));
  background: var(--teal-900); color: #fff; padding: 10px 16px 12px;
  z-index: 25; box-shadow: 0 -6px 20px rgba(18,33,42,.16);
}
.summary-bar.hidden { display: none; }
.summary-line { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.summary-total { font-size: 19px; font-weight: 700; }
.summary-sub { font-size: 12px; opacity: .8; }

/* ----------------------------------------------------------- bottom nav */
nav.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(255,255,255,.96); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(6, 1fr);
}
nav.tabbar button {
  min-height: 0; border: 0; background: none; border-radius: 0;
  flex-direction: column; gap: 3px; font-size: 10.5px; font-weight: 600; color: var(--ink-3);
  padding: 0;
}
nav.tabbar button .ic { font-size: 19px; line-height: 1; }
nav.tabbar button span:not(.ic) {
  max-width: 100%; padding: 0 2px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
@media (max-width: 360px) { nav.tabbar button { font-size: 9.5px; } }
nav.tabbar button.active { color: var(--teal-900); }

/* ---------------------------------------------------------- bottom sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(18,33,42,.45); z-index: 50;
  -webkit-tap-highlight-color: transparent;
  display: flex; align-items: flex-end; opacity: 0; pointer-events: none; transition: opacity .18s;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  width: 100%; max-height: 84vh; overflow-y: auto; background: var(--bg);
  border-radius: 18px 18px 0 0;
  /* Clear the tab bar, which now floats above the backdrop. */
  padding: 8px 16px calc(var(--nav-h) + var(--safe-b) + 20px);
  transform: translateY(14px); transition: transform .18s;
}
.sheet-backdrop.open .sheet { transform: translateY(0); }
/* Sticky sheet header: the close button must stay reachable one-handed even
   when a long form (new patient) scrolls past the top of the screen. */
.sheet-head {
  position: sticky; top: 0; z-index: 3; background: var(--bg);
  margin: 0 -16px 4px; padding: 10px 16px 12px; display: flex; align-items: center;
}
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto; }
.sheet-close {
  position: absolute; right: 12px; top: 4px;
  width: 36px; height: 36px; min-height: 36px; padding: 0;
  border-radius: 50%; border: 0; background: rgba(18, 33, 42, .07);
  color: var(--ink-2); font-size: 14px; line-height: 1;
}
.sheet-close:active { background: rgba(18, 33, 42, .14); }
.sheet h2 { margin: 0 0 4px; font-size: 17px; }

.material {
  display: flex; gap: 12px; align-items: center; padding: 12px;
  background: var(--card); border-radius: 12px; margin-bottom: 9px; box-shadow: var(--shadow);
}
.material.selected { outline: 2px solid var(--teal-500); }
.material .grow { flex: 1; min-width: 0; }
.material .name { font-weight: 650; font-size: 14px; }
.material .price { font-weight: 700; font-size: 14px; text-align: right; white-space: nowrap; }
.material .price small { display: block; font-weight: 500; color: var(--ink-3); font-size: 11.5px; }

/* -------------------------------------------------------------- timeline */
.tl { position: relative; padding-left: 26px; }
.tl::before {
  content: ''; position: absolute; left: 9px; top: 8px; bottom: 8px; width: 2px; background: var(--line);
}
.tl-item { position: relative; margin-bottom: 14px; }
.tl-item::before {
  content: ''; position: absolute; left: -22px; top: 5px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px #fff;
}
.tl-item.amber::before { background: var(--amber); }
.tl-item.red::before { background: var(--red); }
.tl-item .when { font-size: 12px; color: var(--ink-3); }
.tl-item .what { font-weight: 620; font-size: 14px; }
.alert {
  border-radius: 12px; padding: 12px 14px; font-size: 13.5px; margin-bottom: 12px; line-height: 1.5;
}
.alert.red { background: #fdecea; color: #8e2b20; border: 1px solid #f5c6c0; }
.alert.green { background: #e7f5ee; color: #145c3f; border: 1px solid #bfe3d1; }
.alert.amber { background: #fdf3e3; color: #7a4f11; border: 1px solid #f0dcb8; }

/* ---------------------------------------------------------------- clocks */
.clocks { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.clock { background: var(--card); border-radius: 12px; padding: 12px; text-align: center; box-shadow: var(--shadow); }
.clock .city { font-size: 11.5px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .6px; }
.clock .time { font-size: 25px; font-weight: 700; margin: 3px 0 1px; font-variant-numeric: tabular-nums; }
.clock .date { font-size: 11.5px; color: var(--ink-3); }

/* ----------------------------------------------------------------- vault */
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.media-tile {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  background: #e8eef0; border: 0; padding: 0;
}
.media-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-tile .cat {
  position: absolute; left: 0; right: 0; bottom: 0; font-size: 8.5px; font-weight: 700;
  background: rgba(13,79,87,.82); color: #fff; padding: 3px 4px; letter-spacing: .2px;
}
.ba-wrap { position: relative; border-radius: 12px; overflow: hidden; background: #000; touch-action: none; }
.ba-wrap img { width: 100%; display: block; }
.ba-after { position: absolute; inset: 0; overflow: hidden; }
.ba-after img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ba-handle {
  position: absolute; top: 0; bottom: 0; width: 3px; background: #fff; margin-left: -1.5px;
  box-shadow: 0 0 8px rgba(0,0,0,.4);
}
.ba-handle::after {
  content: '⟺'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 34px; height: 34px; border-radius: 50%; background: #fff; color: var(--teal-900);
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.ba-tag {
  position: absolute; top: 8px; font-size: 10.5px; font-weight: 700; letter-spacing: .6px;
  background: rgba(0,0,0,.55); color: #fff; padding: 3px 8px; border-radius: 999px;
}

/* ---------------------------------------------------------------- misc */
.empty { text-align: center; padding: 44px 20px; color: var(--ink-3); }
.empty .big { font-size: 38px; margin-bottom: 8px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--nav-h) + var(--safe-b) + 18px); z-index: 90;
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 11px;
  font-size: 13.5px; font-weight: 550; opacity: 0; transition: all .2s; pointer-events: none;
  max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.install-hint {
  background: linear-gradient(140deg, var(--teal-900), var(--teal-700)); color: #fff;
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px; font-size: 13.5px; line-height: 1.55;
}
.install-hint b { font-weight: 700; }
.install-hint .close { float: right; opacity: .7; font-size: 18px; }
.template { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); margin-bottom: 10px; overflow: hidden; }
.template summary { padding: 13px 14px; font-weight: 620; font-size: 14px; cursor: pointer; list-style: none; }
.template summary::-webkit-details-marker { display: none; }
.template summary::after { content: '⌄'; float: right; color: var(--ink-3); }
.template[open] summary::after { content: '⌃'; }
.template .body { padding: 0 14px 14px; }
.template pre {
  white-space: pre-wrap; word-wrap: break-word; font: inherit; font-size: 13.5px;
  background: var(--bg); border-radius: 10px; padding: 12px; margin: 0 0 10px; color: var(--ink-2);
}

/* ------------------------------------------------- flight check status box
   Colour carries the verdict at a glance, but never on its own: each state
   also carries an icon and a sentence, so it still reads on a poor screen in
   clinic light and for a colour-blind user. */
.flight-status {
  margin: 4px 0 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  border-left-width: 4px;
  background: var(--card);
  font-size: 14px;
  line-height: 1.45;
}
.flight-status.fs-checking { color: #6b7f88; font-style: italic; }
.flight-status.fs-green { border-left-color: var(--green); background: #f2faf6; }
.flight-status.fs-amber { border-left-color: var(--amber); background: #fdf8f1; }
.flight-status.fs-red   { border-left-color: var(--red);   background: #fdf3f2; }
.flight-status .fs-head { font-weight: 600; margin-bottom: 4px; }
.flight-status.fs-green .fs-head { color: var(--green); }
.flight-status.fs-amber .fs-head { color: var(--amber); }
.flight-status.fs-red   .fs-head { color: var(--red); }
.flight-status .fs-leg { margin-top: 3px; color: var(--ink); }
.flight-status .fs-leg b { font-weight: 600; margin-right: 4px; }
.flight-status .fs-leg.fs-amber { color: #8a5a12; }
.flight-status .fs-leg.fs-red { color: var(--red); }
.flight-status .fs-live { color: #6b7f88; font-size: 13px; }
.flight-status .fs-issue { margin-top: 3px; color: #8a5a12; }
.flight-status.fs-red .fs-issue { color: var(--red); }
.flight-status .fs-foot { margin-top: 6px; font-size: 12px; color: #8fa2ab; }
