/* ── Variables ── */
:root {
  --green:    #1a7f4b;
  --green-dk: #145e37;
  --green-lt: #e8f5ee;
  --accent:   #f0a500;
  --red:      #d93025;
  --text:     #1c2b22;
  --text-2:   #4d6357;
  --border:   #d0e6d9;
  --bg:       #f0f7f3;
  --card:     #ffffff;
  --shadow:   0 1px 4px rgba(0,0,0,.10);
  --radius:   12px;
  --radius-sm:8px;
  --nav-h:    64px;
  --safe-b:   env(safe-area-inset-bottom, 0px);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}
button { cursor: pointer; border: none; background: none; font: inherit; }
input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

/* ── Loading screen ── */
#loading-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 9999;
}
.loading-logo { text-align: center; }
.loading-logo svg { display: block; margin: 0 auto 12px; }
.loading-logo p { color: var(--green); font-size: 1.2rem; font-weight: 700; letter-spacing: .02em; }

/* ── App shell ── */
#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* ── Auth screen ── */
.auth-screen {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--green-dk) 0%, var(--green) 60%, #2d9e64 100%);
}
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo svg { display: block; margin: 0 auto 12px; }
.auth-logo h1 { color: white; font-size: 1.8rem; font-weight: 800; }
.auth-logo p  { color: rgba(255,255,255,.75); font-size: .9rem; margin-top: 4px; }

.auth-card {
  background: white;
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%; max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.auth-tabs { display: flex; gap: 0; margin-bottom: 24px; border-bottom: 2px solid var(--border); }
.auth-tab {
  flex: 1; padding: 10px 0; text-align: center;
  font-size: .95rem; font-weight: 600; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.auth-tab.active { color: var(--green); border-color: var(--green); }

/* ── Form controls ── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .04em; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem; color: var(--text);
  background: white;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(26,127,75,.12);
}
.field textarea { resize: vertical; min-height: 72px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 20px; border-radius: var(--radius-sm);
  font-size: .95rem; font-weight: 600;
  transition: background .15s, transform .1s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--green); color: white; }
.btn-primary:hover { background: var(--green-dk); }
.btn-secondary { background: var(--green-lt); color: var(--green); }
.btn-secondary:hover { background: #d5eee1; }
.btn-danger  { background: #fdecea; color: var(--red); }
.btn-danger:hover { background: #f8c9c5; }
.btn-full { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: .85rem; border-radius: 8px; }
.btn-icon { padding: 10px; border-radius: 50%; }
.btn-gps {
  background: linear-gradient(135deg, #d93025, #e85848);
  color: white; font-size: 1rem; font-weight: 700;
  padding: 16px 24px; border-radius: 50px;
  box-shadow: 0 4px 16px rgba(217,48,37,.35);
  gap: 10px;
}
.btn-gps.tracking {
  background: linear-gradient(135deg, #1a7f4b, #2d9e64);
  box-shadow: 0 4px 16px rgba(26,127,75,.35);
  animation: pulse 1.8s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(26,127,75,.35); }
  50%       { box-shadow: 0 4px 24px rgba(26,127,75,.6); }
}

/* ── Top bar ── */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--green);
  color: white;
  padding: 0 16px;
  height: 56px;
  display: flex; align-items: center; gap: 12px;
  padding-top: env(safe-area-inset-top, 0);
}
.topbar-title { font-size: 1.1rem; font-weight: 700; flex: 1; }
.topbar-back {
  color: white; padding: 8px; margin-left: -8px;
  display: flex; align-items: center;
}

/* ── Bottom nav ── */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-b);
  box-shadow: 0 -2px 12px rgba(0,0,0,.07);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; padding: 10px 4px;
  color: var(--text-2); font-size: .7rem; font-weight: 500;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-item svg { width: 24px; height: 24px; }
.nav-item.active { color: var(--green); }
.nav-item.active svg { stroke: var(--green); }
.nav-fab {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; padding: 6px 4px;
}
.nav-fab-btn {
  width: 52px; height: 52px;
  background: var(--green); color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 12px rgba(26,127,75,.4);
  margin-top: -20px;
  transition: background .15s, transform .1s;
}
.nav-fab-btn:active { transform: scale(.93); }
.nav-fab span { font-size: .7rem; font-weight: 500; color: var(--text-2); }

/* ── Page container ── */
.page {
  flex: 1;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 16px);
  max-width: 600px; margin: 0 auto; width: 100%;
}
.page-full { padding: 0; max-width: none; }

/* ── Cards ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.card-title { font-size: 1rem; font-weight: 700; }
.card-subtitle { font-size: .8rem; color: var(--text-2); margin-top: 2px; }

/* ── Dashboard ── */
.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin-bottom: 12px;
}
.stat-card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.stat-card.accent { background: var(--green); }
.stat-card.accent .stat-label,
.stat-card.accent .stat-value { color: white; }
.stat-label { font-size: .72rem; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.6rem; font-weight: 800; color: var(--text); margin-top: 4px; line-height: 1; }
.stat-unit  { font-size: .8rem; font-weight: 400; }

