/* ============================================================
   Mando's Painting — Shared Admin App Styles
   Used by all /admin-*.html pages.
   "Clipboard" aesthetic: utilitarian, fast, big tap targets.
   Brand tokens match the gold-anchored design system.
   ============================================================ */

:root {
  /* Gold + accent (used sparingly in admin) */
  --gold: #BC9448;
  --gold-bright: #C7A655;
  --gold-dark: #A8783D;
  --gold-pale: #F5EFE3;

  /* Greens & navy for status badges */
  --saguaro: #5C6B4A;
  --saguaro-pale: #EAEDDF;

  /* Anchor darks (used for top bar accents) */
  --midnight: #2A2F3A;
  --midnight-deep: #1B1F26;
  --ink: #2B2420;
  --shadow: #6B6560;

  /* Surfaces (the cool, utilitarian admin palette) */
  --bg: #F5F5F4;
  --card: #FFFFFF;
  --card-alt: #FAFAF8;
  --border: #D4D0CC;
  --border-strong: #B8B2AC;

  /* States */
  --error: #B5532A;
  --error-pale: #FBE9E2;
  --warn: #B5832A;
  --warn-pale: #F5ECD7;
  --info-pale: #E5EBF0;
  --success: #4A6B47;
  --success-pale: #E2EDDF;

  /* Typography */
  --sans: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Courier New', monospace;

  /* Layout */
  --radius: 4px;
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 56px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img { max-width: 100%; display: block; }
a { color: var(--gold-dark); text-decoration: none; }
a:hover { color: var(--gold-deep, var(--gold-dark)); }
button { font-family: inherit; }

/* ============================================================
   APP SHELL: sidebar + topbar + main content
   ============================================================ */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
}

@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas: "topbar" "main";
  }
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  grid-area: sidebar;
  background: var(--midnight-deep);
  color: rgba(250,246,239,0.85);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

@media (max-width: 880px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: var(--sidebar-w);
    z-index: 200;
    transition: left 0.25s ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.3);
  }
  .sidebar.open { left: 0; }
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.95rem 1rem;
  border-bottom: 1px solid rgba(250,246,239,0.08);
  text-decoration: none;
  color: rgba(250,246,239,0.95);
}
.sidebar-brand-logo {
  width: 36px; height: 36px;
  background: var(--midnight);
  border-radius: var(--radius);
  padding: 3px;
  box-shadow: 0 0 0 1px rgba(188,148,72,0.3);
  flex-shrink: 0;
}
.sidebar-brand-logo img { width: 100%; height: 100%; object-fit: contain; }
.sidebar-brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.sidebar-brand-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--gold-bright);
  letter-spacing: -0.005em;
}
.sidebar-brand-sub {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(250,246,239,0.5);
  margin-top: 0.1rem;
}

