*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textbox; }

:root {
  --bg: #f5f0eb;
  --surface: #ffffff;
  --surface2: #f0e8df;
  --border: #e0d5c8;
  --text: #2c2520;
  --text-muted: #8a7e72;
  --primary: #dfc09e;
  --primary-hover: #d4ad84;
  --primary-text: #4a3828;
  --danger: #c0392b;
  --success: #27ae60;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.nav-brand { font-weight: 500; font-size: 0.85rem; color: var(--text-muted); }
.nav-logout { color: var(--text-muted); text-decoration: none; font-size: 0.85rem; }
.nav-logout:hover { color: var(--text); }

main { max-width: 900px; margin: 0 auto; padding: 2rem 1.5rem; }
main:has(.intake-form) { max-width: 100%; }
main:has(.dashboard) { max-width: 100%; padding: 0.75rem 2rem; }
main:has(.cd-page) { max-width: 100%; padding: 1.5rem 2rem; }

h1 { font-size: 1.8rem; font-weight: 700; letter-spacing: -0.03em; margin-bottom: 0.5rem; }
h2 { font-size: 1.2rem; font-weight: 600; margin-bottom: 0.75rem; color: var(--text-muted); }

label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--text-muted); margin-bottom: 0.35rem; margin-top: 1rem; }
.required { color: var(--danger); }

input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], textarea, select {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--surface2);
  text-transform: uppercase;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
input[type="email"] {
  text-transform: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); }
textarea { resize: vertical; }

button, .btn {
  display: inline-block;
  padding: 0.65rem 1.4rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, transform 0.1s;
  text-align: center;
}
button:active, .btn:active { transform: scale(0.98); }

button, .btn-primary {
  background: var(--primary);
  color: var(--primary-text);
}
button:hover, .btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-small {
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
}

.error {
  background: rgba(231, 76, 60, 0.15);
  color: #e74c3c;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* Login Background */
.login-page {
  min-height: 100vh;
  background: url('/login-bg.png') center center / cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

/* Auth */
.auth-container {
  max-width: 380px;
  width: 100%;
  margin: 8vh auto;
  padding: 2.5rem;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.login-page .auth-container {
  margin: 0;
  padding: 2.5rem 2.5rem 2rem;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: none;
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.25);
}
.login-logo-wrap {
  text-align: center;
  padding: 0.5rem 0 1.5rem;
}
.login-logo {
  max-width: 220px;
  height: auto;
}
.login-field {
  margin-bottom: 0.75rem;
}
.login-field input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 0.95rem;
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  text-transform: none;
}
.login-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(223, 192, 158, 0.25);
  background: #fff;
}
.login-field input::placeholder {
  color: #aaa;
  font-weight: 400;
}
.login-btn {
  width: 100%;
  margin-top: 1rem;
  padding: 0.75rem;
  border: none;
  border-radius: 8px;
  background: #3a3a3a;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  letter-spacing: 0.03em;
}
.login-btn:hover {
  background: #555;
}
.login-btn:active {
  transform: scale(0.99);
}
.auth-container h1 { text-align: center; margin-bottom: 0.25rem; }
.auth-container h2 { display: none; }
.auth-container button { width: 100%; }

