:root {
    --primary-green: #0b593a;
    --secondary-green: #1a8f62;
    --background-gray: #f4f6f8;
    --panel-bg: #ffffff;
    --text-dark: #333333;
    --text-muted: #666666;
    --border-color: #e0e0e0;
    --alert-red: #d32f2f;
    --alert-yellow: #fbc02d;
    --alert-green: #388e3c;
    --map-base: #c8e6c9;
    --map-highlight: #4caf50;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--background-gray);
    color: var(--text-dark);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

h1, h2, h3, h4 {
    color: var(--primary-green);
    margin-bottom: 0.5rem;
}

/* Header Panel */
.top-panel {
    background: var(--panel-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 10;
}

.header-left h1 {
    font-size: 1.5rem;
    margin: 0;
}

.header-left p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

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

.header-center h2 {
    font-size: 1.8rem;
    margin: 0;
    color: var(--secondary-green);
}

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

.alert-indicator {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: bold;
    color: white;
}

.alert-indicator.green {
    background-color: var(--alert-green);
}

.alert-indicator.yellow {
    background-color: var(--alert-yellow);
    color: var(--text-dark);
}

.alert-indicator.red {
    background-color: var(--alert-red);
}

.pulse {
    width: 10px;
    height: 10px;
    background-color: white;
    border-radius: 50%;
    margin-right: 10px;
    animation: pulsate 1.5s infinite;
}

@keyframes pulsate {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.5); opacity: 0.5; }
    100% { transform: scale(1); opacity: 1; }
}

/* Workflow Panel */
.workflow-panel {
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--primary-green);
    color: white;
    padding: 0.5rem;
    font-size: 0.9rem;
}

.workflow-step {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    background: rgba(255,255,255,0.1);
}

.workflow-arrow {
    margin: 0 1rem;
    opacity: 0.7;
}

/* Tabs */
.tabs-container {
    display: flex;
    background: #e8ecef;
    padding: 0 2rem;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    background: none;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
}

.tab-btn.active {
    color: var(--primary-green);
    border-bottom-color: var(--primary-green);
}

.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 1rem 2rem;
}

.tab-content.active {
    display: block;
}

/* Dashboard Grid: 3 columns now */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 3fr 2fr;
    gap: 1.5rem;
    height: 100%;
}

.scrollable-content {
    overflow-y: auto;
    flex: 1;
    padding-right: 0.5rem;
}

.sticky-header {
    position: sticky;
    top: 0;
    background: var(--panel-bg);
    z-index: 5;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.state-info-container, .side-panel {
    background: var(--panel-bg);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.map-container {
    background: linear-gradient(160deg, #ffffff 0%, #edf8f0 100%);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 6px 16px rgba(0,0,0,0.06);
    border: 1px solid #dceddf;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.map-header {
    text-align: center;
    margin-bottom: 0.5rem;
}

.map-header h3 {
    margin-bottom: 0.2rem;
}

.map-insight {
    font-size: 0.8rem;
    color: #2e7d32;
    background: rgba(255, 255, 255, 0.6);
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    margin-bottom: 0.75rem;
    border-left: 3px solid #4caf50;
    text-align: center;
}

.map-legend {
    display: flex;
    justify-content: center;
    gap: 1.25rem;
    margin-top: 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 500;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.legend-color.green { background: var(--alert-green); }
.legend-color.yellow { background: var(--alert-yellow); }
.legend-color.red { background: var(--alert-red); }

.panel-section {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
}

.panel-section h4 {
    font-size: 0.95rem;
    color: var(--secondary-green);
    border-bottom: 2px solid var(--map-base);
    padding-bottom: 0.25rem;
    margin-bottom: 0.5rem;
}

.flex-grow {
    flex: 1;
    min-height: 0;
}

/* Mini Chart Wrapper */
.mini-chart-wrapper {
    height: 150px;
    position: relative;
    width: 100%;
}

.map-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0;
}

#map-svg-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
    height: 100%;
}

/* SVG map styling inside wrapper */
.state-path {
    fill: var(--map-base);
    stroke: white;
    stroke-width: 1;
    cursor: pointer;
    transition: fill 0.3s;
}

.state-path:hover {
    fill: var(--map-highlight) !important;
}

.state-info-container {
    overflow-y: auto;
}

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

#reset-map-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    background: var(--secondary-green);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

#reset-map-btn.hidden {
    display: none;
}

.alerts-section {
    margin-bottom: 0.5rem;
    max-height: 15vh;
    overflow-y: auto;
}

.alert-card {
    padding: 0.75rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    border-left: 4px solid var(--alert-red);
    background: #ffebee;
}

.alert-card.warning {
    border-left-color: var(--alert-yellow);
    background: #fff8e1;
}

.alert-card h5 {
    margin: 0 0 0.25rem 0;
    color: var(--text-dark);
}

.alert-card p {
    margin: 0;
    font-size: 0.85rem;
}

/* Insights Box */
.insights-box {
    background: #e3f2fd;
    padding: 0.75rem;
    border-radius: 4px;
    border-left: 4px solid #1976d2;
}

.insights-box h4 {
    color: #1565c0;
    border-color: #bbdefb;
}

.insights-box p {
    font-size: 0.85rem;
    color: #0d47a1;
    margin: 0;
}

/* Top States & Feed */
.top-states-list {
    list-style: none;
    font-size: 0.85rem;
}
.top-states-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    border-bottom: 1px dashed var(--border-color);
}
.top-states-list li:last-child {
    border-bottom: none;
}
.state-name { font-weight: 600; }
.state-count { color: var(--alert-red); font-weight: bold; }

