/* ==========================================================
   Flight Information Dashboard – Airport-inspired dark theme
   ========================================================== */

/* ---------- CSS Custom Properties ---------- */
:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2332;
  --bg-card-hover: #1f2b3d;
  --bg-input: #0d1520;
  --border-color: #1e2d42;
  --border-active: #3b82f6;

  --text-primary: #e8edf5;
  --text-secondary: #8896aa;
  --text-muted: #5a677a;

  --accent-blue: #3b82f6;
  --accent-blue-glow: rgba(59, 130, 246, 0.25);
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --accent-purple: #8b5cf6;

  --status-ontime: #10b981;
  --status-delayed: #f59e0b;
  --status-cancelled: #ef4444;
  --status-departed: #3b82f6;
  --status-arrived: #06b6d4;
  --status-default: #8896aa;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;
}

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

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Background Pattern ---------- */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% -20%, rgba(59, 130, 246, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(6, 182, 212, 0.05), transparent);
  pointer-events: none;
  z-index: 0;
}

/* ---------- Layout ---------- */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 28px;
}

/* ---------- Header ---------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: var(--shadow-glow);
  animation: iconPulse 3s ease-in-out infinite;
}

@keyframes iconPulse {
  0%, 100% { box-shadow: var(--shadow-glow); }
  50% { box-shadow: 0 0 28px rgba(59, 130, 246, 0.3); }
}

.header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.generated-at {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  display: flex;
  align-items: center;
  gap: 6px;
}

.generated-at .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-green);
  animation: liveDot 2s ease-in-out infinite;
}

.generated-at.history-mode .dot {
  background: var(--accent-amber);
  animation: none;
}

@keyframes liveDot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ---------- Controls Bar ---------- */
.controls-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

/* Tabs */
.tab-group {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.tab-btn {
  position: relative;
  padding: 10px 22px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.tab-btn.active {
  color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.1);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent-blue);
}

.tab-badge {
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-blue);
  padding: 2px 7px;
  border-radius: 10px;
  font-family: 'JetBrains Mono', monospace;
}

/* Separator */
.controls-separator {
  width: 1px;
  height: 32px;
  background: var(--border-color);
}

/* History Controls */
.history-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group label {
  position: absolute;
  left: 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
  top: -8px;
  background: var(--bg-card);
  padding: 0 4px;
  border-radius: 3px;
}

input[type="date"],
select.hour-select {
  padding: 9px 14px;
  font-size: 0.85rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  cursor: pointer;
}

input[type="date"]:focus,
select.hour-select:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-glow);
}

input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(0.6);
  cursor: pointer;
}

select.hour-select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238896aa'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

