/* ========== CSS Variables & Theme ========== */
:root {
  --bg-primary: #f2f2f7;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e5e5ea;
  --text-primary: #1c1c1e;
  --text-secondary: #636366;
  --text-tertiary: #aeaeb2;
  --accent: #007aff;
  --accent-hover: #005ecb;
  --border: #c6c6c8;
  --row-even: #ffffff;
  --row-odd: #f9f9fb;
  --queue-green: #34c759;
  --queue-orange: #ff9500;
  --queue-red: #ff3b30;
  --header-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  --header-text: #ffffff;
  --shadow: 0 2px 10px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  --bg-primary: #1c1c1e;
  --bg-secondary: #2c2c2e;
  --bg-tertiary: #3a3a3c;
  --text-primary: #f2f2f7;
  --text-secondary: #aeaeb2;
  --text-tertiary: #636366;
  --border: #48484a;
  --row-even: #2c2c2e;
  --row-odd: #333338;
  --shadow: 0 2px 10px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.4);
}

/* ========== Base Reset ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

/* ========== App Container ========== */
#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

/* ========== Header ========== */
header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 24px;
  border-radius: 0 0 var(--radius) var(--radius);
  margin: 0 -16px 24px;
  box-shadow: var(--shadow-lg);
}

header h1 {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.park-hours {
  text-align: center;
  font-size: 14px;
  opacity: 0.85;
  margin-bottom: 16px;
  min-height: 20px;
}

.park-hours:empty {
  display: none;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  align-items: center;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.control-group label {
  font-size: 14px;
  font-weight: 500;
  opacity: 0.9;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius-sm);
  padding: 8px 32px 8px 12px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  backdrop-filter: blur(10px);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='white' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: background 0.2s;
}

select:hover {
  background-color: rgba(255,255,255,0.25);
}

select option {
  background: #2c2c2e;
  color: white;
}

.refresh-btn {
  background: rgba(255,255,255,0.2);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

.refresh-btn:hover {
  background: rgba(255,255,255,0.35);
  transform: scale(1.02);
}

.refresh-btn:active {
  transform: scale(0.98);
}

.theme-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.theme-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: rotate(20deg);
}

/* ========== Search Box ========== */
.search-container {
  margin-bottom: 20px;
}

.search-box {
  position: relative;
  max-width: 500px;
  margin: 0 auto;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  pointer-events: none;
  z-index: 1;
}

#search-input {
  width: 100%;
  padding: 12px 44px 12px 44px;
  font-size: 15px;
  font-family: inherit;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 2px solid var(--border);
  border-radius: 50px;
  outline: none;
  transition: all 0.25s ease;
  box-shadow: var(--shadow);
}

#search-input::placeholder {
  color: var(--text-tertiary);
  font-weight: 400;
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15), var(--shadow);
}

[data-theme="dark"] #search-input:focus {
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.25), var(--shadow);
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-tertiary);
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.search-clear:hover {
  background: var(--border);
  color: var(--text-primary);
}

.search-result-count {
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 6px;
}

/* ========== Loading & Error ========== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  font-size: 16px;
  color: var(--text-secondary);
}

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

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

.error {
  background: #fff3f3;
  color: #c00;
  padding: 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  border: 1px solid #fcc;
  font-size: 14px;
}

[data-theme="dark"] .error {
  background: #3a1c1c;
  border-color: #5a2c2c;
  color: #ff6b6b;
}

.hidden {
  display: none !important;
}

/* ========== Sections ========== */
.section {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
  transition: background 0.3s;
}

.section h2 {
  font-size: 18px;
  font-weight: 600;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}

/* ========== Tables ========== */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

thead th {
  background: var(--bg-tertiary);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

th.sortable:hover {
  background: var(--border);
}

.sort-arrow {
  font-size: 10px;
  margin-left: 4px;
  opacity: 0.4;
}

th.sort-asc .sort-arrow::after {
  content: ' ▲';
  opacity: 1;
}

th.sort-desc .sort-arrow::after {
  content: ' ▼';
  opacity: 1;
}

tbody tr {
  transition: background 0.15s;
}

tbody tr:nth-child(even) {
  background: var(--row-even);
}

tbody tr:nth-child(odd) {
  background: var(--row-odd);
}

tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 8%, var(--bg-secondary));
}

td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

td:first-child {
  font-weight: 500;
}

/* ========== Queue Color Coding ========== */
.queue-green {
  color: var(--queue-green);
  font-weight: 700;
}

.queue-orange {
  color: var(--queue-orange);
  font-weight: 700;
}

.queue-red {
  color: var(--queue-red);
  font-weight: 700;
}

.queue-na {
  color: var(--text-tertiary);
  font-style: italic;
}

/* ========== Status Badges ========== */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.status-operating {
  background: #d4edda;
  color: #155724;
}

.status-closed {
  background: #f8d7da;
  color: #721c24;
}

.status-down {
  background: #fff3cd;
  color: #856404;
}

[data-theme="dark"] .status-operating {
  background: #1a3a1a;
  color: #6bcf6b;
}

[data-theme="dark"] .status-closed {
  background: #3a1a1a;
  color: #f08080;
}

[data-theme="dark"] .status-down {
  background: #3a3a1a;
  color: #f0c060;
}

/* ========== Location Links ========== */
.location-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.location-link:hover {
  text-decoration: underline;
}

/* ========== Height Requirement ========== */
.height-req {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ========== FP / Return Time ========== */
.fp-time {
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
}

.showtime {
  font-weight: 600;
  font-size: 13px;
}

/* ========== History Section ========== */
.history-log {
  padding: 16px 20px;
  max-height: 300px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.8;
  color: var(--text-secondary);
}

.history-entry {
  padding: 2px 0;
  border-bottom: 1px solid var(--border);
}

.clear-btn {
  display: inline-block;
  margin: 8px 20px 16px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.clear-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
  font-size: 15px;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  header h1 {
    font-size: 22px;
  }

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

  .control-group {
    justify-content: center;
  }

  table {
    font-size: 13px;
  }

  td, thead th {
    padding: 8px 10px;
  }

  .section h2 {
    font-size: 16px;
    padding: 12px 16px;
  }
}

@media (max-width: 480px) {
  header {
    padding: 16px;
  }

  header h1 {
    font-size: 20px;
  }

  table {
    font-size: 12px;
  }

  td, thead th {
    padding: 6px 8px;
  }
}

/* ========== Scrollbar Styling ========== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ========== Last Updated ========== */
.last-updated {
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 8px;
  padding: 8px;
}
