@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #f0f4f8;
  --card: #ffffff;
  --primary: #1e3a5f;
  --accent: #2563eb;
  --accent-light: #eff6ff;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --text: #1e293b;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-full: 100px;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overscroll-behavior: none;
}

/* ── Utilities ── */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-2 { color: var(--text-2); }
.text-sm { font-size: .875rem; }
.fw-600 { font-weight: 600; }
.mt-4 { margin-top: 1rem; }
.mt-8 { margin-top: 2rem; }

/* ── Layout ── */
.page { min-height: 100vh; }
.container { max-width: 480px; margin: 0 auto; padding: 0 1rem; }

/* ── Spinner ── */
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
  margin: 2rem auto;
}
.spinner-sm {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
  border-radius: 50%; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
#toast-wrap {
  position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: .5rem;
  z-index: 9999; pointer-events: none; width: 90%; max-width: 420px;
}
.toast {
  padding: .875rem 1.25rem; border-radius: var(--radius-sm);
  font-size: .9rem; font-weight: 500; color: #fff;
  animation: toastIn .25s ease forwards;
  pointer-events: all; box-shadow: var(--shadow-lg);
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
@keyframes toastIn { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:none; } }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 1000; backdrop-filter: blur(2px);
  animation: fadeIn .2s ease;
}
.modal-overlay.center { align-items: center; }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
.modal {
  background: var(--card); border-radius: var(--radius) var(--radius) 0 0;
  padding: 2rem 1.5rem 2.5rem; width: 100%; max-width: 480px;
  animation: slideUp .25s ease;
}
.modal-center {
  background: var(--card); border-radius: var(--radius);
  padding: 2rem 1.5rem; width: 90%; max-width: 380px;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform:translateY(40px); opacity:0; } to { transform:none; opacity:1; } }
.modal-icon {
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.75rem; margin: 0 auto 1rem;
}
.modal-icon-warn { background: var(--warning-light); }
.modal-icon-danger { background: var(--danger-light); }
.modal h3 { font-size: 1.15rem; font-weight: 700; margin-bottom: .5rem; }
.modal p { color: var(--text-2); font-size: .95rem; line-height: 1.5; }
.modal-btns { display: flex; gap: .75rem; margin-top: 1.75rem; }
.modal-btns .btn { flex: 1; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .875rem 1.5rem; border-radius: var(--radius-full);
  font-size: .95rem; font-weight: 600; font-family: inherit;
  border: none; cursor: pointer; transition: all .15s ease;
  -webkit-tap-highlight-color: transparent; text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff; box-shadow: 0 4px 14px rgba(37,99,235,.4);
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(37,99,235,.5); }
.btn-secondary {
  background: var(--border); color: var(--text);
}
.btn-success {
  background: linear-gradient(135deg, #16a34a, #15803d);
  color: #fff; box-shadow: 0 4px 14px rgba(22,163,74,.35);
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost {
  background: transparent; color: var(--accent);
  border: 1.5px solid var(--accent);
}
.btn-lg { padding: 1rem 2rem; font-size: 1rem; }
.btn-full { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ── STATUS CHIPS ── */
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .3rem .75rem; border-radius: var(--radius-full);
  font-size: .8rem; font-weight: 600;
}
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.chip-pending { background: #f1f5f9; color: #64748b; }
.chip-pending::before { background: #94a3b8; }
.chip-active { background: var(--accent-light); color: var(--accent); }
.chip-active::before { background: var(--accent); animation: pulse 1.4s ease infinite; }
.chip-ended { background: var(--warning-light); color: var(--warning); }
.chip-ended::before { background: var(--warning); }
.chip-complete { background: var(--success-light); color: var(--success); }
.chip-complete::before { background: var(--success); }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.4;} }

/* ── LOGIN PAGE ── */
#page-login {
  min-height: 100vh;
  background: linear-gradient(160deg, #0f2444 0%, #1e3a5f 50%, #1e40af 100%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 1.5rem;
}
.login-logo {
  margin-bottom: 2.5rem; text-align: center;
}
.login-logo .logo-icon {
  width: 72px; height: 72px; background: rgba(255,255,255,.12);
  border-radius: 22px; display: flex; align-items: center; justify-content: center;
  font-size: 2.25rem; margin: 0 auto 1rem; border: 1.5px solid rgba(255,255,255,.2);
}
.login-logo h1 { color: #fff; font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; }
.login-logo p { color: rgba(255,255,255,.6); font-size: .875rem; margin-top: .3rem; }
.login-card {
  background: #fff; border-radius: var(--radius);
  padding: 2rem; width: 100%; max-width: 380px;
  box-shadow: 0 24px 64px rgba(0,0,0,.3);
}
.login-card h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: .4rem; }
.login-card p { color: var(--text-2); font-size: .875rem; margin-bottom: 1.75rem; }
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block; font-size: .8rem; font-weight: 600;
  color: var(--text-2); margin-bottom: .4rem; text-transform: uppercase; letter-spacing: .04em;
}
.form-group input {
  width: 100%; padding: .875rem 1rem; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); font-size: 1rem; font-family: inherit;
  outline: none; transition: border-color .15s, box-shadow .15s;
  background: var(--bg);
}
.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
  background: #fff;
}
.login-footer { margin-top: 2rem; text-align: center; color: rgba(255,255,255,.45); font-size: .8rem; }

