:root {
  --bg: #F3F4F1;
  --surface: #FFFFFF;
  --ink: #1B1F23;
  --sub: #5c6068;
  --border: rgba(27,31,35,0.08);
  --accent: #2E5EE8;
  --accent-wash: rgba(46,94,232,0.10);
  --amber: #C97A1D;
  --amber-wash: rgba(201,122,29,0.12);
  --green: #1E8A5F;
  --green-wash: rgba(30,138,95,0.12);
  --red: #C4432B;
  --red-wash: rgba(196,67,43,0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

:root[data-theme="dark"] {
  --bg: #15181B;
  --surface: #1D2124;
  --ink: #E9EAE7;
  --sub: #9BA0A6;
  --border: rgba(233,234,231,0.12);
  --amber: #E0A252;
  --amber-wash: rgba(224,162,82,0.16);
  --green: #4FB98A;
  --green-wash: rgba(79,185,138,0.16);
  --red: #E27461;
  --red-wash: rgba(226,116,97,0.16);
}

* { box-sizing: border-box; }

html, body {
  overscroll-behavior-y: contain; /* kills the Android WebView pull-to-refresh/bounce gesture */
  height: 100%;
}

body {
  margin: 0;
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top); /* keeps content clear of the status bar in the Android app */
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, .heading {
  font-family: 'Space Grotesk', -apple-system, sans-serif;
  font-weight: 600;
  line-height: 1.1;
  margin: 0;
}

#app { min-height: 100vh; }

/* ---------- Layout ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 208px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}
.sidebar .brand { font-family: 'Geist', sans-serif; font-weight: 600; font-size: 16px; padding: 0 8px 18px; }
.brand-row { display: flex; align-items: center; justify-content: space-between; padding-right: 4px; }
.brand-row .brand { padding-bottom: 0; }
.bell-btn { position: relative; background: none; border: none; font-size: 18px; cursor: pointer; color: var(--sub); padding: 4px; }
.bell-badge {
  position: absolute; top: -2px; right: -2px; background: var(--red); color: #fff; font-size: 10px;
  min-width: 16px; height: 16px; border-radius: 999px; display: flex; align-items: center; justify-content: center; padding: 0 3px;
}
.tab-bell { display: none; position: relative; font-size: 18px; padding: 6px; }
@media (max-width: 720px) {
  .tab-bell { display: flex; align-items: center; justify-content: center; }
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 8px; border-radius: var(--radius-sm);
  color: var(--ink); font-size: 14px; text-decoration: none; cursor: pointer;
}
.nav-item.active { background: var(--accent-wash); color: var(--accent); font-weight: 500; }
.nav-item:not(.active) { color: var(--sub); }

.main { flex: 1; padding: 24px 28px; min-width: 0; }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.topbar .sub { font-size: 13px; color: var(--sub); margin-top: 2px; }

.btn-primary {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 9px 16px; font-size: 13px; font-weight: 500; cursor: pointer;
}
.btn-primary:active { transform: scale(0.98); }
.btn-secondary {
  background: transparent; color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 16px; font-size: 13px; font-weight: 500; cursor: pointer;
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 22px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px 16px; }
.stat-card .label { font-size: 12px; color: var(--sub); margin-bottom: 4px; }
.stat-card .value { font-size: 24px; font-weight: 600; }

.list-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.list-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-row .title { font-size: 14px; font-weight: 500; }
.list-row .meta { font-size: 12px; color: var(--sub); margin-top: 2px; }

.badge { font-size: 12px; font-weight: 500; padding: 4px 12px; border-radius: 999px; white-space: nowrap; }
.badge.status-scheduled { background: var(--amber-wash); color: var(--amber); }
.badge.status-in_progress { background: var(--accent-wash); color: var(--accent); }
.badge.status-done { background: var(--green-wash); color: var(--green); }
.badge.status-cancelled { background: var(--red-wash); color: var(--red); }

/* ---------- Login ---------- */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px; width: 100%; max-width: 360px; }
.login-card h1 { font-size: 20px; margin-bottom: 6px; }
.login-card p { font-size: 13px; color: var(--sub); margin: 0 0 22px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--sub); margin-bottom: 5px; }
.field input {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--ink); font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.login-error { color: var(--red); font-size: 13px; margin-bottom: 12px; display: none; }

