/* General Design System & Tokens */
:root {
    --bg-primary: #0a0f1d;
    --bg-secondary: #121829;
    --card-bg: rgba(20, 28, 52, 0.6);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --neon-cyan: #06b6d4;
    --neon-cyan-glow: rgba(6, 182, 212, 0.3);
    --neon-green: #10b981;
    --neon-green-glow: rgba(16, 185, 129, 0.3);
    --neon-red: #ef4444;
    --neon-red-glow: rgba(239, 68, 68, 0.3);
    --neon-amber: #f59e0b;
    --neon-amber-glow: rgba(245, 158, 11, 0.3);
    --neon-purple: #8b5cf6;
    
    --glass-blur: blur(12px);
    
    /* Saab R4 LCD Colors */
    --r4-lcd-bg-day: #8da388;
    --r4-lcd-text-day: #182218;
    --r4-lcd-text-dim-day: rgba(24, 34, 24, 0.6);
    --r4-lcd-glow-day: rgba(141, 163, 136, 0.3);
    
    --r4-lcd-bg-night: #250808;
    --r4-lcd-text-night: #ff4545;
    --r4-lcd-text-dim-night: rgba(255, 69, 69, 0.5);
    --r4-lcd-glow-night: rgba(255, 69, 69, 0.2);
    
    /* Configurable variables for R4 */
    --r4-backlight: 90%;
    --r4-contrast: 100%;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Premium Header styling */
header {
    background: linear-gradient(180deg, var(--bg-secondary) 0%, rgba(10, 15, 29, 0.8) 100%);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    backdrop-filter: var(--glass-blur);
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand svg {
    color: var(--neon-cyan);
    filter: drop-shadow(0 0 8px var(--neon-cyan-glow));
}

.brand h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    background: linear-gradient(90deg, #fff 0%, #cbd5e1 50%, var(--neon-cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand span {
    font-size: 0.8rem;
    color: var(--neon-cyan);
    border: 1px solid var(--neon-cyan);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-weight: 600;
    margin-left: 0.5rem;
    text-transform: uppercase;
}

.version-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    -webkit-text-fill-color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 0.05rem 0.3rem;
    border-radius: 4px;
    margin-left: 0.5rem;
    vertical-align: middle;
    display: inline-block;
}

/* Controls & View Toggles */
.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.view-toggles {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.25rem;
    border-radius: 8px;
    display: flex;
    border: 1px solid var(--border-color);
}

.btn-toggle {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-toggle.active {
    background: var(--neon-cyan);
    color: #000;
    font-weight: 600;
    box-shadow: 0 0 10px rgba(6, 182, 212, 0.4);
}

.btn-toggle:hover:not(.active) {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.btn-simulator-ctrl {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.btn-simulator-ctrl:hover {
    background: rgba(239, 68, 68, 0.2);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.2);
}

/* Master Layout */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.workspace-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 1.5rem;
    flex: 1;
    transition: all 0.3s ease;
}

body.view-r40-only .workspace-grid {
    grid-template-columns: 1fr 0fr;
}
body.view-r40-only .r4-column {
    display: none;
}

body.view-r4-only .workspace-grid {
    grid-template-columns: 0fr 1fr;
}
body.view-r4-only .r40-column {
    display: none;
}

/* Columns */
.r40-column {
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    backdrop-filter: var(--glass-blur);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.r4-column {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* Simulation Controls Drawer */
.sim-controls-panel {
    background: rgba(18, 24, 41, 0.95);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 12px 12px;
    padding: 1rem;
    margin: 0 1.5rem 1.5rem 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.sim-controls-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--neon-amber);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    margin-bottom: 0.5rem;
}

.sim-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.sim-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.sim-btn.active-event {
    background: rgba(245, 158, 11, 0.15);
    border-color: var(--neon-amber);
    color: var(--neon-amber);
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.2);
}

/* ==========================================================================
   MODULE 1: Saab R40 Web Base Station GUI
   ========================================================================== */
.r40-web-app {
    display: flex;
    flex-direction: column;
    height: 720px;
}

/* Navigation tabs in R40 Web Panel */
.r40-nav {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border-color);
}

.r40-tab {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 1rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.r40-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.02);
}

.r40-tab.active {
    color: var(--neon-cyan);
    border-bottom-color: var(--neon-cyan);
    background: rgba(6, 182, 212, 0.05);
}

