/* ============================================================
   EMRSystems Clinical Workspace — Design System
   Brand tokens extracted from emrsystems.us
   ============================================================ */
:root {
  --radius: .625rem;
  --background: #f7fbfd;
  --foreground: #233447;
  --surface: #fff;
  --card: #fff;
  --card-foreground: #233447;
  --primary: #003c5c;
  --primary-hover: #005580;
  --primary-foreground: #f7fbfd;
  --secondary: #3cc3ab;
  --secondary-dark: #2ba18c;
  --secondary-foreground: #05131d;
  --muted: #e9f0f5;
  --muted-foreground: #414f5d;
  --accent: #f4a437;
  --accent-foreground: #0b1c2c;
  --success: #33ac5a;
  --success-foreground: #fcfcfc;
  --destructive: #ee3533;
  --destructive-foreground: #fcfcfc;
  --border: #d8dfe4;
  --input: #dfe6eb;
  --ring: #3cc3ab;
  --sidebar-bg: #002c44;
  --sidebar-fg: #b8cbd8;
  --font-sans: "Source Sans 3", "Source Sans Pro", system-ui, sans-serif;
  --font-heading: "Montserrat", var(--font-sans);
  --font-mono: "Source Code Pro", ui-monospace, monospace;
  --shadow-sm: 0 1px 2px rgba(2, 32, 51, .06);
  --shadow-md: 0 2px 8px rgba(2, 32, 51, .09);
  --shadow-lg: 0 8px 28px rgba(2, 32, 51, .16);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--foreground);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-heading); color: var(--primary); }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Layout shell ---------- */
.shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex; flex-direction: column;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo svg { flex-shrink: 0; }
.sidebar-logo .brand {
  font-family: var(--font-heading);
  font-weight: 700; font-size: 17px; color: #fff; letter-spacing: -.2px;
}
.sidebar-logo .brand span { color: var(--secondary); }

.nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6d8598; padding: 14px 10px 6px; font-weight: 600; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; margin-bottom: 2px;
  border-radius: 8px;
  color: var(--sidebar-fg); text-decoration: none;
  font-size: 14px; font-weight: 500;
  transition: background .12s, color .12s;
}
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: var(--secondary); color: var(--secondary-foreground); font-weight: 600; }
.nav a.active svg { stroke: var(--secondary-foreground); }
.nav a svg { width: 17px; height: 17px; stroke: currentColor; flex-shrink: 0; }

.sidebar-footer { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #6d8598; }
.sidebar-footer .badges { display: flex; gap: 6px; margin-top: 6px; }
.sidebar-footer .badge-mini { border: 1px solid rgba(255,255,255,.18); border-radius: 4px; padding: 1px 6px; font-size: 10px; color: #9fb4c2; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 58px; flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 22px;
}
.topbar .page-title { font-size: 17px; font-weight: 600; }
.topbar .spacer { flex: 1; }
.global-search { position: relative; width: 320px; }
.global-search input {
  width: 100%; padding: 8px 12px 8px 34px;
  border: 1px solid var(--input); border-radius: 8px;
  background: var(--background); font-size: 14px;
  outline: none;
}
.global-search input:focus { border-color: var(--ring); box-shadow: 0 0 0 3px rgba(60,195,171,.18); }
.global-search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; stroke: var(--muted-foreground); }
.search-results {
  position: absolute; top: 42px; left: 0; right: 0; z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); max-height: 320px; overflow-y: auto;
}
.search-results .sr-item { padding: 10px 14px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.search-results .sr-item:hover { background: var(--muted); }
.search-results .sr-empty { padding: 14px; color: var(--muted-foreground); font-size: 13px; }

.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px; flex-shrink: 0;
}
.avatar.teal { background: var(--secondary); color: var(--secondary-foreground); }
.user-chip .u-name { font-size: 13.5px; font-weight: 600; line-height: 1.15; }
.user-chip .u-role { font-size: 11.5px; color: var(--muted-foreground); }

.content { flex: 1; overflow-y: auto; padding: 24px; }

