/* MnemOS — modern dark glassmorphic UI */

:root {
    --bg-0: #0a0e1a;
    --bg-1: #0f1525;
    --surface: rgba(20, 26, 44, 0.72);
    --surface-2: rgba(28, 36, 58, 0.6);
    --surface-3: rgba(36, 46, 72, 0.5);
    --border: rgba(148, 163, 184, 0.12);
    --border-strong: rgba(148, 163, 184, 0.2);
    --text: #e6e9f0;
    --text-dim: #94a3b8;
    --text-faint: #64748b;
    --accent: #a78bfa;
    --accent-2: #60a5fa;
    --accent-grad: linear-gradient(135deg, #a78bfa 0%, #60a5fa 100%);
    --accent-grad-soft: linear-gradient(135deg, rgba(167,139,250,0.18) 0%, rgba(96,165,250,0.18) 100%);
    --walking: #34d399;
    --cycling: #fbbf24;
    --driving: #f87171;
    --transit: #60a5fa;
    --danger: #ef4444;
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.45);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 24px rgba(167, 139, 250, 0.18);
    --radius: 14px;
    --radius-sm: 10px;
    --radius-pill: 999px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg-0);
    overflow: hidden;
    font-feature-settings: 'cv11', 'ss01';
    -webkit-font-smoothing: antialiased;
}

/* Animated background orbs */
.bg-orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.55;
    pointer-events: none;
    z-index: 0;
    will-change: transform;
}
.bg-orb-1 {
    width: 520px; height: 520px;
    background: radial-gradient(circle, #a78bfa 0%, transparent 70%);
    top: -180px; left: -120px;
    animation: float1 22s ease-in-out infinite;
}
.bg-orb-2 {
    width: 460px; height: 460px;
    background: radial-gradient(circle, #60a5fa 0%, transparent 70%);
    bottom: -160px; right: -100px;
    animation: float2 28s ease-in-out infinite;
}
.bg-orb-3 {
    width: 380px; height: 380px;
    background: radial-gradient(circle, #f472b6 0%, transparent 70%);
    top: 30%; right: 25%;
    opacity: 0.25;
    animation: float3 34s ease-in-out infinite;
}
@keyframes float1 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(80px, 60px) scale(1.1); } }
@keyframes float2 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(-100px, -80px) scale(0.9); } }
@keyframes float3 { 0%,100% { transform: translate(0,0) scale(1); } 33% { transform: translate(-60px, 40px) scale(1.15); } 66% { transform: translate(40px, -60px) scale(0.95); } }

#app {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ===== Header ============================================================ */

header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.7rem 1.2rem;
    background: rgba(10, 14, 26, 0.7);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}
.brand-logo {
    width: 36px; height: 36px;
    background: var(--accent-grad-soft);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow-glow);
}
.brand-logo svg { width: 22px; height: 22px; }
.brand-text { line-height: 1.1; }
.brand-name {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    background: var(--accent-grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.brand-sub {
    font-size: 0.7rem;
    color: var(--text-faint);
    margin-top: 1px;
    letter-spacing: 0.02em;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem 0.75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    color: var(--text-dim);
    font-weight: 500;
}
.header-status .dot {
    width: 7px; height: 7px;
    background: var(--walking);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--walking);
    animation: pulse-dot 2.4s ease-in-out infinite;
}
.header-status.thinking .dot {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
    animation: pulse-dot 0.9s ease-in-out infinite;
}
.header-status.error .dot {
    background: var(--danger);
    box-shadow: 0 0 8px var(--danger);
}
@keyframes pulse-dot {
    0%,100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.55; transform: scale(0.85); }
}

.actions {
    margin-left: auto;
    display: flex;
    gap: 0.4rem;
}
.hbtn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.85rem;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.16s ease;
}
.hbtn svg { opacity: 0.8; }
.hbtn:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
    transform: translateY(-1px);
}
.hbtn-accent {
    background: var(--accent-grad-soft);
    border-color: rgba(167, 139, 250, 0.35);
    color: #ddd6fe;
}
.hbtn-accent:hover {
    border-color: rgba(167, 139, 250, 0.5);
    box-shadow: 0 0 16px rgba(167, 139, 250, 0.2);
}

/* ===== Main + chat ======================================================= */

main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

#chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.4rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.18);
    border-radius: 4px;
}
#messages::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.3); }