/* ---------- Theme settings ---------- */
.theme-panel { display: flex; flex-direction: column; gap: 16px; }
.mode-row { display: flex; gap: 6px; }
.mode-btn { border: 1px solid var(--border); background: transparent; border-radius: 6px; padding: 7px 14px; font-size: 13px; cursor: pointer; color: var(--sub); }
.mode-btn.active { background: var(--accent-wash); color: var(--accent); border-color: transparent; }
.accent-row { display: flex; gap: 10px; }
.accent-swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.accent-swatch.active { border-color: var(--ink); }

/* ---------- Mobile: bottom tab bar for technicians in the field ---------- */
@media (max-width: 720px) {
  .sidebar { display: none; }
  .main { padding: 16px; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; height: 60px;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-around;
  }
  .tabbar .tab-item { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10px; color: var(--sub); text-decoration: none; flex: 1; text-align: center; padding: 6px 2px 4px; }
  .tabbar .tab-icon { font-size: 18px; line-height: 1; width: 34px; height: 26px; display: flex; align-items: center; justify-content: center; border-radius: 8px; transition: background 0.15s; }
  .tabbar .tab-item.active .tab-icon { background: var(--accent-wash); }
  .tabbar .tab-item.active .tab-label { color: var(--accent); font-weight: 500; }
  .tabbar .tab-label { font-size: 10px; }
}
@media (min-width: 721px) { .tabbar { display: none; } }

/* ---------- Modal (job form) ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
@media (min-width: 721px) { .modal-overlay { align-items: center; } }
.modal-overlay.top-sheet { align-items: flex-start; }
.modal-overlay.top-sheet .modal-card { border-radius: 0 0 var(--radius-lg) var(--radius-lg); margin-top: env(safe-area-inset-top); }
@media (min-width: 721px) { .modal-overlay.top-sheet .modal-card { margin-top: 24px; border-radius: var(--radius-lg); } }
.modal-card {
  background: var(--surface); width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 22px 22px 26px;
}
@media (min-width: 721px) { .modal-card { border-radius: var(--radius-lg); } }
.modal-card .modal-title { font-size: 18px; margin-bottom: 18px; }
.field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--ink); font-size: 14px; font-family: inherit;
}
.field textarea { min-height: 70px; resize: vertical; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.form-actions button { flex: 1; }
.form-note { font-size: 12px; color: var(--sub); margin-top: 4px; }

/* ---------- Sync status ---------- */
.sync-badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  color: var(--amber); background: var(--amber-wash); padding: 4px 10px;
  border-radius: 999px; margin-left: 8px;
}
.offline-tag {
  font-size: 11px; color: var(--amber); background: var(--amber-wash);
  padding: 2px 8px; border-radius: 999px; margin-left: 6px;
}

/* ---------- Business profile / help text / misc ---------- */
.help-box {
  background: var(--accent-wash); border-radius: 10px; padding: 12px 14px;
  font-size: 12.5px; color: var(--ink); line-height: 1.5; margin-bottom: 14px;
}
.help-box b { color: var(--accent); }
.logo-preview {
  width: 64px; height: 64px; border-radius: 10px; object-fit: contain;
  background: var(--bg); border: 1px solid var(--border); margin-bottom: 10px;
}
.file-input-label {
  display: inline-flex; align-items: center; gap: 8px; border: 1px dashed var(--border);
  border-radius: 8px; padding: 9px 14px; font-size: 13px; color: var(--sub); cursor: pointer;
}
.file-input-label input[type="file"] { display: none; }
.section-title { font-size: 13px; font-weight: 500; color: var(--ink); margin: 18px 0 10px; }
.detail-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 14px; }
.checkbox-row input { width: 16px; height: 16px; }

/* ---------- Pull-to-refresh ---------- */
#ptr-indicator {
  position: fixed; top: env(safe-area-inset-top); left: 50%; transform: translate(-50%, -60px);
  z-index: 80; width: 38px; height: 38px; border-radius: 50%; background: var(--surface);
  border: 1px solid var(--border); box-shadow: 0 6px 16px rgba(27,31,35,0.18);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  transition: transform 0.15s; pointer-events: none;
}
#ptr-indicator.ptr-spin { animation: ptr-rotate 0.7s linear infinite; }
@keyframes ptr-rotate { from { transform: translate(-50%, 10px) rotate(0deg); } to { transform: translate(-50%, 10px) rotate(360deg); } }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 6px; }
.photo-thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-remove { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%; background: rgba(0,0,0,0.6); color: #fff; border: none; font-size: 12px; line-height: 1; cursor: pointer; }

/* ---------- Validation ---------- */
.input-invalid { border-color: var(--red) !important; background: var(--red-wash) !important; }
.field-error-msg { color: var(--red); font-size: 12px; margin-top: 4px; display: none; }
