:root {
    /* Color Palette */
    --primary: #2563EB; /* Deep Blue */
    --primary-hover: #1D4ED8;
    --secondary: #0EA5E9; /* Sky Blue */
    --bg-main: #F1F5F9; /* Slate 100 Light Grayish Blue */
    --card-bg: rgba(255, 255, 255, 0.85);
    --text-main: #0F172A; /* Slate 900 */
    --text-muted: #475569; /* Slate 600 */

    /* Urgency Colors */
    --urgency-low: #3b82f6;      /* Blue */
    --urgency-medium: #f59e0b;   /* Amber */
    --urgency-high: #ef4444;     /* Red */

    /* Typography */
    --font-family: 'Inter', sans-serif;
    
    /* Shadows & Effects */
    --shadow-soft: 0 10px 25px -5px rgba(15, 23, 42, 0.05), 0 8px 10px -6px rgba(15, 23, 42, 0.01);
    --shadow-hover: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 10px 10px -5px rgba(15, 23, 42, 0.04);
    --border-radius-lg: 16px;
    --border-radius-md: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    /* Beautiful elegant Blue/Gray gradient mesh overlay */
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(14, 165, 233, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(71, 85, 105, 0.10) 0px, transparent 50%),
        radial-gradient(at 0% 100%, rgba(30, 64, 175, 0.10) 0px, transparent 50%);
    background-attachment: fixed;
    min-height: 100vh;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* ================= HEADER ================= */
.hero-section {
    text-align: center;
    margin-bottom: 3rem;
    animation: fadeInDown 0.8s ease-out;
}

.logo-container {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2);
}

.logo-icon svg {
    width: 28px;
    height: 28px;
}

.hero-section h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.highlight {
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.125rem;
}

/* ================= SEARCH FORM ================= */
.search-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--border-radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-soft);
    margin-bottom: 3rem;
    animation: fadeInUp 0.8s ease-out;
}

.search-card h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group.full-width {
    grid-column: 1 / -1;
}

label {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-main);
}

