/* public/css/app.css */
@font-face {
  font-family: 'Space Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/space-mono-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Space Mono';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/space-mono-latin-700-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/dm-sans-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/dm-sans-latin-500-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/dm-sans-latin-600-normal.woff2') format('woff2');
}

:root {
  --navy: #0a1628;
  --navy-mid: #112240;
  --navy-light: #1e3a5f;
  --teal: #00b4d8;
  --teal-dim: #0096b7;
  --amber: #f59e0b;
  --red: #ef4444;
  --green: #22c55e;
  --white: #e8f0fe;
  --muted: #8ba3c7;
  --card: #112240cc;
  --radius: 12px;
  --radius-sm: 8px;
  --font-mono: 'Space Mono', monospace;
  --font-body: 'DM Sans', sans-serif;
  --transition: 0.2s ease;
}

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

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; overflow-x: hidden; }

body { overflow-x: hidden;
  font-family: var(--font-body);
  background: var(--navy);
  color: var(--white);
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ── BACKGROUND ── */
body::before {
  content: '';
  position: fixed; inset: 0;
  background: 
    radial-gradient(ellipse 80% 60% at 20% 10%, #1e3a5f55 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 90%, #00b4d820 0%, transparent 60%);
  pointer-events: none; z-index: 0;
}

/* ── SCREENS ── */
.screen { display: none; min-height: 100dvh; position: relative; z-index: 1; }
.screen.active { display: flex; flex-direction: column; }

/* ── AUTH ── */
#screen-auth {
  align-items: center; justify-content: center;
  padding: 2rem 1.5rem;
}

body.auth-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.auth-box {
  width: 100%; max-width: 420px;
  background: var(--card);
  backdrop-filter: blur(20px);
  border: 1px solid #1e3a5f;
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
}

.auth-logo {
  text-align: center; margin-bottom: 2rem;
}
.auth-logo .logo-icon {
  width: 64px; height: 64px; margin: 0 auto 1rem;
  background: linear-gradient(135deg, var(--teal), var(--navy-light));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem;
  box-shadow: 0 0 30px #00b4d840;
}
.auth-logo h1 {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  color: var(--teal);
  letter-spacing: 0.05em;
}
.auth-logo p { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }

/* ── FORMS ── */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  background: #0a1628aa;
  border: 1px solid #1e3a5f;
  border-radius: var(--radius-sm);
  color: var(--white);
  padding: 0.75rem 1rem;
  font-family: var(--font-body);
  font-size: 1rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px #00b4d820;
}
.form-group input::placeholder { color: #4a6080; }
.form-group textarea { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 1rem; font-weight: 600;
  border: none; cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: linear-gradient(135deg, var(--teal), var(--teal-dim));
  color: var(--navy);
  box-shadow: 0 4px 15px #00b4d830;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px #00b4d840; }
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid #1e3a5f;
}
.btn-ghost:hover { border-color: var(--teal); color: var(--teal); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid #ef444440;
}
.btn-danger:hover { background: #ef444415; }

.btn-full { width: 100%; }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.875rem; }

.link-btn {
  background: none; border: none; color: var(--teal);
  cursor: pointer; font-size: 0.9rem; text-decoration: underline;
  font-family: var(--font-body);
}
.link-btn:hover { color: white; }

/* ── HEADER ── */
.app-header {
  background: #112240dd;
  backdrop-filter: blur(20px);
  border-bottom: 1px solid #1e3a5f;
  padding: 0 1rem;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
}
.header-logo {
  font-family: var(--font-mono);
  font-size: 1.1rem; color: var(--teal);
  display: flex; align-items: center; gap: 0.5rem;
}
.header-logo span { font-size: 1.3rem; }
.header-actions { display: flex; gap: 0.5rem; }
.icon-btn {
  background: none; border: 1px solid #1e3a5f;
  border-radius: var(--radius-sm);
  color: var(--muted); cursor: pointer;
  padding: 0.4rem 0.6rem; font-size: 1rem;
  transition: all var(--transition);
}
.icon-btn:hover { border-color: var(--teal); color: var(--teal); }

/* ── BOTTOM NAV ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #112240ee;
  backdrop-filter: blur(20px);
  border-top: 1px solid #1e3a5f;
  display: flex;
  z-index: 9999;
  isolation: isolate;
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
}
.nav-item {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 0.5rem 0.25rem;
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-family: var(--font-body);
  font-size: 0.65rem; font-weight: 500;
  gap: 0.2rem;
  transition: color var(--transition);
  overflow: hidden;
  white-space: nowrap;
}
.nav-item .nav-icon { font-size: 1.25rem; }
.nav-item.active { color: var(--teal); }
.nav-item:hover { color: var(--white); }
/* Abbreviate long labels on very narrow screens */
@media (max-width: 360px) {
  .nav-item { font-size: 0.6rem; }
  .nav-item .nav-icon { font-size: 1.1rem; }
}

/* ── MAIN CONTENT ── */
.app-content { 
  flex: 1; 
  padding: 1.5rem 1rem calc(5rem + env(safe-area-inset-bottom));
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  overflow-x: hidden;
}

/* ── CARDS ── */
.card {
  background: var(--card);
  backdrop-filter: blur(20px);
  border: 1px solid #1e3a5f;
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}
.card-title {
  font-family: var(--font-mono);
  font-size: 0.8rem; font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 1rem;
  display: flex; align-items: center; gap: 0.5rem;
}

/* ── INR DISPLAY ── */
.inr-hero {
  text-align: center;
  padding: 1.5rem 0;
}
.inr-value-display {
  font-family: var(--font-mono);
  font-size: 5rem; font-weight: 700;
  line-height: 1;
  margin-bottom: 0.5rem;
  transition: color 0.3s;
}
.inr-value-display.in-range { color: var(--green); }
.inr-value-display.high { color: var(--red); }
.inr-value-display.low { color: var(--amber); }

.inr-badge {
  display: inline-block;
  padding: 0.3rem 1rem;
  border-radius: 999px;
  font-size: 0.8rem; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.inr-badge.in-range { background: #22c55e20; color: var(--green); border: 1px solid #22c55e40; }
.inr-badge.high { background: #ef444420; color: var(--red); border: 1px solid #ef444440; }
.inr-badge.low { background: #f59e0b20; color: var(--amber); border: 1px solid #f59e0b40; }

.inr-range-label {
  color: var(--muted); font-size: 0.85rem; margin-top: 0.5rem;
}

/* ── DOSE SCHEDULE ── */
.dose-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.4rem;
  margin-top: 0.75rem;
}
.dose-day {
  text-align: center;
  background: #0a162880;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.25rem;
  border: 1px solid #1e3a5f;
  transition: all 0.2s;
}
.dose-day.today {
  border-color: var(--teal);
  background: #00b4d815;
}
.dose-day .day-name {
  font-size: 0.65rem; color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}
.dose-day .day-dose {
  font-family: var(--font-mono);
  font-size: 0.9rem; font-weight: 700;
  color: var(--white);
}
.dose-day.today .day-dose { color: var(--teal); }

/* ── READINGS LIST ── */
.reading-item {
  display: flex; align-items: center;
  padding: 0.875rem 0;
  border-bottom: 1px solid #1e3a5f20;
  gap: 1rem;
}
.reading-item:last-child { border-bottom: none; }
.reading-inr {
  font-family: var(--font-mono);
  font-size: 1.5rem; font-weight: 700;
  min-width: 3.5rem;
}
.reading-inr.in-range { color: var(--green); }
.reading-inr.high { color: var(--red); }
.reading-inr.low { color: var(--amber); }
.reading-info { flex: 1; }
.reading-date { font-size: 0.85rem; color: var(--muted); }
.reading-dose { font-size: 0.9rem; color: var(--white); margin-top: 0.15rem; }
.reading-status { font-size: 0.75rem; }

/* ── STATS ── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.stat-card {
  background: #0a162880;
  border: 1px solid #1e3a5f;
  border-radius: var(--radius-sm);
  padding: 1rem;
  text-align: center;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 1.75rem; font-weight: 700;
  color: var(--teal);
}
.stat-label { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

.chart-bar-container {
  display: flex; align-items: flex-end; gap: 4px;
  height: 80px; padding: 0 0.25rem;
  margin-top: 0.5rem;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}
.chart-bar-wrap { min-width: 28px; flex-shrink: 0; }
.chart-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; }
.chart-bar {
  width: 100%; border-radius: 3px 3px 0 0;
  background: var(--teal);
  transition: height 0.4s ease;
  min-height: 4px;
}
.chart-bar.high { background: var(--red); }
.chart-bar.low { background: var(--amber); }
.chart-bar-label { font-size: 0.55rem; color: var(--muted); text-align: center; }
.chart-bar-val { font-size: 0.65rem; color: var(--white); font-family: var(--font-mono); }

/* ── TOAST ── */
.toast-container {
  position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%);
  z-index: 10000; display: flex; flex-direction: column; gap: 0.5rem;
  pointer-events: none;
}
.toast {
  background: var(--navy-mid);
  border: 1px solid #1e3a5f;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  min-width: 220px; max-width: 350px;
  display: flex; align-items: center; gap: 0.5rem;
  animation: toastIn 0.3s ease;
  box-shadow: 0 8px 30px #00000060;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--teal); }
@keyframes toastIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* ── TABS ── */
.tab-group {
  display: flex; gap: 0.5rem;
  background: #0a162880;
  border-radius: var(--radius-sm);
  padding: 0.25rem;
  margin-bottom: 1.5rem;
}
.tab-btn {
  flex: 1; padding: 0.5rem;
  background: none; border: none; border-radius: 6px;
  color: var(--muted); cursor: pointer;
  font-family: var(--font-body); font-size: 0.875rem; font-weight: 500;
  transition: all var(--transition);
}
.tab-btn.active {
  background: var(--navy-light);
  color: var(--teal);
}

/* ── SECTION TITLE ── */
.section-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin: 1.5rem 0 0.75rem;
}
.section-title:first-child { margin-top: 0; }

/* ── MISC ── */
.divider { height: 1px; background: #1e3a5f; margin: 1.25rem 0; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 0.875rem; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }

.loading {
  display: flex; align-items: center; justify-content: center;
  padding: 2rem; color: var(--muted);
}
.spinner {
  width: 24px; height: 24px;
  border: 2px solid #1e3a5f;
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 0.75rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

.qr-container { text-align: center; margin: 1rem 0; }
.qr-container img { border-radius: var(--radius-sm); }

.alert {
  padding: 0.875rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.alert-success { background: #22c55e15; border: 1px solid #22c55e40; color: var(--green); }
.alert-error { background: #ef444415; border: 1px solid #ef444440; color: var(--red); }
.alert-info { background: #00b4d815; border: 1px solid #00b4d840; color: var(--teal); }
.alert-warn { background: #f59e0b15; border: 1px solid #f59e0b40; color: var(--amber); }

.pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* Settings */
.settings-section { margin-bottom: 2rem; }
.settings-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid #1e3a5f20;
}
.settings-row:last-child { border-bottom: none; }

/* Surgery view */
.patient-card {
  background: #0a162880;
  border: 1px solid #1e3a5f;
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
  transition: border-color var(--transition);
}
.patient-card:hover { border-color: var(--teal); }
.patient-name { font-weight: 600; }
.patient-meta { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }

/* Modal / Bottom sheet */
.modal-overlay {
  position: fixed; inset: 0;
  background: #00000080;
  z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-sheet {
  background: var(--navy-mid);
  border: 1px solid #1e3a5f;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.5rem;
  width: 100%; max-width: 600px;
  max-height: 80dvh; overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
}
.modal-overlay.open .modal-sheet { transform: translateY(0); }
.modal-handle {
  width: 40px; height: 4px;
  background: #1e3a5f;
  border-radius: 2px;
  margin: 0 auto 1.25rem;
}

/* HA Display */
#screen-ha {
  min-height: 100dvh;
  background: #000;
  color: #00ff88;
  font-family: var(--font-mono);
  align-items: center; justify-content: center;
  flex-direction: column;
  font-size: clamp(0.8rem, 3vw, 1.2rem);
}
#screen-ha.active { display: flex; }
.ha-display {
  padding: 1rem;
  text-align: center;
}
.ha-inr { font-size: clamp(3rem, 15vw, 6rem); font-weight: 700; line-height: 1; }
.ha-label { font-size: 0.8em; opacity: 0.6; text-transform: uppercase; letter-spacing: 0.2em; }
.ha-dose { font-size: 2em; margin-top: 0.5em; }
.ha-status-ok { color: #00ff88; }
.ha-status-high { color: #ff4444; }
.ha-status-low { color: #ffaa00; }

/* Responsive */
@media (min-width: 480px) {
  body.auth-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.auth-box { padding: 3rem 2.5rem; }
  .app-content { padding: 2rem 1.5rem 5rem; }
}

/* ── TOGGLE SWITCH ── */
.toggle-switch {
  position: relative; display: inline-block;
  width: 48px; height: 26px; flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer;
  inset: 0; background: #1e3a5f;
  border-radius: 26px;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  height: 18px; width: 18px;
  left: 4px; bottom: 4px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.toggle-switch input:checked + .toggle-slider { background: #00b4d830; border: 1px solid var(--teal); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(22px); background: var(--teal); }

/* ── DOSE TRACKER ── */
.dose-tracker-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid #1e3a5f15;
}
.dose-tracker-row:last-child { border-bottom: none; }
.dose-tracker-row.dose-today-row {
  background: #00b4d808;
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.5rem;
  margin: 0 -0.5rem;
  border-bottom: 1px solid var(--teal) !important;
}
.dose-tracker-icon { font-size: 1.25rem; width: 1.75rem; text-align: center; flex-shrink: 0; }
.dose-tracker-info { flex: 1; }
.dose-tracker-day  { font-size: 0.75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.dose-tracker-row.dose-today-row .dose-tracker-day { color: var(--teal); }
.dose-tracker-mg   { font-family: var(--font-mono); font-size: 0.95rem; font-weight: 700; color: var(--white); margin-top: 0.1rem; }
.dose-tracker-action { flex-shrink: 0; }
.dose-taken .dose-tracker-mg   { color: var(--green); }
.dose-missed .dose-tracker-mg  { color: var(--muted); text-decoration: line-through; }
.dose-future .dose-tracker-day { color: #4a6080; }
.dose-future .dose-tracker-mg  { color: #4a6080; }
