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

:root {
  --bg: #0a0a0a;
  --bg-2: #141414;
  --bg-3: #1e1e1e;
  --bg-4: #282828;
  --border: rgba(255,255,255,0.10);
  --border-mid: rgba(255,255,255,0.18);
  --border-hi: rgba(255,255,255,0.28);
  --text: #ffffff;
  --text-2: #c8c4bc;
  --text-3: #8a8680;
  --accent: #e8c06a;
  --accent-dim: rgba(232,192,106,0.18);
  --accent-border: rgba(232,192,106,0.45);
  --success: #4fd183;
  --danger: #f07070;
  --required: #f07070;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --font: 'DM Sans', sans-serif;
  --mono: 'DM Mono', monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --fz-label: 12px;
  --fz-input: 16px;
  --fz-btn: 16px;
  --fz-section: 14px;
  --pad-field: 14px 16px;
  --input-h: 44px;
}

body.zoom-lg {
  --fz-label: 15px;
  --fz-input: 20px;
  --fz-btn: 19px;
  --fz-section: 17px;
  --pad-field: 18px 18px;
  --input-h: 56px;
}
body.zoom-sm {
  --fz-label: 10px;
  --fz-input: 13px;
  --fz-btn: 13px;
  --fz-section: 12px;
  --pad-field: 10px 14px;
  --input-h: 36px;
}

html { height: 100%; background: var(--bg); }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
#app { max-width: 520px; margin: 0 auto; min-height: 100vh; position: relative; }

/* ── Header ── */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(10,10,10,0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-mid);
  padding-top: var(--safe-top);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
}
.header-brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 30px; height: 30px;
  background: var(--accent); color: #1a1000;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; flex-shrink: 0;
}
.brand-name { font-size: 17px; font-weight: 600; color: var(--text); letter-spacing: -0.3px; }
.header-right { display: flex; align-items: center; gap: 14px; }
.header-date { font-size: 11px; color: var(--text-3); font-family: var(--mono); }

/* ── Zoom controls ── */
.zoom-controls { display: flex; align-items: center; gap: 4px; }
.zoom-btn {
  background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text-3); border-radius: 6px; cursor: pointer;
  font-family: var(--font); line-height: 1; padding: 4px 7px;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s;
}
.zoom-btn:nth-child(1) { font-size: 11px; }
.zoom-btn:nth-child(2) { font-size: 14px; }
.zoom-btn:nth-child(3) { font-size: 17px; }
.zoom-btn.active { background: var(--accent-dim); border-color: var(--accent-border); color: var(--accent); }
.zoom-btn:active { opacity: 0.7; }