.signup-info {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.success-box {
  text-align: center;
  padding: 1.5rem;
  margin-top: 1.5rem;
  background: rgba(39, 174, 96, 0.1);
  border: 1px solid rgba(39, 174, 96, 0.3);
  border-radius: var(--radius);
}
.success-box h2 { color: var(--success); }
.success-box p { color: var(--text-muted); margin-top: 0.5rem; }

/* Dashboard */
.dashboard { }
.dash-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.75rem;
}
.dash-left {
  flex: 0 0 auto;
}
.dash-center {
  flex: 1;
  text-align: center;
}
.dash-logo {
  max-width: 220px;
  height: auto;
}
.btn-new-deal {
  padding: 0.6rem 1.8rem;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  border: 2px solid var(--primary-text);
  background: var(--surface);
  color: var(--primary-text);
  border-radius: 4px;
  text-transform: uppercase;
}
.btn-new-deal:hover {
  background: var(--primary);
  color: var(--primary-text);
}
.dash-search-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.search-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.search-by-select {
  width: auto;
  min-width: 90px;
  padding: 0.45rem 0.6rem;
  font-size: 0.88rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  text-transform: none;
  margin-top: 0;
}
.search-input {
  width: 160px;
  padding: 0.45rem 0.6rem;
  font-size: 0.88rem;
  margin-top: 0 !important;
}
.dash-search-form .btn {
  padding: 0.45rem 1rem;
  font-size: 0.88rem;
  margin-top: 0;
}

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.clients-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: var(--surface);
}
.clients-table thead th {
  background: #4a4a4e;
  color: #fff;
  padding: 0.7rem 0.8rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.82rem;
  white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,0.1);
  position: sticky;
  top: 0;
}
.clients-table thead th:last-child { border-right: none; }
.clients-table thead th a {
  color: #fff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.clients-table thead th a:hover { color: var(--primary); }
.clients-table tbody td {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
  text-transform: uppercase;
}
.clients-table tbody tr:nth-child(even) {
  background: var(--surface2);
}
.clients-table tbody tr:hover {
  background: var(--primary);
  color: var(--primary-text);
}
.clients-table tbody tr:hover td {
  color: var(--primary-text);
}
.empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 0 !important;
  font-style: italic;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
}
.btn-danger:hover { background: #a93226; }

.empty { text-align: center; color: var(--text-muted); padding: 3rem 0; }

/* New Client Form */
.form-container {
  max-width: 550px;
  margin: 0 auto;
  background: var(--surface);
  padding: 2rem 2.5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.form-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 2rem; }

/* Client Detail Page */
.cd-page { max-width: 100%; padding: 0 1rem; }
.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  display: inline-block;
  margin-bottom: 0.75rem;
}
.back-link:hover { color: var(--text); }

.cd-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
.cd-header-left { flex: 1; min-width: 0; }
.cd-name { font-size: 1.5rem; font-weight: 700; margin: 0 0 0.15rem; text-transform: uppercase; }
.cd-app-num {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--surface);
  background: #4a4a4e;
  padding: 0.15rem 0.6rem;
  border-radius: 3px;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}
.cd-contact-info {
  margin-top: 0.5rem;
}
.cd-contact-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.2rem 0;
  font-size: 0.9rem;
}
.cd-contact-label {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  min-width: 3.5rem;
}
.cd-contact-value {
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
  text-transform: uppercase;
}
.cd-contact-email {
  text-transform: none;
}
.cd-created {
  margin-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.cd-header-right {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}

.cd-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.cd-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
.cd-card-header {
  background: #4a4a4e;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.55rem 1rem;
}
.cd-card-body {
  padding: 0.75rem 1rem;
}
.cd-big-text {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}
.cd-empty {
  color: var(--text-muted);
  font-style: italic;
  font-weight: 400;
  font-size: 0.85rem;
  text-transform: none;
}
.cd-summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.cd-summary-table tr { border-bottom: 1px solid #f0ebe4; }
.cd-summary-table tr:last-child { border-bottom: none; }
.cd-summary-table td { padding: 0.25rem 0; vertical-align: top; }
.cd-summary-table .sr-label {
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  padding-right: 0.75rem;
  width: 45%;
}
.cd-summary-table .sr-value {
  color: var(--text);
  font-weight: 500;
  text-align: right;
  text-transform: uppercase;
}
.cd-summary-table tr.sr-bold td {
  font-weight: 700;
  border-top: 1px solid var(--border);
  padding-top: 0.35rem;
}

.cd-product-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid #f0ebe4;
  font-size: 0.82rem;
}
.cd-product-item:last-child { border-bottom: none; }
.cd-product-type {
  font-weight: 600;
  color: var(--text);
  min-width: 0;
  text-transform: uppercase;
}
.cd-product-detail {
  flex: 1;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}
.cd-product-price {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.cd-details-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 2rem;
}
.cd-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
.cd-panel.collapsed .cd-panel-body { display: none; }
.cd-panel.collapsed .cd-chevron { transform: rotate(-90deg); }
.cd-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary-text);
}
.cd-panel-header:hover { background: var(--primary); }
.cd-chevron {
  font-size: 0.6rem;
  transition: transform 0.2s;
  color: var(--text-muted);
}
.cd-panel-body {
  padding: 0.75rem 1rem;
}
.cd-detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.cd-detail-table tr { border-bottom: 1px solid #f0ebe4; }
.cd-detail-table tr:last-child { border-bottom: none; }
.cd-detail-table td { padding: 0.3rem 0; vertical-align: top; }
.cd-detail-table .sr-label {
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  padding-right: 0.75rem;
  width: 40%;
}
.cd-detail-table .sr-value {
  color: var(--text);
  font-weight: 500;
  text-transform: uppercase;
}

.cd-changes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.cd-changes-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.7rem;
  padding: 0.3rem 0.4rem;
  border-bottom: 2px solid var(--border);
}
.cd-changes-table td {
  padding: 0.25rem 0.4rem;
  border-bottom: 1px solid #f0ebe4;
  color: var(--text);
  text-transform: uppercase;
}

