/* RMS - modern, mobile-first UI */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; }
/* Default icon size so any inline svg without explicit sizing stays small */
svg { width: 18px; height: 18px; flex-shrink: 0; }
.fab svg, .splash svg { width: auto; height: auto; }
:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-light: #ccfbf1;
  --accent: #f59e0b;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --info: #2563eb;
  --info-bg: #dbeafe;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.15);
  --radius: 14px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --topbar-h: 56px;
  --bottomnav-h: 64px;
}
html[data-theme="dark"] {
  --primary: #2dd4bf;
  --primary-dark: #14b8a6;
  --primary-light: #134e4a;
  --bg: #020617;
  --surface: #0f172a;
  --surface-2: #1e293b;
  --border: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --danger-bg: #450a0a;
  --success-bg: #052e16;
  --warning-bg: #451a03;
  --info-bg: #172554;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro Text", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, textarea, select {
  font: inherit; color: inherit;
}
button { cursor: pointer; background: none; border: 0; }
a.btn { text-decoration: none; }
a { color: inherit; }
input, textarea, select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: 0; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
textarea { resize: vertical; min-height: 80px; }

/* Splash */
.splash {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; z-index: 9999; transition: opacity .3s;
}
.splash-mark { width: 96px !important; height: 96px !important; }
.splash-logo {
  font-size: 36px; font-weight: 800; letter-spacing: 3px;
}
.splash-sub { opacity: .9; font-size: 14px; }
.splash.hide { opacity: 0; pointer-events: none; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-logo { width: 28px !important; height: 28px !important; }

/* Layout */
#app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h); padding: 0 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 4px; }
.brand-mark {
  font-weight: 800; font-size: 18px; letter-spacing: 1px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text); transition: background .15s;
}
.icon-btn:hover, .icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.user-btn {
  background: var(--primary); color: #fff; font-weight: 700;
  width: 36px; height: 36px; font-size: 14px;
}
.user-btn:hover { background: var(--primary-dark); }
main {
  flex: 1; padding: 16px;
  padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 16px);
  max-width: 980px; margin: 0 auto; width: 100%;
}

/* Bottom nav */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
  flex: 1; height: var(--bottomnav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--text-muted); font-size: 11px; font-weight: 500;
  transition: color .15s;
}
.bottom-nav button.active { color: var(--primary); }
.bottom-nav button svg { width: 24px; height: 24px; }

/* Drawer */
.scrim {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(2px);
  opacity: 0; transition: opacity .2s;
}
.scrim.show { opacity: 1; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 280px; z-index: 70;
  background: var(--surface); transform: translateX(-100%); transition: transform .25s ease;
  padding: 20px; display: flex; flex-direction: column; gap: 16px;
  border-right: 1px solid var(--border);
}
.drawer.show { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; gap: 12px;
  padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.drawer-name { font-weight: 700; }
.drawer-role { font-size: 12px; color: var(--text-muted); text-transform: capitalize; }
.drawer nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.drawer nav button {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-radius: var(--radius-sm); font-weight: 500; color: var(--text);
  width: 100%; text-align: left; transition: background .15s;
}
.drawer nav button:hover, .drawer nav button.active {
  background: var(--surface-2); color: var(--primary);
}
.drawer nav button.active { background: var(--primary-light); }
.drawer nav svg { width: 20px; height: 20px; }
.drawer-logout { justify-self: end; }

/* Avatar */
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.avatar.lg { width: 48px; height: 48px; font-size: 18px; }
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }

/* Cards */
.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.card + .card { margin-top: 12px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.card-title { font-weight: 700; font-size: 16px; }

/* Headings */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 18px; flex-wrap: wrap; gap: 8px;
}
.page-head h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }
.page-head p.sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 14px; transition: all .15s;
  background: var(--primary); color: #fff;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }

/* FAB */
.fab {
  position: fixed; right: 18px; z-index: 30;
  bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 18px);
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg);
}
.fab:active { transform: scale(0.93); }
.fab svg { width: 26px; height: 26px; }

/* Lists */
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); margin-bottom: 8px;
  transition: transform .12s;
}
.list-item:active { transform: scale(0.99); }
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; font-size: 15px; }
.list-item-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.list-item-aside { text-align: right; }