/* ── Form ── */
.form-container {
  padding: 16px 16px calc(48px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 14px;
}

/* ── Sections ── */
.form-section {
  background: var(--bg-2);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
/* Session section needs overflow:visible so searchable dropdowns aren't clipped */
.session-section {
  overflow: visible;
}
/* But keep the rounded corners on child elements */
.session-section .section-header {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.section-header {
  display: flex; align-items: center; gap: 8px;
  padding: 13px 16px 11px;
  font-size: var(--fz-section); font-weight: 600;
  color: var(--text); letter-spacing: 0.01em;
  border-bottom: 1px solid var(--border-mid);
  background: var(--bg-3);
}
.section-header i { font-size: 17px; color: var(--accent); }
.window-count {
  margin-left: auto;
  background: var(--accent-dim); color: var(--accent);
  border: 1px solid var(--accent-border);
  font-size: 11px; font-weight: 700;
  padding: 2px 9px; border-radius: 20px; font-family: var(--mono);
}

/* ── Fields ── */
.field-stack { display: flex; flex-direction: column; }
.field {
  display: flex; flex-direction: column;
  padding: var(--pad-field);
  border-bottom: 1px solid var(--border);
  gap: 5px; min-height: var(--input-h);
  justify-content: center;
}
.field:last-child { border-bottom: none; }
.field label {
  font-size: var(--fz-label); font-weight: 700;
  color: var(--accent); text-transform: uppercase; letter-spacing: 0.08em;
}
.field label .req { color: var(--required); margin-left: 2px; }
.field input, .field select, .field textarea {
  background: transparent; border: none; outline: none;
  color: var(--text); font-family: var(--font);
  font-size: var(--fz-input); font-weight: 500; padding: 0; width: 100%;
  -webkit-appearance: none; appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23e8c06a' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0px center;
  padding-right: 22px; cursor: pointer;
}
.field select option { background: #1e1e1e; color: #ffffff; }
.field input::placeholder, .field textarea::placeholder { color: var(--text-3); font-weight: 400; }
.field textarea { resize: none; line-height: 1.6; }

.field-row {
  display: grid; grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border);
}
.field-row .field { border-bottom: none; }
.field-row .field:first-child { border-right: 1px solid var(--border); }

/* ── Measurement row ── */
.meas-row {
  display: grid; grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border);
}
.meas-row .field { border-bottom: none; }
.meas-row .field:first-child { border-right: 1px solid var(--border); }
.meas-input-wrap { position: relative; }
.meas-unit {
  position: absolute; right: 0; top: 0;
  font-size: 13px; color: var(--accent); font-family: var(--mono);
  font-weight: 600; pointer-events: none;
}

/* ── Fabric loading state ── */
.fabric-loading {
  font-size: var(--fz-input); color: var(--text-3);
  font-style: italic; padding: 2px 0;
}

/* ── Window cards ── */
.window-card { border-bottom: 1px solid var(--border-mid); }
.window-card:last-of-type { border-bottom: none; }
.window-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg-3);
  border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none; -webkit-user-select: none;
}
.window-card-header-left { display: flex; align-items: center; gap: 10px; }
.window-number {
  font-size: 11px; font-weight: 700; font-family: var(--mono);
  color: var(--accent); background: var(--accent-dim);
  border: 1px solid var(--accent-border); padding: 2px 8px; border-radius: 20px;
}
.window-label-preview { font-size: var(--fz-section); color: var(--text-2); font-weight: 500; }
.window-card-header-right { display: flex; align-items: center; gap: 10px; }
.window-toggle { font-size: 18px; color: var(--text-3); transition: transform 0.2s; }
.window-toggle.open { transform: rotate(180deg); }
.remove-window-btn {
  background: none; border: none; color: var(--text-3);
  cursor: pointer; font-size: 18px; padding: 4px;
  display: flex; align-items: center; -webkit-tap-highlight-color: transparent;
}
.remove-window-btn:active { color: var(--danger); }
.window-body { display: none; }
.window-body.open { display: block; }

/* ── Required field highlight ── */
.field.required-missing { background: rgba(240,112,112,0.08); }
.field.required-missing label { color: var(--required); }
.field.required-missing input, .field.required-missing select {
  color: var(--required);
}

/* ── Photo section ── */
.photo-section {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
}
.photo-label {
  font-size: var(--fz-label); font-weight: 700;
  color: var(--accent); text-transform: uppercase; letter-spacing: 0.08em;
}
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo-slot {
  aspect-ratio: 1; border: 1.5px dashed var(--border-mid);
  border-radius: var(--radius-sm);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 5px;
  cursor: pointer; background: var(--bg-3);
  position: relative; overflow: hidden;
  -webkit-tap-highlight-color: transparent; transition: border-color 0.15s;
}
.photo-slot:active { border-color: var(--accent); background: var(--accent-dim); }
.photo-slot i { font-size: 22px; color: var(--text-3); }
.photo-slot span { font-size: 9px; color: var(--text-3); text-align: center; line-height: 1.3; padding: 0 4px; }
.photo-slot.has-photo { border-color: var(--success); border-style: solid; border-width: 2px; }
.photo-slot.has-photo i { color: var(--success); }
.photo-slot input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.photo-slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius-sm); }
.photo-hints-list { display: flex; flex-direction: column; gap: 5px; }
.photo-hint-item {
  font-size: 12px; color: var(--text-3);
  display: flex; align-items: flex-start; gap: 6px; line-height: 1.4;
}
.photo-hint-item i { font-size: 12px; margin-top: 1px; flex-shrink: 0; }