@media (max-width: 700px) {
  .cd-header { flex-direction: column; gap: 1rem; }
}

.collapsible-header {
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}
.collapsible-header:hover {
  color: var(--accent);
}
.collapsible-header .collapse-arrow {
  color: var(--muted);
}
.collapsible-header:hover .collapse-arrow {
  color: var(--accent);
}
.subsection-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--primary-text);
  margin: 1.5rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--primary);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.5rem 0 2rem;
  background: var(--surface);
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.detail-item .label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
  margin-top: 0;
}
.detail-item.full { grid-column: 1 / -1; }

.section {
  margin-top: 2rem;
  padding: 1.5rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.section h2 { margin-bottom: 1rem; }

.status-badge {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}
.status-badge.active { background: rgba(39, 174, 96, 0.15); color: var(--success); }
.status-badge.pending { background: rgba(139, 143, 163, 0.15); color: var(--text-muted); }

.invite-list { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.invite-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
}
.invite-row.used { opacity: 0.5; }
.invite-status {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  min-width: 50px;
}
.invite-url {
  flex: 1;
  font-size: 0.8rem;
  padding: 0.4rem 0.6rem;
  margin-top: 0;
}

/* Intake Form */
.intake-form {
  max-width: 100%;
  margin: 0 auto;
  padding: 0 1.5rem;
  padding-bottom: 5rem;
}
.intake-form h1 {
  margin-bottom: 0.5rem;
}
.application-number {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.app-num-badge {
  display: inline-block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  margin-top: 0.25rem;
}

.header-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 0;
  background: var(--surface2);
}
.dealer-row {
  display: flex;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  align-items: flex-end;
}
.dealer-row-bottom {
  border-bottom: none;
  background: rgba(0,0,0,0.015);
}
.dealer-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
  min-width: 0;
}
.dealer-field label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.dealer-field input {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
  font-size: 0.82rem;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  box-sizing: border-box;
}
.dealer-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(223, 192, 158, 0.2);
}
.dealer-name-field {
  flex: 2;
}
.dealer-row-top .dealer-field:not(.dealer-name-field) {
  flex: 1;
}

.intake-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  cursor: pointer;
  user-select: none;
  background: var(--surface);
  transition: background 0.2s;
}
.section-header:hover {
  background: var(--surface2);
}
.section-header h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text);
}
.section-header .chevron {
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}
.section-header .chevron.collapsed {
  transform: rotate(-90deg);
}

.section-body {
  padding: 0 1.5rem 1.5rem;
}
.section-body.collapsed {
  display: none;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.25rem;
}

