/* ============================================================
   Dealer Google Ads Reporting Portal — Shared Styles
   ============================================================ */

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --primary-light: #e8f0fe;
  --success: #188038;
  --success-light: #e6f4ea;
  --warning: #e37400;
  --warning-light: #fef3e2;
  --danger: #d93025;
  --danger-light: #fce8e6;
  --neutral: #5f6368;
  --neutral-light: #f1f3f4;
  --border: #dadce0;
  --white: #ffffff;
  --text-primary: #202124;
  --text-secondary: #5f6368;
  --text-muted: #9aa0a6;
  --sidebar-width: 240px;
  --header-height: 60px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
  --shadow: 0 2px 8px rgba(0,0,0,0.12);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.15);
  --transition: 0.18s ease;
}

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

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  color: var(--text-primary);
  background: #f8f9fa;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ─────────────────────────────────────────────── */
.app-wrapper { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  min-height: var(--header-height);
}

.sidebar-logo .logo-icon {
  width: 32px; height: 32px;
  background: var(--primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--white);
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-logo .logo-text {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.sidebar-logo .logo-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.sidebar-nav { padding: 12px 0; flex: 1; }

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 20px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
  position: relative;
}

.nav-item:hover {
  background: var(--neutral-light);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.nav-item .nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-muted);
}

.sidebar-footer .status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  margin-right: 6px;
  vertical-align: middle;
}

/* Main content */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-header-left h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.page-header-left p {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.page-body { padding: 24px 28px; flex: 1; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-header h2 {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.card-header .card-actions { display: flex; gap: 8px; align-items: center; }

.card-body { padding: 20px; }

/* ── Stat / KPI Cards ────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.kpi-trend {
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.kpi-trend.up { color: var(--success); }
.kpi-trend.down { color: var(--danger); }
.kpi-trend.neutral { color: var(--text-muted); }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  background: var(--neutral-light);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

thead th:hover { background: #e4e6e8; }

thead th.sort-asc::after { content: ' ↑'; }
thead th.sort-desc::after { content: ' ↓'; }

tbody tr {
  border-bottom: 1px solid #f1f3f4;
  transition: background var(--transition);
}

tbody tr:hover { background: #f8f9fa; }
tbody tr:last-child { border-bottom: none; }

tbody td {
  padding: 11px 14px;
  color: var(--text-primary);
  vertical-align: middle;
}

.td-right { text-align: right; }
.td-center { text-align: center; }

/* ── Badges & Pills ─────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger  { background: var(--danger-light);  color: var(--danger); }
.badge-neutral { background: var(--neutral-light); color: var(--neutral); }
.badge-blue    { background: var(--primary-light); color: var(--primary); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover { opacity: 0.88; }
.btn:active { opacity: 0.75; }

.btn-primary { background: var(--primary); color: var(--white); }
.btn-outline {
  background: var(--white);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--neutral-light); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Form controls ───────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

label.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: var(--font);
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,115,232,0.15);
}

select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%235f6368'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

/* ── Filter bar ──────────────────────────────────────────── */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 18px;
}

.filter-item { display: flex; flex-direction: column; gap: 4px; }
.filter-item label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); }
.filter-item .form-control { min-width: 160px; }

/* ── Charts ──────────────────────────────────────────────── */
.chart-container {
  position: relative;
  width: 100%;
}

/* ── Grid helpers ────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }

/* ── Progress bar ────────────────────────────────────────── */
.progress-bar {
  height: 6px;
  background: var(--neutral-light);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* ── Misc helpers ────────────────────────────────────────── */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary-color { color: var(--primary); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.gap-12 { gap: 12px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.align-center { align-items: center; }

/* ── Loader / Empty ─────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
  gap: 10px;
}

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

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

.empty-icon { font-size: 36px; margin-bottom: 10px; }

/* ── Toast ───────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #3c4043;
  color: var(--white);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 340px;
}

.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Checklist items (launch page) ─────────────────────── */
.checklist { display: flex; flex-direction: column; gap: 10px; }

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--white);
}

.check-item .check-icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  margin-top: 1px;
}

.check-item.done   .check-icon { background: var(--success-light); color: var(--success); }
.check-item.todo   .check-icon { background: var(--warning-light); color: var(--warning); }
.check-item.needed .check-icon { background: var(--danger-light);  color: var(--danger); }

.check-item .check-text strong { display: block; font-size: 13px; font-weight: 600; }
.check-item .check-text span   { font-size: 12px; color: var(--text-secondary); line-height: 1.4; }

