/* ============================================
   NAUTIX - Tema nautico
   ============================================ */

:root {
    --bg-primary: #0a1628;
    --bg-secondary: #111f3a;
    --bg-panel: #162040;
    --bg-card: #1a2850;
    --text-primary: #e0e8f0;
    --text-secondary: #8899b0;
    --text-dim: #556680;
    --accent: #00aaff;
    --accent-glow: rgba(0, 170, 255, 0.3);
    --success: #00cc88;
    --warning: #ffaa00;
    --danger: #ff4466;
    --border: rgba(100, 140, 200, 0.15);
    --radius: 10px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-text-size-adjust: 100%;
}

/* ============ LAYOUT ============ */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
}

#map {
    flex: 1;
    z-index: 1;
}

/* ============ HEADER ============ */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    min-height: 48px;
}
.header-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}
.header-brand svg { width: 28px; height: 28px; }
.header-brand h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 1px;
    background: linear-gradient(135deg, var(--accent), #00ddff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
#user-display {
    font-size: 13px;
    color: var(--text-secondary);
}
.btn-header {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-header:hover { border-color: var(--accent); color: var(--accent); }

/* ============ BOTTOM NAV ============ */
.bottom-nav {
    display: flex;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom);
    z-index: 1000;
}
.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 4px 6px;
    border: none;
    background: none;
    color: var(--text-dim);
    font-size: 10px;
    cursor: pointer;
    transition: color 0.2s;
    gap: 2px;
}
.nav-btn .icon { font-size: 20px; }
.nav-btn.active { color: var(--accent); }

/* ============ VIEWS (sliding panels) ============ */
.view {
    display: none;
    position: absolute;
    left: 0; right: 0;
    bottom: 52px;
    max-height: 55vh;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    overflow-y: auto;
    z-index: 900;
    padding: 16px;
    animation: slideUp 0.25s ease;
}
.view.active { display: block; }

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ============ AUTH VIEW ============ */
.auth-container {
    max-width: 360px;
    margin: 0 auto;
    text-align: center;
}
.auth-container h2 {
    font-size: 22px;
    margin-bottom: 6px;
    color: var(--accent);
}
.auth-container p { color: var(--text-secondary); font-size: 13px; margin-bottom: 20px; }
.auth-tabs {
    display: flex;
    margin-bottom: 16px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.auth-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}
.auth-tab.active { background: var(--accent); color: #fff; }
.auth-form { display: none; }
.auth-form.active { display: block; }

/* ============ FORM ELEMENTS ============ */
.form-group {
    margin-bottom: 12px;
    text-align: left;
}
.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.form-group input, .form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-primary {
    background: linear-gradient(135deg, #0077cc, #00aaff);
    color: #fff;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-success {
    background: linear-gradient(135deg, #009966, var(--success));
    color: #fff;
}
.btn-danger {
    background: linear-gradient(135deg, #cc3344, var(--danger));
    color: #fff;
}
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}
.btn-sm { padding: 8px 14px; font-size: 13px; width: auto; }

/* ============ ROUTES LIST ============ */
.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.view-header h2 { font-size: 17px; }

.route-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--bg-card);
    border-radius: var(--radius);
    margin-bottom: 8px;
    transition: background 0.2s;
}
.route-card:hover { background: var(--bg-panel); }
.route-color {
    width: 6px;
    height: 40px;
    border-radius: 3px;
    flex-shrink: 0;
}
.route-info { flex: 1; min-width: 0; }
.route-info h3 {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.route-meta { font-size: 11px; color: var(--text-dim); }
.route-actions { display: flex; gap: 4px; flex-shrink: 0; }

.btn-icon {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s;
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.btn-icon.btn-nav:hover { border-color: var(--success); color: var(--success); }
.btn-icon.btn-del:hover { border-color: var(--danger); color: var(--danger); }

/* ============ NAVIGATION PANEL ============ */
.nav-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.nav-data {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 10px;
    text-align: center;
}
.nav-data.wide { grid-column: 1 / -1; }
.nav-data .label {
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.nav-data .value {
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.2;
}
.nav-data .value.small { font-size: 14px; }
.nav-data .sub {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* XTE Bar */
.xte-bar {
    position: relative;
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    margin-top: 6px;
    overflow: visible;
}
.xte-center {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--text-dim);
    transform: translateX(-50%);
}
.xte-dot {
    position: absolute;
    top: 50%;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--success);
    transform: translate(-50%, -50%);
    transition: left 0.3s, background 0.3s;
}
.xte-dot.xte-warn { background: var(--warning); }
.xte-dot.xte-danger { background: var(--danger); }

/* Progress bar */
.progress-track {
    height: 6px;
    background: var(--bg-secondary);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 6px;
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--success));
    border-radius: 3px;
    transition: width 0.5s;
}

/* ============ GPS PANEL ============ */
.gps-panel {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    font-size: 12px;
}
.gps-item {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 8px;
    text-align: center;
}
.gps-item .label { font-size: 9px; color: var(--text-dim); text-transform: uppercase; }
.gps-item .value { font-family: var(--font-mono); font-size: 13px; font-weight: 600; }
.gps-item.wide { grid-column: 1 / -1; }

/* ============ COMPASS ============ */
.compass {
    width: 60px;
    height: 60px;
    margin: 0 auto 8px;
    position: relative;
}
.compass-ring {
    width: 100%;
    height: 100%;
    border: 2px solid var(--border);
    border-radius: 50%;
    position: relative;
}
.compass-n {
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    font-weight: 700;
    color: var(--danger);
}
.compass-needle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 24px;
    background: linear-gradient(var(--danger) 50%, var(--text-dim) 50%);
    transform-origin: 50% 50%;
    transform: translate(-50%, -50%);
    transition: transform 0.3s;
}

