/* CSS Variables for light/dark mode support */
:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8f9fa;
    --text-primary: #333333;
    --text-secondary: #7f8c8d;
    --text-muted: #7f8c8d;
    --border-color: #ddd;
    --border-light: #eee;
    --accent-color: #3498db;
    --accent-hover: #2980b9;
    --header-color: #2c3e50;
    --success-bg: #d4edda;
    --success-text: #155724;
    --success-border: #c3e6cb;
    --error-bg: #f8d7da;
    --error-text: #721c24;
    --error-border: #f1b2b7;
    --loading-bg: #d1ecf1;
    --loading-text: #0c5460;
    --loading-border: #bee5eb;
    --warning-bg: #fff3cd;
    --warning-text: #856404;
    --warning-border: #ffeeba;
    --table-header-bg: #34495e;
    --table-header-hover: #2c3e50;
    --table-hover: #f8f9fa;
    --polar-bg: #2c3e50;
    --polar-border: #34495e;
    --popup-overlay: rgba(0, 0, 0, 0.7);
}

/* Dark mode variables */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a1a;
        --bg-secondary: #2d2d2d;
        --bg-tertiary: #3a3a3a;
        --text-primary: #e0e0e0;
        --text-secondary: #b0b0b0;
        --text-muted: #888888;
        --border-color: #555555;
        --border-light: #444444;
        --accent-color: #4a9eff;
        --accent-hover: #3d8bdb;
        --header-color: #ffffff;
        --success-bg: #1e4d2b;
        --success-text: #90ee90;
        --success-border: #2d5a36;
        --error-bg: #4d1e1e;
        --error-text: #ffb3b3;
        --error-border: #5a2d2d;
        --loading-bg: #1e3a4d;
        --loading-text: #87ceeb;
        --loading-border: #2d4a5a;
        --warning-bg: #4d3c1e;
        --warning-text: #ffd970;
        --warning-border: #5a4a2d;
        --table-header-bg: #404040;
        --table-header-hover: #505050;
        --table-hover: #3a3a3a;
        --polar-bg: #404040;
        --polar-border: #505050;
        --popup-overlay: rgba(0, 0, 0, 0.8);
    }
}

/* Mobile-first responsive design */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    padding: 1rem;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

header {
    text-align: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--header-color);
}

