/* styles.css */

/* Navigation Bar */
.top-nav {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    background-color: #005a9e;
    color: white;
    padding: 8px 16px;
    margin: -20px -20px 20px -20px;
    font-size: 0.95em;
    gap: 6px;
}
.nav-title {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 5px 12px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}
.nav-right { display: contents; }  /* transparent wrapper — children go directly into nav flex */
.nav-links {
    display: flex;
    gap: 2px;
    margin-left: auto;   /* pushes links + logout to the right */
    flex-shrink: 0;
    align-items: center;
}
.nav-link {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.85em;
    white-space: nowrap;
    transition: background-color 0.2s;
}
.nav-link:hover {
    background-color: rgba(255,255,255,0.15);
    color: white;
}
.nav-link.active {
    background-color: rgba(255,255,255,0.2);
    color: white;
    font-weight: 500;
}
.nav-user {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
#nav-username { display: none; }
.nav-logout-btn {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    white-space: nowrap;
    transition: background-color 0.2s;
}
.nav-logout-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* Setup page layout */
.setup-container {
    max-width: 1280px;
    margin: auto;
    padding: 0;
}
.setup-layout {
    display: flex;
    flex-direction: row;
    gap: 0;
    min-height: 600px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.setup-nav {
    width: 220px;
    min-width: 220px;
    border-right: 1px solid #e8ecf0;
    overflow-y: auto;
    padding: 12px 0;
    border-radius: 8px 0 0 8px;
}

.setup-nav-cat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    font-weight: 600;
    font-size: 0.8em;
    color: #555;
    cursor: pointer;
    user-select: none;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.setup-nav-cat-header:hover { background-color: #f5f7fa; }

.setup-nav-chevron {
    font-size: 0.65em;
    color: #999;
    display: inline-block;
    transition: transform 0.15s ease;
}
.setup-nav-cat-header.open .setup-nav-chevron { transform: rotate(90deg); }

.setup-nav-cat-items { display: none; }
.setup-nav-cat-items.open { display: block; }

.setup-nav-item {
    display: block;
    padding: 8px 16px 8px 30px;
    font-size: 0.9em;
    color: #555;
    cursor: pointer;
    border-left: 3px solid transparent;
}
.setup-nav-item:hover { background-color: #f0f4f8; color: #333; }
.setup-nav-item.active {
    border-left-color: #005a9e;
    background-color: #e8f0fb;
    color: #005a9e;
    font-weight: 500;
}

.setup-content {
    flex: 1;
    padding: 24px;
    min-width: 0;
    background: #f7f9fc;
    border-radius: 0 8px 8px 0;
}
.setup-placeholder .placeholder-text, .placeholder-text {
    color: #888;
    font-style: italic;
    margin: 10px 0 0 0;
}

/* Config edit forms */
.config-edit-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}
.config-edit-form label {
    display: flex;
    flex-direction: column;
    font-size: 0.85em;
    color: #555;
    gap: 3px;
}
.config-edit-form input, .config-edit-form select {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.95em;
}
.btn-save {
    padding: 10px;
    border: none;
    border-radius: 4px;
    background-color: #005a9e;
    color: white;
    cursor: pointer;
    font-size: 0.95em;
    margin-top: 5px;
}
.btn-save:hover { background-color: #004b82; }
.btn-add {
    padding: 5px 12px;
    border: none;
    border-radius: 4px;
    background-color: #2e7d32;
    color: white;
    cursor: pointer;
    font-size: 0.85em;
}
.btn-add:hover { background-color: #1b5e20; }
.btn-sm {
    padding: 4px 10px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.8em;
}
.btn-edit { background-color: #1565c0; color: white; }
.btn-edit:hover { background-color: #0d47a1; }
.btn-toggle { background-color: #ff9800; color: white; }
.btn-toggle:hover { background-color: #e68a00; }
.btn-delete { background-color: #d32f2f; color: white; }
.btn-delete:hover { background-color: #b71c1c; }

/* Config list items */
.config-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.config-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background-color: #f7f9fc;
    border-radius: 4px;
    border: 1px solid #eee;
}
.config-list-info { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.config-list-actions { display: flex; gap: 5px; }
.config-tag {
    font-size: 0.75em;
    padding: 2px 6px;
    border-radius: 3px;
    background-color: #e0e0e0;
    color: #555;
}
.tag-on { background-color: #c8e6c9; color: #2e7d32; }
.tag-off { background-color: #ffcdd2; color: #c62828; }
.tag-filter { background-color: #e3f2fd; color: #1565c0; }

/* Form status */
.form-status { font-size: 0.85em; margin-top: 5px; padding: 6px; border-radius: 4px; }
.status-ok { background-color: #e8f5e9; color: #2e7d32; }
.status-err { background-color: #ffebee; color: #c62828; }

/* License banner */
/* NTP status badge */
.ntp-status {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: 500;
    width: fit-content;
}
.ntp-synced     { background-color: #c8e6c9; color: #1b5e20; }
.ntp-nofix      { background-color: #fff3e0; color: #e65100; }
.ntp-nostream   { background-color: #f5f5f5; color: #757575; }
.ntp-unlicensed { background-color: #f5f5f5; color: #9e9e9e; font-style: italic; }

/* Sensor card */
.sensor-card h3 { margin-top: 0; margin-bottom: 12px; }
.ntp-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}
.net-status {
    font-size: 0.88em;
    font-family: 'Courier New', monospace;
    color: #333;
}
.net-active   { color: #1b5e20; }
.net-inactive { color: #9e9e9e; font-style: italic; }

.net-warning {
    background-color: #ffebee;
    border: 1px solid #ef9a9a;
    color: #b71c1c;
    padding: 10px 14px;
    border-radius: 4px;
    font-size: 0.9em;
    margin-bottom: 10px;
}

.btn-reboot {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 4px;
    background-color: #c62828;
    color: white;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
}
.btn-reboot:hover    { background-color: #b71c1c; }
.btn-reboot:disabled { background-color: #e57373; cursor: not-allowed; }

.gnss-section-block {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid #eee;
}
.gnss-section-label {
    font-size: 0.78em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #888;
    margin-bottom: 8px;
    font-weight: 600;
}
.gnss-rtcm-table { width: 100%; border-collapse: collapse; margin-bottom: 4px; }
.gnss-rtcm-table td { padding: 3px 6px; vertical-align: middle; }
.gnss-rtcm-label { font-size: 0.88em; color: #444; width: 130px; }
.gnss-rtcm-table .btn-save { padding: 5px 10px; font-size: 0.82em; margin: 0; }
.gnss-result-box {
    font-family: 'Courier New', monospace;
    font-size: 0.82em;
    color: #333;
    background: #f5f5f5;
    padding: 8px;
    border-radius: 4px;
    min-height: 40px;
    white-space: pre-wrap;
    word-break: break-all;
}

.sensor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}
.sensor-item { display: flex; flex-direction: column; gap: 2px; }
.sensor-label { font-size: 0.78em; color: #777; }
.sensor-value { font-size: 1em; font-weight: 500; color: #222; }

.license-banner {
    background-color: #fff3e0;
    color: #e65100;
    padding: 12px 20px;
    border-radius: 6px;
    text-align: center;
    font-weight: 500;
    margin-bottom: 15px;
    border: 1px solid #ffcc02;
}
.license-status {
    margin-bottom: 10px;
}

/* Modal overlay */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}
.modal-content {
    background: white;
    border-radius: 8px;
    padding: 25px;
    width: 420px;
    max-width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
}
.modal-content h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #005a9e;
}
.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    justify-content: flex-end;
}
.btn-cancel {
    padding: 10px 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 0.95em;
}
.btn-cancel:hover { background: #f5f5f5; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f7f9fc;
    color: #333;
    margin: 0;
    padding: 20px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    display: grid;
    /* --- FIX 1: Make the right column slightly smaller for better balance --- */
    grid-template-columns: minmax(450px, 1fr) 1.1fr; 
    gap: 20px;
    max-width: 1280px;
    margin: auto;
    /* This aligns the top of the cards in each column */
    align-items: start; 
}

.left-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

.right-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
    align-self: start;
}

.card {
    background-color: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

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

.header h2 {
    margin: 0;
    color: #005a9e;
    font-weight: 600;
}

.live-clock {
    font-size: 1.1em;
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    color: #333;
    background-color: #eef2f7;
    padding: 5px 10px;
    border-radius: 5px;
}

/* Position and Status Card */
.position-card {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.position-item {
    display: flex;
    flex-direction: column;
}

.position-item .label {
    font-size: 0.8em;
    color: #777;
    margin-bottom: 4px;
}

.position-item .value {
    font-size: 1.1em;
    font-weight: 500;
}

.rtk-status {
    padding: 3px 8px;
    border-radius: 4px;
    text-align: center;
    color: white;
    background-color: #888;
    transition: background-color 0.5s ease;
    width: fit-content;
}

/* Constellation Table Card */
.card-header-with-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.card-header-with-total h3 {
    margin: 0;
}

.total-sat-count {
    font-size: 0.9em;
    font-weight: 500;
    color: #333;
    background-color: #eef2f7;
    padding: 4px 10px;
    border-radius: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    word-break: break-word; /* Helps prevent table overflow on mobile */
}

th, td {
    text-align: left;
    padding: 10px 4px;
    border-bottom: 1px solid #eee;
}

th {
    color: #555;
    font-weight: normal;
}

.freq-header {
    text-align: center;
}

td:not(:first-child) {
    text-align: center;
}

/* Mean Signal Level */
.mean-signal-value {
    font-size: 1.5em;
    font-weight: bold;
    color: #005a9e;
    margin: 10px 0;
}

.bar-chart-container {
    height: 180px;
    position: relative;
}

/* Skyplot and Legend */
.skyplot-container {
    position: relative;
    width: 100%;
    padding-top: 100%; /* Creates a square aspect ratio container */
}

#skyplot-chart {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

.legend-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 20px;
    font-size: 0.9em;
}

.legend-bar {
    width: 80%;
    height: 15px;
    background: linear-gradient(to right, hsl(0, 65%, 42%), hsl(60, 65%, 42%), hsl(120, 65%, 42%));
    border-radius: 5px;
    margin: 5px 0;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    width: 82%;
    font-size: 0.8em;
    color: #777;
}

/* Satellite hover tooltip */
.skyplot-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 0.8em;
    pointer-events: none;
    z-index: 100;
    display: none;
    white-space: nowrap;
    line-height: 1.5;
}
.skyplot-tooltip.visible { display: block; }

/* Login, Config, and Password Styles */
.hidden {
    display: none !important;
}

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

.login-modal {
    background-color: white;
    padding: 30px 40px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    text-align: center;
    width: 320px;
}

.login-modal h3 {
    margin-top: 0;
    margin-bottom: 25px;
    color: #333;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#login-form input, #password-change-form input {
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1em;
}

#login-form button, #password-change-form button {
    padding: 12px;
    border: none;
    border-radius: 4px;
    background-color: #005a9e;
    color: white;
    font-size: 1em;
    cursor: pointer;
    transition: background-color 0.2s;
}

#login-form button:hover, #password-change-form button:hover {
    background-color: #004b82;
}

.login-error-message {
    color: #d32f2f;
    font-size: 0.9em;
    margin-top: 10px;
    height: 1.2em;
}

.config-card h3, .password-change-card h3 {
    margin-top: 0;
}

.config-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: center;
    margin-top: 15px;
}

#command-select, #custom-command-input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    grid-column: 1 / -1; /* Span full width */
}

#send-command-btn {
    padding: 8px 16px;
    border: none;
    background-color: #2e7d32;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
    grid-column: 2 / 3; /* Position in the second column */
    justify-self: end;
}

#send-command-btn:hover {
    background-color: #1b5e20;
}

.command-status-message, .password-status-message {
    margin-top: 15px;
    padding: 8px;
    border-radius: 4px;
    font-size: 0.9em;
    display: none; /* Hidden by default */
}

.command-status-message.success, .password-status-message.success {
    background-color: #e8f5e9;
    color: #2e7d32;
    display: block;
}

.command-status-message.error, .password-status-message.error {
    background-color: #ffebee;
    color: #c62828;
    display: block;
}

#password-change-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
}


/* --- NEW: RESPONSIVE STYLES FOR MOBILE AND TABLETS --- */

@media (max-width: 992px) {
    body {
        padding: 10px;
    }

    .container {
        grid-template-columns: minmax(0, 1fr);
        gap: 15px;
    }
    .setup-layout {
        flex-direction: column;
    }
    .setup-nav {
        width: 100%;
        min-width: unset;
        border-right: none;
        border-bottom: 1px solid #e8ecf0;
        border-radius: 8px 8px 0 0;
    }
    .setup-content {
        border-radius: 0 0 8px 8px;
    }

    .top-nav {
        margin: -10px -10px 10px -10px;
        gap: 4px;
        overflow-x: auto;
    }

    /* Make text slightly smaller and more readable on mobile */
    .header h2 {
        font-size: 1.3em;
    }
    .card h3 {
        font-size: 1.1em;
    }

    /* Stack position items instead of having them side-by-side */
    .position-card {
        grid-template-columns: 1fr;
    }

    /* Make the config form controls stack vertically */
    .config-form {
        grid-template-columns: 1fr;
    }

    #send-command-btn {
        grid-column: 1 / -1; /* Span full width */
        justify-self: stretch; /* Make button full width */
    }
}

@media (max-width: 480px) {
    /* Further adjustments for very small screens (phones) */
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .card {
        padding: 15px;
    }

    .login-modal {
        width: 90%;
        padding: 20px;
    }
    
    .position-item .value {
        font-size: 1em;
    }
}

/* Mountpoint picker cards */
.mp-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 8px;
    background: #1e2a38;
    border: 1px solid #2e3f52;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.mp-card:hover { background: #253545; border-color: #4a90d9; }
.mp-card.offline { opacity: 0.55; cursor: default; }
.mp-card.offline:hover { background: #1e2a38; border-color: #2e3f52; }
.mp-dot {
    width: 14px; height: 14px; border-radius: 50%;
    flex-shrink: 0;
}
.mp-dot.online  { background: #4caf50; box-shadow: 0 0 6px #4caf5088; }
.mp-dot.offline { background: #555; }
.mp-info { flex: 1; min-width: 0; }
.mp-name { font-weight: 600; font-size: 1em; color: #e0e6ef; }
.mp-desc { font-size: 0.8em; color: #778899; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mp-meta { text-align: right; flex-shrink: 0; font-size: 0.78em; color: #778899; }
.mp-fix  { font-weight: 600; }
.mp-fix.rtk-fixed { color: #4caf50; }
.mp-fix.rtk-float { color: #1e88e5; }
.mp-status-online  { color: #4caf50; font-size: 0.75em; }
.mp-status-offline { color: #666;    font-size: 0.75em; }