/* ── Add window ── */
.add-window-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 16px;
  background: transparent; border: none;
  color: var(--accent); font-family: var(--font);
  font-size: var(--fz-btn); font-weight: 600;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  border-top: 1px solid var(--border-mid); transition: background 0.15s;
}
.add-window-btn:first-child { border-top: none; }
.add-window-btn:active { background: var(--accent-dim); }
.add-window-btn i { font-size: 18px; }

/* ── Submit ── */
.submit-area { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 4px 0 20px; }
.submit-btn {
  width: 100%; padding: 18px;
  background: var(--accent); color: #1a1000;
  border: none; border-radius: var(--radius);
  font-family: var(--font); font-size: var(--fz-btn); font-weight: 700;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
  -webkit-tap-highlight-color: transparent; transition: opacity 0.15s;
  letter-spacing: 0.01em;
}
.submit-btn:active { opacity: 0.8; }
.submit-note { font-size: 12px; color: var(--text-3); }

/* ── Summary ── */
.summary-screen {
  position: fixed; inset: 0; background: var(--bg); z-index: 200;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.summary-header {
  position: sticky; top: 0;
  background: rgba(10,10,10,0.97);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-mid);
  padding: calc(14px + var(--safe-top)) 18px 14px;
  display: flex; align-items: center; gap: 12px;
}
.summary-header h2 { font-size: 18px; font-weight: 600; color: var(--text); }
.back-btn {
  background: none; border: none; color: var(--accent);
  font-family: var(--font); font-size: 15px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; gap: 4px;
  -webkit-tap-highlight-color: transparent;
}
.summary-content { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.summary-job-card, .summary-window-card {
  background: var(--bg-2); border: 1px solid var(--border-mid);
  border-radius: var(--radius-lg); overflow: hidden;
}
.summary-section-title {
  font-size: 11px; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 11px 16px 9px; border-bottom: 1px solid var(--border);
  background: var(--bg-3);
}
.summary-row {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 10px 16px; border-bottom: 1px solid var(--border); gap: 12px;
}
.summary-row:last-child { border-bottom: none; }
.summary-row-label { font-size: 13px; color: var(--text-3); flex-shrink: 0; font-weight: 500; }
.summary-row-value { font-size: 13px; color: var(--text); text-align: right; font-weight: 500; }
.summary-window-title {
  font-size: 13px; font-weight: 700; color: var(--accent);
  font-family: var(--mono); padding: 11px 16px;
  background: var(--bg-3); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.summary-actions {
  padding: 18px; padding-bottom: calc(18px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
.confirm-btn {
  width: 100%; padding: 18px; background: var(--accent); color: #1a1000;
  border: none; border-radius: var(--radius); font-family: var(--font);
  font-size: var(--fz-btn); font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  -webkit-tap-highlight-color: transparent;
}
.confirm-btn:active { opacity: 0.8; }
.cancel-btn {
  width: 100%; padding: 15px; background: transparent;
  border: 1px solid var(--border-mid); border-radius: var(--radius);
  color: var(--text-2); font-family: var(--font); font-size: 15px;
  font-weight: 500; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.cancel-btn:active { background: var(--bg-3); }

/* ── Success ── */
.success-screen {
  position: fixed; inset: 0; background: var(--bg); z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
.success-inner {
  display: flex; flex-direction: column; align-items: center;
  gap: 14px; padding: 40px 30px; text-align: center;
}
.success-icon { font-size: 64px; color: var(--success); line-height: 1; }
.success-inner h2 { font-size: 26px; font-weight: 700; color: var(--text); }
.success-inner p { font-size: 15px; color: var(--text-2); max-width: 280px; line-height: 1.6; font-weight: 500; }
.new-btn {
  margin-top: 16px; padding: 15px 32px;
  background: var(--bg-3); border: 1px solid var(--border-hi);
  border-radius: var(--radius); color: var(--text);
  font-family: var(--font); font-size: 15px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; gap: 8px;
  -webkit-tap-highlight-color: transparent;
}
.new-btn:active { background: var(--bg-4); }

.hidden { display: none !important; }
input, select, textarea, button { -webkit-tap-highlight-color: transparent; }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.7) sepia(1) hue-rotate(10deg) saturate(3); }
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 2px; }

/* ── Stability UI ── */
.save-indicator {
  font-size: 11px; color: var(--success); font-family: var(--mono);
  opacity: 0; transition: opacity 0.3s; white-space: nowrap;
}
.save-indicator.visible { opacity: 1; }

.history-btn, .export-btn {
  background: var(--bg-3); border: 1px solid var(--border-mid);
  color: var(--text-2); border-radius: 8px; cursor: pointer;
  font-size: 18px; padding: 5px 8px; display: flex; align-items: center;
  position: relative; -webkit-tap-highlight-color: transparent;
  transition: all 0.15s;
}
.history-btn:active, .export-btn:active { background: var(--bg-4); color: var(--accent); }

.queue-badge {
  position: absolute; top: -5px; right: -5px;
  background: var(--danger); color: white;
  font-size: 10px; font-weight: 700; font-family: var(--mono);
  padding: 1px 5px; border-radius: 10px; min-width: 18px; text-align: center;
}

/* Restore banner */
.restore-banner {
  background: var(--bg-3); border-bottom: 1px solid var(--accent-border);
  padding: 12px 16px; display: flex; align-items: center;
  justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.restore-banner-inner {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-2); font-weight: 500; flex: 1;
}
.restore-banner-inner i { color: var(--accent); font-size: 16px; }
.restore-banner-actions { display: flex; gap: 8px; }
.restore-yes {
  background: var(--accent); color: #1a1000; border: none;
  border-radius: 8px; padding: 7px 14px; font-size: 13px;
  font-weight: 700; cursor: pointer; font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
.restore-no {
  background: transparent; color: var(--text-3);
  border: 1px solid var(--border-mid); border-radius: 8px;
  padding: 7px 14px; font-size: 13px; font-weight: 500;
  cursor: pointer; font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

/* Offline banner */
.offline-banner {
  background: rgba(240,112,112,0.12); border-bottom: 1px solid rgba(240,112,112,0.3);
  padding: 10px 16px; display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--danger); font-weight: 500;
}
.offline-banner i { font-size: 16px; }

/* Export button in summary */
.export-summary-btn {
  width: 100%; padding: 14px; background: var(--bg-3);
  border: 1px solid var(--border-mid); border-radius: var(--radius);
  color: var(--text-2); font-family: var(--font); font-size: 15px;
  font-weight: 500; cursor: pointer; display: flex;
  align-items: center; justify-content: center; gap: 8px;
  -webkit-tap-highlight-color: transparent;
}
.export-summary-btn:active { background: var(--bg-4); }

/* Export button in success */
.export-success-btn {
  padding: 13px 28px; background: var(--bg-3);
  border: 1px solid var(--border-hi); border-radius: var(--radius);
  color: var(--text); font-family: var(--font); font-size: 14px;
  font-weight: 600; cursor: pointer; display: flex;
  align-items: center; gap: 8px; -webkit-tap-highlight-color: transparent;
}
.export-success-btn:active { background: var(--bg-4); }

/* History screen */
.history-screen {
  position: fixed; inset: 0; background: var(--bg); z-index: 200;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.history-content { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.history-section-title {
  font-size: 11px; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 8px 4px 4px;
}
.history-card {
  background: var(--bg-2); border: 1px solid var(--border-mid);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 8px;
  transition: background 0.15s;
}
.history-card.pending { border-color: rgba(240,112,112,0.3); }
.history-card-header {
  display: flex; align-items: center; justify-content: space-between;
}
.history-status {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; display: flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 20px;
}
.history-status.synced {
  color: var(--success); background: rgba(79,209,131,0.12);
  border: 1px solid rgba(79,209,131,0.3);
}
.history-status.pending {
  color: var(--danger); background: rgba(240,112,112,0.12);
  border: 1px solid rgba(240,112,112,0.3);
}
.history-date { font-size: 12px; color: var(--text-3); }
.history-meta { font-size: 13px; color: var(--text-2); }
.history-actions {
  display: flex; gap: 8px; margin-top: 2px;
}
.history-btn-restore {
  flex: 1; padding: 8px 12px; border-radius: 8px;
  background: var(--accent-dim); color: var(--accent);
  border: 1px solid rgba(110,154,63,0.3);
  font-size: 13px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  -webkit-tap-highlight-color: transparent;
}
.history-btn-restore:active { opacity: 0.7; }
.history-btn-delete {
  padding: 8px 12px; border-radius: 8px;
  background: rgba(240,112,112,0.1); color: var(--danger);
  border: 1px solid rgba(240,112,112,0.25);
  font-size: 13px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  -webkit-tap-highlight-color: transparent;
}
.history-btn-delete:active { opacity: 0.7; }
.history-empty {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; padding: 60px 20px; color: var(--text-3);
}
.history-empty i { font-size: 40px; }
.history-empty p { font-size: 15px; font-weight: 500; }

/* Toast */
#toast {
  position: fixed; bottom: calc(24px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-4); border: 1px solid var(--border-hi);
  color: var(--text); font-family: var(--font); font-size: 13px;
  font-weight: 500; padding: 10px 20px; border-radius: 20px;
  opacity: 0; transition: all 0.25s; pointer-events: none;
  white-space: nowrap; z-index: 999;
}
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Light mode ─────────────────────────────────────────────────────────────── */
body.light-mode {
  /* Override all dark bg/text tokens */
  --bg:           #f5f5f0;
  --bg-2:         #ffffff;
  --bg-3:         #efefea;
  --bg-4:         #e5e5e0;
  --text:         #1a1a1a;
  --text-2:       #444440;
  --text-3:       #888880;
  --border:       #d0d0c8;
  --accent:       #6e9a3f;
  --accent-dim:   rgba(110,154,63,0.12);
  --accent-border:rgba(110,154,63,0.35);
  --surface:      #ffffff;
  --surface2:     #efefea;
}

/* Header */
body.light-mode .app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

body.light-mode .brand-name { color: #1a1a1a; }
body.light-mode .header-date { color: #888880; }

/* Inputs */
body.light-mode input,
body.light-mode select,
body.light-mode textarea {
  background: #fafaf8;
  color: #1a1a1a;
  border-color: var(--border);
}

body.light-mode .field select option {
  background: #ffffff;
  color: #1a1a1a;
}

/* Cards & sections */
body.light-mode .window-card {
  background: #ffffff;
  border-color: var(--border);
}

body.light-mode .form-section {
  background: #ffffff;
  border-color: var(--border);
}

/* Section headers — was staying dark */
body.light-mode .section-header {
  background: #efefea;
  color: #1a1a1a;
  border-bottom-color: var(--border);
}

body.light-mode .section-header i { color: var(--accent); }

/* Window card header */
body.light-mode .window-card-header {
  background: #efefea;
}

/* Labels */
body.light-mode .field label { color: var(--accent); }

/* Session bar */
body.light-mode .session-bar {
  background: #ffffff;
  border-color: var(--border);
}

/* Submit / confirm bar */
body.light-mode .submit-bar,
body.light-mode .confirm-bar {
  background: #ffffff;
  border-top-color: var(--border);
}

/* Success & error screens */
body.light-mode .success-screen,
body.light-mode .error-notice {
  background: #ffffff;
  color: #1a1a1a;
}

/* Modal */
body.light-mode .modal-overlay { background: rgba(0,0,0,0.35); }
body.light-mode .modal-box {
  background: #ffffff;
  color: #1a1a1a;
  border-color: var(--border);
}

/* Review screen */
body.light-mode .review-table td { color: #1a1a1a; }
body.light-mode .review-table tr:nth-child(odd) { background: #f5f5f0; }
body.light-mode .review-table tr:nth-child(even) { background: #ffffff; }

/* Zoom buttons */
body.light-mode .zoom-btn {
  background: #efefea;
  border-color: var(--border);
  color: #444440;
}
body.light-mode .zoom-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent-border);
  color: var(--accent);
}

/* ── Theme toggle button ─────────────────────────────────────────────────────── */
.theme-toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 18px;
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: color 0.2s;
}
.theme-toggle-btn:hover { color: var(--accent); }

/* ── Session section ─────────────────────────────────────────────────────────── */
.session-section {
  border-left: 3px solid var(--accent);
}

.field-note {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 400;
  margin-left: 4px;
}

/* ── Checkbox field ──────────────────────────────────────────────────────────── */
.checkbox-field {
  display: flex;
  align-items: center;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-2);
  font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  cursor: pointer;
  border: 2px solid var(--border-hi);
  border-radius: 6px;
  background: var(--bg-3);
  position: relative;
  transition: background 0.15s, border-color 0.15s;
}

.checkbox-label input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox-label input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 7px;
  height: 12px;
  border: 2.5px solid #1a1000;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

/* ── Field error ─────────────────────────────────────────────────────────────── */
.field-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
}

/* ── Submit error banner ─────────────────────────────────────────────────────── */
.submit-error-banner {
  background: #fff0f0;
  border: 1.5px solid var(--danger);
  border-radius: 10px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.6;
  padding: 10px 14px;
  margin-bottom: 10px;
}
.submit-error-banner div + div { margin-top: 2px; }

/* ── Upload fail badge ───────────────────────────────────────────────────────── */
.upload-fail-badge {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 6px;
  padding: 2px 6px;
  white-space: nowrap;
  pointer-events: none;
}
.photo-slot.upload-failed { border: 2px solid var(--danger); }

/* ── Auto-applied surcharge tag (Fix 9 — blind color surcharge) ─────────────── */
.auto-surcharge-tag {
  background: color-mix(in srgb, var(--accent) 15%, transparent) !important;
  border-color: var(--accent) !important;
  cursor: default;
}
.auto-tag-label {
  font-size: .7rem;
  opacity: .75;
  font-style: normal;
  margin-left: 4px;
  background: var(--accent);
  color: #fff;
  border-radius: 3px;
  padding: 0 3px;
}

/* ── Measurement split input (Fix 4) ────────────────────────────────────────── */
.meas-split-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.meas-split-wrap input[type="number"] {
  flex: 0 0 72px;
  width: 72px;
  min-width: 0;
}
.meas-split-wrap select {
  flex: 0 0 auto;
  min-width: 68px;
}
.meas-unit {
  color: var(--text-muted);
  font-size: .85rem;
  white-space: nowrap;
}

/* ── Custom surcharge form (Fix 3) ──────────────────────────────────────────── */
.surcharge-custom-wrap {
  margin-top: 8px;
}
.surcharge-custom-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface-alt, var(--surface));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.surcharge-custom-form input {
  width: 100%;
}
.surcharge-custom-actions {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}
.surcharge-custom-actions button {
  flex: 1;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
}
.surcharge-custom-actions .btn-add-surcharge {
  background: var(--accent);
  color: #fff;
}
.surcharge-custom-actions .btn-cancel-surcharge {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.hidden { display: none; }

.modal-box {
  background: #1e1e1e;
  border-radius: 12px;
  padding: 28px 24px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}

.modal-icon {
  font-size: 36px;
  color: #f59e0b;
  margin-bottom: 12px;
}

.modal-box h3 {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  margin: 0 0 12px;
}

.modal-box p {
  font-size: 14px;
  color: #aaa;
  margin: 0 0 10px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.modal-confirm {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.modal-confirm:hover { background: var(--accent-h); }

.modal-cancel {
  background: transparent;
  color: var(--text-3);
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

.modal-cancel:hover { color: var(--text-1); }

/* ── Product global sections (session bar) ──────────────────────────────────── */
.product-global-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}

.product-global-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-3);
  border: none;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}

.product-global-toggle:active { background: var(--bg-4); }
.product-global-icon { font-size: 16px; color: var(--accent); }
.product-global-title { font-weight: 700; }
.product-global-summary {
  flex: 1;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-global-chevron {
  font-size: 16px;
  color: var(--text-3);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.product-global-body {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
}

/* ── Product type toggle (per window) ───────────────────────────────────────── */
.product-type-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

.ptype-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  background: var(--bg-3);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  color: var(--text-3);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.ptype-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent-border);
  color: var(--accent);
}

.ptype-btn:active { opacity: 0.8; }

/* ── Globals hint bar (per window) ───────────────────────────────────────────── */
.globals-hint-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  background: var(--bg-3);
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font);
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, background 0.15s;
}

.globals-hint-bar:active { opacity: 0.8; }

.globals-hint-bar.has-override {
  border-color: var(--accent-border);
  background: var(--accent-dim);
}

.globals-hint-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  flex: 1;
  line-height: 1.4;
}

.globals-hint-bar.has-override .globals-hint-text {
  color: var(--accent);
}

.globals-hint-chevron {
  color: var(--text-3);
  font-size: 14px;
  flex-shrink: 0;
  transition: transform 0.2s;
}

/* ── Window overrides (expandable) ───────────────────────────────────────────── */
.window-overrides {
  padding: 4px 0 8px;
  border-left: 2px solid var(--accent-border);
  padding-left: 12px;
  margin-bottom: 8px;
}

/* ── Product tabs (session globals) ─────────────────────────────────────────── */
.product-tabs { margin-bottom: 12px; }

.product-tabs-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.product-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 6px 8px;
  background: var(--bg-3);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text-3);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.product-tab i { font-size: 18px; }

.product-tab.active {
  background: var(--accent-dim);
  border-color: var(--accent-border);
  color: var(--accent);
}

.product-tab:active { opacity: 0.8; }

.ptab-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
}

