/* ============================================================
   Beyond Movement Voice EMR - design system
   Tokens lifted from beyondmovement.in so the two products match.
   Mobile-first: 44px+ touch targets, thumb-reachable actions, 2 taps max.
   ============================================================ */
:root {
  --green: #40BB6A;
  --green-d: #2E9E54;
  --green-l: #E7F6EC;
  --green-ll: #F1FAF4;
  --ink: #12211B;
  --muted: #5C6B63;
  --faint: #8A978F;
  --line: #E4EAE6;
  --bg: #F5F8F6;
  --card: #FFFFFF;
  --amber: #C97A1E;
  --amber-bg: #FBF1E2;
  --red: #C9492F;
  --red-bg: #FAE9E4;
  --good: #2E9E54;
  --good-bg: #E7F6EC;
  --shadow: 0 1px 2px rgba(18,33,27,.04), 0 8px 24px rgba(18,33,27,.05);
  --shadow-lg: 0 2px 6px rgba(18,33,27,.06), 0 18px 40px rgba(18,33,27,.10);
  --display: "Space Grotesk", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, sans-serif;
  --r: 16px;
  --r-sm: 12px;
  --nav-h: 68px;
}

[data-theme="dark"] {
  --ink: #EAF2ED; --muted: #A3B3AA; --faint: #7C8C84;
  --line: #23342B; --bg: #0C1511; --card: #131F19;
  --green-l: #16301F; --green-ll: #10251A;
  --amber-bg: #2C2110; --red-bg: #2E1712; --good-bg: #16301F;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 2px 6px rgba(0,0,0,.4), 0 18px 40px rgba(0,0,0,.5);
}

* { -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--body);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  overscroll-behavior-y: contain;
}

h1, h2, h3, h4, h5, .display-font { font-family: var(--display); font-weight: 700; letter-spacing: -.02em; }
.text-muted-2 { color: var(--muted) !important; }
.text-faint { color: var(--faint) !important; }
.text-brand { color: var(--green-d) !important; }
.bg-brand-soft { background: var(--green-l) !important; }

/* ---------- App chrome ---------- */
.appbar {
  position: sticky; top: 0; z-index: 1030;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
}
.appbar .brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--green); color: #fff;
  display: grid; place-items: center;
  font-family: var(--display); font-weight: 700; font-size: 18px;
}

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1040;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
}
.bottomnav button {
  background: none; border: 0; color: var(--faint);
  font-size: 10.5px; font-weight: 600; letter-spacing: .01em;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 0; min-height: 56px;background-color: #fff;
}
.bottomnav button i { font-size: 21px; }
.bottomnav button.active { color: var(--green-d); }

