:root {
  --primary: #1e3a5f;
  --primary-light: #2a5080;
  --accent: #d09722;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1a1a2e;
  --muted: #5a6177;
  --border: #dde1e8;
  --danger: #d9534f;
  --success: #28a745;
  --radius: 10px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: 80px;
  -webkit-tap-highlight-color: transparent;
}

/* ===== TAB BAR ===== */
.tab-bar {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.tab {
  flex: 1; padding: 12px 0;
  background: none; border: none; color: rgba(255,255,255,0.6);
  font-size: 11px; font-weight: 600;
  cursor: pointer; text-align: center;
  transition: all 0.2s;
  border-bottom: 3px solid transparent;
}

.tab.active { color: white; border-bottom-color: var(--accent); }
.tab-icon { display: block; font-size: 18px; margin-bottom: 2px; }

/* ===== VIEWS ===== */
.view { display: none; padding: 8px; padding-top: 4px; }
.view.active { display: block; }

/* ===== CARDS ===== */
.card {
  background: var(--card);
  margin: 8px 4px;
  border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  overflow: hidden;
}

.card-header {
  background: var(--primary);
  color: white;
  padding: 10px 16px;
  font-size: 14px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; user-select: none;
}

.card-header .arrow { font-size: 11px; transition: transform 0.2s; }
.card-header.collapsed .arrow { transform: rotate(-90deg); }
.card-body { padding: 14px 16px; }
.card-body.collapsed { display: none; }

/* ===== DOC TYPE BAR ===== */
.doc-type-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
}

.new-job-btn {
  padding: 10px 18px; border: none;
  border-radius: 8px; font-size: 14px;
  font-weight: 700; cursor: pointer;
  background: var(--accent); color: white;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
  transition: opacity 0.2s;
}

.new-job-btn:active { opacity: 0.85; }

.type-slider {
  display: flex; flex: 1; padding: 3px;
  background: #e8eaef; border-radius: 10px;
}

.type-btn {
  flex: 1; padding: 10px; border: none;
  border-radius: 8px; font-size: 14px;
  font-weight: 700; cursor: pointer;
  background: transparent; color: var(--muted);
  transition: all 0.2s;
}

.type-btn.active {
  background: var(--primary); color: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.type-btn.active.invoice-active {
  background: var(--accent);
}

.inv-bar {
  display: flex; gap: 8px;
  padding: 12px;
}

/* ===== FORM ===== */
.field { margin-bottom: 10px; position: relative; }
.field label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.4px; margin-bottom: 3px;
}

.field input, .field textarea, .field select {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 15px; font-family: inherit;
  color: var(--text); background: #fafbfc;
  -webkit-appearance: none;
}

.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--primary); background: white;
}

.field textarea { resize: vertical; min-height: 60px; }
.row { display: flex; gap: 8px; }
.row .field { flex: 1; }

.tiny-input {
  width: 60px !important; padding: 5px 8px !important;
  border: 1.5px solid var(--border); border-radius: 6px;
  font-size: 14px; text-align: center;
}