/* ============ CREATE/EDIT ROUTE ============ */
.edit-wp {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}
.edit-wp-num {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}
.edit-wp input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    min-width: 0;
}
.edit-wp-coord {
    font-size: 10px;
    color: var(--text-dim);
    font-family: var(--font-mono);
    flex-shrink: 0;
}

/* ============ GPX IMPORT DROP ZONE ============ */
.gpx-drop {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    transition: all 0.2s;
    cursor: pointer;
    margin-bottom: 12px;
}
.gpx-drop.dragover {
    border-color: var(--accent);
    background: var(--accent-glow);
    color: var(--accent);
}
.gpx-drop input[type="file"] { display: none; }

/* ============ POSITION MARKER ============ */
.position-marker {
    background: none !important;
    border: none !important;
}
.pos-dot {
    width: 16px;
    height: 16px;
    background: var(--accent);
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 12px var(--accent-glow), 0 2px 6px rgba(0,0,0,0.3);
    position: absolute;
    top: 4px; left: 4px;
}
.pos-heading {
    display: none;
    position: absolute;
    top: -6px;
    left: 8px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 12px solid var(--accent);
    transform-origin: 50% 18px;
}
.accuracy-circle {
    fill: var(--accent);
    fill-opacity: 0.08;
    stroke: var(--accent);
    stroke-opacity: 0.25;
    stroke-width: 1;
}

/* ============ WAYPOINT MARKERS ============ */
.wp-marker { background: none !important; border: none !important; }
.wp-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 2px solid var(--accent);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.wp-dot.wp-start { background: var(--success); border-color: var(--success); color: #fff; }
.wp-dot.wp-end { background: var(--danger); border-color: var(--danger); color: #fff; }
.wp-dot.wp-edit { background: #FF6600; border-color: #FF6600; color: #fff; }

/* ============ MAP BUTTONS OVERLAY ============ */
.map-controls {
    position: absolute;
    top: 56px;
    left: 10px;
    z-index: 800;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.map-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-panel);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: all 0.2s;
}
.map-btn:hover { background: var(--bg-card); border-color: var(--accent); }
.map-btn.active { background: var(--accent); color: #fff; }

/* ============ TOASTS ============ */
#toasts {
    position: fixed;
    top: 56px;
    right: 10px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.toast {
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    color: #fff;
    opacity: 0;
    transform: translateX(30px);
    transition: all 0.3s;
    max-width: 300px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    white-space: pre-line;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); color: #222; }
.toast-info { background: var(--accent); }

/* ============ NAV STOP BUTTON ============ */
.btn-stop-nav {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 950;
    padding: 12px 28px;
    border-radius: 30px;
    border: none;
    background: var(--danger);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    box-shadow: 0 4px 16px rgba(255, 68, 102, 0.4);
    cursor: pointer;
    display: none;
}
.btn-stop-nav.visible { display: block; }

/* ============ EMPTY STATE ============ */
.empty-state {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-dim);
}
.empty-state p:first-child { font-size: 15px; margin-bottom: 6px; }

/* ============ LEAFLET OVERRIDES ============ */
.leaflet-control-layers {
    background: var(--bg-panel) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
}
.leaflet-control-layers label { color: var(--text-primary) !important; }
.leaflet-control-zoom a {
    background: var(--bg-panel) !important;
    color: var(--text-primary) !important;
    border-color: var(--border) !important;
}
.leaflet-popup-content-wrapper {
    background: var(--bg-panel) !important;
    color: var(--text-primary) !important;
    border-radius: 8px !important;
}
.leaflet-popup-tip { background: var(--bg-panel) !important; }

/* ============ SCROLLBAR ============ */
.view::-webkit-scrollbar { width: 4px; }
.view::-webkit-scrollbar-track { background: transparent; }
.view::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ============ RESPONSIVE ============ */
@media (min-width: 768px) {
    .view {
        max-width: 420px;
        right: auto;
        left: 10px;
        bottom: 10px;
        border-radius: var(--radius);
        max-height: 70vh;
    }
    .bottom-nav {
        position: absolute;
        bottom: 10px;
        left: 440px;
        width: auto;
        border-radius: var(--radius);
        border: 1px solid var(--border);
        gap: 4px;
        padding: 4px;
    }
    .nav-btn { padding: 8px 16px; }
}
