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

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #1a2332;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --wa: #25d366;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 16px rgba(15, 23, 42, .06);
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- auth ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #0f1d3d 0%, #1e3a8a 60%, #1d4ed8 100%);
  padding: 20px;
}
.auth-card {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  padding: 36px 32px; width: 100%; max-width: 400px;
}
.brand-block { text-align: center; margin-bottom: 24px; }
.brand-logo { font-size: 44px; }
.brand-block h1 { font-size: 22px; margin-top: 4px; }
.setup-note { background: #eff6ff; border: 1px solid #bfdbfe; padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }

form label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
form input, form select, form textarea {
  display: block; width: 100%; margin-top: 4px;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 16px; /* 16px+ stops iOS Safari zooming on focus */
  font-family: inherit; color: var(--ink); background: #fff;
}
form input:focus, form select:focus, form textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.form-error { color: var(--danger); font-size: 13px; margin-top: 10px; text-align: center; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid transparent; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 600; padding: 8px 14px; font-family: inherit;
  background: #e2e8f0; color: var(--ink); text-decoration: none;
  transition: filter .12s;
}
.btn:hover { filter: brightness(.95); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-wa { background: var(--wa); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0; background: #0f1d3d; color: #cbd5e1;
  display: flex; flex-direction: column; padding: 18px 12px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { font-size: 17px; font-weight: 700; color: #fff; padding: 4px 10px 18px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  color: #cbd5e1; text-decoration: none; padding: 10px 12px; border-radius: 8px;
  font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 8px;
}
.sidebar nav a:hover { background: rgba(255,255,255,.08); }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,.12); padding-top: 12px; }
.staff-name { font-size: 13px; color: #94a3b8; padding: 0 10px 8px; word-break: break-word; }
.badge {
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 1px 7px; margin-left: auto;
}

.main { flex: 1; padding: 28px 32px; max-width: 1100px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header h1 { font-size: 22px; }

/* ---------- cards & tables ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.card h2 { font-size: 16px; margin-bottom: 12px; }
.card h3 { font-size: 14px; margin-bottom: 8px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8fafc; }

.pill {
  display: inline-block; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 2px 10px; white-space: nowrap;
}
.pill-service { background: #ede9fe; color: #6d28d9; }
.pill-roadtax { background: #fef3c7; color: #b45309; }
.pill-insurance { background: #dbeafe; color: #1d4ed8; }
.pill-puspakom { background: #ccfbf1; color: #0f766e; }
.pill-warranty { background: #fce7f3; color: #be185d; }
.pill-overdue { background: #fee2e2; color: var(--danger); }
.pill-ok { background: #dcfce7; color: var(--ok); }
.pill-archived { background: #e2e8f0; color: var(--muted); }
.pill-repair { background: #fee2e2; color: #b91c1c; }
.pill-fix { background: #ffedd5; color: #c2410c; }
.pill-reminder { background: #f1f5f9; color: var(--muted); }
.count-badge { display: inline-block; min-width: 34px; text-align: center; padding: 2px 8px; border-radius: 999px; background: #eef2f7; color: var(--ink, #1e293b); font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; }
.pill-other { background: #f1f5f9; color: var(--muted); }

.empty-state { text-align: center; color: var(--muted); padding: 32px 16px; font-size: 14px; }
.search-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.search-row input[type="text"] {
  flex: 1; min-width: 200px; padding: 9px 14px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 15px; font-family: inherit;
}

/* ---------- stats ---------- */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; display: flex; flex-direction: column;
  min-width: 0; /* let grid cells shrink so long numbers wrap instead of overflowing */
}
.stat-card b {
  font-size: clamp(17px, 1.6vw, 26px); line-height: 1.15;
  overflow-wrap: anywhere; font-variant-numeric: tabular-nums;
}
.stat-card span { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-card.stat-warn b { color: var(--warn); }
.stat-card.stat-danger b { color: var(--danger); }

/* ---------- reminder rows ---------- */
.rem-row { display: flex; gap: 14px; align-items: flex-start; padding: 14px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.rem-row:last-child { border-bottom: 0; }
.rem-info { flex: 1; min-width: 220px; }
.rem-info .name { font-weight: 700; }
.rem-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.flag-warn { color: var(--warn); font-size: 13px; font-weight: 600; }

/* ---------- customer detail ---------- */
.link-box {
  display: flex; gap: 8px; align-items: center; background: #f8fafc; border: 1px dashed var(--line);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; overflow: hidden;
}
.link-box code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.lorry-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.lorry-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; margin-bottom: 8px; }
.lorry-head .title { font-size: 16px; font-weight: 700; }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 16px; margin: 10px 0; }
.kv-grid .kv b { display: block; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; background: #f1f5f9; border-radius: 8px;
  padding: 4px 10px; font-size: 13px; margin: 2px 4px 2px 0; text-decoration: none; color: var(--ink);
}
.file-chip:hover { background: #e2e8f0; }
.inline-actions { display: inline-flex; gap: 4px; }
.thumb-wrap { display: inline-flex; flex-direction: column; align-items: center; margin: 3px 6px 3px 0; }
.thumb { width: 96px; height: 72px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.thumb-del { font-size: 12px; margin-top: 2px; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 14px; padding: 2px 4px; border-radius: 4px; }
.icon-btn:hover { background: #f1f5f9; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal { background: #fff; border-radius: 14px; max-width: 480px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
.modal-header h2 { font-size: 17px; }
.modal-close { background: none; border: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 20px 20px; }
.modal-body .btn-row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f1d3d; color: #fff; padding: 10px 20px; border-radius: 999px;
  font-size: 14px; z-index: 100; box-shadow: var(--shadow); max-width: 90vw;
}
.toast.error { background: var(--danger); }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 30;
    flex-direction: row; align-items: center; padding: 8px 10px; gap: 6px;
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar-brand { padding: 0 6px 0 0; font-size: 15px; white-space: nowrap; }
  .sidebar-brand span { display: none; }
  .sidebar nav { flex-direction: row; gap: 2px; }
  .sidebar nav a { padding: 9px 10px; white-space: nowrap; font-size: 13px; }
  .sidebar-footer { border-top: 0; padding-top: 0; margin-left: auto; display: flex; align-items: center; gap: 6px; }
  .staff-name { display: none; }
  .main { padding: 16px 14px; }

  /* comfortable thumb targets */
  .btn { padding: 10px 15px; }
  .btn-sm { padding: 8px 12px; font-size: 13.5px; }
  .icon-btn { font-size: 17px; padding: 6px 7px; }
  .rem-actions { width: 100%; }
  .page-header h1 { font-size: 19px; }
}

/* customers table folds into tap-friendly cards on phones */
@media (max-width: 640px) {
  .cards-table thead { display: none; }
  .cards-table, .cards-table tbody { display: block; }
  .cards-table tr {
    display: block; border: 1px solid var(--line); border-radius: 10px;
    margin-bottom: 10px; padding: 10px 14px; background: #fff;
  }
  .cards-table tr.clickable:active { background: #f1f5f9; }
  .cards-table td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border: 0; padding: 3px 0; }
  .cards-table td::before {
    content: attr(data-label);
    color: var(--muted); font-size: 12px; font-weight: 600; flex-shrink: 0;
  }
  .cards-table td[data-label=""]::before { display: none; }
  .cards-table td:empty { display: none; }
  .cards-table td:first-child { font-size: 16px; }
}
