/* ===== UMQI shared styles ===== */

:root {
    --umqi-primary: #003A6B;
    --umqi-primary-dark: #002b50;
    --umqi-accent: #FF6B35;
    --umqi-bg: #f9fafb;
    --umqi-card: #ffffff;
    --umqi-border: #e5e7eb;
    --umqi-muted: #64748b;
}

body { background: var(--umqi-bg); }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
.animate-fadeIn { animation: fadeIn 0.5s ease-out; }
.animate-slide { animation: slideIn 0.3s ease-out; }

/* Brand gradient */
.umqi-gradient { background: linear-gradient(135deg, var(--umqi-primary) 0%, var(--umqi-primary-dark) 100%); }

/* Cards */
.umqi-card {
    background: var(--umqi-card);
    border-radius: 0.75rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    padding: 1.25rem;
}
.hover-lift { transition: transform 0.2s ease, box-shadow 0.2s ease; }
.hover-lift:hover { transform: translateY(-2px); box-shadow: 0 12px 20px -8px rgba(0, 58, 107, 0.25); }

/* Primary button */
.btn-primary {
    background: var(--umqi-primary);
    color: #fff;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 500;
    transition: background-color 0.2s ease, transform 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
    cursor: pointer;
}
.btn-primary:hover { background: var(--umqi-accent); }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary {
    background: #f3f4f6;
    color: #374151;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    transition: background-color 0.2s ease;
    border: none;
    cursor: pointer;
}
.btn-secondary:hover { background: #e5e7eb; }

/* Form controls */
.umqi-input,
.umqi-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    background: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.umqi-input:focus,
.umqi-select:focus {
    outline: none;
    border-color: var(--umqi-accent);
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.15);
}
.umqi-label { display: block; font-size: 0.875rem; font-weight: 500; color: #374151; margin-bottom: 0.25rem; }

/* Navigation links */
.nav-link {
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.875rem;
    transition: background-color 0.15s ease;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.10); }
.nav-link.active { background: rgba(255, 255, 255, 0.20); font-weight: 600; }