.msg {
    max-width: 76%;
    padding: 0.85rem 1.1rem;
    border-radius: 16px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.92rem;
    animation: msg-in 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.msg.user {
    align-self: flex-end;
    background: var(--accent-grad);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 14px rgba(167, 139, 250, 0.25);
    font-weight: 500;
}
.msg.assistant {
    align-self: flex-start;
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-md);
}
.msg.assistant strong { color: #ddd6fe; font-weight: 600; }
.msg.system-note {
    align-self: center;
    background: transparent;
    color: var(--text-faint);
    font-size: 0.78rem;
    font-style: italic;
    padding: 0.2rem 0.5rem;
    max-width: 80%;
    text-align: center;
}

/* Closer bubble — small, warm, after the map. Visually distinct from the
   main reasoning bubble so the user notices it's the prompt for feedback. */
.msg.assistant-closer {
    align-self: flex-start;
    background: var(--accent-grad-soft);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #ddd6fe;
    border: 1px solid rgba(167, 139, 250, 0.3);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-md);
    font-weight: 500;
    font-size: 0.93rem;
    max-width: 60%;
    margin-top: 0.2rem;
}

/* Mode-selection buttons */
.mode-buttons {
    align-self: center;
    display: flex;
    gap: 0.55rem;
    flex-wrap: wrap;
    padding: 0.5rem 0;
    margin: 0.3rem 0;
    animation: msg-in 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text);
    font-family: inherit;
    transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}
.mode-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--mode-color, var(--accent));
    opacity: 0;
    transition: opacity 0.18s;
    z-index: -1;
}
.mode-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    border-color: var(--mode-color, var(--accent));
    color: var(--mode-color, var(--accent));
    box-shadow: 0 8px 20px -8px var(--mode-color, var(--accent));
}
.mode-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}
.mode-btn.mode-walking { --mode-color: var(--walking); }
.mode-btn.mode-cycling { --mode-color: var(--cycling); }
.mode-btn.mode-driving { --mode-color: var(--driving); }
.mode-btn.mode-transit { --mode-color: var(--transit); }

/* Proposed-route card — Broca's primary recommendation surface */
.proposed-card {
    align-self: stretch;
    flex-shrink: 0;  /* CRITICAL: column flex parent would otherwise squeeze the map */
    background: var(--surface);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    overflow: hidden;
    margin: 0.4rem 0;
    box-shadow: var(--shadow-lg), 0 0 24px -8px var(--mode-color, var(--accent));
    animation: msg-in 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}
.proposed-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--mode-color, var(--accent)) 0%, transparent 100%);
}
.proposed-card.mode-walking { --mode-color: var(--walking); }
.proposed-card.mode-cycling { --mode-color: var(--cycling); }
.proposed-card.mode-driving { --mode-color: var(--driving); }
.proposed-card.mode-transit { --mode-color: var(--transit); }