select {
    padding: 0.75rem 1rem;
    border: 1px solid #e2e8f0;
    border-radius: var(--border-radius-md);
    font-family: inherit;
    font-size: 1rem;
    background-color: white;
    transition: var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1.2rem;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

/* Urgency Radio Buttons */
.urgency-options {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.urgency-radio {
    cursor: pointer;
    position: relative;
}

.urgency-radio input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.custom-radio {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1.5px solid #e2e8f0;
    transition: var(--transition);
    background-color: white;
}

.urgency-radio input:checked + .custom-radio.low {
    background-color: rgba(59, 130, 246, 0.1);
    border-color: var(--urgency-low);
    color: var(--urgency-low);
}

.urgency-radio input:checked + .custom-radio.medium {
    background-color: rgba(245, 158, 11, 0.1);
    border-color: var(--urgency-medium);
    color: var(--urgency-medium);
}

.urgency-radio input:checked + .custom-radio.high {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: var(--urgency-high);
    color: var(--urgency-high);
}

.submit-btn {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    border: none;
    border-radius: var(--border-radius-md);
    font-size: 1.125rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.submit-btn:hover {
    box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3);
    transform: translateY(-2px);
}

.submit-btn:active {
    transform: translateY(0);
}

/* ================= LIVE DATABASE FEED & MODAL ================= */

.map-section {
    position: relative;
}

.show-data-btn {
    position: absolute;
    top: 25px;
    left: 20px;
    z-index: 1000; /* above Leaflet */
    background: var(--primary);
    color: white;
    border: 2px solid white;
    padding: 0.75rem 1.2rem;
    border-radius: var(--border-radius-md);
    font-weight: 700;
    box-shadow: 0 8px 15px rgba(0,0,0,0.3);
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.show-data-btn:hover {
    transform: scale(1.05);
    background: var(--primary-hover);
}

.data-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(5px);
    z-index: 10001; /* above everything */
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.data-modal-content {
    background: var(--card-bg);
    width: 90%;
    max-width: 800px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-hover);
    padding: 2rem;
    border: 1px solid rgba(255, 255, 255, 0.5);
    transform: translateY(0);
    animation: slideUp 0.3s ease-out;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.close-data-btn {
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px; height: 32px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    display:flex; justify-content:center; align-items:center;
    transition: background 0.2s;
}

.close-data-btn:hover { background: #dc2626; }

.db-feed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.db-feed-header h2 {
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.live-dot {
    width: 12px; height: 12px;
    background-color: var(--secondary);
    border-radius: 50%;
    display: inline-block;
    animation: pulseGreen 2s infinite;
}

@keyframes pulseGreen {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.table-container {
    overflow-x: auto;
}

.db-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.db-table th, .db-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

.db-table th {
    background-color: #f8fafc;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.05em;
}

.db-table tbody tr {
    transition: background-color 0.2s;
}

.db-table tbody tr:hover {
    background-color: #f1f5f9;
}

/* ================= RESULTS SECTION ================= */
.hidden {
    display: none !important;
}

.results-title {
    text-align: center;
    margin-bottom: 2rem;
    font-size: 1.8rem;
    color: var(--text-main);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 2rem;
}

.result-card {
    background: white;
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-soft);
    border: 1px solid #f1f5f9;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

.result-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
}

.card-header {
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid #f1f5f9;
}

.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.bfs-badge { background: #e0e7ff; color: #4338ca; }
.dfs-badge { background: #fce7f3; color: #be185d; }
.cost-badge { background: #d1fae5; color: #047857; }

.card-header h4 {
    font-size: 1.25rem;
    color: var(--text-main);
}

.card-body {
    padding: 1.5rem;
    flex-grow: 1;
}

.result-item {
    margin-bottom: 1rem;
}

.result-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.result-stat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.result-stat strong {
    color: var(--text-main);
}

.card-footer {
    background: #f8fafc;
    padding: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    border-top: 1px solid #f1f5f9;
}

.card-footer strong {
    color: var(--text-main);
    display: block;
    margin-bottom: 0.25rem;
}

.highlight-text {
    font-weight: 600;
    color: var(--primary);
}

.formula {
    background: #e2e8f0;
    padding: 0.5rem;
    border-radius: 6px;
    margin: 0.5rem 0;
    font-family: monospace;
    text-align: center;
    color: #334155;
}

/* Animations */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Loader */
.loader {
    border: 3px solid rgba(255,255,255,0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ================= MAP SECTION ================= */
.map-section {
    width: 100%;
    margin-bottom: 2.5rem;
    animation: fadeInUp 0.8s ease-out;
}

#map {
    height: 400px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(255, 255, 255, 0.4);
    z-index: 10;
}

/* ================= FOOTER ================= */
.app-footer {
    text-align: center;
    margin-top: 3rem;
    padding: 1.5rem 0;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    background-color: var(--primary); /* Blue */
    color: #fef08a; /* Bright Yellow */
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    animation: fadeInUp 0.8s ease-out;
    border-bottom-left-radius: var(--border-radius-lg);
    border-bottom-right-radius: var(--border-radius-lg);
}

/* ================= PREDICTIVE BANNER ================= */
.predictive-banner {
    background: linear-gradient(90deg, #1e293b, #0f172a, #1e293b);
    color: #38bdf8;
    text-align: center;
    padding: 0.75rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--border-radius-md);
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    animation: fadeInUp 0.8s ease-out;
    border: 1px solid #334155;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

#prediction-text {
    color: #f8fafc;
    transition: opacity 0.5s ease;
}

/* ================= SOS BUTTON ================= */
.sos-btn {
    width: 100%;
    margin-top: 1rem;
    padding: 1rem;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    border: none;
    border-radius: var(--border-radius-md);
    font-size: 1.125rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
    animation: pulseRed 2s infinite;
}

.sos-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 25px rgba(239, 68, 68, 0.6);
}

.sos-btn:active {
    transform: translateY(0);
}

@keyframes pulseRed {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* ================= SOS RADAR MODAL ================= */
.sos-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.95);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    backdrop-filter: blur(8px);
}

.radar-container {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: 2px solid rgba(239, 68, 68, 0.5);
    position: relative;
    overflow: hidden;
    margin-bottom: 2rem;
    background: radial-gradient(circle, rgba(239,68,68,0.1) 0%, transparent 70%);
}

.radar-sweep {
    position: absolute;
    top: 50%; left: 50%;
    width: 100px; height: 100px;
    background: linear-gradient(45deg, rgba(239,68,68,0.8), transparent);
    transform-origin: 0 0;
    animation: radarSpin 1.5s linear infinite;
}

@keyframes radarSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.radar-dot {
    position: absolute;
    width: 8px; height: 8px;
    background: #ef4444;
    border-radius: 50%;
    box-shadow: 0 0 10px #ef4444;
    opacity: 0;
}

.dot-1 { top: 30%; left: 20%; animation: blinkDot 2s infinite 0.5s; }
.dot-2 { top: 70%; left: 60%; animation: blinkDot 2s infinite 1.2s; }
.dot-3 { top: 40%; left: 75%; animation: blinkDot 2s infinite 1.8s; }

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

.sos-title { font-size: 2rem; color: #ef4444; text-transform: uppercase; letter-spacing: 2px; margin-bottom: 0.5rem; text-align: center; }
.sos-subtitle { color: #cbd5e1; font-size: 1.1rem; text-align: center; }

/* ================= TRUST BADGES & DISPATCH ================= */
.verified-icon {
    width: 20px; height: 20px;
    color: #0ea5e9;
    vertical-align: middle;
    margin-left: 0.25rem;
}

.dispatch-btn {
    width: 100%;
    margin-top: 1rem;
    padding: 0.85rem;
    background: #0f172a;
    color: white;
    border: none;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
}

.dispatch-btn:hover { background: #334155; transform: scale(1.02); }
.dispatch-btn:active { transform: scale(0.98); }

/* ================= AI CHAT AGENT ================= */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    font-family: var(--font-family);
}

.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.3);
    cursor: pointer;
    font-size: 28px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 15px 25px -5px rgba(0,0,0,0.4);
}

.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-hover);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: chatPopUp 0.3s ease-out;
    border: 1px solid #e2e8f0;
}

.chat-window.hidden {
    display: none !important;
}

@keyframes chatPopUp {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}

.chat-header {
    background: linear-gradient(135deg, var(--primary), #312e81);
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h4 {
    margin: 0;
    font-size: 1.1rem;
}

.online-status {
    font-size: 0.75rem;
    color: #a7f3d0;
    font-weight: 600;
}

.close-chat-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: color 0.2s;
}

.close-chat-btn:hover { color: #f87171; }

.chat-messages {
    flex-grow: 1;
    padding: 1rem;
    overflow-y: auto;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-message {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
}

.ai-message {
    background: white;
    color: var(--text-main);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    border: 1px solid #e2e8f0;
}

.user-message {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 4px rgba(79,70,229,0.2);
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.5rem;
    align-items: center;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.chat-input-area {
    display: flex;
    padding: 0.75rem;
    background: white;
    border-top: 1px solid #e2e8f0;
    gap: 0.5rem;
}

#chat-input {
    flex-grow: 1;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

#chat-input:focus { border-color: var(--primary); }

.send-chat-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
}

.send-chat-btn:hover { background: var(--primary-hover); }
