/* =================== GLOBAL STYLES =================== */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;               /* body never scrolls — #tab-pane does */
    background-color: #f0f2f6;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}

/* =================== APP SHELL =================== */

/*
  #app fills the entire viewport, fixed in place.
  It is NOT a scroll container — it just holds the
  fixed nav bar and the #tab-pane scroll zone.
*/
#app {
    position: fixed;
    inset: 0;                           /* top/right/bottom/left = 0 */
    width: 100%;
    max-width: 650px;
    margin: 0 auto;
    background-color: white;
    display: block;                     /* simple block — children use position */
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 0 30px rgba(0,0,0,0.12);
}

/* ── Scrollable content pane ──────────────────────────────
   Fills the full viewport height, then shrinks by the nav bar
   height so content is never hidden behind it.
   The padding-bottom/top switches based on nav position.
*/
#tab-pane {
    position: absolute;
    left: 0;
    right: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

/* Default: nav bar is at BOTTOM — pane fills top, leaves room at bottom */
body #tab-pane {
    top: env(safe-area-inset-top, 0px);
    bottom: calc(60px + env(safe-area-inset-bottom, 0px));
}

/* Top nav: nav bar is at TOP — pane starts below it, fills to bottom */
body.nav-top #tab-pane {
    top: calc(60px + env(safe-area-inset-top, 0px));
    bottom: env(safe-area-inset-bottom, 0px);
}

/* .app-container is a legacy wrapper that just holds the .tab bar — transparent to layout */
.app-container {
    display: contents;
}

/* ── Desktop / tablet centering ─────────────────────────── */
@media (min-width: 651px) {
    body {
        background-color: #dde1e9;
    }
    #app {
        left: 50%;
        transform: translateX(-50%);
        border-radius: 0;
    }
}

/* =================== INPUT FIXES =================== */

input, textarea, select {
    border: none;
    outline: none;
    box-shadow: none;
    background: transparent;
}

@media (hover: none) {
    .map-controls button {
        padding: 8px 12px;
    }
}

/* =================== TYPOGRAPHY =================== */