/* The single most important control in the product. */
.mic-fab {
  width: 62px; height: 62px; border-radius: 50%;
  background: linear-gradient(160deg, var(--green), var(--green-d));
  color: #fff; border: 0; margin-top: -26px;
  box-shadow: 0 10px 24px rgba(64,187,106,.42);
  display: grid; place-items: center;
}
.mic-fab i { font-size: 26px !important; }
.mic-fab.listening { animation: pulse 1.4s infinite; background: linear-gradient(160deg, #ff6b57, var(--red)); box-shadow: 0 10px 28px rgba(201,73,47,.5); }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.07); } }

/* ---------- Surfaces ---------- */
.card-bm {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 12px;
}
.card-bm.tight { padding: 12px 14px; }
.card-bm.tap:active { transform: scale(.99); }

.stat-tile { display: flex; flex-direction: column; gap: 2px; }
.stat-tile .n { font-family: var(--display); font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat-tile .l { font-size: 11.5px; color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  background: var(--green-l); color: var(--green-d);
  border: 1px solid transparent;
}
.chip.amber { background: var(--amber-bg); color: var(--amber); }
.chip.red   { background: var(--red-bg); color: var(--red); }
.chip.grey  { background: var(--bg); color: var(--muted); border-color: var(--line); }

.avatar {
  width: 42px; height: 42px; border-radius: 12px; flex: 0 0 42px;
  background: var(--green-l); color: var(--green-d);
  display: grid; place-items: center;
  font-family: var(--display); font-weight: 700; font-size: 15px;
}

/* ---------- Controls ---------- */
.btn { border-radius: var(--r-sm); font-weight: 600; min-height: 44px; }
.btn-brand { background: var(--green); border-color: var(--green); color: #fff; }
.btn-brand:hover, .btn-brand:focus { background: var(--green-d); border-color: var(--green-d); color: #fff; }
.btn-soft { background: var(--green-l); color: var(--green-d); border: 1px solid transparent; }
.btn-ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn-lg-tap { min-height: 52px; font-size: 15px; }

.form-control, .form-select {
  background: var(--card); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--r-sm); min-height: 46px; font-size: 15px;
}
.form-control:focus, .form-select:focus {
  background: var(--card); color: var(--ink);
  border-color: var(--green); box-shadow: 0 0 0 3px rgba(64,187,106,.16);
}
.form-control::placeholder { color: var(--faint); }
.form-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 4px; }

/* A field the voice engine just wrote into */
.field-voice { animation: flash 1.1s ease-out; }
@keyframes flash {
  0% { background: var(--green-l); box-shadow: 0 0 0 3px rgba(64,187,106,.3); }
  100% { background: var(--card); box-shadow: none; }
}

/* ---------- Voice sheet ---------- */
.voice-sheet {
  position: fixed; inset: auto 0 0 0; z-index: 1050;
  background: var(--card); border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-lg); border-top: 1px solid var(--line);
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 78vh; overflow-y: auto;
}
.voice-backdrop { position: fixed; inset: 0; background: rgba(8,18,13,.45); z-index: 1045; }

.wave { display: flex; align-items: flex-end; gap: 3px; height: 34px; }
.wave span {
  width: 4px; background: var(--green); border-radius: 2px;
  animation: bar .9s ease-in-out infinite;
}
.wave span:nth-child(2n) { animation-delay: .12s; }
.wave span:nth-child(3n) { animation-delay: .24s; }
.wave span:nth-child(4n) { animation-delay: .36s; }
@keyframes bar { 0%,100% { height: 8px; opacity:.55 } 50% { height: 32px; opacity:1 } }

.transcript-live {
  background: var(--bg); border: 1px dashed var(--line); border-radius: var(--r-sm);
  padding: 12px; font-size: 15px; min-height: 84px; max-height: 190px; overflow-y: auto;
}
.transcript-live .interim { color: var(--faint); }

/* ---------- Lists ---------- */
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: 0; }
.list-row .t { font-weight: 600; font-size: 15px; }
.list-row .s { font-size: 12.5px; color: var(--faint); text-wrap: wrap; }

.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 9px 6px; font-size: 13px; font-weight: 600; color: var(--muted); min-height: 40px; }
.seg button.active { background: var(--card); color: var(--green-d); box-shadow: var(--shadow); }

.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.timeline .node { position: relative; margin-bottom: 14px; }
.timeline .node::before {
  content: ''; position: absolute; left: -20px; top: 6px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--green); border: 2px solid var(--card);
}

.pain-bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.pain-bar > i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--green), var(--amber), var(--red)); }

.sparkline { display: flex; align-items: flex-end; gap: 4px; height: 46px; }
.sparkline i { flex: 1; background: var(--green-l); border-radius: 3px 3px 0 0; position: relative; }
.sparkline i.hot { background: var(--green); }

.offline-banner { background: var(--amber-bg); color: var(--amber); font-size: 12.5px; font-weight: 600; padding: 6px 16px; text-align: center; }

.toast-bm {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom, 0px));
  z-index: 1060; background: var(--ink); color: var(--bg);
  padding: 11px 18px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-lg); max-width: 90vw;
}

.skeleton { background: linear-gradient(90deg, var(--line) 25%, var(--bg) 50%, var(--line) 75%);
  background-size: 200% 100%; animation: sk 1.3s infinite; border-radius: 8px; }
@keyframes sk { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }

/* Tablet / desktop: same app, more breathing room */
@media (min-width: 768px) {
  body { padding-bottom: 24px; }
  .app-wrap { max-width: 900px; margin: 0 auto; }
  .bottomnav { left: 50%; transform: translateX(-50%); max-width: 520px; border-radius: 22px 22px 0 0; border: 1px solid var(--line); }
}

@media print {
  .appbar, .bottomnav, .no-print { display: none !important; }
  body { background: #fff; padding: 0; }
}