.r40-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.r40-panel {
    display: none;
    flex: 1;
    flex-direction: column;
}

.r40-panel.active {
    display: flex;
}

/* Sub-navigation inside Monitor & Configure */
.r40-subnav {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.5rem;
}

.r40-subtab {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.r40-subtab:hover {
    color: var(--text-secondary);
}

.r40-subtab.active {
    color: var(--neon-cyan);
    background: rgba(6, 182, 212, 0.1);
}

/* Subpanels inside panels */
.r40-subpanel {
    display: none;
    flex: 1;
    flex-direction: column;
}

.r40-subpanel.active {
    display: flex;
}

/* 2.1 MONITOR SECTION */
/* Monitor Alarms List */
.alarms-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.alarm-card {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.3s;
}

.alarm-info h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.alarm-info p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.alarm-badge {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(0,0,0,0.5);
    position: relative;
}

/* Colors for alarms */
.alarm-badge.ok {
    background: var(--neon-green);
    box-shadow: 0 0 10px var(--neon-green-glow);
}
.alarm-badge.warning {
    background: var(--neon-amber);
    box-shadow: 0 0 10px var(--neon-amber-glow);
    animation: pulse 1.5s infinite;
}
.alarm-badge.fault {
    background: var(--neon-red);
    box-shadow: 0 0 10px var(--neon-red-glow);
    animation: pulse-red 1s infinite;
}
.alarm-badge.na {
    background: #4b5563;
    box-shadow: none;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.15); opacity: 1; box-shadow: 0 0 14px var(--neon-amber-glow); }
    100% { transform: scale(1); opacity: 0.8; }
}

@keyframes pulse-red {
    0% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.2); opacity: 1; box-shadow: 0 0 16px var(--neon-red-glow); }
    100% { transform: scale(1); opacity: 0.8; }
}

/* System Status Dashboard */
.status-dashboard {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.status-card {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
}

.status-card h4 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.25rem;
}

.status-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--neon-cyan);
    margin-bottom: 0.25rem;
}

.status-detail {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.load-bar-container {
    background: rgba(255,255,255,0.05);
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    margin: 0.5rem 0;
}
.load-bar-fill {
    background: linear-gradient(90deg, var(--neon-green), var(--neon-cyan));
    height: 100%;
    width: 18%;
    transition: width 0.5s ease;
}

/* Position Reports (Map & Ship List Dual Panel) */
.pos-report-layout {
    display: grid;
    grid-template-rows: 320px 1fr;
    gap: 1rem;
    flex: 1;
    min-height: 0;
}

.map-container-wrapper {
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    height: 100%;
}

#leaflet-map {
    height: 100%;
    width: 100%;
    background: #0f172a;
}

.vessel-list-container {
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(0,0,0,0.15);
    max-height: 250px;
}

.r40-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.8rem;
}

.r40-table th {
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 0.6rem 0.8rem;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid var(--border-color);
}

.r40-table td {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
}

.r40-table tbody tr {
    cursor: pointer;
    transition: background 0.15s;
}

.r40-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.r40-table tbody tr.selected {
    background: rgba(239, 68, 68, 0.15) !important;
    border-left: 3px solid var(--neon-red);
}

.r40-table tbody tr.selected td {
    color: #f87171;
}

.ship-badge {
    font-size: 0.7rem;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-weight: 600;
}
.ship-badge.own {
    background: rgba(6, 182, 212, 0.2);
    color: var(--neon-cyan);
    border: 1px solid rgba(6, 182, 212, 0.4);
}
.ship-badge.ai {
    background: rgba(139, 92, 246, 0.2);
    color: #c084fc;
    border: 1px solid rgba(139, 92, 246, 0.4);
}
.ship-badge.aton {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.4);
}

/* 2.2 CONFIGURATION SECTION */
/* Password Lock Cover */
.lock-cover {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 3rem;
    text-align: center;
}

.lock-icon-box {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
    color: var(--neon-amber);
    animation: pulse-glow-amber 2s infinite;
}

@keyframes pulse-glow-amber {
    0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(245, 158, 11, 0); }
    100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

.lock-cover h3 {
    margin-bottom: 0.5rem;
}

.lock-cover p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

.password-input-group {
    display: flex;
    gap: 0.5rem;
    max-width: 320px;
    width: 100%;
}

