:root {
  --bg: #f5f5f4;
  --bg2: #ffffff;
  --bg3: #e8e8e6;
  --text: #1a1a18;
  --text2: #5a5a57;
  --text3: #9a9a96;
  --border: rgba(0,0,0,0.09);
  --border2: rgba(0,0,0,0.15);
  --accent: #e65c00;
  --accent-bg: #fff3ec;
  --accent-text: #c44a00;
  --success: #166534;
  --success-bg: #f0fdf4;
  --warning: #854d0e;
  --warning-bg: #fefce8;
  --danger: #991b1b;
  --danger-bg: #fef2f2;
  --info: #1e40af;
  --info-bg: #eff6ff;
  --radius: 10px;
  --radius-sm: 6px;
  --nav-h: 68px;
  --bar-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --bg2: #1c1c1a;
    --bg3: #262624;
    --text: #e8e8e4;
    --text2: #9a9a94;
    --text3: #5a5a56;
    --border: rgba(255,255,255,0.07);
    --border2: rgba(255,255,255,0.13);
    --accent: #ff7a2f;
    --accent-bg: #2a1a0a;
    --accent-text: #ff8c45;
    --success: #4ade80;
    --success-bg: #052e16;
    --warning: #fbbf24;
    --warning-bg: #1c1400;
    --danger: #f87171;
    --danger-bg: #1c0a0a;
    --info: #60a5fa;
    --info-bg: #0c1a33;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app { height: 100%; }

.view { height: 100%; }
.view.active { display: flex; flex-direction: column; }

/* LOGIN */
.login-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 24px;
}
.login-logo { text-align: center; }
.login-logo-icon {
  width: 64px; height: 64px;
  background: var(--accent);
  color: white;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 12px;
}
.login-logo-text { font-size: 20px; font-weight: 600; color: var(--text); }
.login-logo-sub { font-size: 13px; color: var(--text3); margin-top: 2px; }
.login-card {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* APPBAR */
.appbar {
  height: var(--bar-h);
  background: var(--bg2);
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top, 0px);
  flex-shrink: 0;
  z-index: 10;
}
.appbar-left { display: flex; align-items: center; gap: 8px; }
.appbar-title { font-size: 17px; font-weight: 600; color: var(--text); }
.appbar-right { display: flex; align-items: center; gap: 8px; }
.user-badge {
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-bg);
  color: var(--accent-text);
  padding: 3px 9px;
  border-radius: 20px;
}

/* PAGES */
#view-app {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.page {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
}
.page.active { display: block; }

/* SEARCH */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px;
  padding: 0 12px;
  height: 40px;
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: 20px;
  color: var(--text3);
}
.search-bar input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

/* LIST */
.list-container { padding: 0 12px 8px; }
.list-item {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.12s;
  display: flex;
  align-items: center;
  gap: 12px;
}
.list-item:hover, .list-item:active { background: var(--bg3); }
.list-avatar {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--accent-bg);
  color: var(--accent-text);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.list-info { flex: 1; min-width: 0; }
.list-name { font-size: 15px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub { font-size: 12px; color: var(--text3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-chevron { color: var(--text3); flex-shrink: 0; }
.empty-state { text-align: center; padding: 48px 24px; color: var(--text3); font-size: 14px; }
.empty-state svg { margin-bottom: 12px; opacity: 0.4; }

/* CLIENT DETAIL */
.detail-section {
  background: var(--bg2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  margin: 12px;
  overflow: hidden;
}
.detail-section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text3);
  padding: 12px 16px 8px;
  border-bottom: 0.5px solid var(--border);
}
.detail-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 0.5px solid var(--border);
  font-size: 14px;
}
.detail-row:last-child { border-bottom: none; }
.detail-row svg { color: var(--text3); flex-shrink: 0; }
.detail-row-label { color: var(--text3); font-size: 12px; min-width: 80px; }
.detail-row-value { color: var(--text); flex: 1; }
.detail-maps-row { display: flex; gap: 8px; padding: 10px 16px; }
.detail-maps-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border2);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.detail-maps-btn:hover { background: var(--bg3); }
.detail-add-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 12px;
  padding: 10px 14px;
  background: transparent;
  border: 0.5px dashed var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
  width: calc(100% - 24px);
}
.detail-add-btn:hover { background: var(--bg3); }