.sidebar-section {
  padding: 1rem 0 0.4rem;
}
.sidebar-section-label {
  padding: 0 1rem 0.4rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(250,246,239,0.4);
}
.sidebar-nav {
  list-style: none;
  padding: 0;
  margin: 0;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 1rem;
  font-size: 0.88rem;
  font-weight: 500;
  color: rgba(250,246,239,0.75);
  border-left: 2px solid transparent;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  cursor: pointer;
}
.sidebar-link:hover {
  background: rgba(250,246,239,0.04);
  color: var(--gold-bright);
}
.sidebar-link.active {
  background: rgba(188,148,72,0.1);
  color: var(--gold-bright);
  border-left-color: var(--gold);
  font-weight: 600;
}
.sidebar-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.85;
}
.sidebar-link.active svg { opacity: 1; }
.sidebar-link-badge {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 8px;
  background: var(--gold);
  color: var(--midnight-deep);
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem;
  border-top: 1px solid rgba(250,246,239,0.08);
  font-size: 0.75rem;
  color: rgba(250,246,239,0.5);
}
.sidebar-footer .user-line {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.sidebar-footer .user-avatar {
  width: 28px;
  height: 28px;
  background: var(--gold);
  color: var(--midnight-deep);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.78rem;
  flex-shrink: 0;
}
.sidebar-footer .user-name {
  color: rgba(250,246,239,0.85);
  font-weight: 600;
  font-size: 0.82rem;
  flex-grow: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-footer a {
  color: rgba(250,246,239,0.55);
  font-size: 0.75rem;
  display: inline-block;
  margin-right: 0.85rem;
}
.sidebar-footer a:hover { color: var(--gold-bright); }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  grid-area: topbar;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink);
  padding: 0.4rem;
}
@media (max-width: 880px) { .topbar-toggle { display: flex; } }
.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}
.topbar-breadcrumb {
  font-size: 0.78rem;
  color: var(--shadow);
  font-weight: 500;
}
.topbar-breadcrumb a { color: var(--shadow); }
.topbar-breadcrumb a:hover { color: var(--gold-dark); }
.topbar-spacer { flex-grow: 1; }
.topbar-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Sidebar overlay on mobile */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
}
.sidebar-backdrop.show { display: block; }

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
.main {
  grid-area: main;
  padding: 1.5rem;
  min-width: 0;
}
@media (max-width: 600px) { .main { padding: 1rem; } }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-head-text h1 {
  font-family: var(--sans);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 0.25rem;
  letter-spacing: -0.01em;
}
.page-head-text p {
  font-size: 0.9rem;
  color: var(--shadow);
  margin: 0;
}
.page-head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ============================================================
   CARD / SECTION
   ============================================================ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: var(--card-alt);
}
.card-head-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--shadow);
}
.card-body { padding: 1.1rem; }
.card-body-flush { padding: 0; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all 0.1s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.3;
}
.btn-primary {
  background: var(--midnight);
  color: var(--gold-bright);
  border-color: var(--midnight);
  box-shadow: inset 0 0 0 1px var(--gold);
}
.btn-primary:hover {
  background: var(--midnight-deep);
  color: var(--gold-bright);
}
.btn-secondary {
  background: var(--card);
  color: var(--ink);
  border-color: var(--border-strong);
}
.btn-secondary:hover {
  background: var(--card-alt);
  border-color: var(--ink);
}
.btn-danger {
  background: var(--card);
  color: var(--error);
  border-color: var(--error);
}
.btn-danger:hover {
  background: var(--error-pale);
}
.btn-text {
  background: none;
  color: var(--ink);
  border-color: transparent;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}
.btn-text:hover { color: var(--gold-dark); }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.82rem; }
.btn-lg { padding: 0.75rem 1.3rem; font-size: 0.95rem; }
.btn-icon {
  padding: 0.45rem;
  background: none;
  border: 1.5px solid transparent;
  color: var(--shadow);
  border-radius: var(--radius);
  cursor: pointer;
}
.btn-icon:hover {
  background: var(--card-alt);
  color: var(--ink);
}
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================
   FORMS
   ============================================================ */
.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.85rem; }
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}
@media (max-width: 500px) { .field-row { grid-template-columns: 1fr; } }
.field label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.field input,
.field select,
.field textarea {
  padding: 0.55rem 0.75rem;
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(188,148,72,0.12);
}
.field textarea { resize: vertical; min-height: 80px; }
.field-helper { font-size: 0.75rem; color: var(--shadow); }
.field-error {
  font-size: 0.75rem;
  color: var(--error);
  display: none;
}
.field.invalid input,
.field.invalid select,
.field.invalid textarea { border-color: var(--error); }
.field.invalid .field-error { display: block; }

/* ============================================================
   STATS / KPI CARDS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.stat-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--shadow);
  margin-bottom: 0.4rem;
}
.stat-value {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
  line-height: 1.1;
}
.stat-value-money { color: var(--ink); }
.stat-value-money::before { content: '$'; color: var(--gold-dark); margin-right: 0.05em; }
.stat-trend {
  font-size: 0.78rem;
  color: var(--shadow);
  margin-top: 0.3rem;
}
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--error); }

/* ============================================================
   TABLES
   ============================================================ */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.data-table thead {
  background: var(--card-alt);
  border-bottom: 1px solid var(--border);
}
.data-table th {
  text-align: left;
  padding: 0.7rem 1rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--shadow);
}
.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--card-alt); }
.data-table td.numeric,
.data-table th.numeric {
  text-align: right;
  font-family: var(--mono);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--shadow);
}
.empty-state-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  opacity: 0.4;
}
.empty-state h3 {
  font-size: 1rem;
  color: var(--ink);
  margin: 0 0 0.4rem;
}
.empty-state p {
  font-size: 0.88rem;
  margin: 0;
  max-width: 400px;
  margin: 0 auto;
}