.r40-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    color: #fff;
    font-family: inherit;
    font-size: 0.85rem;
}

.r40-input:focus {
    outline: none;
    border-color: var(--neon-cyan);
    box-shadow: 0 0 8px rgba(6, 182, 212, 0.2);
}

.r40-btn {
    background: var(--neon-cyan);
    color: #000;
    font-weight: 600;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.r40-btn:hover {
    opacity: 0.9;
    box-shadow: 0 0 10px var(--neon-cyan-glow);
}

.r40-btn.btn-secondary {
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.r40-btn.btn-secondary:hover {
    background: rgba(255,255,255,0.15);
    box-shadow: none;
}

.password-error {
    color: var(--neon-red);
    font-size: 0.75rem;
    margin-top: 0.5rem;
    display: none;
}

/* Config Grid */
.config-layout {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-section {
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.2rem;
}

.form-section h4 {
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-group label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.config-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.unsaved-warning {
    color: var(--neon-amber);
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-right: auto;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.3s;
}

.unsaved-warning.visible {
    opacity: 1;
}

/* AtoN Creation Subpanel */
.aton-layout {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 1.5rem;
}

.aton-form-box {
    background: rgba(0,0,0,0.15);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
}

.aton-list-box {
    background: rgba(0,0,0,0.15);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    max-height: 480px;
}

.aton-list-scroll {
    overflow-y: auto;
    flex: 1;
}

/* Hot Standby (Redundancy) Styles */
.redundancy-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.station-node {
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 1.2rem;
    background: rgba(0,0,0,0.2);
    position: relative;
    transition: all 0.3s;
}

.station-node.active-role {
    border-color: var(--neon-green);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.15);
}
.station-node.standby-role {
    border-color: var(--neon-amber);
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.15);
}

.node-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.node-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.node-status-label {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
}

.node-status-label.online {
    background: rgba(16, 185, 129, 0.2);
    color: var(--neon-green);
    border: 1px solid rgba(16, 185, 129, 0.4);
}

.node-status-label.standby {
    background: rgba(245, 158, 11, 0.2);
    color: var(--neon-amber);
    border: 1px solid rgba(245, 158, 11, 0.4);
}

.redundancy-diagram {
    grid-column: span 2;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
}

.diagram-link {
    flex: 1;
    height: 4px;
    background: repeating-linear-gradient(90deg, var(--neon-green), var(--neon-green) 10px, transparent 10px, transparent 20px);
    position: relative;
}
.diagram-link.failed {
    background: repeating-linear-gradient(90deg, var(--neon-red), var(--neon-red) 10px, transparent 10px, transparent 20px);
}

/* 2.3 HW/SW INFO & MAINTENANCE */
.info-section {
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.2rem;
    margin-bottom: 1.5rem;
}

.license-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.8rem;
    margin-top: 1rem;
}

.license-item {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border-color);
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.license-name {
    font-size: 0.85rem;
    font-weight: 500;
}

.license-status {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-weight: 600;
}

.license-status.active {
    background: rgba(16, 185, 129, 0.2);
    color: var(--neon-green);
}
.license-status.inactive {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
}

/* Maintenance Upload Zone */
.maintenance-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.update-box {
    border: 2px dashed rgba(6, 182, 212, 0.3);
    background: rgba(6, 182, 212, 0.02);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.update-box:hover {
    border-color: var(--neon-cyan);
    background: rgba(6, 182, 212, 0.05);
}

.progress-container {
    width: 100%;
    background: rgba(255,255,255,0.05);
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 1rem;
    display: none;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--neon-cyan);
    transition: width 0.1s linear;
}

.maintenance-log {
    background: #05070f;
    border: 1px solid var(--border-color);
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.75rem;
    color: #a7f3d0;
    padding: 0.8rem;
    border-radius: 6px;
    height: 140px;
    overflow-y: auto;
    white-space: pre-wrap;
    margin-top: 1rem;
}

/* ==========================================================================
   MODULE 2: Saab R4 Ship Transponder Physical Simulation
   ========================================================================== */
.r4-hardware-panel {
    background: linear-gradient(135deg, #374151 0%, #1f2937 100%);
    border: 4px solid #111827;
    border-radius: 20px;
    width: 440px;
    padding: 1.5rem;
    box-shadow: 
        0 15px 35px rgba(0, 0, 0, 0.5), 
        inset 0 2px 4px rgba(255,255,255,0.2), 
        inset 0 -5px 15px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    user-select: none;
    position: relative;
    border-bottom: 8px solid #0b0f19;
}

/* Hardware Screws */
.r4-hardware-panel::before,
.r4-hardware-panel::after,
.screw-bottom-left,
.screw-bottom-right {
    content: " ";
    position: absolute;
    width: 12px;
    height: 12px;
    background: radial-gradient(circle, #6b7280 20%, #374151 60%, #111827 100%);
    border-radius: 50%;
    box-shadow: inset 0 1px 2px rgba(255,255,255,0.4), 0 2px 4px rgba(0,0,0,0.5);
}
.r4-hardware-panel::before { top: 12px; left: 12px; }
.r4-hardware-panel::after { top: 12px; right: 12px; }
.screw-bottom-left { bottom: 12px; left: 12px; }
.screw-bottom-right { bottom: 12px; right: 12px; }

/* Panel Branding */
.r4-brand {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0.5rem;
    margin-top: 0.5rem;
}

.r4-brand-name {
    font-weight: 800;
    font-size: 0.85rem;
    color: #e5e7eb;
    letter-spacing: 0.1em;
    text-shadow: 1px 1px 1px #000;
}

.r4-model {
    font-weight: 700;
    font-size: 0.75rem;
    color: #9ca3af;
    text-shadow: 1px 1px 1px #000;
    border: 1px solid #4b5563;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    background: #111827;
}

/* Hardware Indicators (LEDs) */
.r4-indicators {
    display: flex;
    gap: 1.5rem;
    background: #111827;
    padding: 0.4rem 1.2rem;
    border-radius: 6px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.8), 0 1px 1px rgba(255,255,255,0.1);
    border: 1px solid #374151;
}

.led-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
}

.led-label {
    font-size: 0.6rem;
    font-weight: 700;
    color: #9ca3af;
}

.led-light {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #1f2937;
    border: 1px solid #000;
    box-shadow: inset 0 1px 1px rgba(255,255,255,0.1);
    transition: background 0.15s;
}

/* LED Lit states */
.led-light.tx-lit {
    background: #f97316;
    box-shadow: 0 0 8px #ea580c, inset 0 1px 2px rgba(255,255,255,0.5);
}

.led-light.rx-lit {
    background: #22c55e;
    box-shadow: 0 0 8px #16a34a, inset 0 1px 2px rgba(255,255,255,0.5);
}

.led-light.alarm-lit {
    background: #ef4444;
    box-shadow: 0 0 8px #dc2626, inset 0 1px 2px rgba(255,255,255,0.5);
}

/* LCD Display Assembly */
.r4-screen-bezel {
    width: 100%;
    background: #0f172a;
    border: 6px solid #1f2937;
    border-radius: 8px;
    padding: 0.75rem;
    box-shadow: 
        inset 0 4px 10px rgba(0,0,0,0.9), 
        0 2px 4px rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* LCD Screen Glow & Day/Night contrast overlay */
.r4-lcd-screen {
    height: 220px;
    background-color: var(--r4-lcd-bg-day);
    color: var(--r4-lcd-text-day);
    border-radius: 4px;
    font-family: 'Share Tech Mono', monospace;
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 0.4rem;
    overflow: hidden;
    filter: brightness(var(--r4-backlight)) contrast(var(--r4-contrast));
    box-shadow: inset 0 0 15px rgba(0,0,0,0.3);
    transition: background-color 0.5s, color 0.5s;
}

.r4-lcd-screen.night-mode {
    background-color: var(--r4-lcd-bg-night);
    color: var(--r4-lcd-text-night);
}

/* CRT scanlines effect */
.r4-lcd-screen::before {
    content: "";
    display: block;
    position: absolute;
    top: 0; left: 0; bottom: 0; right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.08) 50%);
    background-size: 100% 3px;
    z-index: 5;
    pointer-events: none;
}

