/* ============================================================
   Lakeview Resident Care — design system
   Modern SaaS look · Indigo/Cyan · Light + Dark
   Sits on top of the Tailwind CDN build.
   ============================================================ */

:root{
  --bg:#f5f6fb;
  --surface:#ffffff;
  --surface-2:#f8fafc;
  --surface-3:#f1f5f9;
  --text:#0f172a;
  --text-muted:#64748b;
  --border:#e7e9f3;
  --border-strong:#d6dae8;
  --brand:#4f46e5;
  --brand-600:#4f46e5;
  --brand-700:#4338ca;
  --accent:#06b6d4;
  --ring:rgba(99,102,241,.20);
  --shadow-sm:0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
  --shadow-md:0 6px 16px -4px rgba(16,24,40,.10), 0 2px 6px -2px rgba(16,24,40,.06);
  --shadow-lg:0 18px 40px -12px rgba(16,24,40,.22);
  --radius:.9rem;
  --radius-sm:.6rem;
}
.dark{
  --bg:#0a0f1e;
  --surface:#0f172a;
  --surface-2:#131d33;
  --surface-3:#1b2740;
  --text:#e6eaf2;
  --text-muted:#94a3b8;
  --border:#1f2a44;
  --border-strong:#2a3656;
  --ring:rgba(129,140,248,.25);
  --shadow-sm:0 1px 2px rgba(0,0,0,.45);
  --shadow-md:0 8px 22px -8px rgba(0,0,0,.6);
  --shadow-lg:0 24px 50px -16px rgba(0,0,0,.7);
}

*{box-sizing:border-box}
[x-cloak]{display:none!important}
html{scroll-behavior:smooth}
body{
  font-family:'Inter',ui-sans-serif,system-ui,-apple-system,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
  background:var(--bg);
  color:var(--text);
  -webkit-font-smoothing:antialiased;
}
/* Heading typeface: Lora (serif) for headings, Inter for everything else.
   Navigation (sidebar, bottom tabs, and slide-up menu) all stay in Inter. */
h1,h2,h3,h4{font-family:'Lora',Georgia,'Times New Roman',serif;letter-spacing:-.01em}
table{border-collapse:collapse}

/* ---------- Surfaces ---------- */
.card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow-sm);
}
.card-hover{transition:box-shadow .16s ease, transform .16s ease, border-color .16s ease}
.card-hover:hover{box-shadow:var(--shadow-md);border-color:var(--border-strong);transform:translateY(-1px)}