header h1 {
    color: var(--header-color);
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

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

/* Top toolbar: help button (left) + config actions (right) */
.top-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.toolbar-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.help-button {
    flex: 0 0 auto;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    border: 2px solid var(--accent-color);
    background: var(--bg-tertiary);
    color: var(--header-color);
    font-size: 1.25rem;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.help-button:hover,
.help-button:focus-visible {
    background: var(--accent-color);
    color: #fff;
}

.help-body ol {
    margin: 0.5rem 0 0.75rem 1.25rem;
}

.help-body li {
    margin-bottom: 0.4rem;
}

.help-body code {
    background: var(--bg-tertiary);
    padding: 0.05rem 0.3rem;
    border-radius: 3px;
    font-size: 0.9em;
}

.help-body .help-note {
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-light);
    padding-top: 0.6rem;
    margin-top: 0.6rem;
}

/* Section styling */
section {
    margin-bottom: 2rem;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: 6px;
    border-left: 4px solid var(--accent-color);
}

section h2 {
    color: var(--header-color);
    font-size: 1.2rem;
    margin-bottom: 1rem;
}

/* Input groups */
.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.input-group small {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* Grid layouts */
.location-grid,
.time-grid {
    display: grid;
    gap: 1rem;
}

/* Observer-location action buttons ("Get My Location" / "Choose from Map"):
   stack them with a vertical gap (mirrors the spacing between the TLE buttons). */
.location-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
}
.location-actions .secondary-button {
    width: auto;
}

.datetime-input {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.datetime-input input[type="date"],
.datetime-input .time-input {
    flex: 1;
    min-width: 0;
}

.datetime-input input[type="date"] {
    min-width: 140px;
}

.datetime-input .time-input {
    min-width: 100px;
    font-family: monospace;
    text-align: center;
}

.time-input:invalid {
    border-color: #e74c3c;
    background-color: rgba(231, 76, 60, 0.1);
}

.time-input:valid {
    border-color: #27ae60;
}

@media (min-width: 768px) {
    .location-grid {
        grid-template-columns: 1fr 1fr 1fr;
    }
    
    .time-grid {
        grid-template-columns: 1fr 1fr 1fr;
    }
    
    .container {
        padding: 2rem;
    }
    
    header h1 {
        font-size: 2.5rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    section h2 {
        font-size: 1.4rem;
    }
}

/* Buttons */
button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.primary-button {
    background-color: var(--accent-color);
    color: white;
    font-weight: 500;
    width: 100%;
    margin-bottom: 1rem;
}

.primary-button:hover:not(:disabled) {
    background-color: var(--accent-hover);
}

.primary-button:disabled {
    background-color: var(--text-muted);
    cursor: not-allowed;
}


@media (min-width: 768px) {
    .primary-button {
        width: auto;
        margin-right: 1rem;
    }
}

/* Status messages */
.status-message {
    padding: 0.75rem;
    border-radius: 4px;
    margin-top: 1rem;
    font-size: 0.9rem;
}

.status-message.success {
    background-color: var(--success-bg);
    color: var(--success-text);
    border: 1px solid var(--success-border);
}

.status-message.error {
    background-color: var(--error-bg);
    color: var(--error-text);
    border: 1px solid var(--error-border);
}

.status-message.loading {
    background-color: var(--loading-bg);
    color: var(--loading-text);
    border: 1px solid var(--loading-border);
}

.status-message.warning {
    background-color: var(--warning-bg);
    color: var(--warning-text);
    border: 1px solid var(--warning-border);
}

/* Dropdown for satellite search */
.dropdown-list {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 200px;
    overflow-y: auto;
    display: none;
    z-index: 1000;
}

.dropdown-list.show {
    display: block;
}

.dropdown-item {
    padding: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}

.dropdown-item:hover,
.dropdown-item:focus {
    background-color: var(--table-hover);
}

.dropdown-item.selected {
    background-color: var(--accent-color);
    color: white;
}

/* Selected satellites list */
.selected-list {
    margin-top: 1rem;
}

.selected-satellite {
    display: inline-block;
    background-color: var(--accent-color);
    color: white;
    padding: 0.5rem 1rem;
    margin: 0.25rem;
    border-radius: 20px;
    font-size: 0.9rem;
}

.selected-satellite .remove {
    margin-left: 0.5rem;
    cursor: pointer;
    font-weight: bold;
}

.selected-satellite .remove:hover {
    color: #e74c3c;
}

/* Results table */
.results-container {
    overflow-x: auto;
    margin-top: 1rem;
}

.satellite-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.satellite-table th,
.satellite-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}

.satellite-table th {
    background-color: var(--table-header-bg);
    color: white;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

.satellite-table th:hover {
    background-color: var(--table-header-hover);
}

.satellite-table tbody tr {
    cursor: pointer;
    transition: background-color 0.2s ease;
    /* Rows are double-clicked to open the pass detail; stop that gesture from
       selecting/highlighting the row text. */
    user-select: none;
    -webkit-user-select: none;
}

.satellite-table tbody tr:hover {
    background-color: var(--table-hover);
}

.satellite-table .no-results {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
}

/* Left-align Culmination column data (3rd column) */
.satellite-table tbody td:nth-child(3) {
    text-align: left;
}

@media (min-width: 768px) {
    .satellite-table th,
    .satellite-table td {
        padding: 1rem;
        font-size: 1rem;
    }
}

/* Polar coordinate visualization */
.polar-display {
    width: 280px;
    height: 280px;
    border-radius: 50%;
    position: relative;
    margin: 1rem auto;
    background: var(--polar-bg);
    border: 2px solid var(--polar-border);
}

@media (min-width: 768px) {
    .polar-display {
        width: 350px;
        height: 350px;
    }
}

/* Popup styles */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--popup-overlay);
    display: none;
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.popup-overlay.show {
    display: flex;
}

.popup-content {
    background: var(--bg-secondary);
    border-radius: 8px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

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

.popup-header h3 {
    color: var(--header-color);
    margin: 0;
}

.close-button {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    width: 2rem;
    height: 2rem;
}

.close-button:hover {
    color: #e74c3c;
}

.popup-body {
    padding: 1rem;
}

.countdown {
    text-align: center;
    font-size: 1.5rem;
    font-weight: bold;
    color: #e67e22;
    margin-bottom: 1rem;
}

.pass-info {
    margin-top: 1rem;
}

.pass-info h4 {
    color: var(--header-color);
    margin-bottom: 0.5rem;
}

.pass-info p {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

/* A text block (ECEF / real-time) with a small floating action button in its
   bottom-right corner (copy-to-clipboard, show-on-map). */
.copyable-box {
    position: relative;
}
.copyable-box > pre {
    margin: 0;
}
.icon-btn {
    position: absolute;
    right: 6px;
    bottom: 6px;
    padding: 2px 6px;
    font-size: 14px;
    line-height: 1.2;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    opacity: 0.85;
    transition: opacity 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover {
    opacity: 1;
    border-color: var(--accent-color);
}
.icon-btn.copied {
    color: #27ae60;
    border-color: #27ae60;
}

/* TLE Display with tooltips */
.tle-display {
    font-family: monospace;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    white-space: pre;
    line-height: 1.6;
    overflow: visible;
    position: relative;
}

.tle-element {
    position: relative;
    cursor: help;
    border-radius: 2px;
    transition: background-color 0.15s ease;
}

.tle-element:hover {
    background-color: var(--accent-color);
    color: white;
}

.tle-element[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #2c3e50;
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    max-width: 300px;
    white-space: normal;
    text-align: center;
    line-height: 1.4;
}

.tle-element[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #2c3e50;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
}

.tle-element:hover[data-tooltip]::after,
.tle-element:hover[data-tooltip]::before {
    opacity: 1;
    visibility: visible;
}

/* Position tooltips that would overflow left edge */
.tle-element.tooltip-right[data-tooltip]::after {
    left: 0;
    transform: translateX(0);
}

.tle-element.tooltip-right[data-tooltip]::before {
    left: 10px;
    transform: translateX(0);
}

/* Position tooltips that would overflow right edge */
.tle-element.tooltip-left[data-tooltip]::after {
    left: auto;
    right: 0;
    transform: translateX(0);
}

.tle-element.tooltip-left[data-tooltip]::before {
    left: auto;
    right: 10px;
    transform: translateX(0);
}

@media (prefers-color-scheme: dark) {
    .tle-element[data-tooltip]::after {
        background: #4a4a4a;
    }

    .tle-element[data-tooltip]::before {
        border-top-color: #4a4a4a;
    }
}

/* Utility classes */
.hidden {
    display: none !important;
}

.loading {
    opacity: 0.7;
    pointer-events: none;
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --table-header-bg: #000000;
        --table-header-hover: #333333;
        --accent-color: #0066cc;
        --accent-hover: #004499;
        --border-color: #666666;
        --border-light: #555555;
    }
    
    .satellite-table th {
        background-color: var(--table-header-bg);
        color: #ffffff;
    }
    
    button {
        border: 2px solid var(--accent-color);
    }
    
    .input-group input,
    .input-group select {
        border: 2px solid var(--border-color);
    }
}

/* Sentinel RESORB Enhancement Styling */
.resorb-controls {
    margin: 15px 0;
    padding: 15px;
    background-color: var(--bg-tertiary);
    border-radius: 8px;
    border-left: 4px solid var(--accent-color);
}

.resorb-controls button {
    margin-right: 10px;
    margin-bottom: 5px;
}

.resorb-controls .secondary-button {
    background-color: var(--text-secondary);
    color: var(--bg-secondary);
    border: 1px solid var(--text-secondary);
}

.resorb-controls .secondary-button:hover:not(:disabled) {
    background-color: var(--text-primary);
    border-color: var(--text-primary);
}

.resorb-controls .secondary-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}


/* Authentication Modal Styling */
#sentinel-auth-modal .popup-content {
    max-width: 450px;
    width: 90%;
}

#sentinel-auth-modal .input-group {
    margin-bottom: 15px;
}

#sentinel-auth-modal .input-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: var(--text-primary);
}