/* Screen Powered Off State */
.r4-lcd-screen.powered-off {
    background: #040804 !important;
    color: transparent !important;
    box-shadow: inset 0 0 20px #000;
}
.r4-lcd-screen.powered-off * {
    display: none !important;
}

/* LCD Screen Subcomponents */
.lcd-header {
    height: 18px;
    border-bottom: 1px solid var(--r4-lcd-text-day);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 700;
    padding-bottom: 0.1rem;
    text-transform: uppercase;
}
.r4-lcd-screen.night-mode .lcd-header {
    border-bottom-color: var(--r4-lcd-text-night);
}

.lcd-header-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lcd-header-status {
    display: flex;
    gap: 0.5rem;
    font-size: 0.65rem;
}

.lcd-body {
    flex: 1;
    padding: 0.3rem 0;
    font-size: 0.75rem;
    line-height: 1.15;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

.lcd-footer {
    height: 20px;
    border-top: 1px dashed var(--r4-lcd-text-day);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.7rem;
    font-weight: 700;
    padding-top: 0.1rem;
}
.r4-lcd-screen.night-mode .lcd-footer {
    border-top-color: var(--r4-lcd-text-night);
}

.softkey-label {
    width: 20%;
    text-align: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    border-right: 1px solid rgba(24, 34, 24, 0.2);
}
.softkey-label:last-child {
    border-right: none;
}
.r4-lcd-screen.night-mode .softkey-label {
    border-right-color: rgba(255, 69, 69, 0.2);
}

/* Boot screen */
.boot-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 1rem;
    text-align: center;
}