.field-group {
  margin-bottom: 0;
}
.field-group label {
  margin-top: 0.75rem;
  margin-bottom: 0.3rem;
}
.field-group.full {
  grid-column: 1 / -1;
}

.toggle-switch {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.75rem 0;
  cursor: pointer;
}
.toggle-switch input[type="checkbox"] {
  display: none;
}
.toggle-switch .slider {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-switch .slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: var(--surface);
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle-switch input:checked + .slider {
  background: var(--primary);
}
.toggle-switch input:checked + .slider::after {
  transform: translateX(20px);
}
.toggle-switch .toggle-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

.co-fields {
  display: none;
}
.co-fields.visible {
  display: block;
}

.coverage-card {
  position: relative;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.coverage-card .remove-coverage {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  line-height: 1;
  border-radius: 4px;
}
.coverage-card .remove-coverage:hover {
  background: rgba(192, 57, 43, 0.1);
}

.add-coverage-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.sticky-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.75rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  z-index: 100;
}
.footer-left {
  display: flex;
  gap: 0.75rem;
}
.footer-right {
  display: flex;
  gap: 0.75rem;
}
.btn-print {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
}
.btn-print:hover {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}

.toast {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  background: var(--success);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 200;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.upload-section {
  margin-bottom: 1.5rem;
}
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  background: var(--surface);
  transition: all 0.2s;
  cursor: pointer;
}
.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--primary);
  background: rgba(223, 192, 158, 0.08);
}
.upload-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}
.upload-area p {
  margin: 0.3rem 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.upload-hint {
  font-size: 0.8rem !important;
  color: var(--muted);
  margin-top: 0.5rem !important;
}
.upload-btn-label {
  display: inline-block;
  margin: 0.5rem 0;
  cursor: pointer;
}
.documents-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.documents-table th {
  background: var(--surface2);
  padding: 0.6rem 0.8rem;
  text-align: left;
  font-weight: 600;
  color: var(--text);
  border-bottom: 2px solid var(--border);
}
.documents-table td {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.documents-table a {
  color: var(--primary-dark);
  text-decoration: none;
  font-weight: 500;
}
.documents-table a:hover {
  text-decoration: underline;
}
.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  border-radius: var(--radius);
}
.btn-danger {
  background: #d9534f;
  color: #fff;
  border: none;
  cursor: pointer;
}
.btn-danger:hover {
  background: #c9302c;
}

.detail-header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: none;
  margin-top: 0.75rem;
  margin-bottom: 0;
  background: transparent;
  overflow-x: hidden;
}
.tab-btn {
  flex: 1;
  padding: 0.75rem 1.5rem;
  background: var(--primary);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--primary-text);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  position: relative;
  top: 1px;
  box-shadow: 0 -2px 4px rgba(0,0,0,0.06);
  white-space: nowrap;
  text-transform: uppercase;
  transition: all 0.2s;
  margin-bottom: -2px;
  text-align: center;
}
.tab-btn:hover { color: var(--primary-text); background: var(--primary-hover); }
.tab-btn.active {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 1px solid var(--surface);
  box-shadow: 0 -3px 6px rgba(0,0,0,0.08);
  z-index: 1;
}
.tab-content {
  display: none;
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
  margin-top: 0;
}
.tab-content.active { display: block; }