.alerts-feed {
    overflow-y: auto;
    font-size: 0.8rem;
    padding-right: 0.5rem;
}

.feed-item {
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    background: #fafafa;
    border-left: 3px solid var(--primary-green);
    border-radius: 0 4px 4px 0;
}
.feed-item.critical { border-left-color: var(--alert-red); background: #ffebee;}
.feed-item.warning { border-left-color: var(--alert-yellow); background: #fff8e1;}
.feed-time { color: var(--text-muted); font-size: 0.75rem; display: block; margin-bottom: 0.2rem;}

/* Risk Cards */
.risk-cards-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.risk-card {
    background: #fdfdfd;
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    border-radius: 4px;
    text-align: center;
}
.risk-card h5 { margin: 0 0 0.25rem 0; color: var(--text-dark); }
.risk-card .r-count { font-size: 1.2rem; font-weight: bold; margin: 0; }
.risk-card .r-status { font-size: 0.75rem; font-weight: bold; text-transform: uppercase; }
.risk-card.Critical { border-color: var(--alert-red); background: #ffebee; }
.risk-card.Critical .r-status { color: var(--alert-red); }
.risk-card.Warning { border-color: var(--alert-yellow); background: #fff8e1; }
.risk-card.Warning .r-status { color: #f57f17; }
.risk-card.Healthy { border-color: var(--alert-green); }
.risk-card.Healthy .r-status { color: var(--alert-green); }

/* Mini Trend Bars */
.mini-trend-bars {
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    height: 100px;
    padding-top: 10px;
}
.trend-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
}
.trend-bar {
    width: 20px;
    background: var(--secondary-green);
    border-radius: 2px 2px 0 0;
    transition: height 0.3s;
}
.trend-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Charts & Tables */
.charts-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    flex: 1;
    overflow-y: auto;
}

.chart-wrapper {
    background: #fafafa;
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    border-radius: 4px;
    flex: 1;
    min-height: 120px;
    position: relative;
    max-height: 150px;
}

.chart-wrapper canvas {
    max-height: 110px !important;
}

.cluster-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
}

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

.cluster-table th {
    background: var(--background-gray);
    color: var(--text-muted);
}

/* Live Ticker */
.live-ticker {
    display: flex;
    background: #222;
    color: #fff;
    align-items: center;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 40px;
    z-index: 100;
}

.ticker-label {
    background: var(--alert-red);
    padding: 0 1rem;
    height: 100%;
    display: flex;
    align-items: center;
    font-weight: bold;
    white-space: nowrap;
    z-index: 2;
}

.ticker-content {
    flex: 1;
    overflow: hidden;
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
}

.ticker-item {
    position: absolute;
    white-space: nowrap;
    animation: ticker linear infinite;
    /* Animation duration set via JS */
}

@keyframes ticker {
    0% { left: 100%; }
    100% { left: -100%; }
}

/* Simulator View */
.simulator-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4rem;
    height: 100%;
}

.phone {
    width: 300px;
    height: 600px;
    background: #111;
    border-radius: 36px;
    padding: 12px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    position: relative;
}

.phone-screen {
    width: 100%;
    height: 100%;
    background: #f0f0f0;
    border-radius: 24px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: #222;
    color: white;
    font-size: 0.8rem;
}

.dialer-screen, .ussd-screen {
    flex: 1;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    background: white;
}

.dialer-screen.active, .ussd-screen.active {
    display: flex;
}

#ussd-input {
    width: 80%;
    padding: 0.75rem;
    text-align: center;
    font-size: 1.2rem;
    margin-bottom: 2rem;
    border: 1px solid #ccc;
    border-radius: 8px;
}