.product-tab-panel {
  padding: 4px 0 2px;
  overflow: visible;
}

/* ── Window confirm modal details ────────────────────────────────────────────── */
.wcm-details {
  background: var(--bg-3);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 12px 0;
}

.wcm-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.wcm-row:last-child { border-bottom: none; }

.wcm-label {
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.wcm-value {
  color: var(--text);
  font-weight: 600;
  text-align: right;
}

/* ── Add gate modal list ─────────────────────────────────────────────────────── */
.gate-list {
  text-align: left;
  padding-left: 20px;
  margin: 10px 0;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1.8;
}

/* ── Light mode tab overrides ────────────────────────────────────────────────── */
body.light-mode .product-tab { background: #efefea; border-color: var(--border); color: #444440; }
body.light-mode .product-tab.active { background: var(--accent-dim); border-color: var(--accent-border); color: var(--accent); }
body.light-mode .product-tab-panel { background: transparent; }
body.light-mode .wcm-details { background: #f5f5f0; }
body.light-mode .wcm-value { color: #1a1a1a; }

/* ── Searchable select ───────────────────────────────────────────────────────── */
.searchable-select-wrap {
  position: relative;
  width: 100%;
}
.searchable-select-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-1);
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
  outline: none;
  transition: border-color .15s;
}
.searchable-select-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
.searchable-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 1200;
  background: var(--surface-1, #1e1e1e);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 280px;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,.55);
}
.searchable-dropdown.hidden { display: none; }
.searchable-group-header {
  padding: 7px 12px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-3);
  border-top: 1px solid var(--border);
  margin-top: 2px;
  background: var(--surface-1, #1e1e1e);
}
.searchable-group-header:first-child { border-top: none; margin-top: 0; }
.searchable-option {
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-1);
  cursor: pointer;
  background: var(--surface-1, #1e1e1e);
  transition: background .1s;
}
.searchable-option:hover,
.searchable-option:active { background: var(--accent-dim); color: var(--accent); }
.searchable-option.selected { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.searchable-empty { color: var(--text-3); font-style: italic; cursor: default; }
.searchable-empty:hover { background: var(--surface-1, #1e1e1e); color: var(--text-3); }

/* Light mode */
body.light-mode .searchable-dropdown,
body.light-mode .searchable-group-header,
body.light-mode .searchable-option { background: #ffffff; }
body.light-mode .searchable-dropdown { box-shadow: 0 6px 20px rgba(0,0,0,.12); }
body.light-mode .searchable-option:hover { background: var(--accent-dim); }

/* ── Photo row (compact 3-up) ───────────────────────────────────────────────── */
.photo-row {
  display: flex;
  gap: 8px;
}
.photo-slot-mini {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 64px;
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  overflow: hidden;
  background: var(--input-bg);
  transition: border-color .15s;
  font-size: 11px;
  color: var(--text-3);
}
.photo-slot-mini i { font-size: 16px; }
.photo-slot-mini input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}
.photo-slot-mini.has-photo { border-color: var(--accent); border-style: solid; }
.photo-slot-mini img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 7px;
}
.photo-mini-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  z-index: 2;
}

/* ── Surcharge widget ───────────────────────────────────────────────────────── */
.surcharge-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-height: 36px;
  padding: 4px 0;
}
.surcharge-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  padding: 3px 8px 3px 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
}
.surcharge-tag button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  opacity: .7;
}
.surcharge-tag button:hover { opacity: 1; }
.surcharge-add-btn {
  background: none;
  border: 1.5px dashed var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-3);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: border-color .15s, color .15s;
}
.surcharge-add-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Duplicate window button ────────────────────────────────────────────────── */
.dup-window-btn {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color .15s, background .15s;
}
.dup-window-btn:hover { color: var(--accent); background: var(--accent-dim); }

