/* ============================================
   FLIGHTLOG — Main Stylesheet
   Aviation Dark Theme — Orbitron + DM Sans
   ============================================ */

:root {
  --bg: #0b0f1a;
  --bg2: #111827;
  --bg3: #1a2236;
  --surface: #1e2d45;
  --surface2: #243552;
  --border: #2d4060;
  --border-light: #3a5070;

  --accent: #38bdf8;
  --accent-dim: #1e7aad;
  --accent2: #f59e0b;
  --danger: #ef4444;
  --success: #22c55e;

  --text: #e2eaf5;
  --text-muted: #7a9ab8;
  --text-dim: #4a6a88;

  --radius: 8px;
  --radius-lg: 14px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);

  --font-display: 'Orbitron', monospace;
  --font-body: 'DM Sans', sans-serif;

  --nav-height: 58px;
  --mobile-nav-height: 60px;
}

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

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* =================== LOGIN PAGE =================== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: hidden;
}

.login-bg {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, #060a14 0%, #0b1628 40%, #0a1f35 100%);
  z-index: 0;
}

.horizon-line {
  position: absolute;
  bottom: 30%;
  left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(56,189,248,0.3), transparent);
}

.grid-overlay {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(56,189,248,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56,189,248,0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.8) 50%, transparent 100%);
}

.login-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  padding: 20px;
}

.login-card {
  background: rgba(30, 45, 69, 0.85);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  box-shadow: 0 0 60px rgba(56,189,248,0.1), var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.logo-icon {
  font-size: 2.8rem;
  line-height: 1;
  filter: drop-shadow(0 0 16px rgba(56,189,248,0.6));
}

.logo-text {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--accent);
  margin-top: 8px;
}

.logo-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 4px;
}

.login-footer {
  text-align: center;
  margin-top: 20px;
}

.section-title {
  font-family: var(--font-display);
  font-size: 1rem;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 8px;
}

/* =================== TOP NAV =================== */
.top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: rgba(11,15,26,0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.nav-icon {
  font-size: 1.3rem;
  color: var(--accent);
  filter: drop-shadow(0 0 8px rgba(56,189,248,0.5));
}

.nav-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.nav-tabs {
  display: flex;
  gap: 4px;
  margin-left: 24px;
}

.nav-tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 6px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.nav-tab:hover { color: var(--text); background: var(--surface); }
.nav-tab.active { color: var(--accent); background: rgba(56,189,248,0.1); }

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-pilot-name {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.nav-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.nav-btn:hover { color: var(--accent); border-color: var(--accent); background: rgba(56,189,248,0.08); }

.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--mobile-nav-height);
  background: rgba(11,15,26,0.97);
  border-top: 1px solid var(--border);
  z-index: 100;
  justify-content: space-around;
  align-items: center;
}

.mob-tab {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 0.7rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius);
  transition: color 0.2s;
}

.mob-tab.active { color: var(--accent); }
.mob-icon { font-size: 1.2rem; }

/* =================== APP MAIN =================== */
.app-page .app-main {
  padding-top: var(--nav-height);
  min-height: 100vh;
}

.view {
  display: none;
  padding: 28px 24px 40px;
  max-width: 1200px;
  margin: 0 auto;
  animation: fadeIn 0.2s ease;
}
.view.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.view-header h1 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text);
}

/* =================== STATS GRID =================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  transition: border-color 0.2s, transform 0.15s;
}

.stat-card:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
}

.stat-card.accent {
  border-color: var(--accent-dim);
  background: rgba(56,189,248,0.08);
}

.stat-label {
  font-size: 0.73rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

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

.dash-info-row {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 28px;
}

/* =================== FLIGHTS TABLE =================== */
.flights-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
}

.flights-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.flights-table th {
  padding: 12px 14px;
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.flights-table th:hover { color: var(--accent); }

.flights-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}

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

.flights-table tr:hover td {
  background: rgba(56,189,248,0.04);
  cursor: pointer;
}

.airport-code {
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
}

.tail-number {
  font-family: var(--font-display);
  font-size: 0.75rem;
  color: var(--accent2);
}

.time-val { font-variant-numeric: tabular-nums; }

.no-flights {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.no-flights .no-flights-icon { font-size: 2.5rem; margin-bottom: 12px; display: block; }

/* =================== PAGINATION =================== */
.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 20px;
  flex-wrap: wrap;
}

.page-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}
.page-btn:hover { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.page-btn:disabled { opacity: 0.3; cursor: default; }

/* =================== FLIGHT FORM =================== */
.flight-form {
  max-width: 900px;
}

.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
}

.form-section-title {
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.form-group-full {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group.required label::after {
  content: ' *';
  color: var(--accent2);
}

.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.92rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56,189,248,0.15);
}