/* LOS badge */
.los-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 4rem; height: 4rem;
    border-radius: 9999px;
    font-size: 2rem; font-weight: 700;
    color: #fff;
    box-shadow: 0 6px 12px -4px rgba(0, 0, 0, 0.2);
}
.los-A { background: #22c55e; }
.los-B { background: #eab308; }
.los-C { background: #fb923c; }
.los-D { background: #ef4444; }

/* Section heading */
.section-title {
    display: flex; align-items: center; gap: 0.5rem;
    font-weight: 600; color: var(--umqi-primary);
    margin-bottom: 0.75rem;
}

/* ===== AI Assistant ===== */
.assistant-card {
    background: #fff;
    border-radius: 0.75rem;
    border: 1px solid var(--umqi-border);
    box-shadow: 0 10px 25px -10px rgba(0, 58, 107, 0.15);
    padding: 1.25rem;
}
.assistant-header {
    display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem;
    flex-wrap: wrap;
}
.assistant-input-row {
    display: flex; flex-direction: column; gap: 0.5rem;
}
@media (min-width: 640px) { .assistant-input-row { flex-direction: row; } }
.assistant-status {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 9999px;
}
.assistant-status.online { background: #dcfce7; color: #166534; }
.assistant-status.offline { background: #fee2e2; color: #991b1b; }
.assistant-status.fallback { background: #fef3c7; color: #92400e; }

.chat-history { max-height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.5rem; }
.chat-row { display: flex; }
.chat-row.user { justify-content: flex-end; }
.chat-row.assistant { justify-content: flex-start; }
.chat-bubble {
    max-width: 90%;
    padding: 0.6rem 0.85rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    line-height: 1.4;
    white-space: normal;
    word-wrap: break-word;
}
.chat-bubble.user { background: #FFF7ED; color: #c2410c; border: 1px solid #FED7AA; }
.chat-bubble.assistant { background: #f1f5f9; color: #0f172a; border: 1px solid #e2e8f0; }

/* Markdown rendered inside assistant bubbles */
.markdown { line-height: 1.5; }
.markdown > *:first-child { margin-top: 0; }
.markdown > *:last-child { margin-bottom: 0; }
.markdown p { margin: 0.35rem 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 {
    font-weight: 600; margin: 0.6rem 0 0.3rem; color: var(--umqi-primary); line-height: 1.25;
}
.markdown h1 { font-size: 1.15rem; }
.markdown h2 { font-size: 1.05rem; }
.markdown h3 { font-size: 0.95rem; }
.markdown h4 { font-size: 0.9rem; }
.markdown ul, .markdown ol { margin: 0.35rem 0 0.35rem 1.25rem; padding: 0; }
.markdown li { margin: 0.15rem 0; }
.markdown li > p { margin: 0; }
.markdown a { color: var(--umqi-primary); text-decoration: underline; }
.markdown strong { font-weight: 600; }
.markdown em { font-style: italic; }
.markdown code {
    background: #e2e8f0; color: #0f172a;
    padding: 0.05rem 0.3rem; border-radius: 0.25rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85em;
}
.markdown pre {
    background: #1e293b; color: #e2e8f0;
    padding: 0.6rem 0.85rem; border-radius: 0.5rem;
    overflow-x: auto; margin: 0.5rem 0;
    font-size: 0.85em; line-height: 1.45;
}
.markdown pre code { background: transparent; color: inherit; padding: 0; font-size: inherit; }
.markdown blockquote {
    border-left: 3px solid #cbd5e1;
    padding: 0.1rem 0 0.1rem 0.75rem; margin: 0.35rem 0;
    color: #64748b;
}
.markdown table { border-collapse: collapse; margin: 0.4rem 0; font-size: 0.85em; }
.markdown th, .markdown td { border: 1px solid #cbd5e1; padding: 0.2rem 0.5rem; text-align: left; }
.markdown th { background: #e2e8f0; font-weight: 600; }
.markdown hr { border: 0; border-top: 1px solid #cbd5e1; margin: 0.6rem 0; }

/* ---- LaTeX (KaTeX) ---- */
.markdown .katex { font-size: 1.05em; }
.markdown .katex-display { margin: 0.5rem 0; overflow-x: auto; overflow-y: hidden; }
/* Shown only when KaTeX hasn't loaded yet — keep the raw TeX readable. */
.katex-fallback {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
    background: #eef2f7;
    border-radius: 3px;
    padding: 0 0.2rem;
}

.chat-loading { display: inline-flex; gap: 0.25rem; padding: 0.6rem 0.85rem; }
.chat-loading span {
    width: 7px; height: 7px; border-radius: 50%;
    background: #94a3b8; animation: pulse 1.4s infinite;
}
.chat-loading span:nth-child(2) { animation-delay: 0.2s; }
.chat-loading span:nth-child(3) { animation-delay: 0.4s; }

/* Thinking block (collapsible) */
.thinking-block {
    margin: 0.5rem 0;
    background: linear-gradient(145deg, #f8fafc, #eef2f7);
    border: 1px solid #e2e8f0;
    border-left: 4px solid #94a3b8;
    border-radius: 0.5rem;
    overflow: hidden;
    font-size: 0.8rem;
}
.thinking-toggle {
    cursor: pointer; user-select: none;
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.45rem 0.75rem;
    color: #475569;
    font-weight: 500;
    transition: background-color 0.15s ease;
}
.thinking-toggle:hover { background: #e2e8f0; color: var(--umqi-primary); }
.thinking-toggle .chevron { transition: transform 0.2s ease; }
.thinking-block.expanded .thinking-toggle .chevron { transform: rotate(90deg); }
.thinking-content {
    display: none;
    padding: 0.6rem 0.85rem;
    border-top: 1px dashed #cbd5e1;
    background: #ffffff;
    white-space: pre-wrap;
    color: #475569;
    font-style: italic;
    line-height: 1.5;
}
.thinking-block.expanded .thinking-content { display: block; }
.thinking-block.partial { border-left-color: var(--umqi-accent); }
.thinking-block.partial .thinking-toggle i.fa-brain { animation: pulse 1.4s infinite; color: var(--umqi-accent); }
.thinking-block.partial .thinking-toggle span { color: var(--umqi-accent); }

/* Voice button active state */
.voice-active { background: var(--umqi-accent) !important; color: #fff !important; }
.voice-on { background: var(--umqi-primary) !important; color: #fff !important; }

/* Breadcrumbs */
.breadcrumbs { font-size: 0.875rem; color: var(--umqi-muted); margin-bottom: 1rem; }
.breadcrumbs a { color: var(--umqi-muted); transition: color 0.15s ease; }
.breadcrumbs a:hover { color: var(--umqi-primary); }
.breadcrumbs .current { color: var(--umqi-primary); font-weight: 500; }
.breadcrumbs i { font-size: 0.7rem; margin: 0 0.5rem; }

/* Page header */
.page-header {
    display: flex; flex-direction: column; gap: 0.25rem;
    margin-bottom: 1.5rem;
}
@media (min-width: 768px) { .page-header { flex-direction: row; align-items: center; justify-content: space-between; } }
.page-title { font-size: 1.875rem; font-weight: 700; color: var(--umqi-primary); display: flex; align-items: center; gap: 0.75rem; }
.page-subtitle { color: var(--umqi-muted); font-size: 0.95rem; }
.page-pill {
    display: inline-flex; align-items: center; gap: 0.5rem;
    background: #EFF6FF; color: var(--umqi-primary);
    padding: 0.5rem 1rem; border-radius: 9999px;
    font-size: 0.875rem;
}

/* Map containers */
.map-default { width: 100%; height: 400px; border-radius: 0.75rem; box-shadow: 0 10px 25px -10px rgba(0, 58, 107, 0.2); overflow: hidden; }
.map-small { width: 100%; height: 240px; border-radius: 0.75rem; overflow: hidden; }

/* OpenLayers: keep the canvas inside the rounded container, and show a
   crosshair while drawing a custom route. */
.map-default .ol-viewport, .map-small .ol-viewport { border-radius: inherit; }
#map.drawing canvas { cursor: crosshair !important; }

/* OpenLayers popup (click) — styled to echo the old Leaflet popup. */
.ol-umqi-popup {
    position: absolute;
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 3px 14px rgba(0, 58, 107, 0.25);
    padding: 0.35rem 0.6rem;
    min-width: 80px;
    font-size: 0.85rem;
    color: #0f172a;
    border: 1px solid #e2e8f0;
}
.ol-umqi-popup::after {
    content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
    border: 7px solid transparent; border-top-color: #fff;
}
.ol-umqi-popup-body { padding-right: 0.6rem; }
.ol-umqi-popup-close {
    position: absolute; top: 2px; right: 5px;
    background: none; border: 0; cursor: pointer;
    font-size: 1rem; line-height: 1; color: #94a3b8;
}
.ol-umqi-popup-close:hover { color: #475569; }

/* OpenLayers tooltip (hover). */
.ol-umqi-tooltip {
    position: absolute;
    background: rgba(15, 23, 42, 0.88);
    color: #fff;
    padding: 0.2rem 0.45rem;
    border-radius: 0.3rem;
    font-size: 0.78rem;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