/* STATUS BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
}
.badge-planned { background: var(--info-bg); color: var(--info); }
.badge-done { background: var(--success-bg); color: var(--success); }
.badge-to_order { background: var(--warning-bg); color: var(--warning); }
.badge-ordered { background: var(--info-bg); color: var(--info); }
.badge-received { background: var(--success-bg); color: var(--success); }

/* FILTER ROW */
.filter-row {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 20px;
  border: 0.5px solid var(--border2);
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
}
.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* FORM */
.form-container { padding: 12px; }
.form-section { background: var(--bg2); border: 0.5px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.form-section-title { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text3); padding: 12px 16px 0; }
.field { padding: 10px 16px; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--text2); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: none; }
.field-hint { font-size: 11px; color: var(--text3); margin-top: 4px; }

/* ADDRESS FIELD */
.addr-field { position: relative; }
#addr-suggestions {
  background: var(--bg2);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius-sm);
  margin-top: 2px;
  overflow: hidden;
  display: none;
}
.addr-suggestion {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 0.5px solid var(--border);
  font-size: 13px;
}
.addr-suggestion:last-child { border-bottom: none; }
.addr-suggestion:hover { background: var(--bg3); }
.addr-suggestion svg { color: var(--text3); flex-shrink: 0; margin-top: 1px; }
.addr-suggestion-main { color: var(--text); }
.addr-suggestion-sub { color: var(--text3); font-size: 11px; }
.addr-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: var(--success-bg);
  border: 0.5px solid var(--success);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--success);
}
.addr-pill span { flex: 1; }
.addr-clear {
  background: none;
  border: none;
  color: var(--success);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
}
.maps-row { display: flex; gap: 8px; margin-top: 8px; }
.maps-link {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border2);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  color: var(--text);
}
.maps-link:hover { background: var(--bg3); }
.maps-link.waze { color: var(--info); border-color: var(--info); }
.maps-link.gmaps { color: var(--success); border-color: var(--success); }

/* BOTTOM NAV */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg2);
  border-top: 0.5px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  padding-top: 8px;
  z-index: 100;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text3);
  font-size: 11px;
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.1s;
}
.nav-btn.active { color: var(--accent); }
.nav-btn span { line-height: 1; }
.fab-btn {
  width: 48px; height: 48px;
  background: var(--accent);
  color: white !important;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -8px;
  box-shadow: 0 2px 12px rgba(230, 92, 0, 0.35);
  flex: 0 0 auto;
}

/* FAB MENU */
.fab-menu {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg2);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 200;
  min-width: 200px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.15);
}
.fab-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  width: 100%;
  background: none;
  border: none;
  border-bottom: 0.5px solid var(--border);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
}
.fab-item:last-child { border-bottom: none; }
.fab-item:hover { background: var(--bg3); }
.fab-item svg { color: var(--accent); }

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  display: flex;
  align-items: flex-end;
}
.modal {
  background: var(--bg2);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding-bottom: calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 16px;
  font-weight: 600;
}

/* PHOTO UPLOAD */
.photo-upload-zone {
  position: relative;
  border: 1.5px dashed var(--border2);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  color: var(--text3);
  font-size: 13px;
  line-height: 1.5;
  cursor: pointer;
}
.photo-upload-zone svg { color: var(--text3); margin-bottom: 8px; }
.photo-upload-zone span { font-size: 11px; }

/* BUTTONS */
.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.1s;
  margin-top: 4px;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { opacity: 0.8; transform: scale(0.99); }
.icon-btn {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  border-radius: 8px;
  font-size: 20px;
}
.icon-btn:hover { background: var(--bg3); }

/* MISC */
.error-msg { font-size: 13px; color: var(--danger); padding: 8px 12px; background: var(--danger-bg); border-radius: var(--radius-sm); }
.section-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 4px; }
.section-header-title { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text3); }
.part-status-btn { font-size: 11px; padding: 4px 10px; border-radius: 20px; border: 0.5px solid var(--border2); background: transparent; color: var(--text2); cursor: pointer; }
.part-status-btn:hover { background: var(--bg3); }
