:root {
  --primary: #1a3c6e;
  --primary-dark: #12294d;
  --accent: #d4a017;
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #dfe3e8;
  --text: #1f2937;
  --text-muted: #6b7280;
  --danger: #c0392b;
  --success: #1e824c;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* Top bar */
.topbar {
  background: var(--primary);
  color: #fff;
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar .brand { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.3px; }
.topbar .brand small { display: block; font-weight: 400; font-size: 0.7rem; opacity: 0.8; margin-top: 2px; }
.brand-logo { display: block; height: 32px; width: auto; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a, .topbar nav button {
  color: #fff; text-decoration: none; padding: 8px 14px; border-radius: var(--radius);
  font-size: 0.9rem; background: transparent; border: none; cursor: pointer; font-family: inherit;
}
.topbar nav a.active, .topbar nav a:hover, .topbar nav button:hover { background: rgba(255,255,255,0.12); }
.topbar .userinfo { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; }
.badge-role {
  background: var(--accent); color: #3a2a00; padding: 2px 8px; border-radius: 20px;
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
}

main { flex: 1; padding: 24px; max-width: 1100px; margin: 0 auto; width: 100%; }

/* Login */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--card); padding: 40px; border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  width: 100%; max-width: 360px; text-align: center;
}
.login-card h1 { font-size: 1.3rem; color: var(--primary); margin: 0 0 4px; }
.login-logo { display: block; max-width: 100%; height: auto; margin: 0 auto 8px; }
.login-card .subtitle { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 24px; }
.login-card form { text-align: left; }

label { display: block; font-size: 0.82rem; font-weight: 600; margin: 12px 0 4px; color: var(--text); }
.ncd-check-link { font-weight: 400; font-size: 0.78rem; margin-left: 8px; color: var(--primary); text-decoration: none; }
.ncd-check-link:hover { text-decoration: underline; }
input[type=text], input[type=password], input[type=search], input[type=email], input[type=date], input[type=file], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.95rem; font-family: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.btn {
  display: inline-block; padding: 10px 18px; border-radius: var(--radius); border: none;
  font-size: 0.9rem; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-secondary:hover { background: #eef2f9; }
.btn-danger { background: #fff; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: #fdecea; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg { background: #fdecea; color: var(--danger); padding: 10px 14px; border-radius: var(--radius); font-size: 0.85rem; margin: 12px 0; }
.success-msg { background: #e8f7ef; color: var(--success); padding: 10px 14px; border-radius: var(--radius); font-size: 0.85rem; margin: 12px 0; }

/* Cards / sections */
.card { background: var(--card); border-radius: 10px; padding: 20px; margin-bottom: 18px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.card h2 { margin-top: 0; font-size: 1.05rem; color: var(--primary); }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { font-size: 1.4rem; margin: 0; color: var(--primary-dark); }

/* Search */
.search-row { display: flex; gap: 10px; margin-bottom: 18px; }
.search-row input { flex: 1; }

/* Table */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; }
th.sortable-th { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable-th:hover { color: var(--primary); }
th.phone-col, td.phone-col { min-width: 160px; white-space: nowrap; }

.copy-cell { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; border-radius: 4px; padding: 2px 4px; margin: -2px -4px; }
.copy-cell:hover { background: #eef2f9; color: var(--primary); }
.copy-cell .copy-icon { font-size: 0.85em; color: var(--text-muted); }
.copy-cell.copied { color: var(--success); }
.copy-cell.copied .copy-icon { color: var(--success); }
tr:hover td { background: #fafbfc; }
.row-link { cursor: pointer; }
.row-link:hover { background: #f0f4fa; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

/* Forms grid */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.vehicle-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; position: relative; }
.vehicle-card .plate {
  display: inline-block; background: var(--primary); color: #fff; font-weight: 700; padding: 4px 10px;
  border-radius: 4px; letter-spacing: 1px; font-size: 0.95rem; margin-bottom: 8px;
}
.vehicle-meta { font-size: 0.88rem; color: var(--text); line-height: 1.6; }
.vehicle-meta .label { color: var(--text-muted); }
.caretaker-tag { display: inline-block; background: #fff3d6; color: #8a6100; padding: 2px 8px; border-radius: 20px; font-size: 0.75rem; margin-top: 6px; }
.vehicle-actions { position: absolute; top: 14px; right: 14px; display: flex; gap: 6px; }
.vehicle-actions button { font-size: 0.75rem; padding: 4px 10px; }

.actions-row { display: flex; gap: 10px; margin-top: 16px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal { background: #fff; border-radius: 10px; padding: 24px; max-width: 520px; width: 100%; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin-top: 0; color: var(--primary); font-size: 1.1rem; }
.modal-close { float: right; background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted); }

.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 30px; text-align: center; color: var(--text-muted);
  margin: 14px 0;
}
.upload-summary { font-size: 0.88rem; }
.upload-summary .stat { display: inline-block; background: #eef2f9; padding: 6px 14px; border-radius: 20px; margin: 4px 6px 4px 0; font-weight: 600; color: var(--primary); }
.upload-errors { max-height: 180px; overflow-y: auto; background: #fdecea; padding: 10px 14px; border-radius: var(--radius); font-size: 0.82rem; color: var(--danger); margin-top: 10px; }
.upload-errors div { padding: 2px 0; }

.tag-admin { background: #e8f7ef; color: var(--success); padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 700; }
.tag-staff { background: #eef2f9; color: var(--primary); padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 700; }
.tag-inactive { background: #f3f4f6; color: var(--text-muted); padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 700; }
.tag-ok { background: #e8f7ef; color: var(--success); padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 700; white-space: nowrap; }
.tag-duesoon { background: #fff3d6; color: #8a6100; padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 700; white-space: nowrap; }
.tag-expired { background: #fdecea; color: var(--danger); padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 700; white-space: nowrap; }

.helper-text { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

.pie-chart-row { display: flex; align-items: center; gap: 32px; flex-wrap: wrap; padding: 8px 4px; }
.pie-chart-svg-wrap svg { display: block; }
.pie-legend { display: flex; flex-direction: column; gap: 12px; }
.legend-row { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; }
.legend-swatch { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; }
.legend-label { color: var(--text-muted); }
.legend-value { font-weight: 700; color: var(--text); margin-left: auto; padding-left: 16px; }
.legend-pct { font-weight: 400; color: var(--text-muted); font-size: 0.82rem; }

.ncd-tag { display: inline-block; background: #e8f7ef; color: var(--success); padding: 2px 8px; border-radius: 20px; font-size: 0.75rem; margin-top: 6px; margin-left: 6px; font-weight: 700; }
.roadtax-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--text-muted); margin-top: 8px; margin-left: 6px; }

.reminder-links { display: flex; gap: 6px; flex-wrap: wrap; }
.reminder-link { padding: 4px 10px; font-size: 0.75rem; text-decoration: none; }

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-tile { background: var(--card); border-radius: 10px; padding: 18px 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.stat-tile-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); line-height: 1.1; }
.stat-tile-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

.insurance-section { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }

.vehicle-block { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; background: #fafbfc; }
.vehicle-block-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.vehicle-block-header h3 { margin: 0; font-size: 0.9rem; color: var(--primary); }
.insurance-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.insurance-header h3 { margin: 0; font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.insurance-table { font-size: 0.82rem; }
.insurance-table th, .insurance-table td { padding: 6px 8px; }
.back-link { display: inline-block; margin-bottom: 14px; color: var(--primary); text-decoration: none; font-size: 0.88rem; cursor: pointer; }
.back-link:hover { text-decoration: underline; }

/* Checkbox fields (e.g. "Commercial vehicle") */
.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 0.82rem; margin: 14px 0 4px; cursor: pointer; }
.checkbox-label input[type=checkbox] { width: 16px; height: 16px; margin: 0; }

/* Attachments */
.attachment-upload-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.attachment-file-input { flex: 1; min-width: 180px; font-size: 0.85rem; }
.attachment-list { list-style: none; padding: 0; margin: 10px 0 0; }
.attachment-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.attachment-list li:last-child { border-bottom: none; }
.attachment-list a { color: var(--primary); font-weight: 600; font-size: 0.88rem; text-decoration: none; }
.attachment-list a:hover { text-decoration: underline; }
.attachment-meta { font-size: 0.78rem; color: var(--text-muted); }

/* Insurer chips (Administration) */
.insurer-chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.insurer-chip { display: inline-flex; align-items: center; gap: 6px; background: #eef2f9; color: var(--primary); padding: 5px 8px 5px 12px; border-radius: 20px; font-size: 0.82rem; font-weight: 600; }
.insurer-remove-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 2px; }
.insurer-remove-btn:hover { color: var(--danger); }

/* Print-friendly customer summary */
.print-only { display: none; }
@media print {
  .no-print { display: none !important; }
  .print-only { display: block; }
  .topbar { display: none; }
  body { background: #fff; }
  main { max-width: 100%; padding: 0; }
  .card { box-shadow: none; border: 1px solid var(--border); break-inside: avoid; }
}

/* Table overflow on small screens */
table { min-width: 100%; }
.card { overflow-x: auto; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 8px; }
  .topbar nav { flex-wrap: wrap; }
  .topbar .userinfo { flex-wrap: wrap; }
  main { padding: 14px; }
  .page-header { flex-direction: column; align-items: stretch; }
  .stat-tiles { grid-template-columns: repeat(2, 1fr); }
  .pie-chart-row { flex-direction: column; align-items: flex-start; }
}
