:root {
    --bg-color: #171d20;
    --glass-bg: rgba(23, 29, 32, 0.85);
    --glass-border: rgba(23, 147, 209, 0.2);
    --accent-color: #1793d1;
    /* Arch Linux Blue */
    --accent-glow: rgba(23, 147, 209, 0.3);
    --text-primary: #f0f0f0;
    --text-secondary: #9eaab5;
    --msg-sent: #1793d1;
    --msg-received: #2a3439;
    --error-red: #ff5555;
    --success-green: #55ff55;
    --font-main: 'Inter', sans-serif;
    --font-heading: 'JetBrains Mono', monospace;
    --font-mono: 'JetBrains Mono', monospace;
}

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

body {
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 0% 0%, rgba(23, 147, 209, 0.05) 0%, transparent 50%);
    color: var(--text-primary);
    font-family: var(--font-heading);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

#app {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Login Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 50px 40px;
    text-align: center;
    animation: fadeInScale 0.4s ease-out;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.login-card h1 {
    font-size: 1.8rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.login-card .subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 25px;
}

h1 {
    font-family: var(--font-heading);
    font-size: 2rem;
    margin-bottom: 8px;
    background: linear-gradient(to right, #fff, var(--accent-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 0.9rem;
}

.error-text {
    color: var(--error-red);
    background: rgba(255, 85, 85, 0.1);
    border: 1px solid var(--error-red);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.8rem;
    margin-bottom: 20px;
    font-family: var(--font-mono);
}

.input-group {
    text-align: left;
    margin-bottom: 20px;
}

label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    margin-left: 4px;
}

input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 12px 16px;
    color: white;
    font-family: inherit;
    transition: all 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-primary {
    width: 100%;
    background: var(--accent-color);
    color: #000;
    border: none;
    border-radius: 12px;
    padding: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 10px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.help-text {
    margin-top: 20px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.help-text a {
    color: var(--accent-color);
    text-decoration: none;
}

/* Dashboard */
/* Dashboard */
#dashboard {
    width: 98%;
    height: 95vh;
    display: flex;
    flex-direction: column;
    gap: 20px;
    animation: fadeIn 0.5s ease-out;
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.glass-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 15px;
}

.logo-text {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.2rem;
}

.accent {
    color: var(--accent-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error-red);
}

.status-dot.online {
    background: var(--success-green);
    box-shadow: 0 0 8px var(--success-green);
}

.content-wrapper {
    flex: 1;
    display: flex;
    gap: 20px;
    height: calc(100% - 80px);
}

.sidebar {
    width: 300px;
    display: flex;
    flex-direction: column;
}

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

.sidebar-header h2 {
    font-size: 1rem;
    color: var(--text-secondary);
}

#add-contact-btn {
    background: none;
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
}

.contact-list {
    list-style: none;
    overflow-y: auto;
}

.contact {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 20px;
    cursor: pointer;
    transition: background 0.2s;
}

.contact:hover {
    background: rgba(255, 255, 255, 0.03);
}

.contact.active {
    background: rgba(56, 189, 248, 0.1);
    border-left: 3px solid var(--accent-color);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--glass-border);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    font-size: 0.8rem;
}

.contact-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.name {
    font-weight: 600;
    font-size: 0.9rem;
}

.last-msg {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
}

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

.chat-header h2 {
    font-size: 1.1rem;
}

.chat-header .status {
    font-size: 0.8rem;
    color: var(--success-green);
}