.form-group input.error { border-color: var(--danger); }

.form-group textarea { resize: vertical; min-height: 80px; }

.form-group select option { background: var(--bg2); }

.field-hint {
  font-size: 0.75rem;
  color: var(--accent);
  font-style: italic;
}

.label-hint {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-dim);
  text-transform: none;
  letter-spacing: 0;
}

/* Airport autocomplete */
.airport-group { position: relative; }

.airport-input-wrap { position: relative; }

.airport-suggestions {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--bg3);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  max-height: 240px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: var(--shadow);
  margin-top: 2px;
}

.airport-suggestion {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.airport-suggestion:last-child { border-bottom: none; }
.airport-suggestion:hover { background: rgba(56,189,248,0.12); }

.ap-code {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  margin-right: 8px;
}

.ap-name {
  font-size: 0.85rem;
  color: var(--text);
}

.ap-city {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Form errors */
.form-errors {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.4);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 20px;
}

.form-errors ul { list-style: none; }
.form-errors li { color: #fca5a5; font-size: 0.88rem; padding: 3px 0; }
.form-errors li::before { content: '⚠ '; }

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

/* =================== BUTTONS =================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #0b1628;
  font-weight: 600;
}
.btn-primary:hover { background: #7dd3fc; }

.btn-accent {
  background: var(--accent2);
  color: #0b1628;
  font-weight: 600;
}
.btn-accent:hover { background: #fbbf24; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-light); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(239,68,68,0.4);
}
.btn-danger:hover { background: rgba(239,68,68,0.1); }

.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-lg { padding: 12px 28px; font-size: 0.95rem; }
.btn-full { width: 100%; }

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

/* =================== FILTERS =================== */
.logbook-filters {
  margin-bottom: 16px;
}

.filter-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.88rem;
  min-width: 180px;
  transition: border-color 0.2s;
}

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

.date-filter-wrap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* =================== DATE RANGE (dashboard) =================== */
.date-range-filter {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-left: auto;
}

.date-range-filter label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.date-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.85rem;
}
.date-input:focus { outline: none; border-color: var(--accent); }

/* =================== SETTINGS =================== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  max-width: 1000px;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.settings-card h2 {
  font-family: var(--font-display);
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 8px;
}

.settings-btns {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.import-area {
  margin-top: 16px;
}

.import-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.import-label:hover { border-color: var(--accent); color: var(--accent); }

.import-hint { font-size: 0.75rem; color: var(--text-dim); }

/* =================== MODAL =================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
}

.modal-box {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 60px rgba(0,0,0,0.8);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }

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

.modal-header h2 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: color 0.2s;
}
.modal-close:hover { color: var(--text); }

.modal-content {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.detail-item .detail-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 3px;
}

.detail-item .detail-value {
  font-size: 0.92rem;
  color: var(--text);
}

.detail-item.full-width { grid-column: 1 / -1; }

/* =================== TOAST =================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 0.88rem;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toastIn 0.25s ease;
  pointer-events: all;
  max-width: 320px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }

@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* =================== UTILITIES =================== */
.hidden { display: none !important; }

.error-msg {
  color: #fca5a5;
  font-size: 0.85rem;
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 8px 0;
}

.success-msg {
  color: #86efac;
  font-size: 0.85rem;
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.3);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 8px 0;
}

.helper-text {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

.text-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.88rem;
}
.text-link:hover { text-decoration: underline; }

.loading-spinner {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h2 {
  font-family: var(--font-display);
  font-size: 0.9rem;
  letter-spacing: 0.05em;
  color: var(--text);
}

.recent-flights-section { margin-top: 16px; }

.logbook-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* =================== RESPONSIVE =================== */
@media (max-width: 768px) {
  .top-nav { display: none; }
  .mobile-nav { display: flex; }

  .app-page .app-main {
    padding-top: 0;
    padding-bottom: var(--mobile-nav-height);
  }

  .view { padding: 16px 14px 24px; }

  .view-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .view-header h1 { font-size: 1.1rem; }

  .date-range-filter { margin-left: 0; }

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

  .stat-value { font-size: 1.4rem; }

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

  .filter-row { flex-direction: column; align-items: stretch; }
  .filter-input { min-width: unset; }

  .form-actions { flex-direction: column; }

  .modal-box { max-height: 95vh; }

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

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

  .logbook-actions { margin-left: 0; }

  .flights-table { font-size: 0.8rem; }
  .flights-table th, .flights-table td { padding: 9px 10px; }

  .toast-container { bottom: 80px; right: 12px; left: 12px; }
  .toast { max-width: unset; }
}

@media (min-width: 769px) {
  #view-settings { display: none; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }
