/* ============================================================
   KodiManager — Global Stylesheet
   Design language: Clean, professional, Kenya-grounded.
   Palette: Deep navy authority + warm amber accent + clean white.
   Fonts: Inter (UI) + Sora (display headings)
   ============================================================ */

/* Google Fonts is loaded via a <link rel="stylesheet"> in each page's <head>,
   not an @import here — @import blocks the browser from discovering the font
   request until this whole file is fetched and parsed; a <link> tag lets the
   preload scanner start it immediately, in parallel with everything else. */

/* ── Tokens ──────────────────────────────────────────────── */
:root {
  /* Brand */
  --clr-navy      : #0F2044;   /* primary — trust, authority */
  --clr-amber     : #F5A623;   /* accent  — energy, Kenya warmth */
  --clr-amber-dk  : #D4891A;   /* hover state */
  --clr-green     : #1DB954;   /* success / paid */
  --clr-red       : #E5383B;   /* danger / arrears */
  --clr-sky       : #E8F0FE;   /* light background tint */

  /* Neutral scale */
  --clr-white     : #FFFFFF;
  --clr-bg        : #F7F9FC;
  --clr-surface   : #FFFFFF;
  --clr-border    : #DDE3EE;
  --clr-muted     : #6B7A99;
  --clr-text      : #1A2340;
  --clr-text-soft : #4A5578;

  /* Type */
  --font-display  : 'Sora', sans-serif;
  --font-body     : 'Inter', sans-serif;

  /* Spacing */
  --sp-xs  : 4px;
  --sp-sm  : 8px;
  --sp-md  : 16px;
  --sp-lg  : 24px;
  --sp-xl  : 40px;
  --sp-2xl : 64px;

  /* Radius */
  --r-sm  : 6px;
  --r-md  : 10px;
  --r-lg  : 16px;
  --r-pill: 999px;

  /* Shadow */
  --shadow-sm : 0 1px 3px rgba(15,32,68,0.08);
  --shadow-md : 0 4px 16px rgba(15,32,68,0.10);
  --shadow-lg : 0 8px 32px rgba(15,32,68,0.14);

  /* Transitions — a soft, Apple/Linear-style deceleration curve used
     throughout for hover/press feedback instead of the browser's default
     linear "ease", plus a slightly longer curve for larger, "settling"
     motions (cards, toasts) that shouldn't feel snappy. */
  --transition   : 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --ease-smooth  : cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out-soft: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family : var(--font-body);
  color       : var(--clr-text);
  background  : var(--clr-bg);
  line-height : 1.6;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a   { color: var(--clr-navy); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Typography ──────────────────────────────────────────── */
h1, h2, h3, h4, h5 {
  font-family : var(--font-display);
  line-height : 1.2;
  color       : var(--clr-navy);
}
h1 { font-size: clamp(2rem, 4vw, 3rem);    font-weight: 800; }
h2 { font-size: clamp(1.5rem, 3vw, 2rem);  font-weight: 700; }
h3 { font-size: 1.25rem; font-weight: 600; }
h4 { font-size: 1rem;    font-weight: 600; }
p  { color: var(--clr-text-soft); }

/* ── Layout Utilities ────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 var(--sp-lg);
}
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-col     { display: flex; flex-direction: column; }
.gap-sm  { gap: var(--sp-sm); }
.gap-md  { gap: var(--sp-md); }
.gap-lg  { gap: var(--sp-lg); }
.text-center { text-align: center; }
.mt-sm   { margin-top: var(--sp-sm);  }
.mt-md   { margin-top: var(--sp-md);  }
.mt-lg   { margin-top: var(--sp-lg);  }
.mt-xl   { margin-top: var(--sp-xl);  }

/* ── Card ────────────────────────────────────────────────── */
.card {
  background    : var(--clr-surface);
  border        : 1px solid var(--clr-border);
  border-radius : var(--r-lg);
  padding       : var(--sp-lg);
  box-shadow    : var(--shadow-sm);
  transition    : box-shadow 220ms var(--ease-out-soft), transform 220ms var(--ease-out-soft);
}
.card--raised { box-shadow: var(--shadow-md); }
/* Opt-in hover-lift for cards that are actually clickable (list rows,
   selectable plan cards, etc.) — not applied to .card by default since
   most cards on this site are plain, non-interactive containers. */
.card--hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display         : inline-flex;
  align-items     : center;
  justify-content : center;
  gap             : var(--sp-sm);
  font-family     : var(--font-body);
  font-size       : 0.9375rem;
  font-weight     : 600;
  line-height     : 1;
  padding         : 12px 24px;
  border-radius   : var(--r-md);
  border          : 2px solid transparent;
  cursor          : pointer;
  transition      : background var(--transition), color var(--transition),
                    box-shadow var(--transition), transform var(--transition);
  white-space     : nowrap;
  text-decoration : none; /* .btn is sometimes an <a> (e.g. a modal's "Set payment
                              method" CTA) — without this it'd pick up the global
                              a:hover{text-decoration:underline} rule and look broken */
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.97); transition-duration: 80ms; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn--primary {
  background : var(--clr-amber);
  color      : var(--clr-navy);
  border-color: var(--clr-amber);
}
.btn--primary:hover:not(:disabled) {
  background  : var(--clr-amber-dk);
  border-color: var(--clr-amber-dk);
  box-shadow  : 0 4px 12px rgba(245,166,35,0.35);
}

.btn--navy {
  background : var(--clr-navy);
  color      : var(--clr-white);
  border-color: var(--clr-navy);
}
.btn--navy:hover:not(:disabled) {
  background : #162d5c;
  box-shadow : var(--shadow-md);
}

.btn--outline {
  background   : transparent;
  color        : var(--clr-navy);
  border-color : var(--clr-navy);
}
.btn--outline:hover:not(:disabled) {
  background: var(--clr-sky);
}

.btn--sm { padding: 8px 16px; font-size: 0.875rem; }
.btn--lg { padding: 15px 32px; font-size: 1rem; }
.btn--full { width: 100%; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group {
  display       : flex;
  flex-direction: column;
  gap           : var(--sp-xs);
}
.form-group label {
  font-size  : 0.875rem;
  font-weight: 600;
  color      : var(--clr-text);
}
.form-group input,
.form-group select,
.form-group textarea {
  width         : 100%;
  padding       : 11px 14px;
  border        : 1.5px solid var(--clr-border);
  border-radius : var(--r-sm);
  font-family   : var(--font-body);
  font-size     : 0.9375rem;
  color         : var(--clr-text);
  background    : var(--clr-white);
  transition    : border-color var(--transition), box-shadow var(--transition);
  outline       : none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--clr-amber);
  box-shadow  : 0 0 0 3px rgba(245,166,35,0.15);
}
.form-group input::placeholder { color: #9AA4BF; }

/* ── Auth Error ──────────────────────────────────────────── */
.auth-error {
  font-size    : 0.875rem;
  color        : var(--clr-red);
  background   : #FFF0F0;
  border       : 1px solid #FFD0D0;
  border-radius: var(--r-sm);
  padding      : var(--sp-sm) var(--sp-md);
  min-height   : 36px;
}
.auth-error:empty { display: none; }

/* ── Auth Page Layout ────────────────────────────────────── */
.auth-page {
  min-height  : 100vh;
  display     : grid;
  grid-template-columns: 1fr 1fr;
}
.auth-panel--left {
  position      : relative;
  overflow      : hidden;
  background    : linear-gradient(160deg, var(--clr-sky) 0%, var(--clr-white) 65%);
  color         : var(--clr-navy);
  padding       : var(--sp-2xl) var(--sp-xl);
  display       : flex;
  flex-direction: column;
  justify-content: center;
  border-right  : 1px solid var(--clr-border);
}
/* Two soft, decorative gradient blobs stand in for the old solid navy fill —
   keeps the panel from reading as flat/empty now that it's light, without
   turning it back into a heavy dark block. */
.auth-panel--left::before {
  content       : "";
  position      : absolute;
  width         : 420px; height: 420px;
  right         : -160px; top: -140px;
  background    : radial-gradient(circle, rgba(245,166,35,0.18) 0%, rgba(245,166,35,0) 70%);
  pointer-events: none;
}
.auth-panel--left::after {
  content       : "";
  position      : absolute;
  width         : 320px; height: 320px;
  left          : -120px; bottom: -120px;
  background    : radial-gradient(circle, rgba(15,32,68,0.07) 0%, rgba(15,32,68,0) 70%);
  pointer-events: none;
}
.auth-panel--left > * { position: relative; z-index: 1; }
.auth-panel--left h1 { color: var(--clr-navy); }
.auth-panel--left p  { color: var(--clr-text-soft); font-size: 1.05rem; margin-top: var(--sp-md); }
.auth-panel--left .auth-brand {
  display    : flex;
  align-items: center;
  gap        : var(--sp-sm);
  margin-bottom: var(--sp-xl);
}
.auth-panel--left .auth-brand span {
  font-family : var(--font-display);
  font-size   : 1.5rem;
  font-weight : 800;
  color       : var(--clr-navy);
}
.auth-panel--left .auth-brand span span { color: var(--clr-amber); }

.auth-panel--right {
  background: var(--clr-white);
  padding   : var(--sp-2xl) var(--sp-xl);
  display   : flex;
  flex-direction: column;
  justify-content: center;
}

.auth-form-wrap {
  width    : 100%;
  max-width: 400px;
  margin   : 0 auto;
}
.auth-form-wrap h2 { margin-bottom: var(--sp-xs); }
.auth-form-wrap > p { margin-bottom: var(--sp-xl); font-size: 0.9375rem; }

/* ── Nav ─────────────────────────────────────────────────── */
.nav {
  position  : sticky;
  top       : 0;
  z-index   : 100;
  background: var(--clr-white);
  border-bottom: 1px solid var(--clr-border);
  box-shadow: var(--shadow-sm);
}
.nav__inner {
  height : 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav__logo {
  font-family : var(--font-display);
  font-size   : 1.375rem;
  font-weight : 800;
  color       : var(--clr-navy);
  text-decoration: none;
}
.nav__logo span { color: var(--clr-amber); }
.nav__links { display: flex; align-items: center; gap: var(--sp-lg); }
.nav__links a {
  font-size  : 0.9375rem;
  font-weight: 500;
  color      : var(--clr-text-soft);
  transition : color var(--transition);
}
.nav__links a:hover { color: var(--clr-navy); text-decoration: none; }

/* ── Dashboard Sidebar Layout ────────────────────────────── */
.dashboard {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background    : var(--clr-navy);
  padding       : var(--sp-xl) 0;
  display       : flex;
  flex-direction: column;
}
.sidebar__logo {
  font-family   : var(--font-display);
  font-size     : 1.25rem;
  font-weight   : 800;
  color         : var(--clr-white);
  padding       : 0 var(--sp-lg) var(--sp-xl);
  display       : block;
}
.sidebar__logo span { color: var(--clr-amber); }
.sidebar__nav a {
  display     : flex;
  align-items : center;
  gap         : var(--sp-md);
  padding     : 12px var(--sp-lg);
  color       : rgba(255,255,255,0.65);
  font-size   : 0.9375rem;
  font-weight : 500;
  transition  : background var(--transition), color var(--transition);
  border-left : 3px solid transparent;
}
.sidebar__nav a:hover,
.sidebar__nav a.active {
  background  : rgba(255,255,255,0.08);
  color       : var(--clr-white);
  text-decoration: none;
  border-left-color: var(--clr-amber);
}
.sidebar__nav a svg { width: 18px; height: 18px; flex-shrink: 0; }

.main-content {
  padding   : var(--sp-xl);
  overflow-y: auto;
}
.page-header { margin-bottom: var(--sp-xl); }
.page-header h2 { margin-bottom: var(--sp-xs); }

/* ── Stat Cards ──────────────────────────────────────────── */
.stats-grid {
  display              : grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap                  : var(--sp-lg);
  margin-bottom        : var(--sp-xl);
}
/* Desktop: force all 5 dashboard stat cards onto one row instead of
   auto-fit wrapping to a 4+1 layout once minmax(200px,1fr) can't fit a
   5th column in the available width. */
@media (min-width: 901px) {
  .stats-grid { grid-template-columns: repeat(5, 1fr); }
}
.stat-card {
  background   : var(--clr-surface);
  border       : 1px solid var(--clr-border);
  border-radius: var(--r-lg);
  padding      : var(--sp-lg);
  box-shadow   : var(--shadow-sm);
  transition   : transform 220ms var(--ease-out-soft), box-shadow 220ms var(--ease-out-soft);
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-card__label {
  font-size  : 0.6875rem;
  font-weight: 600;
  color      : var(--clr-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-card__value {
  font-family: var(--font-display);
  font-size  : 2rem;
  font-weight: 700;
  color      : var(--clr-navy);
  margin-top : var(--sp-xs);
}
.stat-card__value--green { color: var(--clr-green); }
.stat-card__value--red   { color: var(--clr-red);   }
.stat-card__value--amber { color: var(--clr-amber-dk); }

/* ── Phones + native app: shorter stat cards ──────────────────
   Desktop padding/value size made sense with more vertical room to
   spare; on a phone, 5 stacked cards ate a lot of scroll before
   reaching the chart/activity below. Trim padding and value size,
   not the label fix above (already handles both). ── */
@media (max-width: 700px) {
  .stat-card { padding: var(--sp-md) var(--sp-lg); }
  .stat-card__value { font-size: 1.375rem; margin-top: 2px; }
}

/* ── Badge ───────────────────────────────────────────────── */
.badge {
  display       : inline-flex;
  align-items   : center;
  padding       : 3px 10px;
  border-radius : var(--r-pill);
  font-size     : 0.75rem;
  font-weight   : 600;
  /* A status badge (e.g. unpaid → paid) swaps color on re-render rather
     than animating in place — this transition is what makes that swap
     read as a soft fade instead of an abrupt snap. */
  transition    : background-color 260ms var(--ease-smooth), color 260ms var(--ease-smooth);
}
.badge--green  { background: #E6F9EF; color: #1A7A3F; }
.badge--red    { background: #FFF0F0; color: #C0392B; }
.badge--amber  { background: #FFF8E7; color: #9A6500; }
.badge--blue   { background: #EBF3FF; color: #1A56DB; }
.badge--grey   { background: #F0F2F7; color: #6B7A99; }

/* ── Table ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width          : 100%;
  border-collapse: collapse;
  font-size      : 0.9375rem;
}
thead th {
  text-align   : left;
  font-size    : 0.8125rem;
  font-weight  : 600;
  color        : var(--clr-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding      : var(--sp-sm) var(--sp-md);
  border-bottom: 2px solid var(--clr-border);
  background   : var(--clr-bg);
}
tbody td {
  padding      : 14px var(--sp-md);
  border-bottom: 1px solid var(--clr-border);
  color        : var(--clr-text);
  vertical-align: middle;
  transition   : background-color 150ms var(--ease-smooth);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--clr-sky); }

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding   : var(--sp-2xl) var(--sp-xl);
  color     : var(--clr-muted);
}
.empty-state svg { margin: 0 auto var(--sp-md); opacity: 0.4; }
.empty-state h3  { color: var(--clr-text-soft); margin-bottom: var(--sp-sm); }

/* ── Toast ───────────────────────────────────────────────────
   Top-center, "Dynamic Island"-style: anchored at the top of the
   viewport instead of the bottom-right corner, and each toast enters
   by stretching outward from its own horizontal center (scaleX) rather
   than sliding up — see toastIn/toastOut below. Moving this to the top
   also sidesteps the native app's bottom tab bar (#bottom-bar), which
   the old bottom-right placement sat uncomfortably close to. */
#toast-container {
  position  : fixed;
  top       : var(--sp-lg);
  left      : 50%;
  transform : translateX(-50%);
  z-index   : 9999;
  display   : flex;
  flex-direction: column;
  align-items: center;
  gap       : var(--sp-sm);
  pointer-events: none; /* toasts are informational, never block taps on what's under them */
}
.toast {
  background   : var(--clr-navy);
  color        : var(--clr-white);
  padding      : 12px 22px;
  border-radius: var(--r-pill);
  font-size    : 0.9375rem;
  box-shadow   : var(--shadow-lg);
  animation    : toastIn 420ms var(--ease-out-soft);
  max-width    : 340px;
  pointer-events: auto;
  transform-origin: center;
}
.toast--success { border-left: 4px solid var(--clr-green); }
.toast--error   { border-left: 4px solid var(--clr-red);   }
.toast--info    { border-left: 4px solid var(--clr-amber);  }
/* Applied by showToast() just before removal, so a toast shrinks back
   toward center instead of disappearing instantly — see per-page
   showToast(). */
.toast--out { animation: toastOut 220ms var(--ease-smooth) forwards; }

@keyframes toastIn {
  from { opacity: 0; transform: scaleX(0.4)  scaleY(0.7); }
  60%  { opacity: 1; transform: scaleX(1.04) scaleY(1.02); }
  to   { opacity: 1; transform: scaleX(1)    scaleY(1);    }
}
@keyframes toastOut {
  from { opacity: 1; transform: scaleX(1)   scaleY(1);   }
  to   { opacity: 0; transform: scaleX(0.5) scaleY(0.75); }
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-panel--left { display: none; }
  .dashboard { grid-template-columns: 1fr; }
  .sidebar { display: none; }  /* mobile nav TODO Phase 5 */
}
@media (max-width: 600px) {
  .container { padding: 0 var(--sp-md); }
  .main-content { padding: var(--sp-lg) var(--sp-md); }
}

/* ── Reduced Motion ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── Mobile top bar ──────────────────────────────────────── */
#mobile-topbar {
  display        : none;
  position       : sticky;
  top            : 0;
  z-index        : 200;
  background     : var(--clr-navy);
  padding        : 0 var(--sp-lg);
  height         : 56px;
  align-items    : center;
  justify-content: space-between;
  border-bottom  : 1px solid rgba(255,255,255,0.1);
}
.mobile-topbar__logo {
  font-family : var(--font-display);
  font-size   : 1.25rem;
  font-weight : 800;
  color       : white;
}
.mobile-topbar__logo span { color: var(--clr-amber); }
.mobile-topbar__burger {
  background : none; border: none; cursor: pointer;
  color      : white; display: flex; align-items: center;
  padding    : 6px;
}

/* ── Mobile nav overlay ──────────────────────────────────── */
#mobile-nav-overlay {
  position  : fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index   : 300;
  opacity   : 0; pointer-events: none;
  transition: opacity 200ms;
}
#mobile-nav-overlay.open { opacity: 1; pointer-events: all; }
#mobile-nav-drawer {
  position  : absolute; left: 0; top: 0; bottom: 0;
  width     : 280px; background: var(--clr-navy);
  display   : flex; flex-direction: column;
  transform : translateX(-100%);
  transition: transform 250ms ease;
  overflow-y: auto;
}
#mobile-nav-overlay.open #mobile-nav-drawer { transform: translateX(0); }

/* ── Subscription badge on sidebar ──────────────────────── */
.sub-badge {
  display       : inline-flex; align-items: center;
  padding       : 2px 8px; border-radius: var(--r-pill);
  font-size     : 0.7rem; font-weight: 700;
  margin-left   : auto; letter-spacing: 0.03em;
}
.sub-badge--ok      { background: rgba(30,185,84,0.2); color: #6EF2A1; }
.sub-badge--warning { background: rgba(245,166,35,0.2); color: var(--clr-amber); }
.sub-badge--expired { background: rgba(229,56,59,0.2);  color: #FF8A8A; }

/* ── Native app (Capacitor): persistent bottom tab bar ─────────
   Only injected/shown when window.Capacitor.isNativePlatform() is
   true (see sidebar.js) — replaces the web hamburger-drawer pattern
   with a native-feeling bottom tab bar. Mobile web keeps its original
   top bar + hamburger drawer, unaffected. A floating rounded pill, with
   the active tab getting its own filled pill behind icon+label. The
   drawer overlay is reused as the "More" sheet, so #mobile-nav-overlay
   stays as-is. */
#bottom-bar {
  display: none;
  position: fixed;
  left: var(--sp-md); right: var(--sp-md);
  bottom: calc(var(--sp-md) + env(safe-area-inset-bottom, 0));
  z-index: 250;
  background: var(--clr-navy);
  border-radius: 999px;
  padding: 6px;
  box-shadow: 0 10px 28px rgba(15,32,68,0.4), 0 2px 8px rgba(15,32,68,0.25);
}
.bottom-bar__tab {
  flex: 1;
  min-width: 0; /* lets the tab shrink below its content's natural width —
    without this, flex items default to min-width:auto and 6 tabs (5 +
    "More") silently overflow past the screen edge on a narrow phone
    instead of actually sharing the available width evenly. */
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,0.55);
  font-family: var(--font-body); font-size: 0.625rem; font-weight: 600;
  text-decoration: none;
}
/* Explicit overrides so the global `a:hover{text-decoration:underline}`
   rule (higher specificity than a plain class alone) can never flash an
   underline under a tab label on tap. */
.bottom-bar__tab:hover, .bottom-bar__tab:focus, .bottom-bar__tab:active { text-decoration: none; }
.bottom-bar__tab svg { width: 19px; height: 19px; flex-shrink: 0; }
.bottom-bar__tab-pill {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  max-width: 100%;
  padding: 7px 4px;
  border-radius: 999px;
  transition: background var(--transition);
}
.bottom-bar__tab-pill span {
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bottom-bar__tab.active { color: var(--clr-white); }
.bottom-bar__tab.active .bottom-bar__tab-pill { background: rgba(255,255,255,0.16); }

/* Keep the branded navy header visible in the native app too (previously
   hidden entirely, which — combined with no top safe-area padding — left
   the status bar bleeding straight into page content with no header at
   all). Grow it by the status-bar inset and hide just the hamburger
   button, since navigation happens via the bottom tab bar/"More" sheet
   instead — no need for a second menu trigger. */
.kt-native-app #mobile-topbar {
  height: calc(56px + env(safe-area-inset-top, 0));
  padding-top: env(safe-area-inset-top, 0);
}
.kt-native-app .mobile-topbar__burger { display: none; }
.kt-native-app #bottom-bar { display: flex; }
/* Toasts sit below the (now safe-area-aware) branded header rather than
   under the status bar. */
.kt-native-app #toast-container { top: calc(var(--sp-lg) + env(safe-area-inset-top, 0)); }
.kt-native-app .main-content { padding-bottom: calc(var(--sp-lg) + 76px + env(safe-area-inset-bottom, 0)); }

/* Public pages (landing, login, signup, join) don't use renderSidebar()
   so they never get the .kt-native-app body class from sidebar.js — each
   of those pages adds it itself via a small inline check (see their own
   scripts). Same status-bar clearance problem as #mobile-topbar above:
   .nav is sticky at top:0 with no safe-area awareness, so it renders
   partly under the status bar in the native app otherwise. */
.kt-native-app .nav { padding-top: env(safe-area-inset-top, 0); }

/* ── Show mobile bar on small screens ────────────────────── */
@media (max-width: 900px) {
  #mobile-topbar { display: flex; }
  .dashboard { grid-template-columns: 1fr; }
  .sidebar   { display: none; }
  .main-content { padding: var(--sp-lg) var(--sp-md); }
  /* Clear the 56px branded header (#mobile-topbar) instead of overlapping
     it — the native-app variant adds its own safe-area-inset-top on top
     of this, since #mobile-topbar itself grows by that same inset there. */
  #toast-container { top: calc(56px + var(--sp-md)); }
  .kt-native-app #toast-container { top: calc(56px + var(--sp-md) + env(safe-area-inset-top, 0)); }
}

/* ── Mobile: Reports page ────────────────────────────────── */
@media (max-width: 600px) {
  /* The report-type picker cards were full vertical cards (big icon
     box, heading, paragraph) which made all three take up most of
     the screen on a phone. Collapse each into a compact horizontal
     row instead — icon + title only, no description. */
  .report-grid           { gap: var(--sp-sm); margin-bottom: var(--sp-lg); }
  .report-type-card {
    display: flex !important; align-items: center; gap: var(--sp-md);
    padding: var(--sp-sm) var(--sp-md) !important;
  }
  .report-type-card__icon {
    width: 36px !important; height: 36px !important; font-size: 1.1rem !important;
    margin-bottom: 0 !important; flex-shrink: 0;
  }
  .report-type-card h3   { font-size: 0.9375rem !important; margin-bottom: 0 !important; }
  .report-type-card p    { display: none !important; }
  .controls-bar          { padding: var(--sp-md); gap: var(--sp-sm); }
  .controls-bar .btn     { width: 100%; }
  .control-group select,
  .control-group input   { min-width: 100%; }
  .rs-cell__val          { font-size: 1.25rem; }
  .report-summary        { flex-wrap: wrap; }
  .rs-cell               { flex: 1 1 50%; border-right: none; border-bottom: 1px solid var(--clr-border); }
  .rs-cell:nth-last-child(-n+2) { border-bottom: none; }
  .report-header         { padding: var(--sp-lg); }
  .report-header__right  { text-align: left; }
}

/* ── Mobile: Reminder modal ──────────────────────────────── */
@media (max-width: 600px) {
  .modal { padding: var(--sp-lg) var(--sp-md); }
  .modal__footer { flex-direction: column; }
  .modal__footer .btn { width: 100%; }
  #remind-modal .modal { max-width: 100%; margin: 0 var(--sp-md); }
}

/* ── Laptop/tablet: Tenants page (701–1300px) ─────────────────
   Previously the tenant-row grid needed ~1000px of fixed column
   width and was force-widened to that floor so it would at least
   scroll rather than silently clip Status/Actions. The columns
   have since been resized to their actual content needs (well
   under 1000px), so that floor is no longer needed — the row
   just fits naturally now. .card still falls back to
   overflow-x:auto below if content ever legitimately needs more
   room than the viewport has (e.g. an unusually long tenant
   name), so nothing is ever unreachable either way. ── */

/* ── Phones only: Tenants page ────────────────────────────────
   Below 700px there's no reasonable way to keep the row-based
   grid at all (even scrolling it is awkward on a small screen), so
   it switches to a labeled stacked card instead — same data-label
   pattern as the Properties/Units/Readings tables, so each value
   is described (Property, Unit, Rent due, Balance, Status, Actions)
   instead of just showing a wall of unlabeled numbers. ── */
@media (max-width: 700px) {
  .tenant-header { display: none !important; } /* labels are redundant once stacked */
  .tenant-row {
    display: block !important;
    min-width: 0 !important;
    padding: var(--sp-md);
  }
  .tenant-row-header {
    display: flex !important;
    align-items: center;
    gap: var(--sp-md);
    margin-bottom: var(--sp-sm);
  }
  .tenant-row > [data-label] {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-md);
    padding: var(--sp-sm) 0;
    border-top: 1px solid var(--clr-border);
    text-align: right;
  }
  .tenant-row > [data-label]::before {
    content: attr(data-label);
    font-size: 0.75rem; font-weight: 700; color: var(--clr-muted);
    text-transform: uppercase; letter-spacing: 0.04em;
    flex-shrink: 0; text-align: left;
  }
  .tenant-unit, .tenant-balance { font-size: 0.875rem; }
  .tenant-actions { flex-wrap: wrap; justify-content: flex-end; }
  .search-bar { flex-direction: column; }
  .search-bar input, .search-bar select { width: 100%; }
}

/* ── Mobile + laptop: filter tab strips (Tenants/Invoices/
   Payments status tabs) ───────────────────────────────────────
   `.tabs` is a plain flex row with no wrap/scroll, so on narrow
   viewports the later tab-btns (e.g. "Paid") were pushed past the
   edge of the screen with no way to reach them. Let the strip
   scroll horizontally instead, and stop tab-btns from shrinking
   or wrapping their label. ── */
@media (max-width: 900px) {
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn { flex-shrink: 0; white-space: nowrap; }
}

/* ── Mobile + laptop: page header action buttons ─────────────
   Button groups in page headers (Add property/tenant/invoice,
   Bulk generate, Send reminders, etc.) were set to nowrap, so
   on narrow viewports they got clipped or pushed off-screen
   instead of wrapping onto a new line. ── */
@media (max-width: 900px) {
  .page-header.flex-between { flex-wrap: wrap; row-gap: var(--sp-md); }
  .page-header.flex-between > *:last-child { flex-wrap: wrap; width: 100%; }
  .page-header.flex-between > *:last-child > .btn,
  .page-header.flex-between > *:last-child.btn { flex: 1 1 auto; }
}

/* ── Mobile + laptop: data tables & grid-row lists ────────────
   Native <table> elements (Properties, Manage Units, Utilities
   readings) and the mobile column-hiding on other list pages
   still need more room than phones/most laptops have. Rather
   than clip columns (and the Actions/Edit/Delete buttons in
   them) completely, let the containing card scroll
   horizontally so nothing is ever unreachable. ── */
@media (max-width: 1300px) {
  .card { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  .prop-table, .unit-table, .readings-table { min-width: 700px; }
}

/* ── Phones only: turn tables into stacked cards ──────────────
   Horizontal scrolling a data table inside a page that already
   scrolls vertically isn't an obvious or reliable gesture on a
   phone. Below 700px, drop the table layout entirely and stack
   each row as a labeled card instead — the same treatment the
   Tenants page uses. Each <td> needs a data-label="..." attribute
   (set by the page's JS) so its column name can show inline. ── */
@media (max-width: 700px) {
  .prop-table, .unit-table, .readings-table { min-width: 0 !important; }
  .prop-table, .unit-table, .readings-table,
  .prop-table tbody, .unit-table tbody, .readings-table tbody,
  .prop-table tr, .unit-table tr, .readings-table tr,
  .prop-table td, .unit-table td, .readings-table td {
    display: block; width: 100%;
  }
  .prop-table thead, .unit-table thead, .readings-table thead,
  .readings-table tfoot { display: none; }
  .prop-table tr, .unit-table tr, .readings-table tr {
    padding: var(--sp-md) 0;
    border-bottom: 1px solid var(--clr-border);
  }
  .prop-table td, .unit-table td, .readings-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-md);
    padding: var(--sp-md) var(--sp-md) !important;
    border-bottom: none !important;
    text-align: right;
  }
  .prop-table td::before, .unit-table td::before, .readings-table td::before {
    content: attr(data-label);
    font-size: 0.75rem; font-weight: 700; color: var(--clr-muted);
    text-transform: uppercase; letter-spacing: 0.04em;
    flex-shrink: 0; text-align: left;
  }
}

/* ── Mobile nav drawer: size the nav icons ────────────────────
   These icons are raw inline <svg> with no width/height
   attributes, so without an explicit size they render at the
   browser's default intrinsic size (huge) and blow up every
   row in the mobile menu. ── */
#mobile-nav-drawer nav a svg,
#mobile-nav-drawer .mobile-topbar__logo svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ── Mobile nav drawer: thinner, more compact rows ────────────
   Each nav row was using the same roomy padding/gap as a desktop
   sidebar link, which — combined with the oversized icons above —
   made every slot in the mobile menu feel very thick. ── */
#mobile-nav-drawer nav a {
  padding: 9px var(--sp-lg) !important;
  gap: 10px !important;
  font-size: 0.875rem !important;
}