/* ---------- Buttons ---------- */
.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:.45rem;
  padding:.55rem .95rem;border-radius:.6rem;font-weight:600;font-size:.875rem;
  line-height:1.1;cursor:pointer;border:1px solid transparent;
  transition:filter .15s, background .15s, box-shadow .15s, border-color .15s;white-space:nowrap;
}
.btn-primary{background:linear-gradient(180deg,#6366f1,#4f46e5);color:#fff;border-color:#4338ca;box-shadow:var(--shadow-sm)}
.btn-primary:hover{filter:brightness(1.06)}
.btn-primary:active{filter:brightness(.96)}
.btn-secondary{background:var(--surface);color:var(--text);border:1px solid var(--border-strong)}
.btn-secondary:hover{background:var(--surface-2)}
.btn-danger{background:#dc2626;color:#fff;border-color:#b91c1c}
.btn-danger:hover{background:#b91c1c}
.btn-ghost{background:transparent;color:var(--text-muted)}
.btn-ghost:hover{background:var(--surface-2);color:var(--text)}
.btn:disabled,.btn[disabled]{opacity:.5;cursor:not-allowed;filter:none}

/* ---------- Forms ---------- */
.form-input,.form-select,.form-textarea{
  width:100%;border:1px solid var(--border-strong);border-radius:var(--radius-sm);
  padding:.55rem .75rem;font-size:.875rem;background:var(--surface);color:var(--text);
  transition:border-color .15s, box-shadow .15s;
}
.form-input::placeholder,.form-textarea::placeholder{color:var(--text-muted)}
.form-input:focus,.form-select:focus,.form-textarea:focus{
  outline:none;border-color:var(--brand);box-shadow:0 0 0 3px var(--ring);
}
.form-label{display:block;font-size:.8rem;font-weight:600;color:var(--text);margin-bottom:.35rem}
.field-error{color:#f43f5e;font-size:.75rem;margin-top:.25rem}

/* ---------- Tables ---------- */
table.w-full{font-variant-numeric:tabular-nums}
.table-row{transition:background .12s}
.table-row:hover{background:var(--surface-2)}

/* ---------- Charts ---------- */
.chart-box{position:relative;width:100%;height:260px}
.chart-box.sm{height:200px}
.chart-box.lg{height:320px}

/* ---------- KPI stat card ---------- */
.kpi{position:relative;overflow:hidden;border-radius:var(--radius)}
.kpi .kpi-ico{display:inline-flex;align-items:center;justify-content:center;width:2.25rem;height:2.25rem;border-radius:.65rem}

/* ---------- Accessibility: visible keyboard focus ---------- */
a:focus-visible,button:focus-visible,[role="button"]:focus-visible,summary:focus-visible,[tabindex]:focus-visible,
.form-input:focus-visible,.form-select:focus-visible{outline:2px solid var(--brand);outline-offset:2px;border-radius:.4rem}
.btn:focus-visible{outline:2px solid var(--brand-700);outline-offset:2px}

/* ============================================================
   Dark-mode remap for legacy utility-based views.
   Re-points the common Tailwind light utilities to dark tones
   so existing pages adapt without editing every file.
   (.dark .x has higher specificity than .x — no !important needed.)
   ============================================================ */
.dark .bg-white{background-color:var(--surface)}
.dark .bg-gray-50{background-color:var(--surface-2)}
.dark .bg-gray-100{background-color:var(--surface-3)}
.dark .bg-gray-50\/40{background-color:rgba(19,29,51,.5)}
.dark .text-gray-900{color:#f1f5f9}
.dark .text-gray-800{color:#e6eaf2}
.dark .text-gray-700{color:#cbd5e1}
.dark .text-gray-600{color:#a8b3c7}
.dark .text-gray-500{color:#94a3b8}
.dark .text-gray-400{color:#7688a3}
.dark .border-gray-100,.dark .border-gray-200{border-color:var(--border)}
.dark .border-gray-50{border-color:#172033}
.dark .border-t,.dark .border-b{border-color:var(--border)}
.dark .divide-gray-100>*+*{border-color:var(--border)}
.dark .hover\:bg-gray-50:hover{background-color:var(--surface-2)}
.dark .hover\:bg-gray-100:hover{background-color:var(--surface-3)}
/* keep brand tints legible on dark surfaces */
.dark .bg-brand-50{background-color:rgba(79,70,229,.16)}
.dark .bg-brand-100{background-color:rgba(79,70,229,.22)}
.dark .text-brand-700{color:#a5b4fc}
.dark .text-brand-600{color:#a5b4fc}
/* soft status tints adapt; keep readable */
.dark .bg-green-50{background-color:rgba(16,185,129,.14)}
.dark .bg-red-50{background-color:rgba(244,63,94,.15)}
.dark .bg-yellow-50{background-color:rgba(234,179,8,.14)}
.dark .bg-blue-50{background-color:rgba(59,130,246,.15)}

/* ---------- Mobile / PWA ---------- */
.bottom-nav{position:fixed;left:0;right:0;bottom:0;z-index:30;background:var(--surface);border-top:1px solid var(--border);padding-bottom:env(safe-area-inset-bottom)}
.bn-item{flex:1 1 0;min-width:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;min-height:54px;padding:6px 2px;color:var(--text-muted);font-size:11px;font-weight:500;background:none;border:0;cursor:pointer;text-align:center;text-decoration:none}
.bn-item svg{width:22px;height:22px;flex:none}
.bn-item span{max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.bn-item.bn-active{color:var(--brand)}
.dark .bn-item.bn-active{color:#a5b4fc}
/* Mobile full-menu sheet */
.nav-tile{display:flex;flex-direction:column;align-items:center;gap:.4rem;padding:.85rem .35rem;border-radius:.85rem;font-size:.72rem;font-weight:500;color:var(--text-muted);text-align:center;text-decoration:none;line-height:1.15}
.nav-tile svg{width:24px;height:24px}
.nav-tile.is-active{background:var(--surface-3);color:var(--brand)}
.dark .nav-tile.is-active{color:#a5b4fc}
/* Slide-up sheet (always in DOM; animates via .is-open — robust across browsers) */
.nav-sheet{position:fixed;inset:0;z-index:50;pointer-events:none}
.nav-sheet__scrim{position:absolute;inset:0;background:rgba(0,0,0,.5);opacity:0;transition:opacity .22s ease}
.nav-sheet__panel{position:absolute;left:0;right:0;bottom:0;max-height:82vh;overflow-y:auto;background:var(--surface);border-top-left-radius:1rem;border-top-right-radius:1rem;box-shadow:var(--shadow-lg);transform:translateY(100%);transition:transform .24s ease-out;padding-bottom:env(safe-area-inset-bottom)}
.nav-sheet.is-open{pointer-events:auto}
.nav-sheet.is-open .nav-sheet__scrim{opacity:1}
.nav-sheet.is-open .nav-sheet__panel{transform:translateY(0)}
/* Login: on phones the form floats as a card over the full-bleed image */
@media (max-width:1023px){
  .auth-card{background:var(--surface);border-radius:1rem;box-shadow:var(--shadow-lg);padding:1.6rem 1.35rem}
}
/* Comfortable touch targets on touch devices */
@media (pointer:coarse){
  .btn{min-height:44px}
  .form-input,.form-select,.form-textarea{min-height:44px}
}
html,body{-webkit-tap-highlight-color:transparent}
/* Prevent stray horizontal scroll on mobile (clip preserves sticky header) */
html,body{overflow-x:clip;max-width:100%}
button,a,.btn,input,select,textarea,label{touch-action:manipulation}

/* Responsive tables: on phones, a `.rtable` collapses each row into a stacked,
   labelled card (no sideways scrolling). Add class `rtable` to the <table> and
   `data-label="…"` to each <td>; the first cell is treated as the row title. */
@media (max-width:639px){
  .rtable, .rtable tbody{display:block}
  .rtable thead{display:none}
  .rtable tr{display:block;padding:.55rem .9rem;border-bottom:1px solid var(--border)}
  .rtable tr:last-child{border-bottom:0}
  .rtable td{display:flex;justify-content:space-between;gap:1rem;align-items:baseline;padding:.22rem 0;text-align:right;border:0;white-space:normal}
  .rtable td::before{content:attr(data-label);color:var(--text-muted);font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.02em;text-align:left;flex:0 0 auto}
  .rtable td:empty{display:none}
  .rtable td:first-child{font-weight:600;padding-bottom:.3rem;font-size:.95rem}
  .rtable td:first-child::before{display:none}
  .rtable td[data-label=""]::before{display:none}
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce){
  *,*::before,*::after{animation-duration:.001ms!important;animation-iteration-count:1!important;transition-duration:.001ms!important;scroll-behavior:auto!important}
}