#sentinel-auth-modal .input-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    box-sizing: border-box;
}

#sentinel-auth-modal .input-group input:focus {
    border-color: var(--accent-color);
    outline: none;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

#sentinel-auth-modal .input-group button {
    margin-right: 10px;
}

#sentinel-auth-modal p {
    margin: 10px 0;
    line-height: 1.5;
}

#sentinel-auth-modal a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: bold;
}

#sentinel-auth-modal a:hover {
    text-decoration: underline;
}


/* Status message enhancements for RESORB */
.status-message.resorb-success {
    background-color: #d4edda;
    color: #155724;
    border-color: #c3e6cb;
    border-left: 4px solid #28a745;
}

.status-message.resorb-loading {
    background-color: #d1ecf1;
    color: #0c5460;
    border-color: #bee5eb;
    border-left: 4px solid #17a2b8;
}

.status-message.resorb-error {
    background-color: #f8d7da;
    color: #721c24;
    border-color: #f1b2b7;
    border-left: 4px solid #dc3545;
}

/* TLE controls row: source select + "Fetch from Celestrak" + "Upload TLE File",
   all on one line and stretched to equal height. */
.tle-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0.5rem;
}
.tle-controls button {
    flex: 0 0 auto;
}

/* Source selector — distinct color, sized to match the buttons' height (align-items: stretch
   equalizes the heights regardless of each control's own padding). */
