/* ============================================================
   Campervan.Win Admin Dashboard
   ============================================================ */

:root {
  --gold: #fad135;
  --red: #e40b25;
  --green: #16a34a;
  --dark: #1a1a1a;
  --white: #ffffff;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --font-heading: 'Bebas Neue', 'Arial Black', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-width: 220px;
}

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

body {
  font-family: var(--font-body);
  background: var(--gray-50);
  color: var(--gray-800);
  display: flex;
  min-height: 100vh;
}

/* ============ Sidebar ============ */

#sidebar {
  width: var(--sidebar-width);
  background: var(--gold);
  color: var(--dark);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 24px 20px;
  text-align: center;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}

.sidebar-logo img {
  width: 70px;
}

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

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: rgba(26,26,26,0.55);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}

.sidebar-nav li a:hover {
  color: var(--dark);
  background: rgba(0,0,0,0.06);
}

.sidebar-nav li a.active {
  color: var(--dark);
  border-left-color: var(--dark);
  background: rgba(0,0,0,0.08);
}

.sidebar-nav li a svg {
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(0,0,0,0.08);
}

.btn-sync {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  background: rgba(0,0,0,0.08);
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 8px;
  color: var(--dark);
  font-size: 13px;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 600;
}

.btn-sync:hover {
  background: rgba(0,0,0,0.14);
  color: var(--dark);
}

.btn-sync.syncing svg {
  animation: spin 1s linear infinite;
}

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

/* ============ Main Content ============ */

#app {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 32px;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 28px;
}

.page-header h1 {
  font-family: var(--font-heading);
  font-size: 32px;
  font-weight: 400;
  letter-spacing: 1.2px;
  color: var(--dark);
}

.page-header p {
  color: var(--gray-500);
  font-size: 14px;
  margin-top: 4px;
}

/* ============ Stat Cards ============ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--white);
  border-radius: 12px;
  padding: 20px 24px;
  border: 1px solid var(--gray-200);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
}

.stat-card .stat-value {
  font-family: var(--font-heading);
  font-size: 36px;
  font-weight: 400;
  color: var(--dark);
  margin-top: 4px;
  letter-spacing: 0.5px;
}

.stat-card .stat-value.red {
  color: var(--red);
}

/* ============ Tables ============ */

.card {
  background: var(--white);
  border-radius: 12px;
  border: 1px solid var(--gray-200);
  overflow: hidden;
  margin-bottom: 24px;
}

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

.card-header h2 {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.8px;
  color: var(--dark);
}

.card-body {
  padding: 0;
}

.card-body.padded {
  padding: 24px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-500);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

table td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

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

table tr:hover {
  background: var(--gray-50);
}

table tr.clickable,
table td.clickable {
  cursor: pointer;
}

table tr.error-row {
  background: #fef2f2;
}

table tr.error-row:hover {
  background: #fee2e2;
}

