/* ================================================================
   DealerMetrics — Application Stylesheet
   Palette: Navy #0f1623, Steel #1a2236, Blue accent #4f8ef7,
            Light blue #7bb3ff, Off-white #e8edf5, Muted #8a95a8
   Signature: KPI tile grid — bordered boxes matching original
               spreadsheet layout, on a deep navy surface
   ================================================================ */

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

:root {
  --navy:       #0f1623;
  --steel:      #1a2236;
  --steel-light:#222d44;
  --border:     #2d3a52;
  --border-light:#3d4e6a;
  --accent:     #4f8ef7;
  --accent-dim: #2d5fa8;
  --text-primary:   #e8edf5;
  --text-secondary: #8a95a8;
  --text-muted:     #5a6478;
  --success:    #2ecc71;
  --warning:    #f0a500;
  --danger:     #e55252;
  --info:       #5bc0de;
  --purple:     #9b7fe8;
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --nav-h:      54px;
  --font:       system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono:  'Cascadia Code', 'Fira Mono', ui-monospace, monospace;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--navy);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Links ───────────────────────────────────────────── */
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ════════════════════════════════════════════════════════
   LOGIN PAGE
   ════════════════════════════════════════════════════════ */
.login-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--navy);
  padding: 2rem 1rem;
}

.login-wrap { width: 100%; max-width: 380px; }

.login-card {
  background: var(--steel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem 2rem 1.5rem;
  margin-bottom: 1rem;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 1.5rem;
}

.login-appname {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.login-heading {
  font-size: 1.4rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
  color: var(--text-primary);
}

.login-footer {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
}

/* ════════════════════════════════════════════════════════
   TOP NAV
   ════════════════════════════════════════════════════════ */
.topnav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--steel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1.5rem;
  z-index: 100;
}

.topnav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  text-decoration: none;
}

.topnav-center {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  overflow: visible;
}

.nav-link {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text-secondary);
  white-space: nowrap;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover,
.nav-link.active { background: var(--steel-light); color: var(--text-primary); text-decoration: none; }

.nav-arrow { font-size: 0.65rem; opacity: 0.5; margin-left: 2px; }

.nav-dropdown { position: relative; }
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--steel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 160px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  overflow: visible;
}
/* Dropdowns open via JS .open class */
.nav-dropdown-menu.open { display: block; }
.nav-dropdown-item {
  display: block;
  padding: 8px 14px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.1s, color 0.1s;
}
.nav-dropdown-item:hover,
.nav-dropdown-item.active {
  background: var(--steel-light);
  color: var(--text-primary);
}

.topnav-right {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
}
.user-chip-name { color: var(--text-secondary); }

/* ════════════════════════════════════════════════════════
   MAIN LAYOUT
   ════════════════════════════════════════════════════════ */
.main-content {
  margin-top: var(--nav-h);
  padding: 1.75rem 1.75rem 3rem;
  width: 100%;
}

/* ════════════════════════════════════════════════════════
   PAGE HEADER
   ════════════════════════════════════════════════════════ */
.page-header { margin-bottom: 1.5rem; }
.page-header-flex {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-title {
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.section-heading {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 1.5rem 0 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.75rem;
}

/* ════════════════════════════════════════════════════════
   BUTTONS
   ════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: var(--font);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn-primary  { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #3a7ae0; text-decoration: none; }
.btn-ghost    { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover  { background: var(--steel-light); color: var(--text-primary); text-decoration: none; }
.btn-danger   { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(229,82,82,.15); }
.btn-sm  { padding: 4px 12px; font-size: 0.8rem; }
.btn-xs  { padding: 3px 8px;  font-size: 0.75rem; }
.btn-block { width: 100%; justify-content: center; }

/* ════════════════════════════════════════════════════════
   FORMS
   ════════════════════════════════════════════════════════ */
.form-group { margin-bottom: 1rem; }
.form-group label,
.entry-row label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
  font-weight: 500;
}
.form-input, .form-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--navy);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-input.is-error { border-color: var(--danger); }
.form-input-sm, .form-select-sm { padding: 5px 8px; font-size: 0.8rem; width: auto; }

.form-group-inline { display: flex; align-items: center; gap: 8px; }
.form-group-inline label { margin-bottom: 0; white-space: nowrap; }
.form-group-inline .form-input,
.form-group-inline .form-select { width: auto; }