/* ===== CLIENT DROPDOWN ===== */
.dropdown {
  display: none; position: absolute; left: 0; right: 0; top: 100%;
  background: white; border: 1.5px solid var(--primary);
  border-radius: 0 0 8px 8px; max-height: 200px; overflow-y: auto;
  z-index: 50; box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.dropdown.open { display: block; }

.dropdown-item {
  padding: 10px 14px; cursor: pointer;
  border-bottom: 1px solid #eee; font-size: 14px;
}

.dropdown-item:hover, .dropdown-item:active { background: #f0f4f8; }
.dropdown-item .sub { font-size: 12px; color: var(--muted); }

/* ===== LINE ITEMS ===== */
.line-item {
  background: #f8f9fb; border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; margin-bottom: 8px;
  position: relative;
}

.line-item .remove-btn {
  position: absolute; top: 6px; right: 6px;
  background: var(--danger); color: white;
  border: none; width: 24px; height: 24px; border-radius: 50%;
  font-size: 15px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

.add-btn {
  width: 100%; padding: 12px;
  background: white; border: 2px dashed var(--border);
  border-radius: 8px; color: var(--primary);
  font-size: 14px; font-weight: 600; cursor: pointer;
}

.add-btn:active { border-color: var(--primary); background: #f0f4f8; }

/* ===== TOTALS ===== */
.totals {
  background: #f8f9fb; border-radius: 8px; padding: 12px; margin-top: 10px;
}

.total-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; font-size: 14px;
}

.total-row.grand {
  border-top: 2px solid var(--primary); margin-top: 6px;
  padding-top: 10px; font-size: 18px; font-weight: 700; color: var(--primary);
}

/* ===== PHOTOS ===== */
.photo-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin-bottom: 10px;
}

.photo-thumb {
  position: relative; aspect-ratio: 1; border-radius: 8px;
  overflow: hidden; background: #eee;
}

.photo-thumb img {
  width: 100%; height: 100%; object-fit: cover;
}

.photo-thumb .del-photo {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,0.6); color: white;
  border: none; width: 22px; height: 22px; border-radius: 50%;
  font-size: 13px; cursor: pointer;
}

.photo-actions { display: flex; gap: 8px; }

.photo-btn {
  flex: 1; padding: 12px;
  background: var(--primary); color: white;
  border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}

.photo-btn:active { opacity: 0.85; }

/* ===== SCAN BUTTON ===== */
.scan-btn {
  padding: 8px 14px; background: var(--accent); color: white;
  border: none; border-radius: 8px; font-size: 13px;
  font-weight: 600; white-space: nowrap; cursor: pointer;
}

/* VIN photo overlay paste field */
#vinPasteField:focus {
  border-color: var(--accent); outline: none;
}

.ocr-processing {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.85); color: white;
  padding: 24px 32px; border-radius: 12px;
  text-align: center; z-index: 310;
  font-size: 15px; font-weight: 600;
}

.ocr-processing .spinner {
  width: 36px; height: 36px; border: 3px solid rgba(255,255,255,0.3);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.scan-target {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 280px; height: 80px;
  border: 3px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.4);
  z-index: 301;
}

/* ===== SHUTTER ===== */
.shutter-btn {
  width: 60px; height: 60px; border-radius: 50%;
  background: white; border: 4px solid #ccc;
  cursor: pointer;
}

