/* ==========================================================================
   SIAGAGEMPA — DESIGN TOKENS
   Konsep: panel instrumen pemantau gempa. Header gelap seperti alat ukur,
   kontras tinggi untuk kondisi darurat, warna risiko sebagai bahasa utama.
   ========================================================================== */

:root {
    /* warna dasar */
    --color-bg: #F3F5F8;
    --color-surface: #FFFFFF;
    --color-ink: #10151F;
    --color-ink-soft: #4B5768;
    --color-border: #E1E6ED;

    /* header instrumen */
    --color-header-bg: #0A1120;
    --color-header-ink: #E9EEF6;
    --color-header-sub: #8291A8;

    /* aksen aksi */
    --color-accent: #1958D6;
    --color-accent-ink: #FFFFFF;
    --color-accent-soft: #E7EFFD;

    /* tingkat risiko */
    --risk-rendah: #22A559;
    --risk-sedang: #E3A912;
    --risk-tinggi: #F0741E;
    --risk-sangat-tinggi: #D6273C;

    /* tipografi */
    --font-display: 'Space Grotesk', 'Inter', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;

    --shadow-panel: 0 -6px 24px rgba(10, 17, 32, 0.10);
    --shadow-card: 0 1px 3px rgba(16, 21, 31, 0.08), 0 1px 2px rgba(16, 21, 31, 0.04);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: var(--font-body);
    color: var(--color-ink);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

button {
    font-family: inherit;
    cursor: pointer;
}

ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

p {
    margin: 0;
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}

/* ==========================================================================
   APP SHELL
   ========================================================================== */

#app {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ==========================================================================
   HEADER — panel instrumen
   ========================================================================== */

.topbar {
    flex: 0 0 auto;
    background: var(--color-header-bg);
    color: var(--color-header-ink);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-mark {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: linear-gradient(155deg, var(--color-accent), #0D3EA0);
    color: #fff;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.02em;
}

.brand-text {
    min-width: 0;
}

.brand-text h1 {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 700;
    margin: 0;
    line-height: 1.1;
    letter-spacing: -0.01em;
}

.brand-sub {
    font-size: 11px;
    color: var(--color-header-sub);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-cluster {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 1 auto;
    min-width: 0;
}

/* Signature element: seismograph idle line, spikes on new quake event */
.seismo {
    display: none;
    width: 120px;
    height: 28px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.seismo svg {
    width: 100%;
    height: 100%;
}

#seismoPath {
    fill: none;
    stroke: #35D07F;
    stroke-width: 1.6;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}

.seismo.alert #seismoPath {
    stroke: var(--risk-sangat-tinggi);
}

.bmkg-clock {
    display: none;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--color-header-sub);
    white-space: nowrap;
}

.pill-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--color-accent);
    color: var(--color-accent-ink);
    border: none;
    border-radius: 999px;
    padding: 9px 14px;
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
}

.pill-btn.is-on {
    background: #16693B;
}

.pill-btn.is-error {
    background: #4B5768;
}

.pill-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.55);
}

.pill-btn.is-on .pill-dot {
    background: #7CF0AA;
    box-shadow: 0 0 0 3px rgba(124, 240, 170, 0.25);
}

/* ==========================================================================
   CONTENT AREA (map + panel)
   ========================================================================== */

.content-area {
    flex: 1 1 auto;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.map-wrap {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
}

#map {
    width: 100%;
    height: 100%;
    background: #DCE3EC;
}

.leaflet-popup-content-wrapper {
    border-radius: var(--radius-sm);
}

.leaflet-popup-content {
    font-family: var(--font-body);
    font-size: 13px;
    margin: 10px 12px;
}

.popup-title {
    font-weight: 700;
    margin-bottom: 3px;
}

.popup-meta {
    color: var(--color-ink-soft);
    font-size: 12px;
}

.popup-link {
    display: inline-block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--color-accent);
    font-weight: 600;
    text-decoration: none;
}

/* map floating controls */
.map-controls {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 400;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ctrl-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-card);
    padding: 9px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-ink-soft);
}

.ctrl-btn.active {
    color: var(--color-accent);
    border-color: var(--color-accent-soft);
    background: var(--color-accent-soft);
}

.legend {
    position: absolute;
    left: 12px;
    bottom: 12px;
    z-index: 400;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(4px);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    box-shadow: var(--shadow-card);
    font-size: 11.5px;
}

.legend-title {
    font-weight: 700;
    margin-bottom: 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-ink-soft);
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 2px 0;
    color: var(--color-ink-soft);
}

.swatch {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    display: inline-block;
}

.swatch[data-risk="rendah"] {
    background: var(--risk-rendah);
}

.swatch[data-risk="sedang"] {
    background: var(--risk-sedang);
}

.swatch[data-risk="tinggi"] {
    background: var(--risk-tinggi);
}

.swatch[data-risk="sangat-tinggi"] {
    background: var(--risk-sangat-tinggi);
}

.banner-error {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 66px;
    z-index: 400;
    background: #FFF4E9;
    border: 1px solid #F3C79A;
    color: #7A3E0B;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 12px;
}

.user-dot {
    background: var(--color-accent);
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 4px rgba(25, 88, 214, 0.25);
}

.evac-pin {
    background: #0F8B5F;
    border: 2px solid #fff;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
}

/* ==========================================================================
   BOTTOM SHEET / SIDEBAR PANEL
   ========================================================================== */

.panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 42vh;
    background: var(--color-surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-panel);
    display: flex;
    flex-direction: column;
    z-index: 500;
    transition: max-height 0.28s ease;
}

.panel.expanded {
    max-height: 82vh;
}