/* ── T-post location inputs ─────────────────────────────────────────────────── */
#wtpost-locs-1, [id^="wtpost-locs-"] {
  /* styling handled by .field already */
}

/* ── Specialty Shape — form button & result display ─────────────────────────── */
.btn-spec-shape {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1.5px dashed var(--border-mid);
  color: var(--text-2);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  width: 100%;
  transition: border-color .15s, color .15s;
}
.btn-spec-shape:hover { border-color: var(--accent); color: var(--accent); }

.spec-shape-result {
  margin-top: 8px;
  background: var(--bg-3);
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.spec-shape-result-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
}
.spec-shape-result-notes {
  font-size: 12px;
  color: var(--text-2);
  font-family: var(--mono);
  word-break: break-all;
}
.btn-spec-shape-clear {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  margin-top: 2px;
  align-self: flex-start;
  font-family: var(--font);
}
.btn-spec-shape-clear:hover { color: var(--danger); }

/* ── Specialty Shape — full-screen overlay ───────────────────────────────────── */
.shape-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.shape-overlay.hidden { display: none !important; }

#shape-category-view,
#shape-grid-view,
#shape-detail-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.shape-overlay-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-mid);
  background: var(--bg-2);
  flex-shrink: 0;
}
.shape-back-btn {
  background: none;
  border: 1px solid var(--border-mid);
  color: var(--text-2);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
}
.shape-back-btn:active { background: var(--bg-4); }
.shape-overlay-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  flex: 1;
}