/* ---------- Cards, stats ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card .card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card .card-head h3 { font-size: 14.5px; font-weight: 600; }
.card .card-body { padding: 18px; }
.card .card-body.flush { padding: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.stat-icon {
  width: 42px; height: 42px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.navy { background: rgba(0,60,92,.1); } .stat-icon.navy svg { stroke: var(--primary); }
.stat-icon.teal { background: rgba(60,195,171,.15); } .stat-icon.teal svg { stroke: var(--secondary-dark); }
.stat-icon.amber { background: rgba(244,164,55,.16); } .stat-icon.amber svg { stroke: #c77f16; }
.stat-icon.red { background: rgba(238,53,51,.1); } .stat-icon.red svg { stroke: var(--destructive); }
.stat-value { font-size: 22px; font-weight: 700; font-family: var(--font-heading); color: var(--primary); line-height: 1.1; }
.stat-label { font-size: 12.5px; color: var(--muted-foreground); }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 8px 15px; font-size: 13.5px; font-weight: 600;
  transition: background .12s, border-color .12s;
  text-decoration: none;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.btn-secondary:hover { background: var(--secondary-dark); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--foreground); }
.btn-outline:hover { background: var(--muted); }
.btn-danger { background: var(--destructive); color: var(--destructive-foreground); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--muted); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; padding: 10px 16px;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted-foreground); font-weight: 600;
  border-bottom: 1px solid var(--border);
  background: #fbfdfe;
  white-space: nowrap;
}
table.data td { padding: 11px 16px; border-bottom: 1px solid #eef2f5; vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: #f2f8fb; }

/* ---------- Badges / pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 999px; padding: 2.5px 10px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill.teal { background: rgba(60,195,171,.15); color: #1d7d6c; }
.pill.navy { background: rgba(0,60,92,.09); color: var(--primary); }
.pill.amber { background: rgba(244,164,55,.16); color: #a56408; }
.pill.red { background: rgba(238,53,51,.1); color: #c22321; }
.pill.green { background: rgba(51,172,90,.12); color: #1f7c3f; }
.pill.gray { background: var(--muted); color: var(--muted-foreground); }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: var(--foreground); }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--input); border-radius: 8px;
  background: var(--surface); outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.field textarea { resize: vertical; min-height: 74px; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--ring); box-shadow: 0 0 0 3px rgba(60,195,171,.18);
}
.field .hint { font-size: 12px; color: var(--muted-foreground); margin-top: 4px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 25, 40, .48);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 20px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px;
  width: 100%; max-width: 560px;
  box-shadow: var(--shadow-lg);
  animation: modal-in .16s ease-out;
}
.modal.wide { max-width: 720px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; }
.modal-close { background: none; border: none; font-size: 22px; line-height: 1; color: var(--muted-foreground); padding: 2px 6px; border-radius: 6px; }
.modal-close:hover { background: var(--muted); }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--primary); color: #fff;
  padding: 11px 18px; border-radius: 10px;
  font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 9px;
  animation: toast-in .18s ease-out;
}
.toast.success { background: #1d7d6c; }
.toast.error { background: var(--destructive); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #002c44 0%, #003c5c 55%, #045d7e 100%);
  padding: 24px;
}
.login-card {
  background: var(--surface); border-radius: 16px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
  padding: 34px 32px;
}
.login-brand { display: flex; align-items: center; gap: 11px; justify-content: center; margin-bottom: 6px; }
.login-brand .brand { font-family: var(--font-heading); font-weight: 700; font-size: 22px; color: var(--primary); }
.login-brand .brand span { color: var(--secondary-dark); }
.login-sub { text-align: center; color: var(--muted-foreground); font-size: 13.5px; margin-bottom: 24px; }
.login-card .field { margin-bottom: 14px; }
.login-demo {
  margin-top: 18px; padding: 12px 14px;
  background: var(--muted); border-radius: 10px;
  font-size: 12.5px; color: var(--muted-foreground); line-height: 1.6;
}
.login-hipaa { text-align: center; margin-top: 18px; font-size: 11.5px; color: var(--muted-foreground); display: flex; gap: 8px; justify-content: center; }
.login-hipaa span { border: 1px solid var(--border); padding: 2px 8px; border-radius: 5px; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 14px; flex-wrap: wrap; }
.page-head h2 { font-size: 20px; }
.page-head .sub { color: var(--muted-foreground); font-size: 13.5px; margin-top: 3px; }
.page-actions { display: flex; gap: 10px; }

/* ---------- Patient chart ---------- */
.chart-header { display: flex; gap: 18px; align-items: center; padding: 20px; flex-wrap: wrap; }
.chart-header .avatar { width: 56px; height: 56px; font-size: 19px; }
.chart-header .p-name { font-size: 19px; font-weight: 700; font-family: var(--font-heading); color: var(--primary); }
.chart-header .p-meta { color: var(--muted-foreground); font-size: 13.5px; margin-top: 3px; display: flex; gap: 14px; flex-wrap: wrap; }
.chart-header .p-meta b { color: var(--foreground); font-weight: 600; }
.chart-alerts { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 20px; }
.tabs button {
  background: none; border: none; padding: 11px 16px;
  font-size: 13.5px; font-weight: 600; color: var(--muted-foreground);
  border-bottom: 2.5px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { color: var(--primary); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--secondary); }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .summary-grid { grid-template-columns: 1fr; } }