/* ── APP HEADER ── */
.app-header {
  background: var(--primary); color: #fff;
  padding: 1rem 1.25rem; position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 1rem;
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
}
.app-header .back-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,.1); border: none; color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 1.25rem; transition: background .15s;
  flex-shrink: 0;
}
.app-header .back-btn:hover { background: rgba(255,255,255,.2); }
.app-header .header-title { flex: 1; }
.app-header .header-title h2 {
  font-size: 1.05rem; font-weight: 700; line-height: 1.2;
}
.app-header .header-title span { font-size: .8rem; opacity: .65; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .95rem; flex-shrink: 0;
}

/* ── DASHBOARD ── */
#page-dashboard { padding-bottom: 2rem; }
.dashboard-welcome {
  background: linear-gradient(135deg, var(--primary), #1e40af);
  color: #fff; padding: 1.5rem 1.25rem 3.5rem;
  margin-bottom: -2.5rem;
}
.dashboard-welcome h3 { font-size: 1.35rem; font-weight: 700; }
.dashboard-welcome p { opacity: .7; font-size: .875rem; margin-top: .25rem; }
.trips-section { padding: 0 1rem; }
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.section-header h4 { font-size: .85rem; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }
.trip-card {
  background: var(--card); border-radius: var(--radius); padding: 1.15rem;
  box-shadow: var(--shadow); margin-bottom: .75rem; cursor: pointer;
  transition: transform .15s, box-shadow .15s; border: 1.5px solid transparent;
  display: flex; flex-direction: column; gap: .5rem;
}
.trip-card:active { transform: scale(.98); box-shadow: none; }
.trip-card:hover { border-color: var(--accent); }
.trip-card-header { display: flex; align-items: center; justify-content: space-between; }
.trip-card-title { font-size: .95rem; font-weight: 700; color: var(--text); }
.trip-card-id { font-size: .78rem; color: var(--text-3); }
.trip-card-meta {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  font-size: .82rem; color: var(--text-2);
}
.trip-card-meta .sep { color: var(--border); }
.empty-state {
  text-align: center; padding: 4rem 1rem;
}
.empty-state .empty-icon { font-size: 3.5rem; margin-bottom: 1rem; }
.empty-state h4 { font-size: 1.1rem; font-weight: 600; margin-bottom: .5rem; }
.empty-state p { color: var(--text-2); font-size: .9rem; }

/* ── TRIP DETAIL ── */
#page-trip { padding-bottom: 7rem; }
.trip-hero {
  background: linear-gradient(135deg, var(--primary), #1e40af);
  padding: 1.5rem 1.25rem; color: #fff;
}
.trip-hero h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: .6rem; }
.trip-fields { padding: 1rem; display: flex; flex-direction: column; gap: .625rem; }
.field-card {
  background: var(--card); border-radius: var(--radius-sm);
  padding: .9rem 1rem; box-shadow: var(--shadow);
}
.field-card .field-label {
  font-size: .75rem; font-weight: 600; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: .3rem;
}
.field-card .field-value { font-size: .95rem; font-weight: 500; color: var(--text); word-break: break-word; }
.field-card .field-value a { color: var(--accent); text-decoration: none; }

/* ── BOTTOM ACTION BAR ── */
.action-bar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; background: var(--card);
  padding: 1rem 1.25rem calc(1rem + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 24px rgba(0,0,0,.1); border-top: 1px solid var(--border);
  z-index: 200;
}
.action-bar-inner { display: flex; flex-direction: column; gap: .625rem; }

/* ── UPLOAD SECTION ── */
.upload-section {
  background: var(--card); border-radius: var(--radius); padding: 1.25rem;
  margin: 0 1rem 1rem; box-shadow: var(--shadow);
}
.upload-section h4 { font-size: .95rem; font-weight: 700; margin-bottom: .75rem; }
.upload-actions { display: flex; gap: .75rem; margin-bottom: 1rem; }
.upload-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: .4rem;
  padding: 1rem; border-radius: var(--radius-sm);
  border: 1.5px dashed var(--border); background: var(--bg);
  cursor: pointer; transition: all .15s; font-size: .8rem; font-weight: 500; color: var(--text-2);
}
.upload-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.upload-btn svg { width: 28px; height: 28px; }
.file-preview-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: 1rem;
}
.file-preview-item {
  aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden;
  position: relative; background: var(--bg);
}
.file-preview-item img {
  width: 100%; height: 100%; object-fit: cover;
}
.file-preview-item .file-icon {
  width: 100%; height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: .3rem;
  font-size: .7rem; color: var(--text-2); padding: .5rem;
}
.file-preview-item .remove-btn {
  position: absolute; top: .25rem; right: .25rem;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,.55); border: none; color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: .7rem;
}
.upload-progress {
  display: flex; align-items: center; gap: .75rem;
  padding: .875rem 1rem; background: var(--accent-light);
  border-radius: var(--radius-sm); font-size: .875rem; color: var(--accent); font-weight: 600;
}
.uploaded-files-list { display: flex; flex-direction: column; gap: .4rem; margin-top: .75rem; }
.uploaded-file-row {
  display: flex; align-items: center; gap: .6rem;
  font-size: .82rem; color: var(--text-2); padding: .4rem 0;
  border-bottom: 1px solid var(--border);
}
.uploaded-file-row:last-child { border-bottom: none; }
.uploaded-file-row .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── ADMIN PAGE ── */
#page-admin { padding-bottom: 2rem; }
.admin-tabs {
  display: flex; background: var(--card); border-bottom: 1.5px solid var(--border);
  position: sticky; top: 65px; z-index: 90;
}
.admin-tab {
  flex: 1; padding: .875rem .5rem; text-align: center;
  font-size: .85rem; font-weight: 600; color: var(--text-2);
  cursor: pointer; border-bottom: 2.5px solid transparent;
  transition: all .15s;
}
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.admin-panel { padding: 1rem; }
.admin-card {
  background: var(--card); border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow); margin-bottom: 1rem;
}
.admin-card h4 { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; }
.driver-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .875rem 0; border-bottom: 1px solid var(--border);
}
.driver-row:last-child { border-bottom: none; }
.driver-info { flex: 1; }
.driver-info .driver-name { font-weight: 600; font-size: .9rem; }
.driver-info .driver-login { font-size: .8rem; color: var(--text-2); margin-top: .1rem; }
.driver-actions { display: flex; gap: .4rem; }
.icon-btn {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  border: none; cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: .9rem; transition: background .15s;
}
.icon-btn-danger { background: var(--danger-light); color: var(--danger); }
.icon-btn-edit { background: var(--accent-light); color: var(--accent); }
.assignment-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .875rem 0; border-bottom: 1px solid var(--border);
}
.assignment-row:last-child { border-bottom: none; }
.assignment-info { flex: 1; }
.assignment-info .task-num { font-weight: 700; font-size: .95rem; color: var(--accent); }
.assignment-info .driver-name { font-size: .82rem; color: var(--text-2); margin-top: .15rem; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.stat-card {
  background: var(--bg); border-radius: var(--radius-sm); padding: 1rem;
  text-align: center;
}
.stat-card .stat-num { font-size: 2rem; font-weight: 800; color: var(--primary); }
.stat-card .stat-label { font-size: .78rem; color: var(--text-2); margin-top: .2rem; }
.input-row { display: flex; gap: .75rem; }
.input-row .form-group { flex: 1; }
.form-group select {
  width: 100%; padding: .875rem 1rem; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); font-size: .95rem; font-family: inherit;
  background: var(--bg); outline: none; cursor: pointer;
  transition: border-color .15s;
}
.form-group select:focus { border-color: var(--accent); background: #fff; }

/* ── LOADING OVERLAY ── */
.page-loader {
  position: fixed; inset: 0; background: rgba(240,244,248,.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; backdrop-filter: blur(2px);
}