#shape-category-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  padding: 20px 16px;
  overflow-y: auto;
  flex: 1;
}
.shape-category-card {
  background: var(--bg-2);
  border: 2px solid var(--border-mid);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.shape-category-card:active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.shape-category-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  padding: 12px;
  box-sizing: border-box;
  background: var(--bg-3);
}
.shape-category-name {
  padding: 10px 10px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: var(--text-1);
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  letter-spacing: 0.01em;
}

#shape-grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}
.shape-loading {
  color: var(--text-3);
  padding: 32px 16px;
  text-align: center;
  grid-column: 1 / -1;
}
.shape-card {
  background: var(--bg-2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s;
  display: flex;
  flex-direction: column;
}
.shape-card:active { border-color: var(--accent); background: var(--accent-dim); }
.shape-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #ffffff;
  padding: 8px;
  box-sizing: border-box;
}
.shape-card-name {
  padding: 7px 8px;
  font-size: 12px;
  color: var(--text-2);
  text-align: center;
  border-top: 1px solid var(--border);
  line-height: 1.3;
}

#shape-detail-view {
  overflow-y: auto;
}
.new-client-form-scroll {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 24px;
}
.shape-detail-img {
  width: calc(100% - 32px);
  max-width: 380px;
  height: auto;
  object-fit: contain;
  background: #ffffff;
  border-radius: 10px;
  padding: 12px;
  margin: 16px auto 0;
  display: block;
  box-sizing: border-box;
}
.shape-dims-form {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.btn-confirm-shape {
  margin: 4px 16px 32px;
  background: var(--accent);
  color: #1a1000;
  border: none;
  border-radius: 8px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  flex-shrink: 0;
  width: calc(100% - 32px);
}
.btn-confirm-shape:active { opacity: 0.85; }