label_h1 {
    display: block;
    font-weight: bold;
    margin-top: 12px;
    margin-bottom: 6px;
    padding: 10px;
    color: #2a3f54;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

label_h2 {
    display: block;
    font-weight: bold;
    margin-top: 6px;
    margin-bottom: 6px;
    padding: 1px;
    color: #2a3f54;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

label {
    display: block;
    font-weight: normal;
    padding: 3px;
    color: #030506;
    font-size: 14px;
    text-align: center;
}

h1 { text-align: center; }

/* =================== BUTTONS & INPUTS =================== */

.button-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin: 8px 0;
    width: 100%;
    box-sizing: border-box;
}

.button-row select,
.button-row input[type="text"],
.button-row button {
    flex: 1;
    border: none;
    border-radius: 8px;
    padding: 10px;
    font-size: 14px;
    background-color: #f0f2f6;
    color: #333;
    transition: background 0.2s;
    min-width: 0;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.button-row button:hover,
.button-row select:hover,
.button-row input[type="text"]:hover { background-color: #e8eaed; }

.button-row button:only-child {
    flex: 1;
    min-width: auto;
    max-width: none;
}

input[type="range"],
button,
input[type="text"] {
    width: 100%;
    margin: 8px 0;
    border: none;
    border-radius: 8px;
    padding: 10px;
    background-color: #f0f2f6;
    color: #333;
    transition: background 0.2s;
    font-size: 14px;
}

input[type="range"]:hover,
button:hover,
input[type="text"]:hover { background-color: #e8eaed; }

input[type="number"] {
    width: 100%;
    padding: 10px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    color: #333;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    transition: all 0.2s ease;
}

input[type="number"]:focus {
    border-color: #4a90e2;
    background: #f5f9ff;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
    outline: none;
}

input[type="number"]:disabled {
    background: #fafafa;
    color: #777;
}

.button-style {
    font-size: 12px;
    margin: 4px 0;
    text-align: center;
    z-index: 1;
    background-color: #e0e0e0;
    border: 1px solid #333333;
    color: #000;
    cursor: pointer;
}

.button-style:hover {
    background-color: #bdbdbd;
    color: #000;
    border: 1px solid #333333;
    box-shadow: 0 6px 18px rgba(42, 63, 84, 0.12);
    transform: translateY(-2px);
}

/* =================== LOGO & IMAGE CONTAINERS =================== */

.logo-container {
    position: relative;
    text-align: center;
    margin: 0;
    margin-top: 10px;
    border-radius: 5px;
    overflow: visible;
    min-height: 80px;
    padding-bottom: 0;
}

.logo-container img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    cursor: pointer;
    transition: transform 0.2s;
    max-height: 60vh;               /* reasonable cap; pane scrolls so no clipping */
    border-radius: 10px;
    z-index: 0;
}

.logo-container img:hover { transform: scale(1.05); }

.coffee-container {
    text-align: center;
    margin: 30px 0;
    border-radius: 10px;
    overflow: hidden;
}

.coffee-container img {
    max-width: 30%;
    min-width: 80px;
    height: auto;
    display: block;
    margin: 0 auto;
    cursor: pointer;
    transition: transform 0.2s;
}

.coffee-container img:hover { transform: scale(1.05); }

/* =================== CANVAS OVERLAYS =================== */

.flare-canvas  { position: absolute; inset: 0; pointer-events: none; z-index: 2; border-radius: 10px; }
.fog-canvas    { position: absolute; inset: 0; pointer-events: none; z-index: 3; border-radius: 10px; }
.cloud-canvas  { position: absolute; inset: 0; pointer-events: none; z-index: 4; border-radius: 10px; }
.snow-canvas   { position: absolute; inset: 0; pointer-events: none; z-index: 5; border-radius: 10px; }
.dark-canvas   { position: absolute; inset: 0; pointer-events: none; z-index: 6; border-radius: 10px; }
.rain-canvas   { position: absolute; inset: 0; pointer-events: none; z-index: 7; border-radius: 10px; }

.controls-wrapper {
    position: absolute;
    inset: 0;
    pointer-events: auto;
    z-index: 8;
    border-radius: 10px;
}

.cloudplot-canvas {
    z-index: 0;
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

/* =================== UTILITY CLASSES =================== */

.warning    { font-size: 12px; color: orange;   margin: 4px 0; text-align: center; }
.info-blue  { font-size: 13px; font-weight: 400; color: #005082; margin: 4px 0; text-align: center; }
.info-gray  { font-size: 10px; font-weight: 400; color: grey;   margin: 4px 0; text-align: center; }
.info       { font-size: 14px; color: dimgray;   margin: 4px 0; text-align: center; }
.disclaimer { font-size: 12px; color: red;       margin: 4px 0; text-align: center; }
.version    { font-size: 8px;  color: gray;      margin: 4px 0; text-align: right; }

.divider {
    height: 1px;
    background: #dcdcdc;
    margin: 16px 0;
}

.border-round-eged {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    background-color: #f5f5f5;
    border-radius: 8px;
    padding: 8px 6px;
    border: 2px solid white;
    margin: 8px 0;
}

.border-round-eged-logo {
    background-color: transparent;
    border-color: transparent;
    border-radius: 8px;
    padding: 8px 6px;
    border: 2px solid white;
    margin: 1px 0 8px 0;
}

/* =================== SPINNER =================== */

.spinner-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
}

.spinner-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid #f3f3f3;
    border-radius: 50%;
    border-top: 6px solid #3498db;
    animation: spin 1s linear infinite;
}

.spinner-text {
    color: white;
    font-size: 14px;
    margin-top: 15px;
    text-align: center;
    white-space: nowrap;
}

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

/* =================== MAP STYLES =================== */

#map-container {
    position: relative;
    height: clamp(220px, 40dvh, 400px);
    width: 100%;
    margin: 20px auto;
    border: 1px solid #ccc;
    border-radius: 4px;
}

@media (min-width: 768px) {
    #map-container { height: clamp(300px, 45dvh, 500px); }
}

.mobile-fullscreen {
    position: fixed !important;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw !important;
    height: 100dvh !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    z-index: 9990;
    background: #000;
}

#route-map {
    height: 100%;
    width: 100%;
    border-radius: 4px;
    background: #fff;
}

.leaflet-control-container .leaflet-top { z-index: 1000; }

.map-controls {
    background: rgba(255, 255, 255, 0.9);
    padding: 8px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    font-size: 14px;
    user-select: none;
    touch-action: manipulation;
    text-align: center;
    margin-bottom: 10px;
}

.map-controls label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.map-controls input[type="checkbox"] { margin: 0; cursor: pointer; }

.map-controls button,
.map-controls select {
    padding: 5px 10px;
    margin: 0 5px;
    min-width: 32px;
    min-height: 32px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.map-controls button:active { background-color: #eee; }

#fullscreen-btn {
    position: absolute !important;
    top: 10px;
    right: 10px;
    z-index: 2000 !important;
    pointer-events: auto;
}

body.map-fullscreen #fullscreen-btn,
:fullscreen #fullscreen-btn,
:-webkit-full-screen #fullscreen-btn,
.mobile-fullscreen #fullscreen-btn {
    position: fixed !important;
    right: 12px !important;
    z-index: 99999 !important;
    background: rgba(255,255,255,0.92) !important;
    border-radius: 8px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25) !important;
}