/* ════════════════════════════════════════════════════════
   ALERTS
   ════════════════════════════════════════════════════════ */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
  border: 1px solid;
}
.alert-danger  { background: rgba(229,82,82,.12);  color: #f88; border-color: rgba(229,82,82,.3); }
.alert-success { background: rgba(46,204,113,.12); color: #6ee; border-color: rgba(46,204,113,.3); }
.alert-warning { background: rgba(240,165,0,.12);  color: #fca; border-color: rgba(240,165,0,.3); }
.alert-info    { background: rgba(79,142,247,.12); color: #9cf; border-color: rgba(79,142,247,.3); }

/* ════════════════════════════════════════════════════════
   BADGES & DOTS
   ════════════════════════════════════════════════════════ */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.badge-success  { background: rgba(46,204,113,.18); color: #2ecc71; }
.badge-danger   { background: rgba(229,82,82,.18);  color: #e55252; }
.badge-warning  { background: rgba(240,165,0,.18);  color: #f0a500; }
.badge-info     { background: rgba(79,142,247,.18); color: #7bb3ff; }
.badge-purple   { background: rgba(155,127,232,.18);color: #9b7fe8; }
.badge-neutral  { background: rgba(138,149,168,.15);color: #8a95a8; }

.role-badge.role-admin      { background: rgba(229,82,82,.15); color: #e55252; }
.role-badge.role-supervisor { background: rgba(240,165,0,.15); color: #f0a500; }
.role-badge.role-staff      { background: rgba(79,142,247,.15);color: #7bb3ff; }

.dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  vertical-align: middle;
  margin-left: 4px;
}
.dot-green { background: var(--success); }
.dot-gray  { background: var(--text-muted); }

/* ════════════════════════════════════════════════════════
   STAT ROW (home page)
   ════════════════════════════════════════════════════════ */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--steel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
}
.stat-label { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.stat-value { font-size: 1.8rem; font-weight: 500; color: var(--text-primary); }

/* ════════════════════════════════════════════════════════
   BRAND GRID (home page)
   ════════════════════════════════════════════════════════ */
.brand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 2rem;
}
.brand-card {
  background: var(--steel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}
.brand-card-name { font-weight: 500; margin-bottom: 10px; }
.brand-card-links { display: flex; flex-direction: column; gap: 4px; }
.brand-link { font-size: 0.8rem; color: var(--text-secondary); display: flex; align-items: center; justify-content: space-between; }
.brand-link:hover { color: var(--accent); text-decoration: none; }

.quick-links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.quick-card {
  background: var(--steel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  transition: border-color 0.15s, background 0.15s;
  text-decoration: none;
}
.quick-card:hover { border-color: var(--accent); background: var(--steel-light); text-decoration: none; }
.quick-icon  { font-size: 1.5rem; margin-bottom: 8px; }
.quick-label { font-weight: 500; color: var(--text-primary); margin-bottom: 4px; }
.quick-desc  { font-size: 0.8rem; color: var(--text-secondary); }

/* ════════════════════════════════════════════════════════
   PERIOD BAR
   ════════════════════════════════════════════════════════ */
.period-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.period-tabs { display: flex; gap: 2px; }
.period-tab {
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-secondary);
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.period-tab:hover { background: var(--steel-light); color: var(--text-primary); text-decoration: none; }
.period-tab.active {
  background: var(--steel-light);
  color: var(--text-primary);
  border-color: var(--border);
}
.period-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.period-current {
  font-size: 0.875rem;
  color: var(--text-primary);
  font-weight: 500;
  min-width: 120px;
  text-align: center;
}
.brand-subnav { display: flex; gap: 2px; flex-wrap: wrap; }
.brand-subnav-item {
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  text-decoration: none;
  transition: background 0.1s, color 0.1s;
}
.brand-subnav-item:hover { background: var(--steel-light); color: var(--text-primary); text-decoration: none; }
.brand-subnav-item.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ════════════════════════════════════════════════════════
   ★ SIGNATURE — KPI TILE GRID
   Replicates the spreadsheet's bordered KPI tile layout.
   Each tile has a small grey header label and a large value.
   The grid is 5-wide matching the source dashboards.
   ════════════════════════════════════════════════════════ */
.kpi-header-bar {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 10px;
  padding: 8px 12px;
  background: var(--steel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
}
.kpi-header-item { display: flex; align-items: center; gap: 8px; }
.kpi-header-label { font-size: 0.75rem; color: var(--text-secondary); }
.kpi-header-value { font-size: 0.9rem; font-weight: 500; }

.kpi-grid {
  display: grid;
  gap: 6px;
}
.kpi-grid-5 { grid-template-columns: repeat(5, 1fr); }

.kpi-tile {
  background: var(--steel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 12px 12px;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.15s;
}
.kpi-tile:hover { border-color: var(--accent); }

.kpi-tile-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  line-height: 1.3;
  text-transform: none;
  background: rgba(255,255,255,.04);
  padding: 2px 5px;
  border-radius: 3px;
  align-self: flex-start;
}

.kpi-tile-value {
  font-size: 1.3rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.record-meta {
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ════════════════════════════════════════════════════════
   CHARTS
   ════════════════════════════════════════════════════════ */
.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 1.5rem;
  width: 100%;
}
.chart-card {
  background: var(--steel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem 1.25rem;
  min-width: 0;
}
.chart-card canvas {
  width: 100% !important;
  height: 260px !important;
  max-height: 260px;
}
.chart-card-title {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

/* ════════════════════════════════════════════════════════
   DATA TABLES
   ════════════════════════════════════════════════════════ */
.table-wrap {
  overflow-x: visible;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.data-table th {
  background: var(--steel);
  color: var(--text-secondary);
  font-weight: 500;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
  white-space: nowrap;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,.025); }
.data-table .row-empty td { color: var(--text-muted); }
.data-table .row-inactive td { opacity: 0.5; }
.col-brand { font-weight: 500; white-space: nowrap; }
.cell-empty { color: var(--text-muted); }
.cell-mono  { font-family: var(--font-mono); font-size: 0.8rem; }
.cell-details pre {
  font-size: 0.75rem;
  background: var(--navy);
  padding: 6px 8px;
  border-radius: 4px;
  overflow-x: auto;
  max-width: 400px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.cell-details summary { cursor: pointer; color: var(--accent); font-size: 0.8rem; }
.table-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ════════════════════════════════════════════════════════
   FILTER BAR
   ════════════════════════════════════════════════════════ */
.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
  padding: 10px 14px;
  background: var(--steel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

/* ════════════════════════════════════════════════════════
   PAGINATION
   ════════════════════════════════════════════════════════ */
.pagination { display: flex; gap: 4px; margin-top: 1rem; flex-wrap: wrap; }
.page-btn {
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.1s;
}
.page-btn:hover { background: var(--steel-light); text-decoration: none; }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ════════════════════════════════════════════════════════
   DATA ENTRY FORM
   ════════════════════════════════════════════════════════ */
.entry-form { max-width: 760px; }
.entry-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.entry-fieldset legend {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 8px;
}
.legend-note { font-weight: 400; color: var(--text-muted); text-transform: none; letter-spacing: 0; }
.entry-row {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}
.entry-row label { font-size: 0.8rem; color: var(--text-secondary); font-weight: 500; text-align: right; }
.entry-row input { width: 100%; }
.entry-period-bar {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--steel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
}
.entry-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  padding-top: 0.5rem;
}
.entry-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  max-width: 800px;
}
.entry-picker-item {
  background: var(--steel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  color: var(--text-primary);
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
.entry-picker-item:hover { border-color: var(--accent); background: var(--steel-light); text-decoration: none; }
.entry-picker-item strong { display: block; margin-bottom: 4px; }
.entry-picker-item span { font-size: 0.8rem; color: var(--text-secondary); }

/* ════════════════════════════════════════════════════════
   PERMISSIONS TABLE
   ════════════════════════════════════════════════════════ */
.perm-table td, .perm-table th { text-align: left; }
.toggle-label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle-text  { font-size: 0.875rem; color: var(--text-secondary); }

/* ════════════════════════════════════════════════════════
   EMPTY STATE
   ════════════════════════════════════════════════════════ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
  gap: 12px;
}
.empty-icon { font-size: 2.5rem; opacity: 0.5; }
.empty-text { color: var(--text-secondary); font-size: 0.9rem; }
.error { color: var(--danger); padding: 1rem; }


/* ════════════════════════════════════════════════════════
   SORTABLE TABLE HEADERS
   ════════════════════════════════════════════════════════ */
.data-table th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 20px;
}
.data-table th.sortable:hover { color: var(--text-primary); }
.data-table th.sortable::after {
  content: '⇅';
  position: absolute;
  right: 4px;
  opacity: 0.3;
  font-size: 0.7rem;
}
.data-table th.sort-asc::after  { content: '↑'; opacity: 0.9; color: var(--accent); }
.data-table th.sort-desc::after { content: '↓'; opacity: 0.9; color: var(--accent); }
.data-table th.sort-asc,
.data-table th.sort-desc { color: var(--accent); }

/* ════════════════════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .kpi-grid-5 { grid-template-columns: repeat(3, 1fr); }
  .chart-row  { grid-template-columns: 1fr; }
  .chart-card canvas { height: 220px !important; max-height: 220px; }
  .entry-row  { grid-template-columns: 1fr; }
  .entry-row label { text-align: left; }
}
@media (max-width: 600px) {
  .kpi-grid-5 { grid-template-columns: repeat(2, 1fr); }
  .topnav-center { display: none; }
  .main-content { padding: 1rem; }
}