.proposed-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.2rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(167, 139, 250, 0.05), transparent);
}
.proposed-flag {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.65rem;
    background: var(--accent-grad-soft);
    border: 1px solid rgba(167, 139, 250, 0.35);
    border-radius: var(--radius-pill);
    font-size: 0.7rem;
    font-weight: 600;
    color: #ddd6fe;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.proposed-spark {
    background: var(--accent-grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    font-size: 0.85rem;
}
.proposed-mode {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
    padding: 0.4rem 0.85rem;
    background: var(--mode-color, var(--accent));
    color: #0a0e1a;
    border-radius: var(--radius-pill);
    font-weight: 700;
}
.proposed-mode-emoji { font-size: 1.05rem; }
.proposed-mode-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.proposed-meta {
    display: inline-flex;
    gap: 0.7rem;
    font-size: 0.85rem;
    color: var(--text-dim);
    font-family: 'JetBrains Mono', monospace;
}
.proposed-meta strong {
    color: var(--text);
    font-weight: 600;
}
.proposed-map {
    height: 360px;
    flex-shrink: 0;
    width: 100%;
    background: #1e293b;
    position: relative;
    transition: height 0.25s ease, opacity 0.2s ease;
}
.proposed-card.collapsed .proposed-map {
    height: 0;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
    border: none;
}
.proposed-card.collapsed .proposed-context {
    border-top: none;
}

/* Show/Hide map toggle button in the header */
.map-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.8rem;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    transition: all 0.16s;
}
.map-toggle:hover {
    background: var(--surface-3);
    border-color: rgba(167, 139, 250, 0.45);
    color: #ddd6fe;
}
.map-toggle .map-toggle-icon {
    transition: transform 0.2s ease;
}
.proposed-card:not(.collapsed) .map-toggle .map-toggle-icon {
    transform: rotate(180deg);
}
.proposed-map.loading {
    display: flex;
    align-items: center;
    justify-content: center;
}
.proposed-map.empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-faint);
    font-style: italic;
    background: rgba(30, 41, 59, 0.6);
    height: 80px;
}
.map-loading {
    color: var(--text-faint);
    font-size: 0.85rem;
    font-style: italic;
    letter-spacing: 0.02em;
    animation: pulse-dot 1.6s ease-in-out infinite;
}
.proposed-context {
    padding: 0.65rem 1.2rem;
    font-size: 0.78rem;
    background: rgba(10, 14, 26, 0.4);
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.proposed-context .ctx-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.6rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    color: var(--text-dim);
    font-weight: 500;
}
.proposed-context .ctx-chip.endpoints {
    margin-left: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.73rem;
    color: var(--text-faint);
    background: transparent;
    border: none;
}
.proposed-considered {
    border-top: 1px solid var(--border);
    background: rgba(10, 14, 26, 0.25);
    padding: 0;
}
.proposed-considered summary {
    padding: 0.7rem 1.2rem;
    cursor: pointer;
    font-size: 0.78rem;
    color: var(--text-faint);
    user-select: none;
    transition: color 0.15s, background 0.15s;
    list-style: none;
}
.proposed-considered summary::-webkit-details-marker { display: none; }
.proposed-considered summary::before {
    content: '▸';
    display: inline-block;
    margin-right: 0.4rem;
    transition: transform 0.18s;
    color: var(--text-faint);
}
.proposed-considered[open] summary::before { transform: rotate(90deg); }
.proposed-considered summary:hover { color: var(--text-dim); background: var(--surface-2); }
.proposed-considered ul {
    margin: 0;
    padding: 0.2rem 1.2rem 0.85rem 2.1rem;
    list-style: none;
}
.proposed-considered ul li {
    font-size: 0.78rem;
    color: var(--text-dim);
    padding: 0.25rem 0;
    line-height: 1.5;
}
.proposed-considered ul li strong {
    color: var(--text);
    font-weight: 600;
    text-transform: capitalize;
}

/* Route map cards */
.route-card {
    align-self: stretch;
    flex-shrink: 0;  /* CRITICAL: column flex parent would otherwise squeeze the map */
    background: var(--surface);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin: 0.3rem 0;
    box-shadow: var(--shadow-lg);
    animation: msg-in 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.route-card .route-meta {
    padding: 0.85rem 1.1rem;
    background: linear-gradient(180deg, rgba(167, 139, 250, 0.08), transparent);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.85rem;
    flex-wrap: wrap;
    font-size: 0.86rem;
}
.route-card .route-meta .badge {
    background: var(--mode-color, var(--accent-grad));
    color: #0a0e1a;
    padding: 0.25rem 0.7rem;
    border-radius: var(--radius-pill);
    font-weight: 700;
    text-transform: capitalize;
    font-size: 0.78rem;
    letter-spacing: 0.02em;
}
.route-card.mode-walking { --mode-color: var(--walking); }
.route-card.mode-cycling { --mode-color: var(--cycling); }
.route-card.mode-driving { --mode-color: var(--driving); }
.route-card.mode-transit { --mode-color: var(--transit); }

.route-card .route-meta .meta-item {
    color: var(--text-dim);
    font-size: 0.85rem;
}
.route-card .route-meta .meta-item strong { color: var(--text); font-weight: 600; }
.route-card .route-meta .meta-item.endpoints {
    margin-left: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    color: var(--text-faint);
}
.route-card .route-map {
    height: 480px;
    flex-shrink: 0;
    width: 100%;
    background: #1e293b;
    position: relative;
}
.route-card .route-context {
    padding: 0.6rem 1.1rem;
    font-size: 0.75rem;
    color: var(--text-faint);
    background: rgba(10, 14, 26, 0.4);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.9rem;
    flex-wrap: wrap;
    align-items: center;
}
.route-card .route-context .ctx-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.6rem;
    background: var(--surface-2);
    border-radius: var(--radius-pill);
    color: var(--text-dim);
    font-weight: 500;
}

/* ===== Composer ========================================================== */