body.map-fullscreen-bottom #fullscreen-btn {
    top: auto !important;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px) !important;
}
body.map-fullscreen-bottom .leaflet-top.leaflet-left {
    top: auto !important;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px) !important;
}

body.map-fullscreen-top #fullscreen-btn {
    top: calc(env(safe-area-inset-top, 0px) + 12px) !important;
    bottom: auto !important;
}
body.map-fullscreen-top .leaflet-top.leaflet-left {
    top: calc(env(safe-area-inset-top, 0px) + 12px) !important;
    bottom: auto !important;
}

#fullscreen-btn:hover { background-color: #f0f0f0; }

#fullscreen-btn svg {
    width: 24px; height: 24px;
    margin: 8px;
    fill: #333;
    transition: opacity 0.2s ease-in-out;
}

#fullscreen-btn .fullscreen-exit { display: none; }

body.no-scroll { overflow: hidden; touch-action: none; }

body.map-fullscreen          { overflow: visible !important; }
body.map-fullscreen #app     { overflow: visible !important; }

body.map-fullscreen .tab,
body.map-fullscreen #tab-bar,
body.map-fullscreen .tab-bar,
body.map-fullscreen .navbar,
body.map-fullscreen #navbar,
body.map-fullscreen .top-nav,
body.map-fullscreen #top-nav,
body.map-fullscreen .bottom-nav,
body.map-fullscreen #bottom-nav,
body.map-fullscreen .menu-bar,
body.map-fullscreen #menu-bar,
body.map-fullscreen #bottom-container,
body.map-fullscreen #bottom-buttons,
body.map-fullscreen .output-box { display: none !important; }

.mobile-fullscreen ~ * #bottom-container,
.mobile-fullscreen ~ * #bottom-buttons,
.mobile-fullscreen ~ * .output-box,
body.no-scroll #bottom-container,
body.no-scroll #bottom-buttons,
body.no-scroll .output-box { display: none !important; }

/* =================== COLLAPSIBLE SECTIONS =================== */

.collapsible {
    font-size: 14px;
    border: 1px solid #ccc;
    border-radius: 6px;
    margin: 8px 0;
    overflow: hidden;
    background: #f5f5f5;
}

.collapsible:hover {
    border-color: #b0b0b0;
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

.collapsible-header {
    padding: 10px 14px;
    background: #e9e9e9;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.collapsible-header::after {
    content: "▼";
    font-size: 10px;
    transition: transform 0.2s;
}

.collapsible.open .collapsible-header::after { transform: rotate(-180deg); }

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease-out;
    padding: 0 14px;
    background: #f5f5f5;
}