.shutter-btn:active { background: #ddd; transform: scale(0.9); }

/* ===== BUTTONS ===== */
.btn {
  flex: 1; padding: 14px; border: none; border-radius: 10px;
  font-size: 15px; font-weight: 700; cursor: pointer; text-align: center;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:active { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:active { opacity: 0.85; }
.btn-outline { background: white; color: var(--danger); border: 2px solid var(--danger); }

.action-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: white; padding: 10px 14px;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  display: flex; gap: 8px; z-index: 90;
}

/* ===== OVERLAYS ===== */
.overlay {
  display: none; position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: white; z-index: 200; overflow-y: auto;
}

.overlay.active { display: block; }

.overlay-bar {
  position: sticky; top: 0; z-index: 210;
  display: flex; justify-content: center; align-items: center;
  gap: 8px; padding: 10px 16px; background: var(--primary);
  flex-wrap: wrap;
}

.overlay-bar button {
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3);
  color: white; padding: 8px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--success); color: white;
  padding: 12px 28px; border-radius: 8px;
  font-size: 15px; font-weight: 600; z-index: 9000;
  opacity: 0; transition: opacity 0.3s; pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

.toast.show { opacity: 1; }

/* ===== ITEM LIST ===== */
.item-list .list-item {
  padding: 12px 14px; border-bottom: 1px solid #eee;
  cursor: pointer; transition: background 0.15s;
}

.item-list .list-item:active { background: #f0f4f8; }
.list-item .title { font-weight: 600; font-size: 15px; }
.list-item .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.list-item .badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
}

.badge-paid { background: #d4edda; color: #155724; }
.badge-unpaid { background: #fff3cd; color: #856404; }
.badge-draft { background: #e2e3e5; color: #383d41; }

/* ===== PRINT INVOICE ===== */
.invoice-print { max-width: 700px; margin: 0 auto; padding: 20px; font-size: 13px; color: #222; }
.invoice-print .hdr { display:flex; justify-content:space-between; border-bottom:3px solid var(--primary); padding-bottom:14px; margin-bottom:18px; }
.invoice-print .hdr h2 { font-size:20px; color:var(--primary); margin-bottom:4px; }
.invoice-print .hdr p { font-size:13px; color:#333; line-height:1.7; }
.invoice-print .hdr .meta { text-align:right; }
.invoice-print .hdr .meta h3 { font-size:20px; color:#d09722; margin-bottom:4px; }
.invoice-print .parties { display:flex; gap:24px; margin-bottom:18px; }
.invoice-print .party { flex:1; }
.invoice-print .party h4 { font-size:11px; text-transform:uppercase; color:var(--primary); letter-spacing:1px; border-bottom:1px solid var(--border); padding-bottom:3px; margin-bottom:6px; }
.invoice-print .party p { font-size:13px; line-height:1.6; }
.invoice-print .ins-box { background:#fef9f0; border:1px solid #f0d9a8; border-radius:6px; padding:12px 16px; margin-bottom:18px; }
.invoice-print .ins-box h4 { font-size:11px; text-transform:uppercase; color:#d09722; letter-spacing:1px; margin-bottom:6px; }
.invoice-print .ins-grid { display:grid; grid-template-columns:1fr 1fr; gap:4px 16px; font-size:13px; }
.invoice-print .ins-grid span { color:#999; font-size:11px; }
.invoice-print .photo-strip { display:flex; gap:8px; flex-wrap:wrap; margin-bottom:18px; }
.invoice-print .photo-strip img { width:120px; height:90px; object-fit:cover; border-radius:6px; border:1px solid #ddd; }
.invoice-print table { width:100%; border-collapse:collapse; margin-bottom:18px; }
.invoice-print th { background:var(--primary); color:white; padding:8px 12px; text-align:left; font-size:11px; text-transform:uppercase; }
.invoice-print th:last-child, .invoice-print td:last-child { text-align:right; }
.invoice-print td { padding:9px 12px; border-bottom:1px solid #eee; }
.invoice-print tr:nth-child(even) td { background:#fafbfc; }
.invoice-print .totals-box { display:flex; justify-content:flex-end; margin-bottom:20px; }
.invoice-print .totals-inner { width:250px; }
.invoice-print .t-row { display:flex; justify-content:space-between; padding:4px 0; font-size:13px; }
.invoice-print .t-row.grand { border-top:2px solid var(--primary); margin-top:4px; padding-top:8px; font-size:17px; font-weight:700; color:var(--primary); }
.invoice-print .notes-sec { border-top:1px solid var(--border); padding-top:12px; margin-top:8px; }
.invoice-print .notes-sec h4 { font-size:11px; text-transform:uppercase; color:var(--primary); letter-spacing:1px; margin-bottom:3px; }
.invoice-print .notes-sec p { font-size:12px; color:#555; white-space:pre-wrap; }
.invoice-print .footer { text-align:center; margin-top:28px; padding-top:12px; border-top:1px solid var(--border); font-size:11px; color:#999; }

/* ===== REPAIR MODE BAR ===== */
.repair-mode-bar {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.damage-toggle {
  display: flex; padding: 4px;
  background: #e8eaef; border-radius: 10px;
}

.damage-btn {
  flex: 1; padding: 10px; border: none;
  border-radius: 8px; font-size: 13px;
  font-weight: 700; cursor: pointer;
  background: transparent; color: var(--muted);
  transition: all 0.2s;
}

.damage-btn.active {
  background: var(--accent); color: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.matrix-notes {
  background: #fff8e1; border: 1px solid #f0d9a8;
  border-radius: 8px; padding: 10px 14px;
  margin-bottom: 10px; font-size: 12px; color: #8b6914;
  line-height: 1.6;
}

/* ===== HAIL LINE ITEM (compact, two-row) ===== */
.hail-line {
  border-bottom: 1px solid #eee;
  padding: 7px 6px;
  font-size: 13px;
}

.hail-main {
  display: flex; align-items: flex-start; gap: 5px;
}

.hail-line .panel-name {
  flex: 1; font-weight: 600; min-width: 0;
  font-size: 13px; line-height: 1.2;
  word-wrap: break-word; overflow-wrap: break-word;
  padding-top: 5px;
}

.hail-controls {
  display: flex; flex-direction: column; gap: 6px; flex-shrink: 0;
}

.hail-row1, .hail-row2 {
  display: flex; align-items: center; gap: 8px;
}

.hail-line select, .hail-line input {
  padding: 5px 4px; border: 1.5px solid var(--border);
  border-radius: 6px; font-size: 13px; font-family: inherit;
  background: #fafbfc; flex-shrink: 0;
}

.hail-row1 .size-select { width: 68px; }
.hail-line .dent-count-input { width: 44px; text-align: center; }
.hail-line .price-input { width: 62px; text-align: right; }

/* ===== MODIFIER ROW (OS / Material / 2P) ===== */
.hail-row2 .os-count-input {
  width: 36px; text-align: center;
  padding: 4px 3px !important; font-size: 12px !important;
}

.hail-row2 .material-select {
  width: 62px !important;
  padding: 4px 3px !important; font-size: 12px !important;
}

.mod-label {
  display: flex; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.3px;
}

.na-toggle {
  padding: 4px 7px;
  border: 1.5px solid var(--border); border-radius: 6px;
  background: #fafbfc; color: var(--muted);
  font-size: 11px; font-weight: 700; cursor: pointer;
  font-family: inherit; transition: all 0.15s; flex-shrink: 0;
}

.na-toggle.active {
  background: var(--accent); color: white; border-color: var(--accent);
}

.hail-line .remove-sm {
  background: var(--danger); color: white;
  border: none; width: 20px; height: 20px; border-radius: 50%;
  font-size: 12px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

.hail-header {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 6px; font-size: 10px; font-weight: 600;
  color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.3px; border-bottom: 2px solid var(--border);
}

.hail-header span { text-align: center; }
.hail-header .panel-name { flex: 1; text-align: left; }
.hail-controls-header { display: flex; gap: 5px; flex-shrink: 0; }

/* ===== PARTS FIELD (per-panel, expands on focus) ===== */
.parts-input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 4px 8px;
  border: 1.5px solid #e0e3e8;
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  background: #fafbfc;
  resize: none;
  overflow: hidden;
  height: 26px;
  line-height: 1.5;
  transition: height 0.2s ease, border-color 0.15s;
  box-sizing: border-box;
}

.parts-input:focus {
  height: 46px;
  overflow: auto;
  outline: none;
  border-color: var(--primary);
  background: white;
}

.parts-input::placeholder {
  color: #888;
  font-size: 11px;
}

/* ===== MATRIX LIST IN SETUP ===== */
.matrix-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid #eee;
}

.matrix-item .matrix-info { flex: 1; }
.matrix-item .matrix-info .title { font-weight: 600; font-size: 14px; }
.matrix-item .matrix-info .meta { font-size: 12px; color: var(--muted); }
.matrix-item .matrix-actions { display: flex; gap: 6px; }

.badge-default {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  background: #d4edda; color: #155724;
}

.btn-sm {
  padding: 5px 10px; border: none; border-radius: 6px;
  font-size: 11px; font-weight: 600; cursor: pointer;
}

@media print {
  body { background:white; padding:0; }
  .tab-bar, .action-bar, .overlay-bar { display:none !important; }
  #mainApp { display:none !important; }
  .overlay { position:static; padding:0; display:none !important; }
  .overlay.active { display:block !important; }
  .invoice-print { max-width:100%; padding:10px; }
}

/* ===== AUTH SCREEN ===== */
.auth-screen {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, var(--primary) 0%, #0d2137 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.auth-container {
  width: 100%; max-width: 380px;
}

.auth-logo {
  text-align: center; margin-bottom: 32px; color: white;
}

.auth-icon {
  font-size: 48px; color: var(--accent); margin-bottom: 8px;
}

.auth-logo h1 {
  font-size: 24px; font-weight: 700; margin-bottom: 4px;
}

.auth-logo p {
  font-size: 13px; color: rgba(255,255,255,0.6);
}

.auth-form {
  background: white; border-radius: var(--radius); padding: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.auth-form .field { margin-bottom: 16px; }
.auth-form .field label { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 4px; display: block; }
.auth-form .field input {
  width: 100%; padding: 11px 14px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 15px; background: #f9fafc;
  transition: border-color 0.2s;
}
.auth-form .field input:focus {
  outline: none; border-color: var(--primary); background: white;
}

.auth-btn {
  width: 100%; padding: 13px; font-size: 16px; font-weight: 700;
  border-radius: 8px; margin-top: 4px; cursor: pointer;
}

.auth-switch {
  text-align: center; margin-top: 16px; font-size: 13px; color: var(--muted);
}

.auth-switch a {
  color: var(--primary); font-weight: 600; text-decoration: none;
}

.auth-error {
  background: #fee; color: #c0392b; padding: 10px 14px;
  border-radius: 8px; margin-top: 12px; font-size: 13px; text-align: center;
}

/* ===== CAR DIAGRAM (car-diagram-ui branch) ===== */
.car-diagram-wrap {
  padding: 4px 0 8px;
}

.car-diagram-hint {
  font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 6px;
}

/* SVG panel touch feedback */
.car-panel rect {
  transition: filter 0.1s;
}

.car-panel:active rect {
  filter: brightness(0.85);
}

/* Panel detail overlay — large, comfortable form */
#panelDetailOverlay .field label,
#panelDetailOverlay #pdNaLabel {
  font-size: 13px;
}

#panelDetailOverlay .field input,
#panelDetailOverlay .field select,
#panelDetailOverlay .field textarea {
  font-size: 16px; /* larger for easy tapping */
}

#panelDetailOverlay textarea {
  min-height: 72px;
}

/* Center-align the labels above the two top rows of controls
   (Size / Count / Price  and  O.S. Count / Material / Double Panel).
   R&I and Parts labels below remain left-aligned since their textareas
   are full-width. */
#panelDetailOverlay .pd-row .field > label,
#panelDetailOverlay .pd-row #pdNaLabel {
  display: block;
  text-align: center;
}

/* Center the selected value inside the Size and Material dropdowns. */
#panelDetailOverlay #pdSize,
#panelDetailOverlay #pdMaterial {
  text-align: center;
  text-align-last: center;
}
/* Also center the individual option rows when the dropdown is open. */
#panelDetailOverlay #pdSize option,
#panelDetailOverlay #pdMaterial option {
  text-align: center;
}

/* ===== EXTRA PANEL BUTTONS (under the car diagram) ===== */
.extra-panels-heading-wrap {
  text-align: center;
  margin: 18px 0 10px;
}

.extra-panels-heading {
  display: inline-block;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 5px 14px;
  border-radius: 6px;
  margin: 0;
}

.panel-buttons-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 4px 4px;
}

.panel-button {
  padding: 5px 12px;
  border: 1.5px solid #888;
  border-radius: 8px;
  background: white;
  color: #222;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  text-align: center;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.panel-button:active {
  opacity: 0.7;
}

.panel-button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.panel-button .pb-price {
  display: inline-block;
  margin-left: 6px;
  font-size: 13px;
  font-weight: 800;
  opacity: 0.95;
}