/* ── Step blocks ─────────────────────────────────────────── */
.step-block {
  display: flex;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.step-block:last-child { border-bottom: none; }

.step-num {
  width: 30px; height: 30px;
  background: var(--primary);
  color: var(--white);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.step-content strong { display: block; font-size: 13.5px; font-weight: 700; margin-bottom: 4px; }
.step-content p { font-size: 12.5px; color: var(--text-secondary); line-height: 1.5; }
.step-content code {
  background: var(--neutral-light);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
  color: var(--primary-dark);
}

/* ── Alert box ───────────────────────────────────────────── */
.alert {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 16px;
}

.alert-info    { background: var(--primary-light);  color: var(--primary-dark); border: 1px solid #c6d9f9; }
.alert-warning { background: var(--warning-light);  color: #6d4200;              border: 1px solid #fdd9a0; }
.alert-success { background: var(--success-light);  color: var(--success);       border: 1px solid #b6dfbd; }
.alert-danger  { background: var(--danger-light);   color: var(--danger);        border: 1px solid #f5c0bb; }

/* ── Custom date range pickers (dealer-setup.html patch) ──────
   Uses CSS :has() to show the date row whenever "custom" is the
   selected value — zero JavaScript required.
   Works in Chrome 105+, Edge 105+, Safari 15.4+, Firefox 121+.
──────────────────────────────────────────────────────────────── */

/* Base styles for the injected date rows */
#a-date-row, #e-date-row,
#a-cdr, #e-cdr {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 10px;
  padding: 14px;
  background: #f0f7ff;
  border: 1.5px solid #1a73e8;
  border-radius: 10px;
}

/* Show Add date row when Custom is selected */
.modal-body:has(#a-report-range option[value="custom"]:checked) #a-date-row,
.modal-body:has(#a-report-range option[value="custom"]:checked) #a-cdr,
.modal:has(#a-report-range option[value="custom"]:checked) #a-date-row,
.modal:has(#a-report-range option[value="custom"]:checked) #a-cdr {
  display: grid !important;
}

/* Show Edit date row when Custom is selected */
.modal-body:has(#e-report-range option[value="custom"]:checked) #e-date-row,
.modal-body:has(#e-report-range option[value="custom"]:checked) #e-cdr,
.modal:has(#e-report-range option[value="custom"]:checked) #e-date-row,
.modal:has(#e-report-range option[value="custom"]:checked) #e-cdr {
  display: grid !important;
}

/* Also handle the modal-overlay wrapper used in dealer-setup.html */
.modal-overlay:has(#a-report-range option[value="custom"]:checked) #a-date-row,
.modal-overlay:has(#a-report-range option[value="custom"]:checked) #a-cdr {
  display: grid !important;
}
.modal-overlay:has(#e-report-range option[value="custom"]:checked) #e-date-row,
.modal-overlay:has(#e-report-range option[value="custom"]:checked) #e-cdr {
  display: grid !important;
}

/* Fallback: if the date row is a sibling of the grid-2, still show it */
#a-report-range:has(option[value="custom"]:checked) ~ #a-date-row,
#a-report-range:has(option[value="custom"]:checked) ~ #a-cdr {
  display: grid !important;
}
#e-report-range:has(option[value="custom"]:checked) ~ #e-date-row,
#e-report-range:has(option[value="custom"]:checked) ~ #e-cdr {
  display: grid !important;
}

/* Date input styling */
#a-date-row input[type="date"],
#e-date-row input[type="date"],
#a-cdr input[type="date"],
#e-cdr input[type="date"] {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid #dadce0;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  box-sizing: border-box;
  background: #fff;
}
#a-date-row input[type="date"]:focus,
#e-date-row input[type="date"]:focus,
#a-cdr input[type="date"]:focus,
#e-cdr input[type="date"]:focus {
  outline: none;
  border-color: #1a73e8;
  box-shadow: 0 0 0 3px rgba(26,115,232,.12);
}
#a-date-row label, #e-date-row label,
#a-cdr label, #e-cdr label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: #5f6368;
  margin-bottom: 6px;
}

.alert .alert-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

/* ── Pagination ──────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 14px;
}

.page-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: 6px;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background var(--transition);
}

.page-btn:hover { background: var(--neutral-light); }
.page-btn.active { background: var(--primary); color: var(--white); border-color: var(--primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

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

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 { font-size: 15px; font-weight: 700; }

.modal-close {
  background: none; border: none;
  color: var(--text-muted);
  font-size: 20px; cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background var(--transition);
}

.modal-close:hover { background: var(--neutral-light); }

.modal-body  { padding: 20px 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .page-body { padding: 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .page-header { padding: 12px 16px; }
}