.messages-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.messages-table th, .messages-table td {
  padding: 0.6rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.messages-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.messages-table tr:hover td { background: var(--surface2); }

/* Two-column layout */
.two-col-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 2.5rem;
  align-items: start;
}
.three-col-layout {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 2rem;
  align-items: start;
}
.col-vehicle, .col-deal, .col-lender, .col-account {
  min-width: 0;
}
.two-col-layout.applicant-layout {
  grid-template-columns: 1fr 1fr;
}
.col-left, .col-right {
  min-width: 0;
  max-width: 420px;
}
.applicant-layout .col-left,
.applicant-layout .col-right {
  max-width: none;
}
.field-stack {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.field-stack .field-group {
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid #ece5dc;
  padding: 0.4rem 0;
}
.field-stack .field-group label {
  margin: 0;
  min-width: 140px;
  flex-shrink: 0;
  font-size: 0.82rem;
  white-space: nowrap;
}
.field-stack .field-group input,
.field-stack .field-group select {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
  text-align: right;
  background: var(--surface);
  border: 1px solid var(--border);
}
.field-stack .field-group input[type="date"] {
  text-align: left;
}
.field-stack .field-group input[type="text"] {
  text-align: left;
}
.field-stack .field-group select {
  text-align: left;
}
.field-stack .field-group input[readonly] {
  background: var(--surface2);
  font-weight: 600;
}
.field-stack .field-group.calc-result {
  border-top: 1px dashed var(--border);
  margin-top: 2px;
}
.field-stack .field-group.calc-grand {
  border-top: 2px solid var(--primary);
  padding-top: 0.5rem;
}
.field-stack .field-group.calc-grand label {
  font-weight: 700;
}
.field-stack .field-group.calc-grand input {
  font-weight: 700;
}
.field-stack .field-group .radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}
.field-stack .field-group .radio-group .radio-label {
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
  flex: none;
}
.field-stack .field-group .radio-group .radio-label input[type="radio"] {
  flex: none;
  width: auto;
  min-width: auto;
}
.field-row {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid #ece5dc;
  padding: 0.4rem 0;
  align-items: center;
}
.field-row .field-group {
  flex: 1;
  min-width: 0;
  border-bottom: none;
  padding: 0;
}
.field-row .field-group label {
  min-width: 60px;
  font-size: 0.78rem;
}
.field-row .field-group input {
  max-width: 120px;
}
.subsection-title-sm {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--primary-text);
  margin-top: 1.25rem;
  margin-bottom: 0.15rem;
  padding-bottom: 0.35rem;
  border-bottom: 2px solid var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.78rem;
}
.field-note {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* Line Items (Taxable / Non-Taxable) */
.ledger-block {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  background: var(--surface);
}
.ledger-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary-text);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}
.ledger-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0;
}
.ledger-row label {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text);
  white-space: nowrap;
}
.ledger-row input, .ledger-row select {
  width: 120px;
  flex-shrink: 0;
  text-align: right;
  font-size: 0.8rem;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface);
}
.ledger-row input[readonly] {
  background: var(--surface2);
  font-weight: 600;
}
.ledger-row.ledger-add label { color: var(--success); }
.ledger-row.ledger-sub label { color: var(--danger); }
.ledger-row.ledger-total {
  border-top: 1px solid var(--border);
  padding-top: 0.35rem;
  margin-top: 0.15rem;
}
.ledger-row.ledger-total label { font-weight: 700; }
.ledger-row.ledger-grand {
  border-top: 2px solid var(--primary);
  padding-top: 0.5rem;
  margin-top: 0.35rem;
}
.ledger-row.ledger-grand label { font-weight: 700; font-size: 0.9rem; }
.ledger-row.ledger-grand input { font-weight: 700; font-size: 0.9rem; }
.ledger-divider {
  border-top: 1px dashed var(--border);
  margin: 0.5rem 0;
}
.ledger-label-sm {
  font-size: 0.8rem;
  color: var(--success);
  font-weight: 600;
}
.deal-type-section { margin-top: 0.5rem; }
.line-items-section {
  margin-top: 1rem;
}
.line-items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}
.line-items-header .subsection-title-sm {
  margin: 0;
  border: none;
  padding: 0;
}
.btn-add-line {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  background: var(--surface);
  color: var(--primary-text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-add-line:hover {
  background: var(--primary);
  color: #fff;
}
.line-item-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}
.line-item-row input[type="text"] {
  flex: 2;
  max-width: none;
  text-align: left;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
}
.line-item-row input[type="number"] {
  flex: 1;
  max-width: 110px;
  text-align: right;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
}
.line-item-tax-cb {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.line-item-tax-cb input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--primary);
  cursor: pointer;
}
.btn-remove-line {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--danger);
  padding: 0.2rem;
  border-radius: 4px;
  transition: background 0.2s;
  line-height: 1;
}
.btn-remove-line:hover {
  background: rgba(192, 57, 43, 0.1);
}