/* Pills / Badges */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 99px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px;
}
.pill-green { background: var(--success-bg); color: var(--success); }
.pill-red { background: var(--danger-bg); color: var(--danger); }
.pill-amber { background: var(--warning-bg); color: var(--warning); }
.pill-blue { background: var(--info-bg); color: var(--info); }
.pill-gray { background: var(--surface-2); color: var(--text-muted); }
.pill-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Stat tiles */
.stats-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px;
}
@media (min-width: 640px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  padding: 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.5px; font-weight: 600; }
.stat-value { font-size: 24px; font-weight: 800; margin-top: 4px; }
.stat-trend { font-size: 12px; margin-top: 4px; color: var(--text-muted); }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* Login */
.login-wrap {
  min-height: calc(100vh - var(--topbar-h));
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.login-card h1 { font-size: 26px; font-weight: 800; margin-bottom: 4px; }
.login-card .login-sub { color: var(--text-muted); margin-bottom: 24px; font-size: 14px; }
.login-card .field { margin-bottom: 12px; }
.field-label { display: block; font-size: 12px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }

.demo-pills {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px;
}
.demo-pill {
  padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  text-align: left; transition: all .15s; background: var(--surface);
}
.demo-pill:hover { border-color: var(--primary); background: var(--primary-light); }
.demo-pill .role { font-size: 11px; color: var(--text-muted); font-weight: 600;
  text-transform: uppercase; }
.demo-pill .name { font-weight: 700; }
.demo-pill .creds { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

/* Job card (visit) */
.job {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 10px; overflow: hidden;
  position: relative;
}
.job-stripe {
  position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--primary);
}
.job.overdue .job-stripe { background: var(--danger); }
.job.due .job-stripe { background: var(--warning); }
.job.done .job-stripe { background: var(--success); }
.job.inprog .job-stripe { background: var(--info); }
.job-body { padding: 14px 14px 14px 22px; }
.job-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.job-title { font-weight: 700; }
.job-addr { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.job-meta {
  display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px;
  font-size: 12px; color: var(--text-muted);
}
.job-meta-item { display: inline-flex; align-items: center; gap: 4px; }
.job-meta svg { width: 14px; height: 14px; }
.job-actions {
  display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap;
}
.job-photo-strip {
  display: flex; gap: 6px; margin-top: 10px; overflow-x: auto;
  padding-bottom: 4px;
}
.job-photo-strip img {
  width: 64px; height: 64px; object-fit: cover; border-radius: 8px;
  flex-shrink: 0; cursor: pointer;
}

/* Toast */
.toast {
  position: fixed; bottom: calc(var(--bottomnav-h) + 80px); left: 50%;
  transform: translateX(-50%); z-index: 200;
  padding: 12px 20px; background: var(--text); color: var(--surface);
  border-radius: 99px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toastIn .25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(20px); } }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: modalFade .2s;
}
@media (min-width: 640px) { .modal { align-items: center; } }
@keyframes modalFade { from { opacity: 0; } }
.modal-card {
  background: var(--surface); width: 100%; max-width: 520px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  max-height: 90vh; overflow-y: auto; animation: modalSlide .25s ease;
}
@media (min-width: 640px) { .modal-card { border-radius: var(--radius-lg); } }
@keyframes modalSlide { from { transform: translateY(40px); opacity: 0; } }
.modal-head {
  position: sticky; top: 0; background: var(--surface);
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  z-index: 1;
}
.modal-head h2 { font-size: 18px; font-weight: 700; }
.modal-body { padding: 20px; }
.modal-foot {
  position: sticky; bottom: 0; background: var(--surface);
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}

/* Photo gallery */
.gallery {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.gallery img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: var(--radius-sm); cursor: pointer;
}
.lightbox {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0, 0, 0, 0.92);
  display: flex; align-items: center; justify-content: center;
}
.lightbox img { max-width: 96vw; max-height: 96vh; object-fit: contain; }
.lightbox .lb-close {
  position: absolute; top: 16px; right: 16px; color: #fff; font-size: 20px;
  width: 44px; height: 44px; background: rgba(255,255,255,0.1); border-radius: 50%;
}

/* Photo picker */
.photo-picker {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px;
}
.photo-add {
  width: 80px; height: 80px; border-radius: var(--radius-sm);
  border: 2px dashed var(--border); display: flex; align-items: center;
  justify-content: center; color: var(--text-muted); flex-shrink: 0;
  transition: all .15s;
}
.photo-add:hover { border-color: var(--primary); color: var(--primary); }
.photo-add svg { width: 28px; height: 28px; }
.photo-thumb {
  position: relative; width: 80px; height: 80px; flex-shrink: 0;
}
.photo-thumb img {
  width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius-sm);
}
.photo-thumb .rm {
  position: absolute; top: -6px; right: -6px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--danger); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
}

/* Checklist */
.checklist { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.check-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--surface-2); border-radius: var(--radius-sm);
}
.check-item input[type="checkbox"] {
  width: 20px; height: 20px; accent-color: var(--primary); flex-shrink: 0;
  padding: 0;
}
.check-item.checked { opacity: 0.6; }
.check-item.checked .check-label { text-decoration: line-through; }
.check-label { flex: 1; }

/* Map / Schedule grid */
.week-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 4px; margin-bottom: 16px; overflow-x: auto;
}
.week-day {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px; min-height: 80px;
  font-size: 12px;
}
.week-day-label { font-weight: 700; font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; margin-bottom: 6px; }
.week-day.today { border-color: var(--primary); background: var(--primary-light); }
.week-job {
  background: var(--primary); color: #fff; padding: 4px 6px;
  border-radius: 4px; margin-bottom: 3px; font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Empty state */
.empty {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.empty svg { width: 48px; height: 48px; opacity: 0.4; margin-bottom: 12px; }
.empty h3 { color: var(--text); font-weight: 700; margin-bottom: 4px; }

/* Misc */
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* File-protocol warning */
.file-warning {
  margin: 40px auto; max-width: 520px; padding: 24px;
  background: var(--warning-bg); border: 1px solid var(--warning);
  border-radius: var(--radius);
}
.file-warning h2 { color: var(--warning); margin-bottom: 8px; }
.file-warning code { background: var(--surface); padding: 2px 6px; border-radius: 4px;
  font-family: monospace; font-size: 13px; }

/* Credit footer */
.credit {
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 11px; text-align: center; color: var(--text-faint);
  letter-spacing: 0.3px;
}
.credit a { color: var(--text-muted); text-decoration: none; transition: color .15s; }
.credit a:hover { color: var(--primary); text-decoration: underline; }

/* Install banner */
.install-banner {
  position: fixed; left: 12px; right: 12px;
  bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + 12px);
  z-index: 45;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
  animation: slideUp .3s ease;
  max-width: 480px;
  margin: 0 auto;
}
@keyframes slideUp { from { transform: translateY(50px); opacity: 0; } }
.install-banner-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.install-banner-body { flex: 1; min-width: 0; }
.install-banner-title { font-weight: 700; font-size: 14px; }
.install-banner-sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