.list-item { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 11px 18px; border-bottom: 1px solid #eef2f5; }
.list-item:last-child { border-bottom: none; }
.list-item .li-title { font-weight: 600; font-size: 14px; }
.list-item .li-sub { font-size: 12.5px; color: var(--muted-foreground); margin-top: 2px; }
.empty-note { padding: 18px; color: var(--muted-foreground); font-size: 13.5px; text-align: center; }

.vitals-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.vital-box { background: var(--background); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.vital-box .v-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-foreground); font-weight: 600; }
.vital-box .v-value { font-size: 17px; font-weight: 700; color: var(--primary); margin-top: 2px; font-family: var(--font-heading); }
.vital-box .v-unit { font-size: 11.5px; color: var(--muted-foreground); font-weight: 500; }

/* ---------- SOAP editor ---------- */
.soap-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .soap-grid { grid-template-columns: 1fr; } }
.soap-section label { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13px; margin-bottom: 6px; color: var(--primary); }
.soap-letter {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--secondary); color: var(--secondary-foreground);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.soap-section textarea { width: 100%; min-height: 120px; }
.note-signed-banner {
  display: flex; align-items: center; gap: 8px;
  background: rgba(51,172,90,.1); color: #1f7c3f;
  border: 1px solid rgba(51,172,90,.3);
  padding: 9px 14px; border-radius: 9px; font-size: 13px; font-weight: 600;
  margin-bottom: 14px;
}

/* ---------- Schedule ---------- */
.sched-controls { display: flex; align-items: center; gap: 10px; }
.sched-controls .current-range { font-weight: 700; font-family: var(--font-heading); color: var(--primary); font-size: 15px; min-width: 210px; text-align: center; }
.cal-grid { display: grid; grid-template-columns: 62px repeat(5, 1fr); border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.cal-head-cell {
  padding: 9px 6px; text-align: center; font-size: 12.5px; font-weight: 600;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  background: #fbfdfe;
}
.cal-head-cell .dnum { display: block; font-family: var(--font-heading); font-size: 16px; color: var(--primary); }
.cal-head-cell.today { background: rgba(60,195,171,.12); }
.cal-time-cell {
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  font-size: 11px; color: var(--muted-foreground); text-align: right;
  padding: 4px 7px 0 0; height: 52px; background: #fbfdfe;
}
.cal-slot { border-right: 1px solid #eef2f5; border-bottom: 1px solid #eef2f5; height: 52px; position: relative; cursor: pointer; }
.cal-slot:hover { background: #f2f8fb; }
.cal-appt {
  position: absolute; left: 3px; right: 3px; z-index: 5;
  border-radius: 7px; padding: 4px 8px;
  font-size: 11.5px; line-height: 1.3; overflow: hidden;
  border-left: 3px solid;
  cursor: pointer;
}
.cal-appt b { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-appt.scheduled { background: rgba(0,60,92,.08); border-color: var(--primary); color: var(--primary); }
.cal-appt.checked-in { background: rgba(244,164,55,.15); border-color: var(--accent); color: #7c4e07; }
.cal-appt.completed { background: rgba(51,172,90,.12); border-color: var(--success); color: #1f7c3f; }
.cal-appt.telehealth { background: rgba(60,195,171,.14); border-color: var(--secondary); color: #14655a; }
.cal-appt.no-show { background: rgba(238,53,51,.08); border-color: var(--destructive); color: #b02220; text-decoration: line-through; }

/* ---------- eRx ---------- */
.interaction-warning {
  display: flex; gap: 10px; align-items: flex-start;
  background: rgba(238,53,51,.07); border: 1px solid rgba(238,53,51,.35);
  border-radius: 10px; padding: 12px 14px; font-size: 13px;
  margin-bottom: 12px;
}
.interaction-warning.moderate { background: rgba(244,164,55,.1); border-color: rgba(244,164,55,.5); }
.interaction-warning b { display: block; margin-bottom: 2px; }
.interaction-warning svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.interaction-ok {
  display: flex; gap: 8px; align-items: center;
  background: rgba(51,172,90,.08); border: 1px solid rgba(51,172,90,.3);
  border-radius: 10px; padding: 10px 14px; font-size: 13px; color: #1f7c3f;
  margin-bottom: 12px; font-weight: 600;
}

/* ---------- Misc ---------- */
.mb-14 { margin-bottom: 14px; }
.mb-18 { margin-bottom: 18px; }
.mt-14 { margin-top: 14px; }
.text-muted { color: var(--muted-foreground); }
.text-sm { font-size: 13px; }
.flex { display: flex; } .items-center { align-items: center; } .gap-8 { gap: 8px; } .gap-10 { gap: 10px; }

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