.panel-handle {
    flex: 0 0 auto;
    width: 100%;
    padding: 10px 0 6px;
    background: none;
    border: none;
}

.panel-handle::after {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 3px;
    background: var(--color-border);
    margin: 0 auto;
}

.tabs {
    flex: 0 0 auto;
    display: flex;
    gap: 4px;
    padding: 0 14px 10px;
    border-bottom: 1px solid var(--color-border);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 6px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--color-ink-soft);
}

.tab-btn.active {
    background: var(--color-accent-soft);
    color: var(--color-accent);
}

.tab-panel {
    display: none;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
    overflow-y: auto;
    min-height: 0;
}

.tab-panel.active {
    display: flex;
}

.panel-subhead {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 700;
    margin: 4px 0 -2px;
}

.panel-hint {
    font-size: 12.5px;
    color: var(--color-ink-soft);
}

.skeleton-text,
.skeleton-item {
    color: var(--color-ink-soft);
    font-size: 12.5px;
}

/* latest quake hero card */
.latest-quake {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 14px;
    background: linear-gradient(180deg, #FBFCFE, #F5F8FC);
}

.latest-quake .lq-top {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.latest-quake .lq-mag {
    font-family: var(--font-mono);
    font-size: 30px;
    font-weight: 500;
    line-height: 1;
}

.latest-quake .lq-tag {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 3px 8px;
    border-radius: 999px;
    color: #fff;
}

.latest-quake .lq-place {
    margin-top: 8px;
    font-weight: 600;
    font-size: 13.5px;
}

.latest-quake .lq-meta {
    margin-top: 6px;
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--color-ink-soft);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 10px;
}

.latest-quake .lq-note {
    margin-top: 10px;
    font-size: 12px;
    color: var(--color-ink-soft);
    border-top: 1px dashed var(--color-border);
    padding-top: 8px;
}

/* quake list */
.quake-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.quake-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

.quake-item .qi-mag {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    color: #fff;
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.quake-item .qi-body {
    min-width: 0;
    flex: 1;
}

.quake-item .qi-place {
    font-size: 12.5px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.quake-item .qi-meta {
    font-size: 11px;
    color: var(--color-ink-soft);
    font-family: var(--font-mono);
    margin-top: 2px;
}

.risk-fill[data-risk="rendah"] {
    background: var(--risk-rendah);
}

.risk-fill[data-risk="sedang"] {
    background: var(--risk-sedang);
}

.risk-fill[data-risk="tinggi"] {
    background: var(--risk-tinggi);
}

.risk-fill[data-risk="sangat-tinggi"] {
    background: var(--risk-sangat-tinggi);
}

.source-note {
    font-size: 10.5px;
    color: var(--color-ink-soft);
    text-align: center;
    padding-top: 2px;
}

/* evacuation list */
.evac-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.evac-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

.evac-item .ei-name {
    font-size: 12.5px;
    font-weight: 600;
}

.evac-item .ei-meta {
    font-size: 11.5px;
    color: var(--color-ink-soft);
    margin-top: 2px;
}

.evac-item .ei-dist {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--color-accent);
    white-space: nowrap;
}

.evac-item a {
    text-decoration: none;
}

/* chat tab */
.chat-log {
    flex: 1;
    min-height: 160px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    padding-right: 2px;
}

.chat-msg {
    max-width: 88%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.45;
}

.chat-msg.bot {
    align-self: flex-start;
    background: #F1F4F9;
    color: var(--color-ink);
    border-bottom-left-radius: 4px;
}

.chat-msg.user {
    align-self: flex-end;
    background: var(--color-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.typing {
    color: var(--color-ink-soft);
    font-style: italic;
}

.chat-form {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
}

.chat-form input {
    flex: 1;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: 10px 14px;
    font-size: 13px;
    font-family: inherit;
}

.chat-form input:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 1px;
}

.chat-form button {
    border: none;
    background: var(--color-accent);
    color: #fff;
    border-radius: 999px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
}

.chat-form button:disabled {
    background: #B7C2D0;
    cursor: not-allowed;
}

.chat-key-hint {
    font-size: 11px;
    color: #7A3E0B;
    background: #FFF4E9;
    border: 1px solid #F3C79A;
    border-radius: var(--radius-sm);
    padding: 8px 10px;
}

/* ==========================================================================
   DISCLAIMER + TOASTS
   ========================================================================== */

.disclaimer {
    flex: 0 0 auto;
    font-size: 10.5px;
    line-height: 1.4;
    color: var(--color-ink-soft);
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 7px 14px;
    text-align: center;
}

.toast-root {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(92vw, 380px);
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    background: var(--color-header-bg);
    color: #fff;
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
    font-size: 12.5px;
    border-left: 4px solid var(--risk-tinggi);
    animation: toast-in 0.22s ease;
}

.toast.danger {
    border-left-color: var(--risk-sangat-tinggi);
}

.toast .toast-title {
    font-weight: 700;
    margin-bottom: 3px;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   RESPONSIVE — desktop layout: sidebar instead of bottom sheet
   ========================================================================== */

@media (min-width: 880px) {
    .brand-sub {
        display: block;
    }

    .seismo {
        display: block;
    }

    .bmkg-clock {
        display: block;
    }

    .content-area {
        flex-direction: row;
    }

    .panel {
        position: static;
        max-height: none;
        width: 380px;
        flex: 0 0 380px;
        border-radius: 0;
        border-left: 1px solid var(--color-border);
        box-shadow: none;
        height: 100%;
    }

    .panel-handle {
        display: none;
    }

    .tab-panel {
        max-height: none;
    }
}

@media (max-width: 879px) {
    .brand-sub {
        display: none;
    }
}