.collapsible.open .collapsible-content { padding: 10px 14px; }

/* =================== GRID LAYOUTS =================== */

.wind-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 10px;
    margin-top: 10px;
    border-radius: 8px;
}

.wind-grid_3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 10px;
    border-radius: 8px;
}

.grid-two-thirds-one-third {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 10px;
    margin-top: 10px;
    border-radius: 8px;
}

.grid-middle-small {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
    border-radius: 8px;
}

.grid-middle-small > .tile {
    grid-column: 2;
    justify-self: center;
    align-self: center;
    border-radius: 8px;
}

/* =================== TILES =================== */

.tile {
    background: linear-gradient(to bottom, #ffffff 0%, #f5f5f5 100%);
    border: 1px solid #dcdcdc;
    border-radius: 10px;
    padding: 12px 10px 8px 10px;
    text-align: center;
    font-size: 16px;
    line-height: 1.2;
    position: relative;
    overflow: hidden;
}

.tile:hover {
    border-color: #b0b0b0;
    background: #fafafa;
    outline: 3px solid rgba(74, 144, 226, 0.1);
}

.tile-value {
    width: 100%;
    box-sizing: border-box;
    font-size: 22px;
    text-align: center;
    font-weight: 700;
    display: block;
    margin-bottom: 6px;
    z-index: 5;
    border-radius: 4px;
    border: none;
    padding: 4px 8px;
}

.tile-label {
    font-size: 11px;
    color: #666;
    font-weight: 400;
    text-align: center;
    border-radius: 8px;
}

.tile-value-dropdown {
    display: block;
    width: 100%;
    box-sizing: border-box;
    font-size: 14px;
    color: #333;
    background: #fff;
    text-align: left;
    font-weight: 700;
    margin-bottom: 6px;
    padding: 8px 6px;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    outline: #f5f5f5;
    transition: all 0.2s ease;
    cursor: pointer;
}

.tile-value-dropdown:hover { border-color: #b0b0b0; background: #f5f9ff; }
.tile-value-dropdown:focus {
    border-color: #4a90e2;
    background: #f5f9ff;
    outline: 3px solid rgba(74, 144, 226, 0.1);
}

/* =================== WEIGHT & BALANCE =================== */

.weight-card-header { font-weight: 500; font-size: 13px; color: #333; margin-bottom: 10px; }

.weight-card {
    background: white;
    border: 1px solid #dcdcdc;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
}

.input-label { font-size: 11px; color: #777; margin-bottom: 4px; display: block; }

.container { max-width: 600px; margin: 0 auto; }

.section-title { font-size: 15px; font-weight: 600; color: #333; margin: 20px 0 12px 0; }

/* =================== FLIGHT CARD =================== */

.flight-card {
    background: linear-gradient(to bottom, #e8e8e8 0%, #d5d5d5 100%);
    border-radius: 8px;
    padding: 20px;
    min-width: 350px;
    width: 100%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 2px solid white;
}

.route-header {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.airport { flex: 1; text-align: center; margin: 1px; min-width: 0; }

.airport-code { font-size: 48px; font-weight: bold; color: #2c2c2c; margin: 1px; }

.airport-name {
    font-size: 14px;
    color: #2c2c2c;
    font-weight: 500;
    margin-bottom: 3px;
    min-height: 2.2em;
    line-height: 1.1em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.plane-icon {
    flex-shrink: 0;
    margin: 0 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.plane-icon:hover  { transform: scale(1.2); filter: drop-shadow(0 2px 3px rgba(0,0,0,0.2)); }
.plane-icon:active { transform: rotate(90deg) scale(0.95); }

.plane-icon svg { width: 40px; height: 40px; fill: #00a1de; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2)); }

.schedule-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 0 10px;
}

.schedule-item { text-align: center; }

.schedule-label {
    font-size: 11px;
    text-align: center;
    font-weight: 500;
    color: #666;
    text-transform: uppercase;
    margin-top: 35px;
    margin-bottom: 5px;
}

.divider-general-section {
    height: 2px;
    background: #b8b8b8;
    margin: 15px 0;
    position: relative;
}

.divider-plane {
    position: absolute;
    top: 50%;
    left: 20%;
    transform: translate(-50%, -50%) rotate(90deg);
    width: 32px;
    height: 32px;
    background: linear-gradient(to bottom, #e8e8e8 0%, #d5d5d5 100%);
    padding: 4px;
    border-radius: 50%;
}

.divider-plane-line { position: absolute; left: 0; height: 0; width: 100%; background: #d5d5d5; }

.distance-section { display: flex; align-items: center; padding: 0 10px; }

.distance-info { display: flex; justify-content: space-between; flex: 1; font-size: 13px; color: #666; }

.clock-input {
    height: 48px;
    line-height: 1;
    font-size: 26px;
    text-align: center;
    font-weight: bold;
    font-family: system-ui, -apple-system, Segoe UI, Roboto;
    background-color: transparent;
    border-radius: 10px;
    border: transparent;
    box-sizing: border-box;
    appearance: none;
}

.clock-input::-webkit-calendar-picker-indicator { display: none; -webkit-appearance: textfield; appearance: textfield; }

.info-row { display: flex; justify-content: space-between; align-items: flex-start; }
.info-item { flex: 1; }

.aircraft-value { font-size: 16px; color: #2c2c2c; font-weight: 600; margin-bottom: 15px; text-align: left; }

.aircraft { display: grid; grid-template-rows: auto 1fr; }
.aircraft .tile-label { align-self: start; font-weight: 500; }
.aircraft .tile-value { align-self: center; }

.flight-card-row { display: flex; align-items: stretch; width: 100%; }

.flight-card-icon {
    position: relative;
    width: 15%;
    min-width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flight-card-content { width: 85%; padding-left: 12px; }

.plane-small {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease;
    transform: rotate(90deg);
}

.plane-small:hover  { transform: scale(1.2) rotate(90deg); filter: drop-shadow(0 2px 3px rgba(0,0,0,0.2)); }
.plane-small:active { transform: scale(0.95); }
.plane-small svg    { width: 36px; height: 36px; fill: #00a1de; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2)); }

/* =================== METAR STYLES =================== */

.metar-station-icon { background: transparent; border: none; }
.metar-popup .leaflet-popup-content-wrapper { border-radius: 8px; box-shadow: 0 3px 14px rgba(0,0,0,0.4); }
.metar-popup .leaflet-popup-content { margin: 10px; min-width: 300px; }

/* =================== TAB CONTENT =================== */

.tabcontent {
    display: none;
    padding: 10px;
    width: 100%;
    max-width: 100%;
    min-width: 350px;
    box-sizing: border-box;
}

#General {
    display: flex;
    flex-direction: column;
    padding-bottom: 10px;
    box-sizing: border-box;
    position: relative;
}

/* =================== FLASHCARDS =================== */

.grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 0;
    width: 100%;
    max-width: 600px;
    border: 1px solid #f5f5f5;
}

.cell {
    border-right: 1px solid #f5f5f5;
    border-bottom: 1px solid #f5f5f5;
    padding: 20px;
    text-align: center;
    box-sizing: border-box;
}

.grid-container .cell:nth-child(3),
.grid-container .cell:nth-child(6)  { border-right: none; }
.grid-container .cell:nth-child(n+4) { border-bottom: none; }

.summary-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px;
    margin-top: 8px;
}

@media (max-width: 480px) {
    .summary-grid { grid-template-columns: repeat(2, 1fr); }
}

input:disabled {
    background-color: #f5f5f5;
    opacity: 0.7;
    cursor: not-allowed;
}

.navlog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 12px;
    margin-top: 6px;
}

.check-tile {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 10px;
    border-radius: 12px;
    background: #ffffff;
    border: 1px solid #dcdcdc;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.check-tile input { transform: scale(1.2); }