.boot-logo {
    font-size: 1.2rem;
    font-weight: 900;
    letter-spacing: 0.1em;
}

.boot-progress-bar {
    width: 140px;
    height: 6px;
    border: 1px solid var(--r4-lcd-text-day);
    padding: 1px;
}
.r4-lcd-screen.night-mode .boot-progress-bar {
    border-color: var(--r4-lcd-text-night);
}

.boot-progress-fill {
    background: var(--r4-lcd-text-day);
    height: 100%;
    width: 0%;
    transition: width 0.1s linear;
}
.r4-lcd-screen.night-mode .boot-progress-fill {
    background: var(--r4-lcd-text-night);
}

/* LCD target list layout */
.lcd-list {
    flex: 1;
    overflow-y: hidden;
    position: relative;
}

.lcd-row {
    display: flex;
    justify-content: space-between;
    padding: 0.1rem 0.2rem;
    white-space: nowrap;
}

.lcd-row.selected {
    background: var(--r4-lcd-text-day);
    color: var(--r4-lcd-bg-day) !important;
    font-weight: 800;
}
.r4-lcd-screen.night-mode .lcd-row.selected {
    background: var(--r4-lcd-text-night);
    color: var(--r4-lcd-bg-night) !important;
    font-weight: 800;
}

/* LCD scrollbar indicator */
.lcd-scroll-indicator {
    position: absolute;
    right: 1px;
    top: 5px;
    bottom: 5px;
    width: 3px;
    background: rgba(0,0,0,0.1);
}
.r4-lcd-screen.night-mode .lcd-scroll-indicator {
    background: rgba(255,255,255,0.05);
}

.lcd-scroll-thumb {
    position: absolute;
    width: 100%;
    background: var(--r4-lcd-text-day);
    top: 0;
    height: 30%;
}
.r4-lcd-screen.night-mode .lcd-scroll-thumb {
    background: var(--r4-lcd-text-night);
}