/* ============================================================
   STATUS BADGES (job pipeline)
   ============================================================ */
.status-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
/* P1 fix #68: tint job statuses are pending/scheduled/in_progress/completed/
   cancelled/paid. `status-pending` and `status-completed` are the tint badge
   colors the job tables now render via `status-${job.status}`. The painting
   classes below (status-new/estimate_sent/signed/complete) are kept because
   settings.html still borrows `status-new` for neutral non-job pills (e.g.
   "Not connected"); they're harmless and avoid breaking that styling. */
.status-pending       { background: var(--info-pale);    color: #3D5A6C; }
.status-new           { background: var(--info-pale);    color: #3D5A6C; }
.status-estimate_sent { background: var(--warn-pale);    color: var(--warn); }
.status-signed        { background: var(--gold-pale);    color: var(--gold-dark); }
.status-scheduled     { background: var(--saguaro-pale); color: var(--saguaro); }
.status-rescheduled   { background: var(--saguaro-pale); color: var(--saguaro); }
.status-in_progress   { background: var(--gold-pale);    color: var(--gold-dark); }
.status-unfinished    { background: rgba(181,83,42,0.12); color: var(--error); font-weight: 700; }
.status-completed     { background: var(--success-pale); color: var(--success); }
.status-complete      { background: var(--success-pale); color: var(--success); }
.status-paid          { background: var(--success-pale); color: var(--success); }
.status-cancelled     { background: var(--card-alt);    color: var(--shadow); }
.status-archived      { background: var(--card-alt);    color: var(--shadow); }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--midnight);
  color: var(--paper, #FAF6EF);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  z-index: 300;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.2s;
  border-left: 3px solid var(--gold);
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { border-left-color: var(--error); }
.toast.success { border-left-color: var(--success); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(27,31,38,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 250;
  padding: 1rem;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--card);
  border-radius: 6px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px rgba(0,0,0,0.25);
}
.modal-head {
  padding: 1.1rem 1.25rem 0.85rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head h3 { margin: 0; font-size: 1.05rem; font-weight: 700; }
.modal-body { padding: 1.25rem; }
.modal-foot {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  background: var(--card-alt);
}

/* ============================================================
   UTILITIES
   ============================================================ */
.mono { font-family: var(--mono); }
.muted { color: var(--shadow); }
.numeric { font-family: var(--mono); text-align: right; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.flex-gap { display: flex; gap: 0.5rem; align-items: center; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.hidden { display: none !important; }

/* ============================================================
   MOBILE OVERHAUL — comprehensive responsive layer
   Added in v1.3 to fix small-screen issues across all admin pages.
   ============================================================ */

/* --- Hamburger / topbar toggle button --- */
/* The button must be very visible and tappable.  On mobile it sits in the
   topbar and is the primary way to open the sidebar nav.  */
.topbar-toggle {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  transition: background 0.15s, color 0.15s;
}
.topbar-toggle:hover,
.topbar-toggle:focus-visible {
  background: rgba(0,0,0,0.06);
  color: var(--gold-dark);
  outline: none;
}
.topbar-toggle svg {
  width: 22px;
  height: 22px;
  display: block;
  stroke: currentColor;
  flex-shrink: 0;
}

/* --- Make all icons in topbar/sidebar render with a guaranteed size --- */
.topbar svg { width: 20px; height: 20px; flex-shrink: 0; }
.sidebar svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ============================================================
   Phone breakpoint (≤ 880px)
   - Sidebar becomes a slide-in drawer
   - Topbar shows hamburger, condenses spacing
   - Main padding tightens
   ============================================================ */
@media (max-width: 880px) {
  .topbar {
    padding: 0 0.85rem;
    gap: 0.6rem;
  }
  .topbar-title {
    font-size: 0.95rem;
    line-height: 1.2;
  }
  .topbar-breadcrumb { font-size: 0.72rem; }
  /* Hide labels in topbar action buttons on mobile — keep just the icon */
  .topbar-actions .btn .btn-label-desktop { display: none; }

  .main {
    padding: 1rem;
  }

  /* Cards should snap to viewport edges, not have giant margins */
  .card {
    border-radius: 6px;
  }
  .card-head,
  .card-body,
  .card-foot {
    padding: 0.85rem 1rem;
  }

  /* Page hero (top of each page) */
  .page-head {
    padding: 0.85rem 0 0.4rem;
  }
  .page-head h1 {
    font-size: 1.25rem;
  }
  .page-head p {
    font-size: 0.9rem;
  }

  /* Stat grids (dashboard, reports) collapse to two columns */
  .stat-grid,
  .stats-grid,
  .pl-cards,
  .summary-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.5rem !important;
  }
  .stat-card,
  .pl-card,
  .summary-card {
    padding: 0.85rem !important;
  }
  .stat-card .stat-value,
  .pl-card .pl-card-value {
    font-size: 1.4rem !important;
  }

  /* Tables: wrap in horizontal scroll so they don't blow out the layout */
  .table-wrap,
  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -1rem; /* let the scroll area touch the viewport edges */
    padding: 0 1rem;
  }
  table {
    font-size: 0.85rem;
  }
  table th,
  table td {
    padding: 0.55rem 0.6rem !important;
    white-space: nowrap;
  }
  /* Allow notes / long text columns to wrap so the table isn't too wide */
  table td.wrap,
  table td .wrap-text { white-space: normal; }

  /* Form rows: stack labels above inputs */
  .field-row,
  .form-row {
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
  }
  .setting-row {
    grid-template-columns: 1fr !important;
    gap: 0.4rem !important;
    padding: 0.8rem 0 !important;
  }
  .setting-field-label {
    font-size: 0.92rem;
  }
  .setting-field-label .helper {
    font-size: 0.78rem;
  }

  /* Inputs that should fill the available width */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="date"],
  input[type="search"],
  input[type="password"],
  select,
  textarea {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    font-size: 16px;  /* Prevents iOS from zooming when focusing */
  }

  /* Buttons: increase tap target */
  .btn {
    min-height: 40px;
    padding: 0.55rem 0.95rem;
  }
  .btn-sm {
    min-height: 34px;
    padding: 0.4rem 0.7rem;
    font-size: 0.85rem;
  }

  /* Filter bars stack on mobile */
  .filter-bar,
  .filters,
  .toolbar {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .filter-bar > *,
  .filters > * {
    flex: 1 1 auto;
    min-width: 0;
  }

  /* Modal: full-width-ish on phones */
  .modal {
    width: calc(100vw - 1.5rem) !important;
    max-width: calc(100vw - 1.5rem) !important;
    max-height: calc(100vh - 1.5rem) !important;
    margin: 0.75rem !important;
  }
  .modal-head,
  .modal-body,
  .modal-foot {
    padding: 0.85rem 1rem !important;
  }
  .modal-foot {
    flex-wrap: wrap;
  }
  .modal-foot .btn {
    flex: 1 1 auto;
  }

  /* Receipt review modal — stack image and form vertically */
  .review-split,
  .review-grid {
    grid-template-columns: 1fr !important;
  }

  /* Long info banners */
  .info-banner {
    padding: 0.8rem !important;
    font-size: 0.85rem;
  }

  /* Sidebar drawer: a touch narrower on tiny screens */
  .sidebar { width: min(280px, 85vw); }
}

/* ============================================================
   Tiny phones (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {
  .main { padding: 0.75rem; }
  .card-head, .card-body, .card-foot { padding: 0.7rem 0.85rem; }
  .topbar { padding: 0 0.6rem; }
  .topbar-title { font-size: 0.9rem; }

  /* Stat grids: single column on tiny screens */
  .stat-grid,
  .stats-grid,
  .pl-cards,
  .summary-grid {
    grid-template-columns: 1fr !important;
  }

  /* Modal: tighter still */
  .modal {
    width: calc(100vw - 1rem) !important;
    max-width: calc(100vw - 1rem) !important;
    margin: 0.5rem !important;
  }

  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.15rem; }
}

/* ============================================================
   MOBILE BOTTOM NAV (≤880px only)
   App-like persistent navigation at the bottom of the viewport.
   Hidden on desktop entirely.
   ============================================================ */
.bottom-nav {
  display: none;
}
@media (max-width: 880px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    background: var(--card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
    /* Respect iPhone home indicator */
    padding-bottom: env(safe-area-inset-bottom);
    /* Hairline divider should stay opaque while content scrolls beneath */
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
  }
  .bottom-nav-link {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.45rem 0.25rem 0.5rem;
    color: var(--shadow);
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-decoration: none;
    min-height: 56px;
    transition: color 0.12s, background 0.12s;
    -webkit-tap-highlight-color: transparent;
  }
  .bottom-nav-link svg {
    width: 22px;
    height: 22px;
    stroke-width: 2;
  }
  .bottom-nav-link.active {
    color: var(--gold-dark);
  }
  .bottom-nav-link:active {
    background: var(--card-alt);
    color: var(--ink);
  }
  /* Main content needs padding so the nav doesn't overlap last item */
  .main {
    padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important;
  }
  /* Sidebar drawer should sit above the bottom nav when open */
  .sidebar {
    z-index: 250;
  }
}

/* ============================================================
   BODY SCROLL LOCK (used when modals are open)
   Prevents background scroll-in-scroll confusion on mobile.
   ============================================================ */
body.no-scroll {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* ============================================================
   MOBILE-FIRST FULL-SCREEN MODALS (≤880px)
   The desktop modal stays as a centered card. On mobile, modals
   take the full viewport, with a sticky header and a sticky footer
   so only the body scrolls (no nested scroll containers).
   ============================================================ */
@media (max-width: 880px) {
  .modal-backdrop {
    padding: 0 !important;
    align-items: stretch !important;
  }
  .modal {
    width: 100vw !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    height: 100vh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    display: flex;
    flex-direction: column;
    overflow: hidden !important; /* container itself doesn't scroll */
  }
  .modal-head {
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 2;
    padding-top: calc(0.85rem + env(safe-area-inset-top)) !important;
    flex-shrink: 0;
  }
  .modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal-foot {
    position: sticky;
    bottom: 0;
    background: var(--card-alt);
    z-index: 2;
    padding-bottom: calc(0.85rem + env(safe-area-inset-bottom)) !important;
    flex-shrink: 0;
  }
  .modal-foot .btn {
    flex: 1 1 auto;
    min-height: 44px;
  }
  /* Modal close button: larger tap target */
  .modal-close {
    min-width: 44px;
    min-height: 44px;
  }
}

/* ============================================================
   MOBILE CARD LIST (replaces tables on mobile)
   Pages with data tables show <table> on desktop and a parallel
   .mobile-card-list on mobile. Hide one or the other based on
   screen size.
   ============================================================ */
.mobile-card-list {
  display: none;
}
@media (max-width: 880px) {
  /* Pages opt-in to card view by adding .has-mobile-cards on the
     wrapper; we hide the table and show the cards there. */
  .has-mobile-cards .table-wrap,
  .has-mobile-cards .table-scroll,
  .has-mobile-cards > table {
    display: none;
  }
  .has-mobile-cards .mobile-card-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  .mobile-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 0.95rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s, transform 0.06s;
  }
  .mobile-card:active {
    background: var(--card-alt);
    transform: scale(0.99);
  }
  .mobile-card-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    min-width: 0;
  }
  .mobile-card-title {
    font-weight: 700;
    color: var(--ink);
    font-size: 0.98rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1 1 auto;
  }
  .mobile-card-amount {
    font-family: var(--mono);
    font-weight: 700;
    color: var(--ink);
    flex-shrink: 0;
  }
  .mobile-card-meta {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--shadow);
  }
  .mobile-card-meta .left,
  .mobile-card-meta .right {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
  }
  .mobile-card-meta .right { flex-shrink: 0; }
  .mobile-card-meta span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* ============================================================
   TOAST: avoid iPhone home indicator
   ============================================================ */
