/* AthleticsMD Finance & Management — design system
   Brand palette lifted from www.athleticsmd.org:
   royal blue #0033A0 · deep navy #062768 · greens #00B454/#00813B/#128274
   neutrals #F4F8FC/#DCE6F2/#C9D7EC/#51607A · Montserrat display */
:root {
  --navy-950: #050F2E;
  --navy-900: #071B45;
  --navy-800: #062768;
  --blue-700: #0033A0;
  --blue-600: #1D4ED0;
  --blue-100: #DCE6F2;
  --green-700: #00813B;
  --green-500: #00B454;
  --green-100: #DDF6E8;
  --teal-600: #128274;
  --amber-600: #B45309;
  --amber-100: #FCEED8;
  --red-600: #C0392B;
  --red-100: #FBE7E3;
  --danger: var(--red-600); /* alias — past-due amounts, warnings, errors */
  --bg: #F4F8FC;
  --surface: #FFFFFF;
  --border: #DCE6F2;
  --border-strong: #C9D7EC;
  --text: #0E1E3E;
  --muted: #51607A;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(6, 39, 104, .06), 0 4px 16px rgba(6, 39, 104, .06);
  --display: 'Montserrat', 'Segoe UI', Arial, sans-serif;
  --body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font: 14.5px/1.55 var(--body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip; /* one page = one vertical scroll; wide tables scroll inside their own cards */
}
a { color: var(--blue-700); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-family: var(--display); font-size: 24px; font-weight: 800; letter-spacing: -.3px; margin: 0 0 4px; color: var(--navy-800); }
h2 { font-family: var(--display); font-size: 15.5px; font-weight: 700; margin: 0 0 14px; color: var(--navy-800); }
h3 { font-family: var(--display); font-size: 14px; font-weight: 700; margin: 0 0 8px; }

::selection { background: var(--blue-100); }
:focus-visible { outline: 2px solid var(--blue-600); outline-offset: 1px; }

/* ── Layout ── */
#app { display: flex; min-height: 100vh; min-height: 100dvh; }
.topbar, .tabbar, .drawer-backdrop { display: none; } /* mobile-only chrome */
.sidebar {
  width: 252px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy-800) 0%, var(--navy-900) 55%, var(--navy-950) 100%);
  color: #D7E2F4; display: flex; flex-direction: column;
  padding: 20px 14px 14px; position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
}
.sidebar .logo {
  font-family: var(--display); font-weight: 800; font-size: 19px; color: #fff;
  padding: 2px 10px 18px; letter-spacing: .2px;
}
.sidebar .logo em { font-style: normal; color: var(--green-500); }
.sidebar .logo small {
  display: block; font-family: var(--body); font-weight: 500; font-size: 10.5px;
  color: #7E96C4; letter-spacing: 1.6px; text-transform: uppercase; margin-top: 3px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  color: #B9C9E6; padding: 8px 12px; border-radius: 9px; font-size: 13.5px; font-weight: 500; display: block;
}
.sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.sidebar nav .nav-group {
  margin: 14px 12px 5px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1.4px; color: #6B84B8;
}