#composer {
    padding: 0.9rem 1.4rem 0.8rem;
}
.composer-inner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--surface);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 0.35rem 0.4rem 0.35rem 0.4rem;
    transition: border-color 0.18s, box-shadow 0.18s;
}
.composer-inner:focus-within {
    border-color: rgba(167, 139, 250, 0.5);
    box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.12);
}
#input {
    flex: 1;
    padding: 0.65rem 0.85rem;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
}
#input::placeholder { color: var(--text-faint); }

#composer button {
    width: 38px; height: 38px;
    background: var(--accent-grad);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.16s;
    box-shadow: 0 4px 14px rgba(167, 139, 250, 0.3);
}
#composer button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(167, 139, 250, 0.45);
}
#composer button:disabled { opacity: 0.45; cursor: not-allowed; }

#status {
    text-align: center;
    color: var(--text-faint);
    font-size: 0.74rem;
    padding: 0.25rem 0 0.5rem;
    min-height: 1.3rem;
    letter-spacing: 0.02em;
}
#status.thinking::before {
    content: '';
    display: inline-block;
    width: 6px; height: 6px;
    background: var(--accent);
    border-radius: 50%;
    margin-right: 0.4rem;
    vertical-align: middle;
    animation: pulse-dot 0.9s ease-in-out infinite;
    box-shadow: 0 0 6px var(--accent);
}

/* ===== Side panel ======================================================== */

#panel {
    width: 380px;
    background: rgba(10, 14, 26, 0.55);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding: 1.2rem;
}
#panel::-webkit-scrollbar { width: 6px; }
#panel::-webkit-scrollbar-track { background: transparent; }
#panel::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.18);
    border-radius: 3px;
}
#panel.hidden { display: none; }

.panel-section {
    margin-bottom: 1.6rem;
    padding-bottom: 1.4rem;
    border-bottom: 1px solid var(--border);
}
.panel-section:last-child { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }

.panel-h {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin-bottom: 0.45rem;
}
.panel-icon {
    width: 26px; height: 26px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.flashbulb-icon { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }
.passport-icon { background: rgba(96, 165, 250, 0.15); color: var(--transit); }
.reflection-icon { background: rgba(167, 139, 250, 0.15); color: var(--accent); }
.archive-icon { background: rgba(148, 163, 184, 0.15); color: var(--text-dim); }

.panel-h h3 {
    margin: 0;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex: 1;
}

.panel-help {
    font-size: 0.72rem;
    color: var(--text-faint);
    margin: 0.1rem 0 0.7rem;
    line-height: 1.45;
}

#flashbulb-list, #reflection-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
#flashbulb-list li {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.1), rgba(251, 191, 36, 0.04));
    border: 1px solid rgba(251, 191, 36, 0.22);
    border-left: 3px solid #fbbf24;
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.45rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--text);
}
#flashbulb-list .empty {
    background: transparent;
    border: 1px dashed var(--border);
    border-left-color: var(--border);
    color: var(--text-faint);
    font-style: italic;
    text-align: center;
}

.count-badge {
    display: inline-block;
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
    border-radius: var(--radius-pill);
    padding: 0.1rem 0.55rem;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 1.4rem;
    text-align: center;
    border: 1px solid rgba(251, 191, 36, 0.3);
}
.count-badge.empty {
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-faint);
    border-color: var(--border);
}

#reflection-list li {
    font-size: 0.78rem;
    color: var(--text-dim);
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border);
    line-height: 1.5;
}
#reflection-list li:last-child { border-bottom: none; }
#reflection-list li .ts {
    color: var(--text-faint);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
}
#reflection-list li .delta {
    display: inline-block;
    background: var(--surface-3);
    padding: 0.05rem 0.4rem;
    border-radius: var(--radius-pill);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--accent);
    margin: 0 0.3rem;
}

/* ===== Cognitive Passport visualization ================================== */

