/* ── CSS Variables: Light / Dark theme ─────────────────────── */
:root {
  --bg-page:    #f0f2f5;
  --bg-card:    #ffffff;
  --bg-sidebar: #1a1a2e;
  --bg-topbar:  #ffffff;
  --text-primary:   #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted:     #9ca3af;
  --border:         #e5e7eb;
  --accent:         #4f8ef7;
  --accent-light:   #eff6ff;
  --input-bg:       #ffffff;
  --input-border:   #d1d5db;
  --shadow:         rgba(0,0,0,0.07);
  --section-title:  #374151;
}

body.dark-mode {
  --bg-page:    #0f1117;
  --bg-card:    #1a1d27;
  --bg-sidebar: #0d0f1a;
  --bg-topbar:  #13161f;
  --text-primary:   #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;
  --border:         #2d3147;
  --accent:         #6366f1;
  --accent-light:   #1e1b4b;
  --input-bg:       #1e2130;
  --input-border:   #374151;
  --shadow:         rgba(0,0,0,0.3);
  --section-title:  #cbd5e1;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-page);
  display: flex;
  height: 100vh;
  height: 100dvh; /* dynamic viewport — fixes iOS browser chrome */
  overflow: hidden;
  color: var(--text-primary);
  /* Safe area for notch/home indicator */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* SIDEBAR */
.sidebar { width: 220px; background: #1a1a2e; color: white; display: flex; flex-direction: column; padding: 0; flex-shrink: 0; }
.logo { padding: 24px 20px; font-size: 18px; font-weight: 700; border-bottom: 1px solid #2d2d4e; letter-spacing: 0.5px; }
nav { padding: 12px 0; flex: 1; }
.nav-item { display: block; padding: 12px 20px; color: #aab4c8; text-decoration: none; font-size: 14px; transition: all 0.2s; border-left: 3px solid transparent; }
.nav-item:hover { background: #2d2d4e; color: white; }
.nav-item.active { background: #2d2d4e; color: white; border-left-color: #4f8ef7; }

/* MAIN */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar { background: white; padding: 16px 28px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #e5e7eb; }
.topbar h1 { font-size: 20px; font-weight: 600; }

/* VIEWS */
.view { display: none; padding: 28px; overflow-y: auto; flex: 1; }
.view.active { display: block; }

/* STATS */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.stat-card { background: white; border-radius: 12px; padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.stat-card .stat-label { font-size: 12px; color: #6b7280; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: #1a1a2e; }
.stat-card .stat-sub { font-size: 12px; color: #9ca3af; margin-top: 4px; }

/* SECTION TITLES */
.section-title { font-size: 15px; font-weight: 600; margin: 24px 0 12px; color: #374151; }

/* WAREHOUSE GRID */
.warehouse-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.warehouse-card { background: white; border-radius: 12px; padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.07); cursor: pointer; transition: box-shadow 0.2s; border-top: 4px solid #4f8ef7; }
.warehouse-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.warehouse-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.warehouse-card .wh-state { font-size: 12px; color: #6b7280; margin-bottom: 12px; }
.warehouse-card .wh-row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; border-bottom: 1px solid #f3f4f6; }
.warehouse-card .wh-row:last-child { border: none; }
.warehouse-card .wh-label { color: #6b7280; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.badge-green { background: #dcfce7; color: #16a34a; }
.badge-yellow { background: #fef9c3; color: #ca8a04; }
.badge-red { background: #fee2e2; color: #dc2626; }
.badge-blue { background: #eff6ff; color: #2563eb; }

/* CREDENTIALS PANEL IN CARDS */
.card-creds-toggle {
  margin-top: 10px;
  width: 100%;
  background: #f3f4f6;
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  color: #374151;
  transition: background 0.2s;
}
.card-creds-toggle:hover { background: #e5e7eb; }
.card-creds-panel {
  display: none;
  margin-top: 8px;
  background: #f9fafb;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
}
.card-creds-panel.open { display: block; }
.cred-item {
  border-bottom: 1px solid #e5e7eb;
  padding: 4px 0;
}
.cred-item:last-child { border: none; }
.cred-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  padding: 5px 0;
  font-weight: 600;
  color: #374151;
}
.cred-item-header:hover { color: #4f8ef7; }
.cred-item-body {
  display: none;
  padding: 6px 0 4px 8px;
  color: #6b7280;
}
.cred-item-body.open { display: block; }
.cred-item-body div { margin-bottom: 3px; word-break: break-all; }
.cred-item-body .val { color: #1a1a2e; font-weight: 500; }
.cred-blur { filter: blur(3px); cursor: pointer; display: inline; transition: filter 0.2s; }
.cred-blur:hover { filter: none; }

/* ALERTS */
.alerts-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.alert-item { background: white; border-radius: 8px; padding: 14px 18px; display: flex; align-items: center; gap: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.06); border-left: 4px solid #f59e0b; }
.alert-item.critical { border-left-color: #ef4444; }
.alert-item.ok { border-left-color: #10b981; }
.alert-icon { font-size: 20px; }
.alert-text { flex: 1; font-size: 14px; }
.alert-text strong { display: block; font-weight: 600; }
.alert-text span { color: #6b7280; font-size: 12px; }
.alert-days { font-size: 13px; font-weight: 600; color: #f59e0b; white-space: nowrap; }
.alert-days.critical { color: #ef4444; }

/* TABLES */
.data-table { width: 100%; background: white; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.07); border-collapse: collapse; }
.data-table th { background: #f9fafb; padding: 12px 16px; text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: #6b7280; border-bottom: 1px solid #e5e7eb; }
.data-table td { padding: 14px 16px; font-size: 14px; border-bottom: 1px solid #f3f4f6; vertical-align: top; }
.data-table tr:last-child td { border: none; }
.data-table tr:hover td { background: #f9fafb; }

/* EXPANDABLE UTILITY ROWS */
.util-expand-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  color: #4f8ef7;
  padding: 2px 6px;
  border-radius: 4px;
  margin-top: 4px;
  display: block;
}
.util-expand-btn:hover { background: #eff6ff; }
.util-cred-row {
  display: none;
  background: #f0f4ff;
}
.util-cred-row.open { display: table-row; }
.util-cred-row td {
  font-size: 12px;
  padding: 10px 16px !important;
  color: #374151;
  background: #f0f4ff !important;
  border-bottom: 2px solid #e5e7eb !important;
}
.util-cred-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}
.util-cred-field { }
.util-cred-field .ucf-label { font-size: 10px; text-transform: uppercase; color: #9ca3af; letter-spacing: 0.4px; }
.util-cred-field .ucf-val { font-weight: 600; color: #1a1a2e; word-break: break-all; }

/* CREDENTIALS */
.credentials-note { background: #fef3c7; border: 1px solid #fcd34d; border-radius: 8px; padding: 10px 14px; font-size: 13px; color: #92400e; margin-bottom: 16px; }

/* BUTTONS */
.btn-primary { background: #4f8ef7; color: white; border: none; padding: 10px 18px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background 0.2s; }
.btn-primary:hover { background: #3b7de8; }
.btn-secondary { background: white; color: #374151; border: 1px solid #d1d5db; padding: 10px 18px; border-radius: 8px; font-size: 14px; cursor: pointer; }
.btn-secondary:hover { background: #f9fafb; }
.btn-danger { background: #fee2e2; color: #dc2626; border: none; padding: 6px 12px; border-radius: 6px; font-size: 12px; cursor: pointer; }
.btn-edit { background: #eff6ff; color: #4f8ef7; border: none; padding: 6px 12px; border-radius: 6px; font-size: 12px; cursor: pointer; margin-right: 4px; }
.btn-remind { background: #fef3c7; color: #92400e; border: none; padding: 6px 12px; border-radius: 6px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.btn-remind:hover { background: #fde68a; }
.btn-reveal { background: #f3f4f6; color: #6b7280; border: 1px solid #d1d5db; padding: 8px 10px; border-radius: 0 8px 8px 0; cursor: pointer; font-size: 13px; flex-shrink: 0; }
.btn-reveal:hover { background: #e5e7eb; }

/* PASS GROUP */
.pass-group { display: flex; margin-bottom: 0; }
.pass-group input { border-radius: 8px 0 0 8px; border-right: none; }

/* EXPORT DROPDOWN */
.export-wrapper { position: relative; }
.export-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  z-index: 200;
  min-width: 200px;
  overflow: hidden;
}
.export-menu a {
  display: block;
  padding: 10px 16px;
  font-size: 14px;
  color: #374151;
  text-decoration: none;
  transition: background 0.15s;
}
.export-menu a:hover { background: #f3f4f6; }

/* SMS BANNER */
.sms-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: #1d4ed8;
  margin-bottom: 16px;
}

/* REMINDERS EMAIL BAR */
.reminders-header {
  background: white;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.reminders-header label { margin: 0; font-size: 13px; font-weight: 600; color: #374151; white-space: nowrap; text-transform: none; letter-spacing: 0; }
.reminders-header input { flex: 1; min-width: 200px; margin: 0; }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: white; border-radius: 16px; width: 600px; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal-header { padding: 20px 24px; border-bottom: 1px solid #e5e7eb; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.modal-header h2 { font-size: 18px; font-weight: 600; }
.close-btn { background: none; border: none; font-size: 18px; cursor: pointer; color: #6b7280; padding: 4px 8px; }
.modal-tabs { display: flex; gap: 0; border-bottom: 1px solid #e5e7eb; padding: 0 24px; flex-shrink: 0; overflow-x: auto; }
.tab-btn { background: none; border: none; padding: 12px 12px; font-size: 13px; font-weight: 500; cursor: pointer; color: #6b7280; border-bottom: 2px solid transparent; transition: all 0.2s; white-space: nowrap; }
.tab-btn.active { color: #4f8ef7; border-bottom-color: #4f8ef7; }
.tab-content { display: none; padding: 20px 24px; overflow-y: auto; flex: 1; }
.tab-content.active { display: block; }
.modal-footer { padding: 16px 24px; border-top: 1px solid #e5e7eb; display: flex; gap: 12px; justify-content: flex-end; flex-shrink: 0; }

/* FORM */
label { display: block; font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 4px; margin-top: 14px; text-transform: uppercase; letter-spacing: 0.3px; }
label:first-child { margin-top: 0; }
input, select, textarea { width: 100%; padding: 9px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; outline: none; transition: border 0.2s; font-family: inherit; }
input:focus, select:focus, textarea:focus { border-color: #4f8ef7; box-shadow: 0 0 0 3px rgba(79,142,247,.1); }
textarea { resize: vertical; }
.utility-section { background: #f9fafb; border-radius: 8px; padding: 14px; margin-bottom: 12px; }
.utility-section h4 { font-size: 13px; font-weight: 600; margin-bottom: 10px; color: #374151; }
.utility-section label:first-of-type { margin-top: 10px; }
.empty-state { text-align: center; padding: 60px 20px; color: #9ca3af; }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 16px; }

/* INSURANCE VIEW */
.insurance-status-active { background: #dcfce7; color: #16a34a; }
.insurance-status-expiring { background: #fef9c3; color: #ca8a04; }
.insurance-status-expired { background: #fee2e2; color: #dc2626; }
.insurance-status-unknown { background: #f3f4f6; color: #6b7280; }

/* DOCUMENT UPLOAD */
.doc-upload-btn { background:#f3f4f6; border:2px dashed #d1d5db; border-radius:8px; padding:12px; font-size:13px; cursor:pointer; color:#374151; transition:all 0.2s; text-align:center; }
.doc-upload-btn:hover { background:#eff6ff; border-color:#4f8ef7; color:#4f8ef7; }
.doc-item { background:#f9fafb; border:1px solid #e5e7eb; border-radius:8px; padding:12px 14px; display:flex; align-items:center; gap:12px; }
.doc-item-icon { font-size:24px; flex-shrink:0; }
.doc-item-info { flex:1; min-width:0; }
.doc-item-info .doc-name { font-size:13px; font-weight:600; color:#374151; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.doc-item-info .doc-meta { font-size:11px; color:#9ca3af; margin-top:2px; }
.doc-item-actions { display:flex; gap:6px; flex-shrink:0; }
.doc-cat-badge { display:inline-block; padding:2px 8px; border-radius:10px; font-size:10px; font-weight:600; }
.doc-cat-lease { background:#eff6ff; color:#2563eb; }
.doc-cat-tax { background:#fef9c3; color:#92400e; }
.doc-cat-insurance { background:#dcfce7; color:#16a34a; }
.doc-cat-other { background:#f3f4f6; color:#6b7280; }

/* CONTACTS & STATE ACCOUNTS */
.contact-row, .state-row { background:#f9fafb; border:1px solid #e5e7eb; border-radius:10px; padding:14px; position:relative; }
.contact-row-grid { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
.contact-row-grid input { padding:8px 10px; border:1px solid #d1d5db; border-radius:6px; font-size:13px; }
.state-row-grid { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
.state-row-grid input { padding:8px 10px; border:1px solid #d1d5db; border-radius:6px; font-size:13px; }
.row-delete-btn { position:absolute; top:10px; right:10px; background:#fee2e2; color:#dc2626; border:none; border-radius:6px; padding:4px 8px; font-size:11px; cursor:pointer; }
.row-label { font-size:10px; font-weight:600; color:#6b7280; text-transform:uppercase; letter-spacing:0.3px; margin-bottom:3px; }

/* CREDENTIALS — Card Layout */
.cred-warehouse-card { background:#fff; border:1px solid #e2e8f0; border-radius:14px; margin-bottom:12px; overflow:hidden; box-shadow:0 1px 4px rgba(0,0,0,0.05); }
.cred-warehouse-header { display:flex; justify-content:space-between; align-items:center; padding:14px 18px; cursor:pointer; user-select:none; transition:background 0.15s; }
.cred-warehouse-header:hover { background:#f8fafc; }
.cred-tabs-row { display:flex; gap:6px; padding:12px 0 8px; border-bottom:1px solid #e2e8f0; margin-bottom:12px; }
.cred-tab { padding:6px 14px; border:1px solid #e2e8f0; border-radius:20px; background:#f8fafc; color:#64748b; font-size:12px; font-weight:600; cursor:pointer; transition:all 0.15s; }
.cred-tab:hover { background:#eff6ff; color:#2563eb; border-color:#bfdbfe; }
.cred-tab-active { background:#4f8ef7 !important; color:white !important; border-color:#4f8ef7 !important; }
.cred-panel { padding-top:4px; }
.cred-field-row { display:flex; align-items:center; gap:12px; padding:8px 0; border-bottom:1px solid #f1f5f9; font-size:13px; }
.cred-field-row:last-child { border-bottom:none; }
.cred-label { font-size:11px; font-weight:600; color:#94a3b8; text-transform:uppercase; letter-spacing:0.3px; min-width:72px; }
.cred-item-card { background:#f8fafc; border:1px solid #e2e8f0; border-radius:10px; padding:14px; margin-bottom:10px; }
.btn-copy-small { background:none; border:none; cursor:pointer; font-size:13px; padding:0 4px; opacity:0.6; }
.btn-copy-small:hover { opacity:1; }
.btn-add-cred { margin-top:8px; padding:8px 16px; background:#f0fdf4; color:#16a34a; border:1px solid #86efac; border-radius:8px; font-size:13px; font-weight:600; cursor:pointer; transition:all 0.15s; }
.btn-add-cred:hover { background:#dcfce7; }

/* INSURANCE ENTRIES */
.insur-entry-card { background:#f8fafc; border:1px solid #e2e8f0; border-radius:10px; padding:14px; margin-bottom:10px; }
.insur-entry-card:last-of-type { margin-bottom:0; }

/* PAYMENTS — Editable Cards */
.pay-form-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
@media (max-width:600px) { .pay-form-grid { grid-template-columns:1fr; } }
.pay-field { display:flex; flex-direction:column; gap:4px; }
.pay-label { font-size:11px; font-weight:600; color:#64748b; text-transform:uppercase; letter-spacing:0.3px; }
.pay-input { padding:9px 12px; border:1px solid #e2e8f0; border-radius:8px; font-size:13px; color:#1e293b; background:#fff; outline:none; width:100%; box-sizing:border-box; transition:border 0.15s; }
.pay-input:focus { border-color:#4f8ef7; box-shadow:0 0 0 3px rgba(79,142,247,0.1); }
select.pay-input { cursor:pointer; }
textarea.pay-input { font-family:inherit; }

/* EXPIRY BADGES */
.badge-urgent { display:inline-block; padding:3px 10px; border-radius:12px; font-size:11px; font-weight:700; background:#fee2e2; color:#dc2626; border:1px solid #fca5a5; animation:pulseRed 1.5s infinite; }
@keyframes pulseRed { 0%,100% { background:#fee2e2; } 50% { background:#fca5a5; } }

/* WAREHOUSE ACCORDION */
.wh-accordion-card { background:#fff; border:1px solid #e2e8f0; border-radius:14px; margin-bottom:10px; overflow:hidden; box-shadow:0 1px 4px rgba(0,0,0,0.04); }
.wh-accordion-header { display:flex; justify-content:space-between; align-items:center; padding:14px 18px; }
.wh-acc-main { display:flex; align-items:center; gap:12px; flex:1; cursor:pointer; }
.wh-accordion-name { font-weight:700; font-size:15px; color:#1e293b; }
.wh-accordion-sub { font-size:12px; color:#64748b; margin-top:2px; }
.wh-acc-right { display:flex; align-items:center; gap:8px; flex-shrink:0; flex-wrap:wrap; justify-content:flex-end; }
.wh-tabs-row { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:16px; }
.wh-tab { padding:6px 14px; border:1px solid #e2e8f0; border-radius:20px; background:#f8fafc; color:#64748b; font-size:12px; font-weight:600; cursor:pointer; transition:all 0.15s; white-space:nowrap; }
.wh-tab:hover { background:#eff6ff; color:#2563eb; border-color:#bfdbfe; }
.wh-tab-active { background:#4f8ef7 !important; color:white !important; border-color:#4f8ef7 !important; }
.wh-panel { padding-top:4px; }

/* WAREHOUSE DETAIL VIEW */
.wh-compact-card { background:#fff; border:1px solid #e2e8f0; border-radius:14px; padding:16px 18px; margin-bottom:10px; cursor:pointer; transition:all 0.15s; box-shadow:0 1px 4px rgba(0,0,0,0.04); }
.wh-compact-card:hover { border-color:#bfdbfe; box-shadow:0 3px 14px rgba(79,142,247,0.13); transform:translateY(-1px); }
.wh-section-card { background:#fff; border:1px solid #e2e8f0; border-radius:12px; padding:18px 20px; margin-bottom:12px; }
.wh-section-title { font-weight:700; font-size:14px; color:#374151; margin-bottom:14px; }
.info-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; font-size:13px; }

/* DRAG & DROP ZONES */
.doc-drop-zone { position:relative; transition:border-color 0.15s, background 0.15s; }
.doc-drop-zone.dz-over { border-color:#4f8ef7 !important; background:#eff6ff !important; }
.doc-drop-zone.dz-over .dz-hint { display:none; }
.dz-overlay { display:none; position:absolute; inset:0; background:rgba(239,246,255,0.93); border-radius:12px; align-items:center; justify-content:center; flex-direction:column; gap:6px; font-size:15px; font-weight:700; color:#2563eb; border:2px dashed #4f8ef7; pointer-events:none; z-index:10; }
.doc-drop-zone.dz-over .dz-overlay { display:flex !important; }
.dz-uploading { opacity:0.6; pointer-events:none; }

/* ============================================================
   MOBILE / iPHONE RESPONSIVE  (≤ 768px)
   ============================================================ */

/* Bottom nav bar — hidden on desktop */
.mobile-nav {
  display: none;
}

@media (max-width: 768px) {

  /* ── Layout ── */
  body { flex-direction: column; overflow: hidden; }
  .sidebar { display: none !important; }
  .main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* leave room for bottom nav + home indicator */
    padding-bottom: calc(68px + env(safe-area-inset-bottom));
  }

  /* ── Topbar ── */
  .topbar { padding: 10px 14px; min-height: 52px; }
  .topbar h1 { font-size: 15px; }
  .topbar button, .topbar select { font-size: 12px !important; padding: 6px 10px !important; }

  /* ── Views ── */
  .view { padding: 14px 12px; }

  /* ── Stats row — 2 columns ── */
  .stats-row { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .stat-card { padding: 12px 14px; }
  .stat-card .stat-value { font-size: 22px; }
  .stat-card .stat-label { font-size: 11px; }

  /* ── Warehouse list cards ── */
  .wh-compact-card { padding: 12px 14px; border-radius: 12px; }
  .warehouse-grid { grid-template-columns: 1fr; }

  /* ── Warehouse detail — tabs scrollable ── */
  .wh-tabs-row {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    margin-bottom: 14px;
    scrollbar-width: none;
    gap: 5px;
  }
  .wh-tabs-row::-webkit-scrollbar { display: none; }
  .wh-tab { font-size: 11px !important; padding: 5px 11px !important; border-radius: 16px !important; flex-shrink: 0; }

  /* ── Credential tabs scrollable ── */
  .cred-tabs-row {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 5px;
  }
  .cred-tabs-row::-webkit-scrollbar { display: none; }
  .cred-tab { font-size: 11px !important; padding: 5px 12px !important; white-space: nowrap; flex-shrink: 0; }

  /* ── Info grid — single column ── */
  .info-grid { grid-template-columns: 1fr !important; gap: 8px; }
  .pay-form-grid { grid-template-columns: 1fr !important; }

  /* ── Section cards ── */
  .wh-section-card { padding: 14px 14px; border-radius: 10px; }

  /* ── Insurance / Cred cards ── */
  .insur-entry-card, .cred-item-card { padding: 12px; }

  /* ── Modals ── */
  .modal-content { margin: 0 !important; border-radius: 20px 20px 0 0 !important; position: fixed !important; bottom: 0 !important; left: 0 !important; right: 0 !important; max-height: 90vh !important; }

  /* ── Tables ── */
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 10px 10px; }

  /* ── Buttons ── */
  .btn-primary, .btn-secondary { padding: 10px 14px; font-size: 13px; }

  /* ── Alert items ── */
  .alert-item { padding: 10px 12px; gap: 10px; }
  .alert-text { font-size: 13px; }

  /* ── Bottom nav bar — visible on mobile ── */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    /* height grows to fit home indicator */
    height: calc(58px + env(safe-area-inset-bottom));
    background: #1a1a2e;
    border-top: 1px solid #2d2d4e;
    z-index: 9999;
    padding-bottom: env(safe-area-inset-bottom);
    /* stay inside safe area on sides */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: #7c8db0;
    text-decoration: none;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.2px;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
  }
  .mobile-nav-item .mn-icon { font-size: 22px; line-height: 1; }
  .mobile-nav-item.active { color: #4f8ef7; }
  .mobile-nav-item:active { color: #93c5fd; }

  /* ── Back button in detail view ── */
  .wh-back-btn { font-size: 13px !important; padding: 6px 12px !important; }

  /* ── Topbar buttons — icon only on mobile ── */
  .topbar-export-text { display: none; }
  .topbar-add-text { display: none; }
  .topbar { gap: 8px; padding: 10px 12px; }
  .topbar h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* ── Dashboard cards ── */
  #dash-customize-panel { font-size: 13px; }

  /* ── Inputs / textareas touch friendly ── */
  input, select, textarea { font-size: 16px !important; } /* prevents iOS zoom on focus */

  /* ── Master panels stack on mobile ── */
  #dash-master-panels > div { grid-template-columns: 1fr !important; }
}

/* ===== MAP SIDEBAR ===== */
#map-sidebar.open {
  right: 0 !important;
}

@media (max-width: 600px) {
  #map-sidebar {
    width: 100% !important;
    height: 50% !important;
    top: auto !important;
    bottom: -50% !important;
    right: 0 !important;
    transition: bottom .3s ease !important;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,.15) !important;
  }
  #map-sidebar.open {
    bottom: 0 !important;
  }
}

/* ===== GLOBAL SEARCH MOBILE ===== */
@media (max-width: 600px) {
  #global-search-dropdown {
    width: 90vw !important;
    right: -50px !important;
  }
}

/* ===== DARK MODE OVERRIDES ===== */
body.dark-mode .main { background: var(--bg-page); }
body.dark-mode .topbar { background: var(--bg-topbar); border-color: var(--border); color: var(--text-primary); }
body.dark-mode .topbar h1 { color: var(--text-primary); }
body.dark-mode .sidebar { background: var(--bg-sidebar); }
body.dark-mode .nav-item { color: #94a3b8; }
body.dark-mode .nav-item.active, body.dark-mode .nav-item:hover { background: #1e2130; color: var(--text-primary); }
body.dark-mode .view { background: var(--bg-page); color: var(--text-primary); }
body.dark-mode .stat-card { background: var(--bg-card); box-shadow: 0 1px 4px var(--shadow); }
body.dark-mode .stat-card .stat-label { color: var(--text-secondary); }
body.dark-mode .stat-card .stat-value { color: var(--text-primary); }
body.dark-mode .stat-card .stat-sub { color: var(--text-muted); }
body.dark-mode .section-title { color: var(--section-title); }
body.dark-mode .warehouse-card { background: var(--bg-card); border-top-color: var(--accent); }
body.dark-mode .warehouse-card h3 { color: var(--text-primary); }
body.dark-mode .warehouse-card .wh-state { color: var(--text-secondary); }
body.dark-mode .warehouse-card .wh-row { border-color: #2d3147; }
body.dark-mode .warehouse-card .wh-label { color: var(--text-secondary); }
body.dark-mode .alert-item { background: #1e2130; border-color: #2d3147; }
body.dark-mode .alert-text strong { color: var(--text-primary); }
body.dark-mode .alert-text span { color: var(--text-secondary); }
body.dark-mode .btn-secondary { background: #1e2130; color: var(--text-primary); border-color: var(--border); }
body.dark-mode .btn-secondary:hover { background: #252838; }
body.dark-mode .btn-primary { background: var(--accent); }
body.dark-mode input, body.dark-mode textarea, body.dark-mode select {
  background: var(--input-bg); color: var(--text-primary); border-color: var(--input-border);
}
body.dark-mode label { color: var(--text-secondary); }
body.dark-mode .modal { background: var(--bg-card); color: var(--text-primary); }
body.dark-mode .modal-header { border-color: var(--border); }
body.dark-mode .modal-footer { border-color: var(--border); background: var(--bg-card); }
body.dark-mode .tab-btn { color: var(--text-secondary); border-color: var(--border); background: var(--bg-page); }
body.dark-mode .tab-btn.active { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }
body.dark-mode .modal-tabs { border-color: var(--border); }
body.dark-mode .mobile-nav { background: var(--bg-topbar); border-color: var(--border); }
body.dark-mode .mobile-nav-item { color: var(--text-muted); }
body.dark-mode .mobile-nav-item.active, body.dark-mode .mobile-nav-item:hover { color: var(--accent); }
body.dark-mode #global-search-dropdown { background: var(--bg-card); border-color: var(--border); }
body.dark-mode #global-search-input { background: var(--input-bg); color: var(--text-primary); border-color: var(--input-border); }
body.dark-mode .pass-group input { background: var(--input-bg); color: var(--text-primary); border-color: var(--input-border); }
body.dark-mode .card-creds-toggle { background: #252838; color: var(--text-primary); }
body.dark-mode .card-creds-panel { background: #1e2130; }
body.dark-mode [style*="background:white"], body.dark-mode [style*="background: white"] { background: var(--bg-card) !important; }
body.dark-mode [style*="background:#f0f2f5"], body.dark-mode [style*="background: #f0f2f5"] { background: var(--bg-page) !important; }
body.dark-mode [style*="background:#f8fafc"], body.dark-mode [style*="background: #f8fafc"] { background: #1e2130 !important; }
body.dark-mode [style*="background:#f1f5f9"], body.dark-mode [style*="background: #f1f5f9"] { background: #252838 !important; }
body.dark-mode [style*="color:#374151"] { color: var(--text-primary) !important; }
body.dark-mode [style*="color:#1a1a2e"] { color: var(--text-primary) !important; }
body.dark-mode [style*="color:#1e293b"] { color: var(--text-primary) !important; }
body.dark-mode [style*="border-color:#e5e7eb"], body.dark-mode [style*="border:1px solid #e5e7eb"] { border-color: var(--border) !important; }
body.dark-mode [style*="border:1px solid #e2e8f0"] { border-color: var(--border) !important; }
body.dark-mode [style*="color:#6b7280"] { color: var(--text-secondary) !important; }
body.dark-mode [style*="color:#9ca3af"] { color: var(--text-muted) !important; }
body.dark-mode #dark-mode-btn { background: #1e2130; border-color: #4f46e5; color: #818cf8; }

/* Topbar dark mode connection indicator */
body.dark-mode #conn-indicator { background: #052e16; border-color: #166534; color: #4ade80; }
body.dark-mode #conn-indicator.offline { background: #450a0a; border-color: #7f1d1d; color: #f87171; }

/* ===== MOBILE WIZARD (Warehouse Modal on phones) ===== */
.wizard-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #f8fafc;
  border-bottom: 1px solid #e5e7eb;
}
.wizard-step-label {
  font-size: 13px;
  font-weight: 700;
  color: #374151;
}
.wizard-step-sub {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 2px;
}
.wizard-progress {
  display: flex;
  gap: 3px;
  justify-content: center;
  padding: 10px 20px 4px;
}
.wizard-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #e5e7eb;
  transition: background 0.2s;
}
.wizard-dot.active {
  background: #4f8ef7;
  width: 20px;
  border-radius: 3px;
}
.wizard-dot.done {
  background: #10b981;
}
.wizard-nav-footer {
  display: none;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid #e5e7eb;
  background: white;
}

@media (max-width: 768px) {
  /* Hide tab buttons, show wizard UI instead */
  .modal .modal-tabs { display: none !important; }
  .wizard-header { display: flex !important; flex-direction: column; align-items: flex-start; gap: 4px; }
  .wizard-nav-footer { display: flex !important; }

  /* Wizard navigation footer replaces modal-footer */
  .modal .modal-footer { display: none !important; }

  .wizard-nav-btn {
    flex: 1;
    padding: 13px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
  }
  .wizard-nav-btn.prev { background: #f1f5f9; color: #374151; }
  .wizard-nav-btn.next { background: #4f8ef7; color: white; }
  .wizard-nav-btn.finish { background: #10b981; color: white; }

  /* Make modal full height on mobile */
  .modal { max-height: 95dvh !important; }
}

body.dark-mode .wizard-header { background: #1e2130; border-color: var(--border); }
body.dark-mode .wizard-step-label { color: var(--text-primary); }
body.dark-mode .wizard-nav-footer { background: var(--bg-card); border-color: var(--border); }
body.dark-mode .wizard-nav-btn.prev { background: #252838; color: var(--text-primary); }

/* ===== PWA / MOBILE ENHANCEMENTS ===== */

/* Prevent text selection on interactive elements for better touch feel */
.mobile-nav-item, .btn-primary, .btn-secondary, .wh-compact-card,
.wh-tab, .stat-card, .nav-item {
  -webkit-user-select: none;
  user-select: none;
}

/* Touch-active feedback (replaces hover on mobile) */
@media (hover: none) and (pointer: coarse) {
  .wh-compact-card:active { transform: scale(0.98); opacity: 0.9; }
  .btn-primary:active { background: #3b7de8 !important; transform: scale(0.97); }
  .btn-secondary:active { background: #e5e7eb !important; }
  .mobile-nav-item:active { color: #93c5fd; }
  .wh-tab:active { background: #e0f2fe !important; }
}

/* Ensure all interactive elements have at least 44px touch target */
@media (max-width: 768px) {
  .btn-primary, .btn-secondary, .btn-danger, .btn-edit, .btn-remind {
    min-height: 44px;
    min-width: 44px;
  }
  .wh-compact-card { min-height: 60px; }
  .mobile-nav-item { min-height: 44px; }
  input, select, textarea { min-height: 44px; }

  /* Smooth scroll for main view */
  .view { -webkit-overflow-scrolling: touch; scroll-behavior: smooth; }

  /* Card shadow on mobile for better depth perception */
  .wh-compact-card { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }

  /* Warehouse list spacing */
  #warehouses-list .wh-compact-card + .wh-compact-card { margin-top: 8px; }

  /* Bottom safe area: extra padding for content above nav */
  .view { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  #view-map { padding-bottom: 0 !important; }

  /* Map container height with bottom nav */
  #map-container { height: calc(100dvh - 60px - env(safe-area-inset-bottom) - 68px) !important; }

  /* Payment & lease badges wrap nicely on small screens */
  .wh-compact-card .badge { font-size: 10px; padding: 2px 7px; }
}

/* Fast tap on iOS — remove 300ms delay */
* { touch-action: manipulation; }

/* PWA status bar background match */
@media (display-mode: standalone) {
  body { background: #1a1a2e; }
  .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
}

/* Scrollbar hide on mobile for cleaner look */
@media (max-width: 768px) {
  ::-webkit-scrollbar { display: none; }
  * { scrollbar-width: none; }
}