.call-btn {
    background: #4caf50;
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 24px;
    font-size: 1.2rem;
    cursor: pointer;
}

.ussd-screen {
    background: rgba(0,0,0,0.5);
    justify-content: center;
}

.ussd-text {
    background: white;
    width: 90%;
    padding: 1rem;
    border-radius: 8px 8px 0 0;
    min-height: 150px;
    white-space: pre-wrap;
    font-family: monospace;
    font-size: 0.9rem;
    color: #333;
    overflow-y: auto;
}

.ussd-reply-input {
    width: 90%;
    padding: 0.75rem;
    border: none;
    border-top: 1px solid #eee;
    outline: none;
}

.ussd-actions {
    width: 90%;
    display: flex;
    background: white;
    border-radius: 0 0 8px 8px;
    border-top: 1px solid #eee;
}

.ussd-actions button {
    flex: 1;
    padding: 0.75rem;
    background: none;
    border: none;
    color: #1976d2;
    font-weight: bold;
    cursor: pointer;
    font-size: 1rem;
}

.ussd-actions button:first-child {
    border-right: 1px solid #eee;
    color: var(--text-muted);
}

.sms-popup {
    position: absolute;
    top: -100px;
    left: 10px;
    right: 10px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    transition: top 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10;
}

.sms-popup.active {
    top: 30px;
}

.sms-header {
    background: var(--primary-green);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.close-sms {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
}

.sms-body {
    padding: 1rem;
    font-size: 0.9rem;
    color: #333;
}

.simulator-instructions {
    max-width: 400px;
}

.simulator-instructions p {
    margin-bottom: 1rem;
    line-height: 1.5;
}

.simulator-instructions code {
    background: #e0e0e0;
    padding: 2px 6px;
    border-radius: 4px;
}

/* Tooltip for map */
.map-tooltip {
    position: absolute;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 1000;
}

/* =========================================
   Responsive Design & Mobile Compatibility
   ========================================= */

@media (max-width: 1024px) {
    /* Tablet View */
    .dashboard-grid {
        grid-template-columns: 1fr 1fr;
    }
    .side-panel {
        order: 2;
    }
    .map-container {
        order: 1;
        grid-column: span 2;
    }
    .state-info-container {
        order: 3;
    }
    body {
        height: auto;
        overflow-y: auto;
        padding-bottom: 50px; /* Space for ticker */
    }
    .scrollable-content {
        overflow-y: visible;
    }
    .simulator-wrapper {
        flex-direction: column;
        gap: 2rem;
    }
}

@media (max-width: 768px) {
    /* Mobile View */
    .top-panel {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
        text-align: center;
    }
    .header-left, .header-center, .header-right {
        justify-content: center;
    }
    .header-left h1 {
        font-size: 1.25rem;
    }
    .header-center h2 {
        font-size: 1.5rem;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    .map-container {
        grid-column: 1;
    }
    
    .tabs-container {
        padding: 0 1rem;
        justify-content: center;
        flex-wrap: wrap;
    }
    .tab-btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
    
    .workflow-panel {
        flex-wrap: wrap;
        font-size: 0.75rem;
        padding: 0.5rem;
        text-align: center;
    }
    .workflow-arrow {
        margin: 0.25rem;
    }
    
    .charts-section {
        overflow: visible;
    }
    
    #map-svg-wrapper {
        min-height: 250px;
    }
    
    .phone {
        width: 100%;
        max-width: 320px;
    }
    .simulator-instructions {
        padding: 0 1rem;
        text-align: center;
    }
}
