/* ============================================================
   SelectDrive Admin Dashboard, Stylesheet
   ============================================================ */

:root {
  /* Marketing site palette */
  --blue: #4f8bd0;
  --navy: #3d628d;
  --accent: #c47315;
  --ink: #171717;
  --muted: #68635d;
  --bg: #f6f3ee;

  /* Admin-specific */
  --sidebar-bg: #0f1117;
  --sidebar-text: #a3a3a3;
  --sidebar-active: #fff;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;

  /* Derived */
  --card-bg: #fff;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.1);
  --radius: 8px;
  --radius-sm: 4px;
  --sidebar-width: 240px;
  --transition: 0.2s ease;
}

/* ---- Reset & Base ---- */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ---- Layout ---- */

.admin-layout {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-logo {
  padding: 1.25rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 64px;
}

.sidebar-logo img {
  width: 130px;
  height: auto;
}

.sidebar-logo .badge {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--accent);
  color: #fff;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
  overflow-y: auto;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 1.25rem;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all var(--transition);
}

.sidebar-nav a:hover {
  color: var(--sidebar-active);
  background: rgba(255, 255, 255, 0.04);
  text-decoration: none;
}

.sidebar-nav a.active {
  color: var(--sidebar-active);
  border-left-color: var(--accent);
  background: rgba(255, 255, 255, 0.06);
  font-weight: 500;
}

.sidebar-nav .nav-icon {
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
  font-size: 1rem;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.3);
}

/* ---- Main Content ---- */

.main-content,
.content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  padding: 2rem;
}