/* ============ Badges ============ */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.badge-live { background: #dcfce7; color: #166534; }
.badge-upcoming { background: #fef9c3; color: #854d0e; }
.badge-scheduled { background: #dbeafe; color: #1e40af; }
.badge-ended { background: var(--gray-100); color: var(--gray-600); }
.badge-sold_out { background: #fce7f3; color: #9d174d; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-canceled { background: var(--gray-100); color: var(--gray-600); }
.badge-past_due { background: #fed7aa; color: #9a3412; }
.badge-one_off { background: #dbeafe; color: #1e40af; }
.badge-membership { background: #f3e8ff; color: #6b21a8; }
.badge-campervan { background: var(--gold); color: var(--dark); }
.badge-bonus { background: #dbeafe; color: #1e40af; }
.badge-yes { background: #dcfce7; color: #166534; }
.badge-no { background: var(--gray-100); color: var(--gray-500); }
.badge-error { background: #fef2f2; color: var(--red); }
.badge-ok { background: #dcfce7; color: #166534; }
.badge-allocated { background: #dbeafe; color: #1e40af; }
.badge-pending { background: #fef9c3; color: #854d0e; }

/* ============ Progress Bar ============ */

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar .fill {
  height: 100%;
  background: var(--red);
  border-radius: 3px;
  transition: width 0.3s;
}

.progress-text {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
}

/* ============ Range Slider (Red) ============ */

.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  margin: 0;
}

/* Filled track (WebKit via JS background-image) */
.range-slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
}

/* Thumb — WebKit */
.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--red);
  border: 2px solid var(--white);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  margin-top: -6px;
  cursor: grab;
  transition: transform 0.1s;
}

.range-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.15);
}

/* Thumb — Firefox */
.range-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--red);
  border: 2px solid var(--white);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  cursor: grab;
}

.range-slider::-moz-range-thumb:active {
  cursor: grabbing;
  transform: scale(1.15);
}

/* Track fill — Firefox */
.range-slider::-moz-range-progress {
  height: 6px;
  background: var(--red);
  border-radius: 3px;
}

.range-slider::-moz-range-track {
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
}

/* ============ Buttons ============ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--red);
  color: var(--white);
}

.btn-primary:hover {
  background: #c0091f;
}

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
}

.btn-secondary:hover {
  background: var(--gray-200);
}

.btn-gold {
  background: var(--gold);
  color: var(--dark);
}

.btn-gold:hover {
  background: #e8c22e;
}

.btn-danger {
  background: #fef2f2;
  color: var(--red);
  border: 1px solid #fecaca;
}

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
}

/* ============ Forms / Inputs ============ */

.search-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.search-bar input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.15s;
}

.search-bar input:focus {
  border-color: var(--gold);
}

.search-bar select {
  padding: 10px 16px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font-body);
  outline: none;
  background: var(--white);
  cursor: pointer;
}

.inline-edit {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-edit input {
  padding: 6px 10px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--font-body);
  outline: none;
  width: 200px;
}

.inline-edit input:focus {
  border-color: var(--gold);
}

/* ============ Winner Card ============ */

.winner-card {
  background: var(--dark);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  margin: 16px 0;
}

.winner-card .winner-label {
  color: var(--gold);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}

.winner-card .winner-ticket {
  font-family: var(--font-heading);
  color: var(--white);
  font-size: 48px;
  margin: 8px 0;
  letter-spacing: 2px;
}

.winner-card .winner-name {
  color: var(--gray-400);
  font-size: 14px;
}

.winner-card .winner-email {
  color: var(--gold);
  font-size: 14px;
  margin-top: 4px;
}

/* ============ Modal ============ */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

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

.modal {
  background: var(--white);
  border-radius: 16px;
  padding: 32px;
  max-width: 480px;
  width: 90%;
  text-align: center;
}

.modal h3 {
  font-family: var(--font-heading);
  font-size: 24px;
  font-weight: 400;
  letter-spacing: 1px;
  margin-bottom: 16px;
}

.modal p {
  color: var(--gray-600);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 8px;
}

.modal .modal-stats {
  background: var(--gray-50);
  border-radius: 10px;
  padding: 16px;
  margin: 16px 0;
}

.modal .modal-stats p {
  margin: 4px 0;
}

.modal .modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
}

/* ============ Filters Row ============ */

.filters-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.filters-row input,
.filters-row select {
  padding: 8px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font-body);
  outline: none;
  background: var(--white);
  transition: border-color 0.15s;
}

.filters-row input:focus,
.filters-row select:focus {
  border-color: var(--gold);
}

/* ============ Form Grid ============ */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-500);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 8px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus {
  border-color: var(--gold);
}

/* ============ Detail Grid ============ */

.detail-grid {
  display: grid;
  gap: 0;
}

.detail-row {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
}

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

.detail-label {
  width: 200px;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-500);
}

.detail-value {
  font-size: 14px;
  color: var(--gray-800);
  word-break: break-all;
}

/* ============ Pagination ============ */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-top: 1px solid var(--gray-100);
}

.pagination .page-info,
.pagination .pagination-info {
  font-size: 13px;
  color: var(--gray-500);
}

.pagination .page-controls {
  display: flex;
  gap: 8px;
}

/* ============ Hidden utility ============ */

.hidden {
  display: none !important;
}

/* ============ Back Link ============ */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--gray-500);
  text-decoration: none;
  font-size: 13px;
  margin-bottom: 16px;
  transition: color 0.15s;
}

.back-link:hover {
  color: var(--dark);
}

/* ============ Detail Header ============ */

.detail-header {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 28px;
}

.detail-header img {
  width: 120px;
  height: 80px;
  object-fit: cover;
  border-radius: 10px;
}

.detail-header .detail-info h1 {
  font-family: var(--font-heading);
  font-size: 28px;
  font-weight: 400;
  letter-spacing: 1px;
}

.detail-header .detail-meta {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* ============ Notification Badges ============ */

.notify-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
}

.notify-badge.sent {
  background: #dcfce7;
  color: #166534;
}

.notify-badge.pending {
  background: #fef9c3;
  color: #854d0e;
}

/* ============ Loading ============ */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: var(--gray-400);
  font-size: 14px;
}

/* ============ Empty State ============ */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-400);
}

.empty-state p {
  font-size: 14px;
}

/* ============ Sidebar Search ============ */

.sidebar-search {
  padding: 8px 16px 4px;
  position: relative;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 8px;
  font-size: 13px;
  font-family: var(--font-body);
  background: rgba(255,255,255,0.5);
  color: var(--dark);
  outline: none;
  transition: all 0.15s;
}

.sidebar-search input::placeholder {
  color: rgba(26,26,26,0.35);
}