.icon-btn-small {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn-small:hover {
    color: var(--error-red);
    border-color: var(--error-red);
    background: rgba(255, 85, 85, 0.1);
}

.messages {
    flex: 1;
    padding: 20px 30px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    max-width: 70%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message.sent {
    align-self: flex-end;
    align-items: flex-end;
}

.message.received {
    align-self: flex-start;
    align-items: flex-start;
}

.msg-bubble {
    padding: 10px 16px;
    border-radius: 4px;
    font-size: 0.85rem;
    line-height: 1.5;
    font-family: var(--font-mono);
}

.sent .msg-bubble {
    background: var(--msg-sent);
    color: white;
    border-bottom-right-radius: 4px;
}

.received .msg-bubble {
    background: var(--msg-received);
    color: white;
    border-bottom-left-radius: 4px;
}

.msg-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
}

.time {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.status-tick {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.status-tick.double {
    color: var(--accent-color);
    /* Blue/Cyan for delivered */
}

.chat-input-area {
    padding: 20px 30px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 15px;
}

.chat-input-area input {
    flex: 1;
    background: rgba(255, 255, 255, 0.03);
    font-family: var(--font-mono);
}

.btn-icon {
    background: var(--accent-color);
    color: #000;
    border: none;
    border-radius: 12px;
    width: 48px;
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-icon:hover {
    transform: scale(1.05);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
}

.btn-secondary:hover {
    color: white;
    border-color: white;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Settings Modal */
.settings-card {
    width: 90%;
    max-width: 500px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-height: 80vh;
}

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

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--error-red);
}

.settings-content {
    overflow-y: auto;
    padding-right: 5px;
}

.symbol-preview {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    margin-bottom: 5px;
}

#current-symbol-display {
    font-size: 1.5rem;
    font-family: var(--font-mono);
    color: var(--accent-color);
}

.symbol-grid-container {
    margin-top: 15px;
}

.symbol-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 10px;
    margin-top: 10px;
    max-height: 200px;
    overflow-y: auto;
    padding: 5px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.symbol-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.symbol-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.symbol-item.selected {
    border-color: var(--accent-color);
    background: rgba(23, 147, 209, 0.2);
}

.symbol-char {
    font-size: 1.2rem;
    font-family: var(--font-mono);
    margin-bottom: 4px;
}

.symbol-name {
    font-size: 0.6rem;
    text-align: center;
    color: var(--text-secondary);
}

.modal-actions {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
}

/* Radar Sidebar */
.radar-sidebar {
    width: 300px;
    display: flex;
    flex-direction: column;
}

.radar-content {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.radar-display {
    aspect-ratio: 1;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    display: flex;
    justify-content: center;
    align-items: center;
}

.radar-status {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.gps-controls .btn-primary {
    background: var(--accent-color);
    color: black;
}

.station-info {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.station-info h3 {
    font-size: 0.9rem;
    margin-bottom: 10px;
    color: var(--accent-color);
    font-family: var(--font-heading);
}

#station-log {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Raw Terminal */
/* Raw Terminal (Top) */
/* Raw Terminal */
/* Raw Terminal (Inline) */
#terminal-panel {
    width: 100%;
    /* margin-top: 15px; */
    background: rgba(0, 0, 0, 0.6);
    border-top: 1px solid var(--glass-border);
    /* border-radius: 12px; */
    font-family: var(--font-mono);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
}

.terminal-header {
    padding: 10px 20px;
    background: rgba(23, 147, 209, 0.2);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--accent-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(23, 147, 209, 0.3);
}

.terminal-toggle-icon {
    transition: transform 0.3s;
}

.terminal-content {
    height: 300px;
    overflow-y: auto;
    padding: 15px;
    background: transparent;
}

.terminal-content.hidden {
    display: none;
}

.log-line {
    font-size: 0.75rem;
    color: #4af626;
    /* Hacker Green */
    white-space: pre-wrap;
    margin-bottom: 2px;
    word-break: break-all;
}

.log-line.system {
    color: #aaa;
}

.log-line.send {
    color: #00e5ff;
}

/* Cyan for TX */
.log-line.recv {
    color: #4af626;
}

/* Green for RX */
.log-line.error {
    color: #ff3333;
}

/* Mobile Optimization */
.mobile-only {
    display: none;
}

.mobile-nav {
    display: none;
}

@media (max-width: 768px) {
    body {
        overscroll-behavior: none;
        align-items: stretch;
        justify-content: flex-start;
    }

    #app {
        width: 100%;
        height: 100dvh;
        display: flex;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
    }

    .mobile-only {
        display: flex !important;
    }

    /* Hide desktop header buttons on mobile */
    #show-terminal-btn,
    #settings-btn,
    .logo {
        display: none !important;
    }

    #display-callsign {
        font-size: 0.85rem;
    }

    /* Hide top header toggle buttons */
    #mobile-menu-btn,
    #mobile-radar-btn {
        display: none !important;
    }

    /* FULL SCREEN DASHBOARD */
    #dashboard {
        width: 100%;
        height: 100dvh;
        /* Use dynamic viewport height */
        margin: 0;
        border-radius: 0;
        gap: 0;
        border: none;
        background: transparent;
        /* Let body bg show */
        box-shadow: none;
        padding-bottom: 65px;
        /* Space for bottom nav */
    }

    /* HEADER */
    .glass-nav {
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
        padding: 10px 20px;
        flex-shrink: 0;
        /* Never shrink header */
    }

    /* MAIN CONTENT AREA */
    .content-wrapper {
        height: auto;
        flex: 1;
        /* Take remaining space */
        position: relative;
        overflow: hidden;
        gap: 0;
    }

    /* TABS */
    .sidebar,
    .radar-sidebar,
    .chat-area {
        width: 100%;
        height: 100%;
        display: none;
        border: none;
        background: transparent;
        box-shadow: none;
        border-radius: 0;
        animation: none;
        /* Remove desktop animations */
    }

    .chat-area.active-tab,
    .sidebar.active-tab,
    .radar-sidebar.active-tab {
        display: flex;
        position: relative;
        /* Normal flow */
        transform: none;
        z-index: 1;
    }

    /* Reset absolute positioning from desktop styles if any leaked */
    .sidebar,
    .radar-sidebar {
        position: relative;
        transform: none;
        left: auto;
        right: auto;
        top: auto;
        bottom: auto;
        background: transparent;
        /* No double background */
        backdrop-filter: none;
    }

    /* Chat Tweaks */
    .chat-header {
        border-radius: 0;
        padding: 10px 20px;
    }

    .messages {
        padding: 15px 20px;
    }

    .chat-input-area {
        border-radius: 0;
        padding: 10px 15px;
        background: var(--glass-bg);
        /* Ensure visible bg for input area */
    }

    /* Bottom Navigation Bar */
    .mobile-nav {
        display: flex !important;
        justify-content: space-around;
        align-items: center;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 60px;
        background: rgba(23, 29, 32, 0.98) !important;
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid var(--glass-border);
        z-index: 99999 !important;
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: 0 -5px 25px rgba(0, 0, 0, 0.5);
        transform: none !important;
    }

    .nav-item {
        -webkit-appearance: none !important;
        appearance: none !important;
        background: transparent !important;
        background-color: transparent !important;
        border: none !important;
        outline: none !important;
        box-shadow: none !important;
        color: var(--text-secondary);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        font-size: 0.65rem;
        font-family: var(--font-main);
        cursor: pointer;
        flex: 1;
        height: 100%;
        padding: 8px 0;
    }

    .nav-item:hover,
    .nav-item:focus,
    .nav-item:active {
        background: transparent !important;
        background-color: transparent !important;
    }

    .nav-item.active {
        color: var(--accent-color);
    }

    .nav-item svg {
        width: 22px;
        height: 22px;
    }

    /* Login Mobile Fix */
    .login-card {
        width: 95%;
        padding: 30px 20px;
        border-radius: 20px;
    }
}