/* Radio group for payment frequency */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.35rem 0;
}
.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  margin: 0;
  flex: none;
}
.radio-label input[type="radio"] {
  width: auto;
  margin: 0;
}

@media (max-width: 900px) {
  .two-col-layout,
  .three-col-layout {
    grid-template-columns: 1fr;
  }
  .col-left, .col-right, .col-lender, .col-vehicle, .col-deal, .col-account {
    max-width: 100%;
  }
}

.paid-in-full-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  margin-top: 0.5rem;
  background: #e8f5e9;
  border: 2px solid #4caf50;
  border-radius: 8px;
  min-height: 120px;
}
.paid-in-full-banner span {
  font-size: 1.4rem;
  font-weight: 800;
  color: #2e7d32;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 22px;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #ccc;
  border-radius: 22px;
  transition: 0.3s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.3s;
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(22px);
}
/* Vehicle Protections layout */
.vp-details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
  padding: 16px;
  background: var(--surface2);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.vp-details-grid .field-group {
  margin-bottom: 0;
}
.vp-details-grid .field-group label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-bottom: 4px;
  display: block;
}
.vp-details-grid .field-group input,
.vp-details-grid .field-group select {
  width: 100%;
  padding: 6px 10px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.vp-extra-provider {
  margin-top: 8px;
}
.vp-extra-provider .vp-details-grid {
  margin-bottom: 0;
}
.vp-remove-provider-btn {
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
  white-space: nowrap;
}
.vp-categories {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.vp-category-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.vp-category-header {
  background: var(--surface2);
  padding: 10px 16px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary-text);
  border-bottom: 1px solid var(--border);
}
.vp-category-body {
  padding: 12px 16px;
}
.vp-category-body .field-stack .field-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid #f0ebe4;
  padding: 0.4rem 0;
  margin-bottom: 0;
}
.vp-category-body .field-stack .field-group:last-child {
  border-bottom: none;
}
.vp-category-body .field-stack .field-group label {
  font-size: 0.78rem;
  color: var(--muted);
  min-width: 80px;
  flex-shrink: 0;
  margin: 0;
}
.vp-category-body .field-stack .field-group input,
.vp-category-body .field-stack .field-group select,
.vp-category-body .field-stack .field-group textarea {
  flex: 1;
  padding: 5px 8px;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.vp-add-btn {
  margin-top: 10px;
  font-size: 12px;
  padding: 4px 14px;
}
.vp-na-label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  margin-left: 8px;
}
.expiry-label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
@media (max-width: 900px) {
  .vp-categories {
    grid-template-columns: 1fr;
  }
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
}
.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
.checkbox-expiry-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid #f0ebe4;
}
.checkbox-expiry-row:last-of-type {
  border-bottom: none;
}
.checkbox-expiry-row .checkbox-row {
  min-width: 150px;
}
.expiry-field {
  display: flex;
  align-items: center;
  gap: 6px;
}
.expiry-field input[type="date"] {
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

@media (max-width: 600px) {
  main { padding: 1rem; }
  nav { padding: 0.75rem 1rem; }
  .detail-grid { grid-template-columns: 1fr; }
  .auth-container { margin: 4vh 1rem; padding: 1.5rem; }
  .form-container { padding: 1.5rem; }
  .dash-header { flex-direction: column; gap: 1rem; align-items: stretch; }
  .search-form { flex-direction: column; }
  .field-grid { grid-template-columns: 1fr; }
  .section-header { padding: 0.75rem 1rem; }
  .section-body { padding: 0 1rem 1rem; }
  .sticky-footer { padding: 0.75rem 1rem; }
}
