:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #10b981;
  --danger: #ef4444;
  --bg: #f3f4f8;
  --surface: #ffffff;
  --text: #1f2430;
  --text-muted: #6b7280;
  --radius: 16px;
  --shadow: 0 4px 16px rgba(20, 20, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { text-decoration: none; color: inherit; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  box-shadow: var(--shadow);
}
.app-header-inner {
  max-width: 480px;
  margin: 0 auto;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand-block { display: flex; flex-direction: column; line-height: 1.1; }
.brand { font-weight: 700; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}
.brand-version { font-size: 0.65rem; opacity: 0.75; font-weight: 400; }
.logout-link { font-size: 0.85rem; opacity: 0.9; }
.logout-link:hover { text-decoration: underline; }
.header-profile { margin-left: auto; margin-right: 14px; display: flex; }
.header-profile img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.6);
}
.header-avatar-fallback {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

/* Main */
.app-main {
  max-width: 480px;
  margin: 0 auto;
  padding: 18px 16px 32px;
}
.app-main.with-nav { padding-bottom: 96px; }

.page-title { font-size: 1.4rem; margin: 4px 0 12px; }
.page-sub { color: var(--text-muted); margin-top: -6px; font-size: 0.92rem; }

/* Auth */
.auth-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 20px 16px 24px;
  background: linear-gradient(160deg, var(--primary), #7c3aed 60%, #0f172a);
}
.auth-logo-blend {
  width: 200px;
  height: 200px;
  object-fit: cover;
  object-position: center 60%;
  -webkit-mask-image: radial-gradient(circle, #000 60%, transparent 78%);
  mask-image: radial-gradient(circle, #000 60%, transparent 78%);
  margin-bottom: -55px;
  position: relative;
  z-index: 2;
  pointer-events: none;
}
.auth-card {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 68px 28px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  position: relative;
  z-index: 1;
}
.auth-logo { font-size: 2.5rem; }
.auth-card h1 { margin: 8px 0 4px; }
.auth-version { color: var(--text-muted); font-size: 0.7rem; margin: 0 0 8px; }
.auth-sub { color: var(--text-muted); margin-bottom: 20px; font-size: 0.9rem; }
.auth-footer { margin-top: 18px; font-size: 0.88rem; color: var(--text-muted); }
.auth-footer a { color: var(--primary); font-weight: 600; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; font-weight: 600; color: var(--text); }
.form input[type="text"],
.form input[type="password"],
.form input[type="number"],
.form input[type="file"],
.form select {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #dfe2ea;
  background: #fbfbfe;
  font-size: 1rem;
  font-weight: 400;
  color: var(--text);
}
.form input:focus, .form select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.form-actions .btn { flex: 1; }
.date-range { display: flex; gap: 10px; }
.date-range label { flex: 1; }
.avatar-preview {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #eef1ff;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  margin: 0 auto 4px;
  overflow: hidden;
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  border-radius: 12px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: #e5e7eb;
  color: var(--text);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-small { padding: 8px 14px; font-size: 0.85rem; background: var(--primary); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-icon {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 8px;
  color: var(--text-muted);
}
.btn-icon-ok { color: var(--accent); }

/* Sections */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 22px 0 10px;
}
.section-head h2 { font-size: 1.05rem; margin: 0; }

/* Stat cards */
.stat-row { display: flex; gap: 12px; margin-bottom: 6px; }
.stat-card {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); }

/* Card list */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.list-card-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}
.list-card-wrap .list-card { box-shadow: none; padding: 0; }
.env-picker { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.env-select, .env-picker input[type="text"] {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #dfe2ea;
  background: #fbfbfe;
  font-size: 0.88rem;
  flex: 1;
  min-width: 120px;
}
.list-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}
.list-card-link {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}
.list-card-icon {
  font-size: 1.5rem;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #eef1ff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.list-card-thumb {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
}
.list-card-body { flex: 1; min-width: 0; }
.list-card-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-card-sub { font-size: 0.82rem; color: var(--text-muted); }
.list-card-arrow { color: var(--text-muted); font-size: 1.3rem; }
.list-card-actions { display: flex; gap: 4px; }

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.empty-state .btn { margin-top: 12px; }

/* Trip vehicle + weight */
.trip-vehicle { color: var(--text-muted); margin-top: -8px; }
.trip-dates { color: var(--text-muted); margin-top: -8px; font-size: 0.88rem; }
.weight-row { display: flex; gap: 10px; }
.weight-card {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.weight-title { font-weight: 700; font-size: 0.9rem; margin-bottom: 8px; }
.weight-card.over { border: 2px solid var(--danger); }
.weight-numbers { display: flex; align-items: baseline; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.weight-current { font-size: 1.3rem; font-weight: 700; }
.weight-max { color: var(--text-muted); font-size: 0.85rem; }
.weight-bar { height: 10px; background: #e5e7eb; border-radius: 6px; overflow: hidden; }
.weight-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--primary)); transition: width 0.3s ease; }
.weight-card.over .weight-bar-fill { background: var(--danger); }
.weight-remaining { margin-top: 10px; font-size: 0.82rem; }
.weight-card.over .weight-remaining strong { color: var(--danger); }
.weight-remaining strong { color: var(--accent); }

/* Material pick rows on trip detail */
.material-pick-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}
.material-pick-card { margin: 0; box-shadow: none; padding: 0; }
.pick-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.qty-pill {
  display: flex !important;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1.5px solid #e5e7eb;
  background: #fbfbfe;
  font-size: 0.82rem !important;
  font-weight: 600 !important;
  white-space: nowrap;
  flex: 1;
}
.qty-pill .qty-input { width: 100%; min-width: 0; padding: 6px 6px; text-align: center; }

/* Choice group (vehicle picker) */
.choice-group { display: flex; gap: 10px; }
.choice-card {
  flex: 1;
  display: flex !important;
  flex-direction: column !important;
  align-items: center;
  gap: 6px;
  padding: 16px;
  border-radius: 14px;
  border: 2px solid #e5e7eb;
  background: var(--surface);
  cursor: pointer;
  font-weight: 600 !important;
}
.choice-card input { display: none; }
.choice-card:has(input:checked) { border-color: var(--primary); background: #eef1ff; }
.choice-icon { font-size: 1.6rem; }


/* Add item form on trip page */
.add-item-form { flex-direction: row !important; align-items: stretch; gap: 8px !important; }
.add-item-form select { flex: 1; }
.qty-input { width: 64px; }

/* Flash messages */
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.flash {
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 500;
}
.flash-error { background: #fee2e2; color: #991b1b; }
.flash-success { background: #d1fae5; color: #065f46; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  box-shadow: 0 -2px 12px rgba(20, 20, 40, 0.08);
  display: flex;
  justify-content: space-around;
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  z-index: 10;
}
.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.68rem;
  color: var(--text-muted);
  gap: 2px;
  padding: 4px 8px;
  border-radius: 10px;
}
.bottom-nav a.active { color: var(--primary); font-weight: 700; }
.bottom-nav .icon { font-size: 1.25rem; position: relative; display: inline-block; }
.nav-badge {
  position: absolute;
  top: -6px;
  right: -10px;
  background: var(--danger);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

@media (min-width: 480px) {
  .app-main, .app-header-inner { max-width: 480px; }
}