#passport-content {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}
.cp-block {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.7rem 0.8rem;
}
.cp-block-title {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.45rem;
}
.cp-narrative {
    font-size: 0.82rem;
    color: var(--text);
    line-height: 1.5;
    font-style: italic;
}
.cp-bars {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.cp-bar-row {
    display: grid;
    grid-template-columns: 60px 1fr 36px;
    align-items: center;
    gap: 0.55rem;
    font-size: 0.78rem;
}
.cp-bar-label {
    color: var(--text-dim);
    text-transform: capitalize;
    font-weight: 500;
}
.cp-bar-track {
    height: 8px;
    background: rgba(148, 163, 184, 0.14);
    border-radius: var(--radius-pill);
    overflow: hidden;
    position: relative;
}
.cp-bar-fill {
    height: 100%;
    background: var(--bar-color, var(--accent-grad));
    border-radius: var(--radius-pill);
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 0 8px var(--bar-color, var(--accent));
}
.cp-bar-row.mode-walking { --bar-color: var(--walking); }
.cp-bar-row.mode-cycling { --bar-color: var(--cycling); }
.cp-bar-row.mode-driving { --bar-color: var(--driving); }
.cp-bar-row.mode-transit, .cp-bar-row.mode-pt { --bar-color: var(--transit); }
.cp-bar-value {
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.74rem;
    text-align: right;
    font-weight: 500;
}

.cp-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}
.cp-chip {
    background: var(--accent-grad-soft);
    color: #ddd6fe;
    border: 1px solid rgba(167, 139, 250, 0.3);
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-pill);
    font-size: 0.72rem;
    font-weight: 500;
}
.cp-chip.flag {
    background: rgba(251, 191, 36, 0.12);
    border-color: rgba(251, 191, 36, 0.3);
    color: #fbbf24;
}
.cp-meta {
    font-size: 0.7rem;
    color: var(--text-faint);
    font-family: 'JetBrains Mono', monospace;
    margin-top: 0.4rem;
}

/* ===== Archive grid ===================================================== */

.archive-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 0.7rem;
}
.stat {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.7rem;
}
.stat-num {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
    line-height: 1.1;
    background: var(--accent-grad);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.stat-label {
    font-size: 0.7rem;
    color: var(--text-faint);
    margin-top: 0.15rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.panel-btn {
    width: 100%;
    padding: 0.55rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text);
    margin-top: 0.4rem;
    font-family: inherit;
    transition: all 0.16s;
}
.panel-btn:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}
.panel-btn.danger {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}
.panel-btn.danger:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.5);
}

/* ===== Modals ============================================================ */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 16, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: modal-fade 0.2s ease-out;
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal.hidden { display: none; }
.modal-card {
    background: var(--surface);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 460px;
    max-width: 92vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modal-rise 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modal-rise { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-card.big { width: 760px; }
.modal-card h2 {
    margin: 0 0 0.4rem;
    font-size: 1.15rem;
    font-weight: 600;
}
.modal-card .muted {
    color: var(--text-faint);
    font-size: 0.82rem;
    margin: 0 0 1rem;
}
.modal-card label {
    display: block;
    margin: 0.6rem 0;
    font-size: 0.82rem;
    color: var(--text-dim);
    font-weight: 500;
}
.modal-card input {
    display: block;
    width: 100%;
    padding: 0.55rem 0.7rem;
    margin-top: 0.3rem;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.16s, box-shadow 0.16s;
}
.modal-card input:focus {
    outline: none;
    border-color: rgba(167, 139, 250, 0.5);
    box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.12);
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.2rem;
}
.btn-secondary, .btn-primary {
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    transition: all 0.16s;
}
.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
}
.btn-secondary:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}
.btn-primary {
    background: var(--accent-grad);
    color: #fff;
    border: none;
    box-shadow: 0 4px 14px rgba(167, 139, 250, 0.3);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(167, 139, 250, 0.45);
}

#archive-pre {
    background: rgba(5, 8, 16, 0.6);
    color: var(--text);
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: auto;
    max-height: 60vh;
    font-size: 0.74rem;
    line-height: 1.5;
    font-family: 'JetBrains Mono', monospace;
}

/* Leaflet tweaks for dark theme */
.leaflet-container {
    background: #1e293b !important;
}
.leaflet-control-attribution {
    background: rgba(10, 14, 26, 0.7) !important;
    color: var(--text-faint) !important;
    font-size: 0.65rem !important;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-control-zoom a {
    background: var(--surface) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover {
    background: var(--surface-3) !important;
}

/* Responsive */
@media (max-width: 880px) {
    #panel { width: 100%; position: absolute; right: 0; top: 0; bottom: 0; height: 100%; box-shadow: -10px 0 40px rgba(0,0,0,0.5); }
    .brand-text { display: none; }
    .actions .hbtn { padding: 0.45rem 0.55rem; }
    .actions .hbtn span, .hbtn:not(.hbtn-accent) { /* keep labels */ }
}