/* LCD Radar Plot Screen */
.lcd-radar-plot {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.lcd-radar-circles {
    border-radius: 50%;
    border: 1px dashed rgba(24, 34, 24, 0.2);
    position: absolute;
}
.r4-lcd-screen.night-mode .lcd-radar-circles {
    border-color: rgba(255, 69, 69, 0.2);
}

.lcd-radar-circle-1 { width: 50px; height: 50px; }
.lcd-radar-circle-2 { width: 100px; height: 100px; }
.lcd-radar-circle-3 { width: 150px; height: 150px; }

.lcd-radar-crosshair-h {
    width: 160px;
    height: 1px;
    border-top: 1px dotted rgba(24, 34, 24, 0.2);
    position: absolute;
}
.lcd-radar-crosshair-v {
    width: 1px;
    height: 160px;
    border-left: 1px dotted rgba(24, 34, 24, 0.2);
    position: absolute;
}
.r4-lcd-screen.night-mode .lcd-radar-crosshair-h { border-top-color: rgba(255, 69, 69, 0.2); }
.r4-lcd-screen.night-mode .lcd-radar-crosshair-v { border-left-color: rgba(255, 69, 69, 0.2); }

.lcd-radar-own {
    width: 5px;
    height: 5px;
    background: var(--r4-lcd-text-day);
    border-radius: 50%;
    position: absolute;
    z-index: 10;
}
.r4-lcd-screen.night-mode .lcd-radar-own {
    background: var(--r4-lcd-text-night);
}

.lcd-radar-dot {
    position: absolute;
    width: 4px;
    height: 4px;
    border: 1px solid var(--r4-lcd-text-day);
    background: transparent;
    transform: translate(-50%, -50%);
    cursor: pointer;
}
.lcd-radar-dot.selected {
    background: var(--r4-lcd-text-day) !important;
}
.r4-lcd-screen.night-mode .lcd-radar-dot {
    border-color: var(--r4-lcd-text-night);
}
.r4-lcd-screen.night-mode .lcd-radar-dot.selected {
    background: var(--r4-lcd-text-night) !important;
}

.lcd-radar-dot.aton-dot {
    transform: translate(-50%, -50%) rotate(45deg);
}

.lcd-radar-range-label {
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 0.65rem;
    font-weight: 700;
}

/* LCD Input Form elements */
.lcd-form {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.lcd-form-row {
    display: flex;
    justify-content: space-between;
    padding: 0.1rem 0.2rem;
}

.lcd-form-row.selected {
    background: var(--r4-lcd-text-day);
    color: var(--r4-lcd-bg-day);
}
.r4-lcd-screen.night-mode .lcd-form-row.selected {
    background: var(--r4-lcd-text-night);
    color: var(--r4-lcd-bg-night);
}

.lcd-form-row.editing {
    border: 1px solid var(--r4-lcd-text-day);
    animation: blink-border 1s infinite;
}
.r4-lcd-screen.night-mode .lcd-form-row.editing {
    border-color: var(--r4-lcd-text-night);
}

@keyframes blink-border {
    0%, 100% { border-color: transparent; }
    50% { border-color: inherit; }
}

.lcd-val {
    font-weight: 700;
}

/* Alert Pop-up on R4 Screen */
.lcd-popup-overlay {
    position: absolute;
    top: 15px;
    left: 15px;
    right: 15px;
    bottom: 15px;
    background: var(--r4-lcd-bg-day);
    border: 2px solid var(--r4-lcd-text-day);
    z-index: 50;
    display: flex;
    flex-direction: column;
    padding: 0.4rem;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}
.r4-lcd-screen.night-mode .lcd-popup-overlay {
    background: var(--r4-lcd-bg-night);
    border-color: var(--r4-lcd-text-night);
}

.lcd-popup-header {
    font-size: 0.75rem;
    font-weight: 900;
    border-bottom: 1px solid var(--r4-lcd-text-day);
    padding-bottom: 0.1rem;
    text-align: center;
    margin-bottom: 0.3rem;
}
.r4-lcd-screen.night-mode .lcd-popup-header {
    border-bottom-color: var(--r4-lcd-text-night);
}

.lcd-popup-body {
    flex: 1;
    font-size: 0.75rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
}

.lcd-popup-footer {
    font-size: 0.65rem;
    text-align: center;
    border-top: 1px dotted var(--r4-lcd-text-day);
    padding-top: 0.2rem;
    font-weight: 700;
}
.r4-lcd-screen.night-mode .lcd-popup-footer {
    border-top-color: var(--r4-lcd-text-night);
}

/* Contrast adjustment visual helper */
.lcd-contrast-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}
.lcd-contrast-bar {
    width: 120px;
    height: 10px;
    border: 1px solid var(--r4-lcd-text-day);
    display: flex;
}
.r4-lcd-screen.night-mode .lcd-contrast-bar {
    border-color: var(--r4-lcd-text-night);
}
.lcd-contrast-segment {
    flex: 1;
    background: var(--r4-lcd-text-day);
    border-right: 1px solid var(--r4-lcd-bg-day);
}
.lcd-contrast-segment.inactive {
    background: transparent;
}
.r4-lcd-screen.night-mode .lcd-contrast-segment {
    background: var(--r4-lcd-text-night);
    border-right-color: var(--r4-lcd-bg-night);
}

/* Hardware Buttons Layout */
.r4-button-grid {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.6rem;
}

/* Softkeys row layout */
.r4-softkeys-row {
    width: 100%;
    display: flex;
    justify-content: space-around;
    padding: 0 0.5rem;
}

.r4-softkey-btn {
    width: 48px;
    height: 18px;
    background: #111827;
    border: 1px solid #4b5563;
    border-radius: 3px;
    cursor: pointer;
    box-shadow: 
        0 2px 2px rgba(0,0,0,0.6), 
        inset 0 1px 0 rgba(255,255,255,0.1);
}
.r4-softkey-btn:active {
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.8);
    transform: translateY(1px);
}