#celestrak-source {
    font-size: 1rem;
    padding: 0.5rem 0.75rem;
    min-width: 13rem;
    max-width: 100%;
    border: 2px solid #1b5e20;
    border-radius: 4px;
    background-color: #2e7d32;
    color: #ffffff;
    font-weight: 600;
    cursor: pointer;
}
#celestrak-source option {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-weight: 400;
    font-size: 1rem;
}

/* ===== Choose-from-map location picker ===== */
.location-map-content { max-width: 900px; }

.location-map-container {
    position: relative;
    width: 100%;
    aspect-ratio: 2 / 1;
    background: var(--polar-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    touch-action: none;
    cursor: grab;
}
.location-map-container.grabbing { cursor: grabbing; }

#location-map-svg { display: block; width: 100%; height: 100%; }
#location-map-svg .lm-ocean  { fill: var(--polar-bg); }
#location-map-svg .lm-grat   { stroke: var(--border-light); fill: none; }
#location-map-svg .lm-land   { fill: var(--bg-secondary); stroke: var(--text-muted); }
#location-map-svg .lm-frame  { fill: none; stroke: var(--text-secondary); }
#location-map-svg .lm-marker { fill: var(--accent-color); stroke: #ffffff; }
#location-map-svg .lm-marker-arrow { fill: #ff5252; stroke: #ffffff; }
#location-map-svg .lm-track-line { stroke: var(--accent-color); fill: none; opacity: 0.85; }
#location-map-svg .lm-site-hit   { fill: transparent; pointer-events: all; cursor: pointer; }
#location-map-svg .lm-site-dot   { fill: #f39c12; stroke: #ffffff; pointer-events: none; }
#location-map-svg .lm-site-label {
    fill: #ffffff;
    stroke: rgba(0, 0, 0, 0.85);
    stroke-width: 2px;
    paint-order: stroke;
    vector-effect: non-scaling-stroke;
    font-family: sans-serif;
    font-weight: 600;
}

.location-map-zoom {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.map-zoom-btn {
    width: 32px;
    height: 32px;
    font-size: 1.2rem;
    line-height: 1;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
}
.map-zoom-btn:hover { border-color: var(--accent-color); }

.location-map-footer {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}
#location-map-readout { font-family: monospace; margin: 0; }
.location-map-footer .primary-button { margin-left: auto; }

@media (max-width: 600px) {
    .location-map-content { max-width: 100%; }
    .location-map-footer .primary-button { margin-left: 0; width: 100%; }
}

/* Responsive adjustments for RESORB controls */
@media (max-width: 768px) {
    .resorb-controls {
        padding: 10px;
    }
    
    .resorb-controls button {
        width: 100%;
        margin: 5px 0;
    }
    
    #sentinel-auth-modal .popup-content {
        width: 95%;
        margin: 20px auto;
    }
    
}