.content-wrapper {
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

/* ---- Hamburger (mobile) ---- */

.hamburger {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 200;
  background: var(--sidebar-bg);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.625rem;
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

/* ---- Stats Grid ---- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 1.25rem 1.5rem;
  transition: box-shadow var(--transition);
}

.stat-card:hover {
  box-shadow: var(--card-shadow-hover);
}

.stat-card .stat-number {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
}

.stat-card .stat-label {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.stat-card .stat-change {
  font-size: 0.75rem;
  margin-top: 0.5rem;
  font-weight: 500;
}

.stat-card .stat-change.up {
  color: var(--success);
}

.stat-card .stat-change.down {
  color: var(--danger);
}

/* ---- Pipeline Funnel ---- */

.pipeline-funnel {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-bottom: 1.5rem;
}

.pipeline-funnel .funnel-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 0.85rem 0.5rem;
  text-align: center;
  min-width: 0;
}

.pipeline-funnel .funnel-bar .funnel-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.pipeline-funnel .funnel-bar .funnel-count {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
}

.funnel-bar[data-stage="new"]       { border-top: 3px solid var(--blue); }
.funnel-bar[data-stage="contacted"] { border-top: 3px solid #8b5cf6; }
.funnel-bar[data-stage="qualified"] { border-top: 3px solid var(--accent); }
.funnel-bar[data-stage="proposal"]  { border-top: 3px solid #ec4899; }
.funnel-bar[data-stage="booked"]    { border-top: 3px solid var(--success); }
.funnel-bar[data-stage="completed"] { border-top: 3px solid #10b981; }

/* ---- Data Table ---- */

.data-table-wrapper {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead {
  background: #fafaf8;
  border-bottom: 1px solid #e8e5df;
}

.data-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
  cursor: default;
  user-select: none;
}

.data-table th.sortable {
  cursor: pointer;
}

.data-table th.sortable:hover {
  color: var(--ink);
}

.data-table th.sortable::after {
  content: " \2195";
  font-size: 0.65rem;
  opacity: 0.4;
}

.data-table th.sort-asc::after {
  content: " \2191";
  opacity: 1;
}

.data-table th.sort-desc::after {
  content: " \2193";
  opacity: 1;
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f0ede8;
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background var(--transition);
}

.data-table tbody tr:hover {
  background: #fdfcfa;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* ---- Badges ---- */

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.6;
  white-space: nowrap;
}

.badge-lead       { background: #dbeafe; color: #1e40af; }
.badge-contacted  { background: #ede9fe; color: #5b21b6; }
.badge-opportunity { background: #fef3c7; color: #92400e; }
.badge-proposal   { background: #fce7f3; color: #9d174d; }
.badge-won        { background: #dcfce7; color: #166534; }
.badge-lost       { background: #f3f4f6; color: #4b5563; }

.badge-pending    { background: #fef3c7; color: #92400e; }
.badge-confirmed  { background: #dbeafe; color: #1e40af; }
.badge-completed  { background: #dcfce7; color: #166534; }
.badge-cancelled  { background: #fee2e2; color: #991b1b; }
.badge-noshow     { background: #f3f4f6; color: #4b5563; }

/* ---- Modal ---- */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.75rem;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--muted);
  padding: 0.25rem;
  line-height: 1;
}

.modal-close:hover {
  color: var(--ink);
}

.modal h2 {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1.125rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  line-height: 1.4;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}

.btn-primary:hover {
  background: var(--navy);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  background: #a86210;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-outline {
  background: transparent;
  border: 1px solid #d5d1cb;
  color: var(--ink);
}

.btn-outline:hover {
  background: #f0ede8;
}

.btn-sm {
  padding: 0.3rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-lg {
  padding: 0.65rem 1.5rem;
  font-size: 1rem;
}

/* ---- Search Bar ---- */

.search-bar {
  width: 100%;
  padding: 0.625rem 1rem 0.625rem 2.5rem;
  border: 1px solid #d5d1cb;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.875rem;
  background: var(--card-bg);
  color: var(--ink);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-bar:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(79, 139, 208, 0.15);
}

.search-bar-wrapper {
  position: relative;
  margin-bottom: 1rem;
}

.search-bar-wrapper::before {
  content: "\1F50D";
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.875rem;
  pointer-events: none;
}

/* ---- Filter Row ---- */

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.filter-row select,
.filter-row input[type="date"] {
  padding: 0.45rem 0.75rem;
  border: 1px solid #d5d1cb;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.8125rem;
  background: var(--card-bg);
  color: var(--ink);
}

.filter-row select:focus,
.filter-row input[type="date"]:focus {
  outline: none;
  border-color: var(--blue);
}

.filter-row label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ---- Activity Timeline ---- */

.activity-timeline {
  position: relative;
  padding-left: 1.75rem;
}

.activity-timeline::before {
  content: "";
  position: absolute;
  left: 0.5rem;
  top: 0.5rem;
  bottom: 0.5rem;
  width: 2px;
  background: #e8e5df;
}

.timeline-item {
  position: relative;
  padding-bottom: 1.25rem;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -1.375rem;
  top: 0.4rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--blue);
  border: 2px solid var(--bg);
}

.timeline-item.event-call::before    { background: #8b5cf6; }
.timeline-item.event-email::before   { background: var(--accent); }
.timeline-item.event-note::before    { background: var(--muted); }
.timeline-item.event-booking::before { background: var(--success); }
.timeline-item.event-stage::before   { background: #ec4899; }

.timeline-item .timeline-time {
  font-size: 0.6875rem;
  color: var(--muted);
  margin-bottom: 0.125rem;
}

.timeline-item .timeline-text {
  font-size: 0.875rem;
  color: var(--ink);
}

/* ---- Calendar Grid ---- */

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: #e8e5df;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.calendar-grid .cal-header {
  background: #fafaf8;
  padding: 0.5rem;
  text-align: center;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.calendar-grid .cal-day {
  background: var(--card-bg);
  padding: 0.5rem;
  min-height: 80px;
  font-size: 0.75rem;
}

.calendar-grid .cal-day .cal-date {
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.25rem;
}

.calendar-grid .cal-day.cal-today .cal-date {
  background: var(--blue);
  color: #fff;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.calendar-grid .cal-day.cal-other {
  color: #ccc;
  background: #fdfcfa;
}

.calendar-grid .cal-event {
  display: block;
  padding: 0.125rem 0.25rem;
  border-radius: 2px;
  font-size: 0.625rem;
  margin-bottom: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #dbeafe;
  color: #1e40af;
}

.calendar-grid .cal-event.cal-conflict {
  background: #fee2e2;
  color: #991b1b;
}

/* ---- Alert Banner ---- */

.alert-banner {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 1rem;
}

.alert-banner.visible {
  display: flex;
}

.alert-banner .alert-close {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 1.125rem;
  cursor: pointer;
  opacity: 0.6;
  color: inherit;
  line-height: 1;
}

.alert-banner .alert-close:hover {
  opacity: 1;
}

.alert-banner.alert-warning {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.alert-banner.alert-danger {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-banner.alert-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.alert-banner.alert-info {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

/* ---- Auth Gate ---- */

.gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--sidebar-bg);
  color: #fff;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.gate.open {
  display: flex;
}

.gate-box {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.gate-box h1 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.gate-box p {
  font-size: 0.875rem;
  color: var(--sidebar-text);
  margin-bottom: 1.5rem;
}

.gate-box input {
  width: 100%;
  padding: 0.625rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-family: inherit;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.gate-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.gate-box .btn {
  width: 100%;
  justify-content: center;
}

/* ---- Utility ---- */

.text-muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-2 { margin-top: 1rem; }

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Quick Quote Tool ---- */

.quick-quote-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.quick-quote-section h2 {
  margin-bottom: 0.25rem;
}

.section-desc {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.quick-quote-form .form-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  align-items: end;
}

.quick-quote-form .form-group {
  flex: 1;
  min-width: 120px;
}

.quick-quote-form label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.25rem;
}

.quick-quote-form label input[type="checkbox"] {
  margin-right: 0.4rem;
}

.quick-quote-form input,
.quick-quote-form select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d5d1cb;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  background: #fff;
  color: var(--ink);
}

.quick-quote-form input:focus,
.quick-quote-form select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(79, 139, 208, 0.15);
}

.qq-result {
  margin-top: 1rem;
  padding: 1.25rem;
  background: #fafaf8;
  border-radius: var(--radius);
  border: 1px solid #e8e5df;
}

.qq-result h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.qq-feasibility {
  margin-bottom: 0.75rem;
}

.badge-good {
  display: inline-block;
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #dcfce7;
  color: #166534;
}

.badge-warn {
  display: inline-block;
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #fef3c7;
  color: #92400e;
}

.badge-bad {
  display: inline-block;
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #fee2e2;
  color: #991b1b;
}

.qq-warnings {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
}

.qq-warnings li {
  font-size: 0.8125rem;
  color: var(--warning);
  padding: 0.15rem 0;
}

.qq-logistics {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.8125rem;
}

.qq-breakdown {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.qq-breakdown td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid #e8e5df;
}

.qq-breakdown td:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.qq-breakdown .total-row td {
  border-top: 2px solid var(--ink);
  border-bottom: none;
  padding-top: 0.5rem;
}

.qq-days {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

.qq-result .error {
  color: var(--danger);
  font-weight: 500;
}

/* ---- Responsive ---- */

@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .hamburger {
    display: block;
  }

  .main-content,
  .content {
    margin-left: 0;
  }

  .content-wrapper {
    padding: 1rem;
    padding-top: 3.5rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .pipeline-funnel {
    flex-direction: column;
    height: auto;
  }

  .pipeline-funnel .funnel-stage {
    padding: 0.5rem;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .filter-row {
    flex-direction: column;
    align-items: stretch;
  }

  .calendar-grid .cal-day {
    min-height: 50px;
    padding: 0.25rem;
  }

  .modal {
    max-width: 100%;
    margin: 1rem;
  }

  .data-table-wrapper {
    overflow-x: auto;
  }
}