@media (max-width: 880px) {
  .toast {
    bottom: calc(72px + env(safe-area-inset-bottom) + 0.5rem) !important;
    right: 0.75rem !important;
    left: 0.75rem !important;
    max-width: none !important;
  }
}

/* ============================================================
   TOUCH POLISH (≤880px)
   ============================================================ */
@media (max-width: 880px) {
  /* Larger checkboxes on mobile */
  input[type="checkbox"] {
    min-width: 20px;
    min-height: 20px;
    transform: scale(1.15);
    transform-origin: left center;
    margin-right: 0.4rem;
  }
  /* Clickable table rows: visible press feedback */
  tbody tr {
    -webkit-tap-highlight-color: transparent;
  }
  tbody tr[onclick]:active,
  tbody tr.clickable:active {
    background: var(--card-alt) !important;
  }
  /* All buttons: subtle press feedback */
  .btn:active {
    transform: scale(0.98);
  }
  /* Card-style press feedback on dashboards */
  .card.clickable:active,
  .stat-card[onclick]:active {
    transform: scale(0.995);
  }
}

/* ============================================================
   TOGGLE SWITCH — used in Settings for deposit on/off, etc.
   ============================================================ */
.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;
  inset: 0;
  cursor: pointer;
  background: var(--border);
  border-radius: 26px;
  transition: background 0.18s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.18s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--saguaro);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(22px);
}
.toggle-switch input:focus-visible + .toggle-slider {
  box-shadow: 0 0 0 3px rgba(76,131,86,0.25);
}

