:root {
    --bg-dark: #090b12;
    --bg-surface: rgba(15, 18, 29, 0.9);
    --bg-card: rgba(23, 27, 42, 0.85);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-blue: #3b82f6;
    --accent-green: #10b981;
    --accent-cyan: #22d3ee;
    --accent-amber: #f59e0b;
    --accent-red: #ef4444;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
}

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

html, body {
    height: 100%;
    background: radial-gradient(circle at top left, #111827 0%, #090b12 55%, #06070c 100%);
    color: var(--text-primary);
    font-family: var(--font-sans);
    overflow-x: hidden;
}

.monitor-shell {
    display: grid;
    grid-template-rows: auto minmax(280px, 47%) 1fr;
    height: 100vh;
    height: 100dvh;
    padding: 12px;
    gap: 12px;
}

/* Header */
.monitor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 18px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    backdrop-filter: blur(12px);
}

.header-left h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: #fff;
}

.header-sub {
    font-size: 12px;
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.audio-btn {
    background: rgba(59, 130, 246, 0.14);
    border: 1px solid rgba(59, 130, 246, 0.4);
    color: #bfdbfe;
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.audio-btn:hover {
    background: rgba(59, 130, 246, 0.28);
    color: #fff;
}

.audio-btn.playing {
    background: rgba(16, 185, 129, 0.25);
    border-color: var(--accent-green);
    color: #ecfdf5;
}

.tx-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: rgba(100, 116, 139, 0.18);
    border: 1px solid rgba(148, 163, 184, 0.3);
    color: var(--text-secondary);
}

.tx-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--text-muted);
}

.tx-status-pill.transmitting {
    background: rgba(16, 185, 129, 0.24);
    border-color: var(--accent-green);
    color: #ecfdf5;
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.55);
}

.tx-status-pill.transmitting .tx-dot {
    background: #34d399;
    box-shadow: 0 0 8px #34d399;
    animation: pulse-green 1.2s infinite;
}

@keyframes pulse-green {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.8); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(52, 211, 153, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

/* TOP HALF: D-Star Live Pane */
.top-dstar-pane {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 10px;
    min-height: 0;
}

.dstar-live-card {
    background: var(--bg-surface);
    border: 2px solid var(--border-color);
    border-radius: 14px;
    padding: 14px 18px;
    transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Highlight bright green while someone is transmitting */
.dstar-live-card.transmitting {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.26) 0%, rgba(6, 78, 59, 0.45) 100%);
    border-color: #10b981;
    box-shadow: 0 0 28px rgba(16, 185, 129, 0.45), inset 0 0 24px rgba(16, 185, 129, 0.14);
}

.live-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
}

.live-identity {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 220px;
}

.live-badge {
    padding: 5px 11px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.7px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.dstar-live-card.transmitting .live-badge {
    background: #10b981;
    border-color: #34d399;
    color: #022c22;
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.8);
}

.live-call-block {
    display: flex;
    flex-direction: column;
}

.live-callsign {
    font-family: var(--font-mono);
    font-size: 24px;
    font-weight: 800;
    color: #fff;
    line-height: 1.1;
}

.live-fullname {
    font-size: 14px;
    font-weight: 600;
    color: #93c5fd;
    margin-top: 2px;
}

.dstar-live-card.transmitting .live-fullname {
    color: #a7f3d0;
}

.live-meta-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(130px, 1fr));
    gap: 10px;
    flex: 1;
}

.meta-chip {
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 7px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.dstar-live-card.transmitting .meta-chip {
    background: rgba(2, 44, 34, 0.45);
    border-color: rgba(52, 211, 153, 0.35);
}

.meta-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.meta-value {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.live-slow-box {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}

.dstar-live-card.transmitting .live-slow-box {
    background: rgba(2, 44, 34, 0.48);
    border-color: rgba(52, 211, 153, 0.35);
}

.slow-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--accent-cyan);
    white-space: nowrap;
}

.slow-text {
    color: #e2e8f0;
    font-family: var(--font-sans);
    word-break: break-word;
}

/* Last 5 Transmissions Table Card */
.recent-tx-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.recent-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
}

.recent-header h2 {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.recent-hint {
    font-size: 11px;
    color: var(--text-muted);
}

.recent-table-wrap {
    flex: 1;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.recent-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.recent-table th {
    position: sticky;
    top: 0;
    background: #111523;
    text-align: left;
    padding: 7px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.recent-table td {
    padding: 7px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
    vertical-align: middle;
}

.recent-row {
    cursor: pointer;
    transition: background 0.15s ease;
}

.recent-row:hover {
    background: rgba(59, 130, 246, 0.12);
}

.cell-call {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--accent-cyan);
}

.cell-name {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-weight: 500;
}

.cell-slow {
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #cbd5e1;
}

.empty-cell {
    text-align: center;
    color: var(--text-muted);
    padding: 20px !important;
}

/* BOTTOM HALF: Map */
.bottom-map-pane {
    position: relative;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    overflow: hidden;
    min-height: 260px;
}

#monitor-map {
    width: 100%;
    height: 100%;
    background: #141724;
}

.osm-dark-tiles {
    filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}

.map-overlay-top-right {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 1005;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    max-width: calc(100% - 60px);
}

.map-overlay-bottom-left {
    position: absolute;
    bottom: 14px;
    left: 14px;
    z-index: 1005;
    background: rgba(15, 17, 26, 0.88);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 6px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.overlay-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.filter-group {
    display: flex;
    gap: 4px;
    background: rgba(15, 17, 26, 0.88);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.map-overlay-bottom-left .filter-group {
    background: transparent;
    border: none;
    padding: 0;
}

.map-pill-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 11px;
    border-radius: 7px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all 0.15s ease;
    touch-action: manipulation;
}

.map-pill-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

.map-pill-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #fff;
}

/* Custom Leaflet Markers */
.mon-marker {
    background: transparent;
    border: none;
}

.mon-pin {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.92);
    border: 2px solid var(--accent-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    position: relative;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.55);
}

.mon-pin.va3odc {
    border-color: #ef4444;
    background: rgba(127, 29, 29, 0.85);
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.85);
}

.mon-pin.dstar {
    border-color: #22d3ee;
    box-shadow: 0 0 12px rgba(34, 211, 238, 0.75);
}

.mon-pin.dstar-tx {
    border-color: #10b981;
    background: rgba(6, 78, 59, 0.92);
    box-shadow: 0 0 20px rgba(16, 185, 129, 1);
    animation: pulse-green 1.2s infinite;
}

.mon-pin-label {
    position: absolute;
    bottom: -17px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.82);
    color: #fff;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 9px;
    font-weight: 700;
    font-family: var(--font-mono);
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.14);
}

.leaflet-popup-content-wrapper {
    background: rgba(15, 17, 26, 0.95) !important;
    border: 1px solid var(--border-color);
    border-radius: 10px !important;
    color: var(--text-primary) !important;
}

.leaflet-popup-tip {
    background: rgba(15, 17, 26, 0.95) !important;
}

/* Mobile Portrait Support */
@media (max-width: 900px) {
    .monitor-shell {
        height: auto;
        min-height: 100vh;
        grid-template-rows: auto auto 420px;
        padding: 8px;
        gap: 8px;
    }

    .live-meta-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .recent-table-wrap {
        max-height: 240px;
    }

    .recent-hint {
        display: none;
    }
}