/* General key cap design */
.r4-key {
    background: linear-gradient(180deg, #4b5563 0%, #1f2937 100%);
    border: 1px solid #111827;
    border-radius: 6px;
    color: #e5e7eb;
    padding: 0.5rem 0.2rem;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    box-shadow: 
        0 4px 0 #111827, 
        inset 0 1px 0 rgba(255,255,255,0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, box-shadow 0.1s;
    min-height: 38px;
}

.r4-key small {
    font-size: 0.55rem;
    color: #9ca3af;
    display: block;
    margin-top: 0.1rem;
}

.r4-key:active {
    transform: translateY(3px);
    box-shadow: 
        0 1px 0 #111827, 
        inset 0 2px 3px rgba(0,0,0,0.5);
}

/* Specific key styles */
.r4-key.key-power {
    background: linear-gradient(180deg, #ef4444 0%, #b91c1c 100%);
    color: #fff;
    box-shadow: 
        0 4px 0 #7f1d1d, 
        inset 0 1px 0 rgba(255,255,255,0.4);
}
.r4-key.key-power:active {
    box-shadow: 
        0 1px 0 #7f1d1d, 
        inset 0 2px 3px rgba(0,0,0,0.5);
}

.r4-key.key-display {
    background: linear-gradient(180deg, #f59e0b 0%, #d97706 100%);
    color: #000;
    box-shadow: 
        0 4px 0 #78350f, 
        inset 0 1px 0 rgba(255,255,255,0.4);
}
.r4-key.key-display:active {
    box-shadow: 
        0 1px 0 #78350f, 
        inset 0 2px 3px rgba(0,0,0,0.5);
}

/* Navigation pad styling (D-pad) */
.r4-dpad-container {
    grid-column: span 2;
    grid-row: span 3;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    height: 120px;
}

.r4-dpad {
    width: 100px;
    height: 100px;
    background: #111827;
    border-radius: 50%;
    border: 3px solid #374151;
    position: relative;
    box-shadow: 
        0 4px 10px rgba(0,0,0,0.6), 
        inset 0 2px 4px rgba(255,255,255,0.05);
}

.dpad-btn {
    position: absolute;
    background: linear-gradient(180deg, #374151 0%, #1f2937 100%);
    border: 1px solid #111827;
    color: #9ca3af;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}

.dpad-btn:active {
    background: #111827;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.8);
}

.dpad-up {
    top: 5px;
    left: 33px;
    width: 34px;
    height: 28px;
    border-radius: 6px 6px 0 0;
}

.dpad-down {
    bottom: 5px;
    left: 33px;
    width: 34px;
    height: 28px;
    border-radius: 0 0 6px 6px;
}

.dpad-left {
    top: 33px;
    left: 5px;
    width: 28px;
    height: 34px;
    border-radius: 6px 0 0 6px;
}

.dpad-right {
    top: 33px;
    right: 5px;
    width: 28px;
    height: 34px;
    border-radius: 0 6px 6px 0;
}

.dpad-center {
    position: absolute;
    top: 33px;
    left: 33px;
    width: 34px;
    height: 34px;
    background: #111827;
    border-radius: 50%;
    z-index: 5;
    pointer-events: none;
    box-shadow: 0 1px 2px rgba(255,255,255,0.05);
}

/* Keypad Grid layout helper */
.keypad-grid-col {
    grid-column: span 3;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
}

/* Responsive Styles */
@media (max-width: 1024px) {
    .workspace-grid {
        grid-template-columns: 1fr;
    }
    body.view-r40-only .workspace-grid,
    body.view-r4-only .workspace-grid {
        grid-template-columns: 1fr;
    }
    .r40-column, .r4-column {
        width: 100%;
    }
}