select.hour-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.btn {
  padding: 9px 18px;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-blue), #2563eb);
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
  background: var(--bg-card-hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ---------- Grid Container ---------- */
.grid-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

/* ---------- AG Grid Theme Overrides ---------- */
.ag-theme-alpine-dark {
  --ag-background-color: var(--bg-card);
  --ag-header-background-color: #141d2b;
  --ag-header-foreground-color: var(--text-secondary);
  --ag-odd-row-background-color: rgba(255,255,255,0.015);
  --ag-row-hover-color: rgba(59, 130, 246, 0.06);
  --ag-selected-row-background-color: rgba(59, 130, 246, 0.1);
  --ag-border-color: var(--border-color);
  --ag-secondary-border-color: transparent;
  --ag-foreground-color: var(--text-primary);
  --ag-row-border-color: rgba(255,255,255,0.04);
  --ag-font-family: 'Inter', sans-serif;
  --ag-font-size: 13px;
  --ag-header-height: 44px;
  --ag-row-height: 40px;
  --ag-cell-horizontal-padding: 14px;
  --ag-input-focus-border-color: var(--accent-blue);
}

.ag-theme-alpine-dark .ag-header-cell-label {
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ag-theme-alpine-dark .ag-cell {
  font-family: 'JetBrains Mono', 'Inter', monospace;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  line-height: normal !important;
}

.ag-theme-alpine-dark .ag-cell[col-id="flightInformationText"] {
  padding-top: 2px;
  padding-bottom: 2px;
  align-items: flex-start;
}

.ag-theme-alpine-dark .ag-row {
  transition: background-color var(--transition-fast);
}

.ag-theme-alpine-dark .ag-paging-panel {
  border-top: 1px solid var(--border-color);
}

/* ---------- Flight Number Cell ---------- */
.cell-flight-number {
  font-weight: 600;
  color: var(--accent-cyan);
  letter-spacing: 0.02em;
}

/* ---------- Airline Badge ---------- */
.cell-airline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.airline-badge {
  font-weight: 600;
  font-size: 0.76rem;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  font-family: 'JetBrains Mono', monospace;
}

.airline-JAL {
  background: rgba(220, 38, 38, 0.15);
  color: #f87171;
  border: 1px solid rgba(220, 38, 38, 0.3);
}

.airline-ANA {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

/* ---------- Status Badge ---------- */
.cell-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-badge {
  font-size: 0.78rem;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 5px;
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Status color mapping */
.status-ontime   { background: rgba(16, 185, 129, 0.12); color: var(--status-ontime); }
.status-ontime .status-dot { background: var(--status-ontime); }

.status-delayed  { background: rgba(245, 158, 11, 0.12); color: var(--status-delayed); }
.status-delayed .status-dot { background: var(--status-delayed); }

.status-cancelled { background: rgba(239, 68, 68, 0.12); color: var(--status-cancelled); }
.status-cancelled .status-dot { background: var(--status-cancelled); }

.status-departed, .status-inair { background: rgba(59, 130, 246, 0.12); color: var(--status-departed); }
.status-departed .status-dot, .status-inair .status-dot { background: var(--status-departed); }

.status-arrived  { background: rgba(6, 182, 212, 0.12); color: var(--status-arrived); }
.status-arrived .status-dot { background: var(--status-arrived); }

.status-default  { background: rgba(136, 150, 170, 0.12); color: var(--status-default); }
.status-default .status-dot { background: var(--status-default); }

/* ---------- Time Cells ---------- */
.cell-time {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  font-size: 0.88rem;
}

.cell-time-scheduled {
  color: var(--text-primary);
}

.cell-time-actual {
  color: var(--accent-green);
}

.cell-time-estimated {
  color: var(--accent-amber);
}

/* ---------- Airport Code ---------- */
.cell-airport {
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.06em;
}

/* ---------- Gate Cell ---------- */
.cell-gate {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  color: var(--accent-purple);
}

/* ---------- Info Text (wrapping) ---------- */
.cell-info-wrap {
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  white-space: normal;
  line-height: 1!important;
  padding: 4px 0;
}

/* ---------- Delay Cell ---------- */
.cell-delay {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  font-size: 0.8rem;
  padding: 2px 8px;
  border-radius: 4px;
}

.cell-delay-ontime {
  color: var(--status-ontime);
  background: rgba(16, 185, 129, 0.12);
}

.cell-delay-minor {
  color: var(--accent-amber);
  background: rgba(245, 158, 11, 0.1);
}

.cell-delay-warning {
  color: var(--accent-amber);
  background: rgba(245, 158, 11, 0.15);
}

.cell-delay-severe {
  color: var(--accent-red);
  background: rgba(239, 68, 68, 0.15);
  animation: delaySeverePulse 2s ease-in-out infinite;
}

@keyframes delaySeverePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ---------- Loading Overlay ---------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 23, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity var(--transition-slow);
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

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

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

.loading-text {
  margin-top: 16px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* ---------- Error Banner ---------- */
.error-banner {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  margin-bottom: 16px;
  color: #fca5a5;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideDown 0.3s ease;
}

.error-banner.hidden {
  display: none;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Footer ---------- */
.footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
}

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

/* Tablet */
@media (max-width: 1024px) {
  .app-container {
    padding: 16px;
  }

  .ag-theme-alpine-dark {
    --ag-font-size: 12px;
    --ag-row-height: 38px;
    --ag-header-height: 40px;
    --ag-cell-horizontal-padding: 10px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  html {
    font-size: 13px;
  }

  .app-container {
    padding: 10px 8px;
  }

  /* Header compact */
  .header {
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 14px;
    gap: 8px;
  }

  .header-icon {
    width: 34px;
    height: 34px;
    font-size: 17px;
    border-radius: var(--radius-sm);
  }

  .header h1 {
    font-size: 1.2rem;
  }

  .generated-at {
    font-size: 0.75rem;
  }

  /* Controls compact */
  .controls-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 12px;
  }

  .controls-separator {
    display: none;
  }

  .tab-group {
    width: 100%;
  }

  .tab-btn {
    flex: 1;
    justify-content: center;
    padding: 8px 12px;
    font-size: 0.82rem;
  }

  .history-controls {
    flex-wrap: wrap;
    gap: 6px;
  }

  .history-controls .input-group {
    flex: 1;
    min-width: 0;
  }

  .history-controls .input-group input[type="date"],
  .history-controls .input-group select.hour-select {
    width: 100%;
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  .history-controls .btn {
    flex: 1;
    justify-content: center;
    padding: 8px 12px;
    font-size: 0.8rem;
  }

  /* Grid compact */
  .grid-wrapper {
    border-radius: var(--radius-sm);
  }

  #flightGrid {
    height: calc(100vh - 200px) !important;
    min-height: 400px;
  }

  .ag-theme-alpine-dark {
    --ag-font-size: 11px;
    --ag-row-height: 34px;
    --ag-header-height: 34px;
    --ag-cell-horizontal-padding: 6px;
  }

  .ag-theme-alpine-dark .ag-header-cell-label {
    font-size: 0.7rem;
    letter-spacing: 0.02em;
  }

  /* Smaller cell elements */
  .cell-flight-number {
    font-size: 0.8rem;
  }

  .airline-badge {
    font-size: 0.68rem;
    padding: 1px 5px;
  }

  .status-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
  }

  .cell-time {
    font-size: 0.78rem;
  }

  .cell-airport {
    font-size: 0.78rem;
  }

  .cell-delay {
    font-size: 0.72rem;
    padding: 1px 5px;
  }

  .cell-info-wrap {
    font-size: 0.75rem;
    line-height: 1.4;
  }

  /* Footer */
  .footer {
    font-size: 0.7rem;
    margin-top: 12px;
    padding-top: 10px;
  }
}

/* Small mobile */
@media (max-width: 480px) {
  .app-container {
    padding: 6px 4px;
  }

  .header {
    margin-bottom: 10px;
    gap: 6px;
  }

  .header-left {
    gap: 10px;
  }

  .header h1 {
    font-size: 1rem;
  }

  #flightGrid {
    height: calc(100vh - 180px) !important;
    min-height: 350px;
  }

  .ag-theme-alpine-dark {
    --ag-font-size: 10px;
    --ag-row-height: 30px;
    --ag-header-height: 30px;
    --ag-cell-horizontal-padding: 4px;
  }

  .ag-theme-alpine-dark .ag-header-cell-label {
    font-size: 0.65rem;
  }

  .ag-theme-alpine-dark .ag-floating-filter-input {
    font-size: 10px !important;
  }
}

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

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

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

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