/* Priority tabs — the four most-used areas, each with its own accent */
.sidebar nav a.nav-primary {
  font-family: var(--display); font-size: 14.5px; font-weight: 700; color: #fff;
  padding: 12px 14px 12px 16px; margin: 3px 0; border-radius: 10px;
  border-left: 4px solid var(--pc, var(--green-500));
  background: linear-gradient(90deg, color-mix(in srgb, var(--pc) 22%, transparent), rgba(255,255,255,.04));
  position: relative;
}
.sidebar nav a.nav-primary small {
  display: block; font-family: var(--body); font-weight: 500; font-size: 10.5px;
  color: #A8BCDF; letter-spacing: .3px; margin-top: 1px;
}
.sidebar nav a.nav-primary:hover {
  background: linear-gradient(90deg, color-mix(in srgb, var(--pc) 38%, transparent), rgba(255,255,255,.06));
}
.sidebar nav a.nav-primary.active {
  background: var(--pc); color: #fff;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--pc) 45%, transparent);
}
.sidebar nav a.nav-primary.active small { color: rgba(255,255,255,.85); }
.nav-primary.pc-green { --pc: #00953F; }
.nav-primary.pc-blue { --pc: #2456C4; }
.nav-primary.pc-teal { --pc: #0F8C7C; }
.nav-primary.pc-amber { --pc: #C97A0A; }

.sidebar .whoami {
  padding: 12px 10px 2px; font-size: 12px; color: #9FB3D8;
  border-top: 1px solid rgba(255,255,255,.12); margin-top: 10px;
}
.sidebar .whoami button { margin-top: 8px; }

.main { flex: 1; padding: 30px 36px 48px; max-width: 1280px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 0; color: var(--muted); font-size: 13px; }

/* ── Cards & stats ── */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 18px;
}
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 17px 13px; box-shadow: var(--shadow); border-top: 3px solid var(--blue-700);
}
.stat:nth-child(2n) { border-top-color: var(--green-500); }
.stat:nth-child(3n) { border-top-color: var(--teal-600); }
.stat .label { font-size: 10.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 1.1px; }
.stat .value { font-family: var(--display); font-size: 25px; font-weight: 800; margin-top: 3px; color: var(--navy-800); font-variant-numeric: tabular-nums; }
.stat .value.small { font-size: 16px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }

/* Contact actions stay on-brand everywhere: call = royal blue, text = green */
button.btn-call, .btn.btn-call {
  background: #fff; border: 1px solid var(--blue-700); color: var(--blue-700);
}
button.btn-call:hover, .btn.btn-call:hover { background: var(--blue-100); box-shadow: none; }
button.btn-text, .btn.btn-text {
  background: #fff; border: 1px solid var(--green-700); color: var(--green-700);
}
button.btn-text:hover, .btn.btn-text:hover { background: var(--green-100); box-shadow: none; }
button.btn-email, .btn.btn-email {
  background: #fff; border: 1px solid var(--teal-600); color: var(--teal-600);
}
button.btn-email:hover, .btn.btn-email:hover { background: #E2F3F0; box-shadow: none; }

/* Embedded (iframe) mode: shrink the chrome so the workspace breathes */
.embedded .sidebar { width: 192px; padding: 14px 10px; }
.embedded .sidebar .nav-primary { font-size: 13.5px; padding: 9px 10px; }
.embedded .sidebar .nav-primary small { font-size: 10px; }
.embedded .main { padding: 14px 16px; }
.embedded .page-head h1 { font-size: 21px; }
.embedded .card { padding: 14px 16px; }

/* Frozen edge columns (e.g. Med Tracker): the first column (patient) and
   last column (actions) stay visible while scrolling sideways, and the
   header row stays visible while scrolling down. */
.table-wrap.freeze { margin: 0; padding: 0; }
.freeze th:first-child, .freeze td:first-child {
  position: sticky; left: 0; z-index: 2; background: var(--surface);
  box-shadow: inset -10px 0 8px -10px rgba(6, 39, 104, .35);
  white-space: nowrap;
}
.freeze th:last-child, .freeze td:last-child {
  position: sticky; right: 0; z-index: 2; background: var(--surface);
  box-shadow: inset 10px 0 8px -10px rgba(6, 39, 104, .35);
}
.freeze thead th:first-child, .freeze thead th:last-child { z-index: 3; }
.freeze tbody tr:hover td:first-child, .freeze tbody tr:hover td:last-child { background: #F7FAFD; }
/* Full-width rows (inline editors) opt out of the frozen columns */
.freeze td[colspan] { position: static; box-shadow: none; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
th {
  text-align: left; font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--muted); padding: 9px 10px;
  border-bottom: 2px solid var(--border-strong); white-space: nowrap;
}
td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover td { background: #F7FAFD; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }

/* ── Badges ── */
.badge {
  display: inline-block; padding: 2.5px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .2px; white-space: nowrap;
}
.badge.green { background: var(--green-100); color: var(--green-700); }
.badge.blue { background: var(--blue-100); color: var(--blue-700); }
.badge.gray { background: #EDF1F7; color: var(--muted); }
.badge.red { background: var(--red-100); color: var(--red-600); }
.badge.yellow { background: var(--amber-100); color: var(--amber-600); }

/* ── Forms & buttons ── */
button, .btn {
  font-family: var(--body); font-size: 13px; font-weight: 600;
  border: 1px solid var(--blue-700); border-radius: 9px;
  background: var(--blue-700); color: #fff; padding: 8px 16px; cursor: pointer; display: inline-block;
  transition: background .12s ease, box-shadow .12s ease;
}
button:hover, .btn:hover { background: var(--navy-800); text-decoration: none; box-shadow: 0 3px 10px rgba(0, 51, 160, .25); }
button.secondary { background: #fff; color: var(--blue-700); }
button.secondary:hover { background: var(--blue-100); box-shadow: none; }
a.btn.secondary { background: #fff; color: var(--blue-700); }
a.btn.secondary:hover { background: var(--blue-100); }
button.danger { background: #fff; border-color: var(--red-600); color: var(--red-600); }
button.danger:hover { background: var(--red-100); box-shadow: none; }
button.small, .btn.small { padding: 4.5px 11px; font-size: 12px; border-radius: 7px; }
button:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

input, select, textarea {
  font: inherit; font-size: 13.5px; padding: 8px 11px; border: 1px solid var(--border-strong);
  border-radius: 9px; background: #fff; color: var(--text); width: 100%;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue-700); box-shadow: 0 0 0 3px rgba(0, 51, 160, .14);
}
label { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; letter-spacing: .2px; }
.field { margin-bottom: 13px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 13px; }
form.inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
form.inline .field { margin-bottom: 0; flex: 1; min-width: 130px; }

/* ── Login ── */
.login-wrap {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh; width: 100%;
  padding: 16px;
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(0, 180, 84, .22), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(0, 51, 160, .5), transparent 55%),
    linear-gradient(155deg, var(--navy-800), var(--navy-950) 70%);
}
.login-card {
  background: #fff; border-radius: 16px; padding: 38px 40px; width: min(400px, 100%);
  box-shadow: 0 24px 70px rgba(2, 8, 30, .5);
  border-top: 5px solid var(--green-500);
}
.login-card h1 { font-size: 23px; }
.login-card h1 em { font-style: normal; color: var(--green-700); }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }

/* ── Misc ── */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--navy-800); color: #fff;
  padding: 12px 18px; border-radius: 11px; font-size: 13.5px;
  box-shadow: 0 8px 28px rgba(2, 8, 30, .35); z-index: 50; max-width: 440px;
  border-left: 4px solid var(--green-500);
}
.toast.error { background: var(--red-600); border-left-color: #fff; }
.muted { color: var(--muted); font-size: 12.5px; }
.right { text-align: right; }
.mt { margin-top: 14px; }
.mb0 { margin-bottom: 0; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.clock-big { font-family: var(--display); font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--navy-800); }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 14px; }
.tabs button { background: none; border: none; color: var(--muted); font-weight: 600; padding: 8px 14px; border-radius: 8px 8px 0 0; }
.tabs button.active { color: var(--blue-700); box-shadow: inset 0 -2px 0 var(--blue-700); }
.empty { text-align: center; color: var(--muted); padding: 30px 0; font-size: 13.5px; }
.doc-view { background: #fff; border: 1px solid var(--border); padding: 26px; border-radius: var(--radius); max-width: 660px; box-shadow: var(--shadow); }
.doc-view .boxes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.doc-view .box { border: 1px solid var(--border); border-radius: 9px; padding: 10px 13px; }
.doc-view .box .k { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; font-weight: 600; }
.doc-view .box .v { font-family: var(--display); font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ── Mobile: app-style shell (slide-in drawer + bottom tab bar) ────────── */
@media (max-width: 880px) {
  #app { flex-direction: column; }

  /* Slim sticky top bar: brand + menu */
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    position: sticky; top: 0; z-index: 40;
    background: linear-gradient(90deg, var(--navy-800), var(--navy-900));
    padding: 9px 12px; padding-top: max(9px, env(safe-area-inset-top));
    box-shadow: 0 2px 12px rgba(2, 8, 30, .25);
  }
  .topbar .logo { font-family: var(--display); font-weight: 800; font-size: 17px; color: #fff; }
  .topbar .logo em { font-style: normal; color: var(--green-500); }
  .topbar .menu {
    background: rgba(255,255,255,.14); border: none; color: #fff; cursor: pointer;
    font-size: 19px; line-height: 1; padding: 9px 13px; border-radius: 9px; min-height: 40px;
  }

  /* The sidebar becomes a slide-in drawer (full nav, account, sign out) */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; height: 100dvh;
    width: min(300px, 84vw); z-index: 60;
    transform: translateX(-105%); transition: transform .22s ease;
    flex-direction: column;
    padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
    box-shadow: 12px 0 40px rgba(2, 8, 30, .45);
  }
  .drawer-open .sidebar { transform: translateX(0); }
  .sidebar nav { flex-direction: column; }
  .drawer-backdrop { position: fixed; inset: 0; background: rgba(5, 15, 46, .55); z-index: 55; }
  .drawer-open .drawer-backdrop { display: block; }

  /* App-style bottom tab bar: the role's core areas, one thumb away */
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    background: var(--surface); border-top: 1px solid var(--border-strong);
    box-shadow: 0 -6px 24px rgba(6, 39, 104, .12);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .tabbar a, .tabbar button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 1px; background: none; border: none; color: var(--muted); cursor: pointer;
    font-family: var(--body); font-size: 10.5px; font-weight: 600;
    padding: 5px 2px; border-radius: 10px; min-height: 52px; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .tabbar .ticon { font-size: 21px; line-height: 1.15; }
  .tabbar a.active { color: var(--blue-700); background: var(--blue-100); }
  .tabbar a:hover { text-decoration: none; }
  .tabbar button:hover { background: none; box-shadow: none; }

  /* Content: single column, room for the tab bar, tighter chrome */
  .main { padding: 15px 13px calc(84px + env(safe-area-inset-bottom)); }
  .page-head { margin-bottom: 14px; }
  h1 { font-size: 21px; }
  .card { padding: 15px 14px; }
  .grid { gap: 12px; }
  .grid.stats { gap: 10px; }
  td, th { padding: 9px 8px; }

  /* Touch comfort: 16px inputs stop iOS zoom-on-focus; bigger tap targets */
  input, select, textarea { font-size: 16px; padding: 10px 12px; }
  button, .btn { min-height: 42px; padding: 9px 16px; }
  button.small, .btn.small { min-height: 34px; padding: 6px 11px; font-size: 12.5px; }
  .tabs { overflow-x: auto; }
  .tabs button { min-height: 40px; white-space: nowrap; }

  .toast {
    left: 12px; right: 12px; max-width: none;
    bottom: calc(72px + env(safe-area-inset-bottom));
  }
  .login-card { padding: 28px 22px; }
  .doc-view { padding: 18px 14px; }
  .doc-view .boxes { grid-template-columns: 1fr 1fr; }
  .clock-big { font-size: 26px; }
}

@media print {
  .sidebar, .page-head button, .page-head .btn, .no-print { display: none !important; }
  .main { padding: 0; max-width: none; }
  body { background: #fff; }
  .card, .doc-view { box-shadow: none; }
}