/* Map Modal */
.map-card {
    width: 90%;
    max-width: 800px;
    padding: 30px;
    display: flex;
    flex-direction: column;
}

/* Fix leaflet z-index issue with modal if needed, though glass-card usually handles it well. 
   Leaflet uses high z-indexes. */
/* Adjust dashboard when terminal is open */
/* Adjust dashboard when terminal is open - DISABLED FOR OVERLAY MODE */
/* 
body.terminal-open #dashboard {
    height: calc(100vh - 280px);
    position: absolute;
    top: 0;
    margin-top: 20px;
    width: 95%;
}
*/

/* Ensure raw terminal stays at bottom - REMOVED (Legacy/Wrong ID) */
/* 
body.terminal-open #terminal-footer {
    height: 250px;
}
*/

/* 
body.terminal-open .terminal-content {
    height: 220px;
}
*/

/* Brand Logo Styles */
.login-logo {
    width: 100%;
    max-width: 280px;
    height: auto;
    margin: 0 auto 20px auto;
    display: block;
    object-fit: contain;
}

.nav-logo {
    height: 45px;
    width: auto;
    max-width: 250px;
    object-fit: contain;
}



/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 60px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 350px;
}

.toast {
    padding: 15px 20px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.9rem;
    backdrop-filter: blur(12px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    animation: slideInRight 0.3s ease-out;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
}

.toast:hover {
    transform: translateX(-5px);
    opacity: 0.9;
}

.toast.success {
    border-left: 4px solid var(--success-green);
}

.toast.error {
    border-left: 4px solid var(--error-red);
}

.toast.info {
    border-left: 4px solid var(--accent-color);
}

.toast.warning {
    border-left: 4px solid #ffa500;
}

@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

.toast.hiding {
    animation: slideOutRight 0.3s ease-in forwards;
}