/* ===== DESIGN TOKENS ===== */
:root {
  --bg-primary: #111111;
  --bg-secondary: #1a1a1a;
  --bg-card: #1e1e1e;
  --bg-card-hover: #252525;
  --text-primary: #e0e0e0;
  --text-secondary: #999999;
  --text-dimmed: #555555;
  --accent: #00bcd4;
  --accent-dim: rgba(0, 188, 212, 0.15);
  --status-landed: #4caf50;
  --status-enroute: #2196f3;
  --status-scheduled: #757575;
  --status-delayed: #ff9800;
  --status-departed: #4caf50;
  --border: #2a2a2a;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --header-height: 48px;
  --subtab-height: 44px;
  --bottomtab-height: 56px;
  --statusbar-height: 32px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #eeeeee;
    --bg-card: #ffffff;
    --bg-card-hover: #fafafa;
    --text-primary: #222222;
    --text-secondary: #666666;
    --text-dimmed: #aaaaaa;
    --border: #e0e0e0;
    --accent-dim: rgba(0, 188, 212, 0.08);
  }
}

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== HEADER ===== */
#app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.app-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

#last-updated {
  font-size: 12px;
  color: var(--text-secondary);
}

#refresh-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

#refresh-btn:active {
  background: var(--accent-dim);
}

#refresh-btn.spinning svg {
  animation: spin 0.8s linear;
}

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

/* ===== MAIN CONTENT ===== */
#tab-content {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: calc(var(--bottomtab-height) + var(--statusbar-height) + var(--safe-bottom));
  overflow: hidden;
}

.tab-panel {
  display: none;
  height: 100%;
  flex-direction: column;
}

.tab-panel.active {
  display: flex;
}

/* ===== SUB-TABS ===== */
.sub-tabs {
  display: flex;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sub-tab {
  flex: 1;
  height: var(--subtab-height);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.sub-tab.active {
  color: var(--accent);
}

.sub-tab.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 3px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
}

/* ===== FLIGHT LIST ===== */
.subtab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.subtab-panel.active {
  display: block;
}

.subtab-panel::-webkit-scrollbar {
  display: none;
}

.subtab-panel {
  scrollbar-width: none;
}

.flight-list {
  padding: 4px 0;
}

/* ===== FLIGHT CARD ===== */
.flight-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: opacity 0.3s, background 0.15s;
}

.flight-card:active {
  background: var(--bg-card-hover);
}

.flight-card.landed {
  opacity: 0.45;
}

.flight-card.departed {
  opacity: 0.45;
}

.flight-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.flight-ident {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.flight-place {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.flight-type {
  font-size: 11px;
  color: var(--text-dimmed);
}

.flight-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 12px;
}

.flight-time {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.flight-time.estimated {
  font-style: italic;
}

/* ===== STATUS BADGES ===== */
.status-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.status-badge.badge-sm {
  font-size: 9px;
  padding: 1px 6px;
}

.status-dual {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.status-landed {
  background: rgba(76, 175, 80, 0.15);
  color: var(--status-landed);
}

.status-departed {
  background: rgba(76, 175, 80, 0.15);
  color: var(--status-departed);
}

.status-en-route {
  background: rgba(33, 150, 243, 0.15);
  color: var(--status-enroute);
}

.status-scheduled {
  background: rgba(117, 117, 117, 0.2);
  color: var(--status-scheduled);
}

.status-delayed {
  background: rgba(255, 152, 0, 0.15);
  color: var(--status-delayed);
}

.status-cancelled {
  background: rgba(244, 67, 54, 0.15);
  color: #f44336;
}

.flight-time-orig {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dimmed);
  text-decoration: line-through;
  margin-left: 4px;
}

.flight-time-alt {
  font-size: 11px;
  color: var(--status-delayed);
  font-style: italic;
}

/* ===== SECTION HEADERS ===== */
.section-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dimmed);
  padding: 12px 16px 6px;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 60px 24px;
  font-size: 14px;
}

/* ===== STATUS BAR ===== */
#status-bar {
  position: fixed;
  bottom: calc(var(--bottomtab-height) + var(--safe-bottom));
  left: 0;
  right: 0;
  height: var(--statusbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dimmed);
  z-index: 100;
}

.ga-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ga-toggle input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
}

#countdown {
  font-variant-numeric: tabular-nums;
}

#offline-badge {
  background: rgba(244, 67, 54, 0.15);
  color: #f44336;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 8px;
}

/* ===== BOTTOM TAB BAR ===== */
#bottom-tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottomtab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  z-index: 100;
}

.bottom-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-dimmed);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s;
  min-height: 48px;
}

.bottom-tab.active {
  color: var(--accent);
}

.bottom-tab svg {
  transition: transform 0.2s;
}

.bottom-tab:active svg {
  transform: scale(0.9);
}

/* ===== BIN CHECKER ===== */
.bin-container {
  padding: 16px;
  overflow-y: auto;
  height: 100%;
  -webkit-overflow-scrolling: touch;
}

.bin-input-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

#bin-input {
  flex: 1;
  height: 56px;
  padding: 0 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 22px;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  outline: none;
  transition: border-color 0.2s;
}

#bin-input:focus {
  border-color: var(--accent);
}

.bin-btn-row {
  display: flex;
  gap: 10px;
}

#bin-search-btn, #bin-clear-btn {
  flex: 1;
  height: 56px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  color: #fff;
}

#bin-search-btn {
  background: var(--accent);
}

#bin-clear-btn {
  background: #757575;
}

#bin-search-btn:active, #bin-clear-btn:active {
  opacity: 0.8;
}

.bin-card {
  border-radius: 12px;
  padding: 16px;
  animation: fadeInUp 0.25s ease-out;
}

.bin-good {
  background: rgba(76, 175, 80, 0.12);
  border: 1px solid rgba(76, 175, 80, 0.3);
}

.bin-bad {
  background: rgba(244, 67, 54, 0.12);
  border: 1px solid rgba(244, 67, 54, 0.3);
}

.bin-status-header {
  font-size: 20px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.bin-good .bin-status-header {
  color: var(--status-landed);
}

.bin-bad .bin-status-header {
  color: #f44336;
}

.bin-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bin-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.bin-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.bin-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  text-align: right;
}

.bin-loading {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px;
}

.bin-error {
  text-align: center;
  color: var(--status-delayed);
  padding: 20px;
  font-size: 14px;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.flight-card {
  animation: fadeInUp 0.25s ease-out both;
}

.flight-card:nth-child(1) { animation-delay: 0s; }
.flight-card:nth-child(2) { animation-delay: 0.02s; }
.flight-card:nth-child(3) { animation-delay: 0.04s; }
.flight-card:nth-child(4) { animation-delay: 0.06s; }
.flight-card:nth-child(5) { animation-delay: 0.08s; }
.flight-card:nth-child(6) { animation-delay: 0.1s; }
.flight-card:nth-child(7) { animation-delay: 0.12s; }
.flight-card:nth-child(8) { animation-delay: 0.14s; }
.flight-card:nth-child(9) { animation-delay: 0.16s; }
.flight-card:nth-child(10) { animation-delay: 0.18s; }