/* ============================================================
   Support assistant (Group 5) — floating helper + panel
   ============================================================ */
.support-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1200;
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
}
.support-launcher:hover { background: var(--brand-ink); }

.support-panel {
  position: fixed;
  right: 20px;
  bottom: 76px;
  z-index: 1200;
  width: 360px;
  max-width: calc(100vw - 40px);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,0.22);
  overflow: hidden;
}
.support-panel[hidden] { display: none; }

.support-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--brand);
  color: #fff;
}
.support-title { font-weight: 600; }
.support-close {
  background: transparent;
  border: 0;
  color: #fff;
  cursor: pointer;
  font: inherit;
  opacity: 0.9;
}
.support-close:hover { opacity: 1; }

.support-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.support-msg { max-width: 90%; }
.support-msg p { margin: 0; padding: 8px 12px; border-radius: 10px; font-size: 14px; line-height: 1.4; }
.support-msg-owner { align-self: flex-end; }
.support-msg-owner p { background: var(--brand); color: #fff; }
.support-msg-assistant { align-self: flex-start; }
.support-msg-assistant p { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }

.support-deeplink {
  display: inline-block;
  margin-top: 6px;
  padding: 6px 12px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.support-inline-action {
  display: inline-block;
  margin-top: 6px;
  margin-right: 6px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--brand);
  color: var(--brand);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.support-status { padding: 0 14px; font-size: 13px; color: var(--muted); min-height: 18px; }
.support-status-error { color: var(--err); }

.support-input-row { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.support-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
}
.support-send {
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.support-send:disabled { opacity: 0.6; cursor: default; }

.support-footer { padding: 0 14px 12px; }
.support-ticket-btn {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 8px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.support-ticket-btn:hover { color: var(--ink); border-color: var(--brand); }

.support-ticket-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.support-ticket-label { font-weight: 600; font-size: 13px; }
.support-ticket-type,
.support-ticket-subject,
.support-ticket-body {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  width: 100%;
}
.support-ticket-body { resize: vertical; }
.support-ticket-actions { display: flex; gap: 8px; }

@media (max-width: 640px) {
  .support-panel { right: 10px; left: 10px; width: auto; bottom: 70px; }
}

/* ============================================================
   Learn tab (Group 6)
   ============================================================ */
.learn-intro {
  max-width: 720px;
  margin-bottom: 1.5rem;
  color: var(--shadow);
  font-size: 0.95rem;
  line-height: 1.5;
}
.learn-loading, .learn-error { color: var(--shadow); }
.learn-error { color: var(--error); }

.learn-group { margin-bottom: 2rem; }
.learn-group-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 0.85rem;
  color: var(--ink);
}

.learn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.learn-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  display: flex;
  flex-direction: column;
}
.learn-card-title {
  font-size: 0.98rem;
  font-weight: 600;
  margin: 0 0 0.6rem;
  color: var(--ink);
}
.learn-steps {
  margin: 0 0 0.85rem;
  padding-left: 1.2rem;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.5;
}
.learn-steps li { margin-bottom: 0.3rem; }

.learn-shot {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.85rem;
}

.learn-go {
  align-self: flex-start;
  margin-top: auto;
  padding: 0.45rem 0.95rem;
  background: var(--gold);
  color: #fff;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}
.learn-go:hover { background: var(--gold-dark); }

/* ============================================================
   Time tracking — worker "My Work" surface (Group 7, U7)
   ============================================================ */
.mywork-intro {
  max-width: 720px;
  margin-bottom: 1.5rem;
  color: var(--shadow);
  font-size: 0.95rem;
  line-height: 1.5;
}
.mywork-loading, .mywork-empty { color: var(--shadow); }
.mywork-error { color: var(--error); font-size: 0.85rem; margin-top: 0.6rem; }

.mywork-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}
.mywork-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.mywork-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}
.mywork-card-title {
  font-size: 0.98rem;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
}
.mywork-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}
.mywork-badge-open {
  background: var(--gold-pale, #f5efe3);
  color: var(--gold-dark);
}
.mywork-meta {
  margin: 0;
  color: var(--shadow);
  font-size: 0.85rem;
}
.mywork-actions { display: flex; gap: 0.5rem; }
.mywork-logform {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.mywork-input {
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.85rem;
  max-width: 8rem;
}
.mywork-btn {
  padding: 0.45rem 0.95rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.mywork-btn:disabled { opacity: 0.6; cursor: default; }
.mywork-btn-primary { background: var(--gold); color: #fff; }
.mywork-btn-primary:hover:not(:disabled) { background: var(--gold-dark); }
.mywork-btn-stop { background: var(--error, #c0392b); color: #fff; }
.mywork-btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--ink);
}
.mywork-btn-ghost:hover:not(:disabled) { background: var(--gold-pale, #f5efe3); }

/* ============================================================
   Time tracking — owner labor surface (Group 7, U8)
   ============================================================ */
.labor-loading, .labor-empty { color: var(--shadow); }
.labor-error { color: var(--error); font-size: 0.85rem; margin-top: 0.6rem; }
.labor-ok { color: var(--gold-dark); font-size: 0.85rem; margin-top: 0.6rem; }
.labor-note { color: var(--shadow); font-size: 0.85rem; margin: 0 0 0.85rem; line-height: 1.5; max-width: 640px; }

.labor-periodbar { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1.2rem; }
.labor-period-label { font-size: 0.85rem; color: var(--shadow); font-weight: 600; }

.labor-cards { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.6rem; }
.labor-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.3rem;
  min-width: 160px;
}
.labor-card-label { font-size: 0.78rem; color: var(--shadow); text-transform: uppercase; letter-spacing: 0.04em; }
.labor-card-value { font-size: 1.5rem; font-weight: 700; color: var(--ink); margin-top: 0.25rem; }

.labor-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
  margin-bottom: 1.4rem;
}
.labor-section-title { font-size: 1.05rem; font-weight: 700; margin: 0 0 0.6rem; color: var(--ink); }
.labor-attention { border-color: var(--error); }
.labor-attention-list { margin: 0; padding-left: 1.2rem; color: var(--ink); font-size: 0.88rem; line-height: 1.6; }

.labor-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.labor-table th, .labor-table td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
.labor-table th { color: var(--shadow); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.labor-flag { font-size: 0.72rem; font-weight: 700; color: var(--error); text-transform: uppercase; letter-spacing: 0.03em; }

.labor-payrow, .labor-pending-row {
  display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap;
  padding: 0.6rem 0; border-bottom: 1px solid var(--border);
}
.labor-payrow:last-child, .labor-pending-row:last-child { border-bottom: none; }
.labor-payrow-name, .labor-pending-label { font-weight: 600; color: var(--ink); font-size: 0.9rem; min-width: 140px; }
.labor-payform, .labor-assignform { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.labor-select, .labor-input {
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit; font-size: 0.85rem;
}
.labor-input { max-width: 9rem; }

.labor-btn {
  padding: 0.45rem 0.95rem; border-radius: var(--radius); border: 1px solid transparent;
  font-size: 0.85rem; font-weight: 600; cursor: pointer; font-family: inherit;
}
.labor-btn:disabled { opacity: 0.6; cursor: default; }
.labor-btn-primary { background: var(--gold); color: #fff; }
.labor-btn-primary:hover:not(:disabled) { background: var(--gold-dark); }
.labor-btn-ghost { background: transparent; border-color: var(--border); color: var(--ink); }
.labor-btn-ghost:hover:not(:disabled) { background: var(--gold-pale, #f5efe3); }