.sidebar-search input:focus {
  background: rgba(255,255,255,0.85);
  border-color: rgba(0,0,0,0.2);
}

.search-dropdown {
  position: absolute;
  top: 100%;
  left: 16px;
  right: 16px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 150;
  max-height: 400px;
  overflow-y: auto;
  margin-top: 4px;
}

.search-section {
  padding: 8px 0;
  border-bottom: 1px solid var(--gray-100);
}

.search-section:last-child {
  border-bottom: none;
}

.search-section-title {
  padding: 4px 14px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--gray-400);
}

.search-item {
  display: block;
  padding: 8px 14px;
  text-decoration: none;
  color: var(--gray-800);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s;
}

.search-item:hover {
  background: var(--gray-50);
}

.search-meta {
  font-size: 11px;
  color: var(--gray-400);
  font-weight: 400;
  margin-top: 1px;
}

.search-empty {
  padding: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--gray-400);
}

/* ============ Nav Badge ============ */

.nav-badge {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  background: var(--red);
  color: var(--white);
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
  letter-spacing: 0.5px;
  animation: badgePulse 2s ease-in-out infinite;
}

@keyframes badgePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ============ Refresh Dot ============ */

.refresh-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  opacity: 0.4;
  transition: opacity 0.3s;
}

.refresh-dot.pulse {
  opacity: 1;
  animation: refreshPulse 1s ease-out;
}

@keyframes refreshPulse {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.6); opacity: 0.6; }
  100% { transform: scale(1); opacity: 0.4; }
}

/* ============ Revenue Chart ============ */

.revenue-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 160px;
  padding-bottom: 20px;
  position: relative;
}

.chart-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  position: relative;
  cursor: default;
}

.chart-bar {
  width: 100%;
  background: var(--red);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: opacity 0.15s;
  opacity: 0.7;
}

.chart-bar:hover {
  opacity: 1;
}

.chart-bar.today {
  background: var(--gold);
  opacity: 1;
}

.chart-label {
  position: absolute;
  bottom: -18px;
  font-size: 9px;
  color: var(--gray-400);
  text-align: center;
}

/* ============ Audit Log ============ */

.audit-detail {
  display: none;
}

.audit-detail.show {
  display: table-row;
}

.audit-detail td {
  background: var(--gray-50);
  padding: 16px 24px;
}

.audit-detail pre {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  line-height: 1.5;
  background: var(--dark);
  color: var(--gray-300);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.badge-competition_updated { background: #dbeafe; color: #1e40af; }
.badge-competitions_bulk_updated { background: #f3e8ff; color: #6b21a8; }
.badge-draw_executed { background: #fef9c3; color: #854d0e; }
.badge-winner_notified { background: #dcfce7; color: #166534; }
.badge-entrants_notified { background: #dcfce7; color: #166534; }
.badge-customer_updated { background: #dbeafe; color: #1e40af; }
.badge-order_updated { background: #dbeafe; color: #1e40af; }
.badge-webflow_synced { background: var(--gold); color: var(--dark); }
.badge-manual_sync { background: var(--gray-100); color: var(--gray-600); }

/* ============ Loading Skeletons ============ */

.skeleton-page {
  animation: skeletonFade 1s ease-in-out infinite alternate;
}

@keyframes skeletonFade {
  0% { opacity: 0.4; }
  100% { opacity: 1; }
}

.skeleton {
  background: var(--gray-200);
  border-radius: 8px;
}

.skeleton-title {
  height: 32px;
  width: 240px;
  margin-bottom: 8px;
}

.skeleton-subtitle {
  height: 16px;
  width: 160px;
}

.skeleton-card {
  height: 80px;
}

.skeleton-table {
  height: 300px;
  margin-top: 8px;
}

/* ============ Responsive Table Wrapper ============ */

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ============ Responsive ============ */

@media (max-width: 768px) {
  #sidebar {
    width: 100%;
    position: relative;
    flex-direction: row;
    height: auto;
  }

  .sidebar-logo {
    padding: 12px 16px;
    border-bottom: none;
  }

  .sidebar-logo img {
    width: 40px;
  }

  .sidebar-nav {
    display: flex;
    padding: 0;
    overflow-x: auto;
  }

  .sidebar-nav li a {
    padding: 12px 16px;
    border-left: none;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
  }

  .sidebar-nav li a.active {
    border-bottom-color: var(--gold);
    border-left-color: transparent;
  }

  .sidebar-footer {
    display: none;
  }

  #app {
    margin-left: 0;
    padding: 20px;
  }

  body {
    flex-direction: column;
  }

  .sidebar-search {
    display: none;
  }

  .card-body {
    overflow-x: auto;
  }

  table {
    min-width: 600px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .detail-header {
    flex-direction: column;
  }

  .detail-header img {
    width: 100%;
    height: 160px;
  }

  .filters-row {
    flex-wrap: wrap;
  }
}