/* ── Trip list ── */
.trip-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  display: flex; align-items: flex-start; gap: 12px;
}
.trip-type-dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0; margin-top: 5px;
}
.trip-type-dot.business { background: var(--green); }
.trip-type-dot.private  { background: var(--accent); }
.trip-info { flex: 1; min-width: 0; }
.trip-purpose { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trip-meta { font-size: .78rem; color: var(--text-2); margin-top: 3px; }
.trip-dist { font-size: 1.05rem; font-weight: 700; color: var(--green); white-space: nowrap; }
.trip-actions { display: flex; gap: 4px; align-items: center; }

/* ── GPS tracker widget ── */
.gps-widget {
  background: linear-gradient(135deg, #1c2b22, #1a3d2a);
  border-radius: var(--radius);
  padding: 24px;
  color: white;
  text-align: center;
  margin-bottom: 16px;
}
.gps-distance {
  font-size: 3.5rem; font-weight: 900; line-height: 1;
  color: #4ade80; margin: 16px 0 4px;
  font-variant-numeric: tabular-nums;
}
.gps-unit { font-size: 1rem; color: rgba(255,255,255,.6); margin-bottom: 8px; }
.gps-status { font-size: .85rem; color: rgba(255,255,255,.5); margin-bottom: 20px; }
.gps-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #4ade80; margin-right: 6px; }
.gps-dot.acquiring { background: var(--accent); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* ── Filter bar ── */
.filter-bar {
  background: var(--card);
  padding: 10px 16px;
  display: flex; gap: 8px; align-items: center;
  overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 56px; z-index: 50;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0; padding: 6px 14px; border-radius: 20px;
  font-size: .82rem; font-weight: 600; border: 1.5px solid var(--border);
  color: var(--text-2); background: white;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
.filter-chip.active { background: var(--green); color: white; border-color: var(--green); }

/* ── Empty state ── */
.empty-state {
  text-align: center; padding: 48px 24px;
  color: var(--text-2);
}
.empty-state svg { margin: 0 auto 16px; opacity: .35; }
.empty-state h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: .9rem; }

/* ── Reports ── */
.pct-bar {
  height: 12px; border-radius: 6px;
  background: #e8f5ee; overflow: hidden; margin: 8px 0;
}
.pct-fill { height: 100%; border-radius: 6px; background: var(--green); transition: width .4s; }
.pct-fill.private { background: var(--accent); }
.report-legend { display: flex; gap: 16px; font-size: .82rem; }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }

/* ── Monthly chart ── */
.month-bars { display: flex; align-items: flex-end; gap: 4px; height: 80px; margin: 12px 0; }
.month-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.month-bar { width: 100%; border-radius: 3px 3px 0 0; background: var(--green); min-height: 2px; transition: height .3s; }
.month-bar.private { background: var(--accent); }
.month-label { font-size: .6rem; color: var(--text-2); }

/* ── Vehicle selector ── */
.vehicle-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.vehicle-chip {
  padding: 8px 16px; border-radius: 20px;
  border: 2px solid var(--border); font-size: .9rem; font-weight: 600;
  background: white; color: var(--text-2);
  transition: all .15s;
}
.vehicle-chip.selected { border-color: var(--green); background: var(--green-lt); color: var(--green); }

/* ── Trip type toggle ── */
.type-toggle { display: flex; gap: 0; border-radius: var(--radius-sm); overflow: hidden; border: 1.5px solid var(--border); }
.type-btn {
  flex: 1; padding: 11px; font-size: .9rem; font-weight: 600;
  color: var(--text-2); background: white;
  transition: background .15s, color .15s;
}
.type-btn.business.active { background: var(--green); color: white; }
.type-btn.private.active  { background: var(--accent); color: white; }

/* ── Section header ── */
.section-hdr {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.section-title { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-height: 92dvh; overflow-y: auto;
  padding: 20px 20px calc(20px + var(--safe-b));
  transform: translateY(100%);
  transition: transform .25s cubic-bezier(.32,.72,0,1);
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 20px; }
.modal-title { font-size: 1.2rem; font-weight: 800; margin-bottom: 20px; }

/* ── Toast ── */
.toast-container {
  position: fixed; top: 80px; left: 50%; transform: translateX(-50%);
  z-index: 999; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none; width: calc(100% - 32px); max-width: 400px;
}
.toast {
  background: #1c2b22; color: white;
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: .9rem; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  display: flex; align-items: center; gap: 10px;
  animation: slideDown .2s ease;
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Misc utils ── */
.text-green  { color: var(--green); }
.text-muted  { color: var(--text-2); }
.text-sm     { font-size: .85rem; }
.text-center { text-align: center; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.badge-business { background: var(--green-lt); color: var(--green); }
.badge-private  { background: #fff3cd; color: #856404; }
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* ── Danger zone ── */
.danger-zone { border: 1.5px solid #fecaca; border-radius: var(--radius-sm); padding: 14px; margin-top: 16px; }
.danger-zone-title { font-size: .8rem; font-weight: 700; color: var(--red); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 10px; }

/* ── Purpose suggestions ── */
.suggestions {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 8px;
}
.suggest-chip {
  padding: 5px 12px; border-radius: 16px;
  font-size: .8rem; border: 1.5px solid var(--border);
  background: white; color: var(--text-2);
  -webkit-tap-highlight-color: transparent;
}
.suggest-chip:active { background: var(--green-lt); border-color: var(--green); color: var(--green); }

@media (prefers-color-scheme: dark) {
  :root {
    --bg:    #0f1a13;
    --card:  #1a2b1f;
    --text:  #e8f5ee;
    --text-2:#7aab8a;
    --border:#2a4033;
    --green-lt: #1a3028;
    --shadow: 0 1px 4px rgba(0,0,0,.35);
  }
  .field input, .field select, .field textarea { background: #1a2b1f; color: var(--text); border-color: var(--border); }
  .type-btn { background: #1a2b1f; }
  .filter-chip, .vehicle-chip, .suggest-chip { background: #1a2b1f; }
  .auth-card { background: #1a2b1f; }
  .month-bars { }
}
