/* Alert Cymru — visual system
   Operational dashboard. Dark base with high-contrast accents.
   Accent palette pulls from Welsh flag red and a deep slate. */

:root {
    --bg: #0d1217;
    --bg-elevated: #161c24;
    --bg-card: #1c242e;
    --bg-overlay: rgba(20, 26, 34, 0.95);
    --line: #2a3441;
    --line-strong: #3d4a5e;

    --text: #e8edf2;
    --text-muted: #98a4b3;
    --text-faint: #6b7785;

    --accent: #c8102e;        /* Welsh red */
    --accent-soft: #d63a4d;
    --accent-bg: rgba(200, 16, 46, 0.08);

    --info: #4a9eff;
    --info-bg: rgba(74, 158, 255, 0.08);

    --warn: #f59e0b;
    --warn-bg: rgba(245, 158, 11, 0.08);

    --success: #10b981;

    --sev-major: #c8102e;
    --sev-significant: #f59e0b;
    --sev-routine: #4a9eff;

    --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;

    --radius: 6px;
    --radius-lg: 10px;

    --header-height: 64px;
}

@import url('https://fonts.googleapis.com/css2?family=Fraunces:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

.cy {
    color: var(--text-muted);
    font-style: italic;
}

/* ============================================================
   LOGIN
   ============================================================ */

.login-body {
    display: grid;
    place-items: center;
    background: linear-gradient(180deg, var(--bg) 0%, #050709 100%);
    background-image:
        radial-gradient(circle at 20% 30%, rgba(200, 16, 46, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(74, 158, 255, 0.05) 0%, transparent 40%),
        linear-gradient(180deg, var(--bg) 0%, #050709 100%);
    min-height: 100vh;
}

.login-shell {
    width: 100%;
    max-width: 420px;
    padding: 24px;
}

.login-card {
    background: var(--bg-elevated);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.brand {
    margin-bottom: 32px;
    text-align: center;
}

.brand-mark {
    display: inline-block;
    color: var(--accent);
    font-size: 32px;
    margin-bottom: 12px;
}

.brand h1 {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 28px;
    letter-spacing: -0.01em;
    margin-bottom: 6px;
}

.tagline {
    color: var(--text-muted);
    font-size: 13px;
}

.login-form { display: grid; gap: 18px; }

.login-form label {
    display: grid;
    gap: 6px;
}

.login-form label span {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.login-form input {
    background: var(--bg-card);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 11px 14px;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 15px;
}

.login-form input:focus {
    outline: none;
    border-color: var(--info);
    box-shadow: 0 0 0 3px var(--info-bg);
}

.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    padding: 12px;
    border-radius: var(--radius);
    font-weight: 500;
    font-family: var(--font-body);
    font-size: 15px;
    cursor: pointer;
    transition: background 0.15s ease;
    margin-top: 8px;
}
.btn-primary:hover { background: var(--accent-soft); }

.alert {
    padding: 11px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-error {
    background: var(--accent-bg);
    border: 1px solid var(--accent);
    color: var(--accent-soft);
}

.login-footer {
    margin-top: 28px;
    text-align: center;
    color: var(--text-faint);
    font-size: 12px;
}

/* ============================================================
   APP LAYOUT
   ============================================================ */

.app-body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.app-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    gap: 32px;
    padding: 0 20px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.brand-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-row .brand-mark { font-size: 24px; margin: 0; }

.brand-text h1 {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 500;
    line-height: 1.1;
}

.brand-text .subtitle {
    font-size: 12px;
    color: var(--text-muted);
}

.status-bar {
    display: flex;
    gap: 24px;
    margin-left: auto;
    padding: 0 24px;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    height: 100%;
    align-items: center;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.1;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 500;
}

.stat-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-top: 2px;
}

.stat-active .stat-value { color: var(--accent); }
.stat-stale .stat-value { color: var(--warn); }
.stat-resolved .stat-value { color: var(--text-faint); }

.user-row {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 14px;
}

.user-name { color: var(--text-muted); font-family: var(--font-mono); font-size: 13px; }

.btn-link {
    color: var(--text);
    font-size: 13px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    transition: border-color 0.15s;
}
.btn-link:hover { border-color: var(--line-strong); text-decoration: none; }

.btn-refresh {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--line);
    padding: 7px 12px 7px 10px;
    border-radius: var(--radius);
    font-size: 13px;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn-refresh:hover:not(:disabled) {
    border-color: var(--info);
    color: var(--info);
}
.btn-refresh:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn-refresh .refresh-icon {
    font-size: 14px;
    line-height: 1;
    display: inline-block;
}
.btn-refresh.refreshing .refresh-icon {
    animation: spin 0.9s linear infinite;
    color: var(--info);
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Toast notifications */
#toast-host {
    position: fixed;
    bottom: 22px;
    right: 22px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 10000;
    pointer-events: none;
}
.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--line);
    border-left: 3px solid var(--info);
    color: var(--text);
    padding: 11px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    max-width: 380px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    animation: toast-in 0.25s ease-out;
    pointer-events: auto;
}
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--accent); }
.toast-fade {
    opacity: 0;
    transform: translateX(20px);
    transition: all 0.4s ease-in;
}
@keyframes toast-in {
    from { transform: translateX(30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.app-grid {
    display: grid;
    grid-template-columns: 260px 1fr 360px;
    flex: 1;
    overflow: hidden;
}

/* ============================================================
   FILTERS RAIL
   ============================================================ */

.filters-rail {
    background: var(--bg-elevated);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    padding: 18px;
}

.rail-heading {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
}

.filter-section { margin-bottom: 24px; }

.filter-section h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    font-weight: 500;
    margin-bottom: 8px;
}

.filter-row {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 0;
    cursor: pointer;
    font-size: 13px;
}

.filter-row input[type="checkbox"] {
    accent-color: var(--info);
    margin: 0;
}

.filter-label { flex: 1; }

.source-dot {
    width: 10px; height: 10px; border-radius: 50%;
    flex-shrink: 0;
}

.severity-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.sev-major { background: var(--sev-major); }
.sev-significant { background: var(--sev-significant); }
.sev-routine { background: var(--sev-routine); }

.type-group { margin-bottom: 6px; }
.type-group summary {
    cursor: pointer;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 4px 0;
    list-style: none;
    user-select: none;
}
.type-group summary::-webkit-details-marker { display: none; }
.type-group summary::before {
    content: '▸';
    display: inline-block;
    margin-right: 6px;
    transition: transform 0.15s;
}
.type-group[open] summary::before { transform: rotate(90deg); }

.select-input {
    width: 100%;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--line);
    padding: 8px 10px;
    border-radius: var(--radius);
    font-size: 13px;
    font-family: var(--font-body);
}

/* ============================================================
   MAP
   ============================================================ */

.map-shell { position: relative; }

#map {
    height: 100%;
    width: 100%;
    background: #0a0e13;
}

/* Dark theme tweaks for Leaflet */
.leaflet-control-attribution {
    background: rgba(13, 18, 23, 0.85) !important;
    color: var(--text-faint) !important;
    font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--info) !important; }

.leaflet-popup-content-wrapper {
    background: var(--bg-elevated) !important;
    color: var(--text) !important;
    border: 1px solid var(--line) !important;
    border-radius: var(--radius) !important;
}
.leaflet-popup-tip { background: var(--bg-elevated) !important; border: 1px solid var(--line) !important; }

.popup-title {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 15px;
    margin-bottom: 6px;
    line-height: 1.2;
}

.popup-meta {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}

.popup-summary {
    font-size: 13px;
    margin-bottom: 8px;
    color: var(--text);
}

.popup-cta {
    display: inline-block;
    font-size: 12px;
    color: var(--info);
    margin-top: 4px;
    cursor: pointer;
}

/* ============================================================
   FEED RAIL
   ============================================================ */

.feed-rail {
    background: var(--bg-elevated);
    border-left: 1px solid var(--line);
    overflow-y: auto;
    padding: 18px;
}

.feed-list { display: flex; flex-direction: column; gap: 10px; }

.feed-item {
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-left: 3px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 14px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.feed-item:hover {
    border-color: var(--line-strong);
    transform: translateX(-1px);
}

.feed-item.sev-major { border-left-color: var(--sev-major); }
.feed-item.sev-significant { border-left-color: var(--sev-significant); }
.feed-item.sev-routine { border-left-color: var(--sev-routine); }

.feed-item.state-stale { opacity: 0.6; }
.feed-item.state-resolved { opacity: 0.45; text-decoration: line-through; text-decoration-color: var(--text-faint); }

.feed-item-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
}

.feed-type {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.feed-time {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-faint);
    white-space: nowrap;
}

.feed-title {
    font-weight: 500;
    font-size: 14px;
    line-height: 1.3;
    margin-bottom: 4px;
}

.feed-summary {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.feed-source {
    margin-top: 8px;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-faint);
    text-transform: uppercase;
}

.feed-empty {
    color: var(--text-faint);
    text-align: center;
    padding: 32px 0;
    font-size: 13px;
}

/* ============================================================
   TIMELINE PANE (slide-out)
   ============================================================ */

.timeline-pane {
    position: fixed;
    top: var(--header-height);
    right: 0;
    width: min(560px, 100vw);
    height: calc(100vh - var(--header-height));
    background: var(--bg-overlay);
    backdrop-filter: blur(12px);
    border-left: 1px solid var(--line);
    z-index: 1000;
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.5);
    overflow-y: auto;
    animation: slideIn 0.25s ease-out;
}

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

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 22px 24px 16px;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    background: var(--bg-overlay);
    z-index: 1;
}

.timeline-header h2 {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 22px;
    line-height: 1.15;
    flex: 1;
}

.btn-close {
    background: none;
    border: 1px solid var(--line);
    color: var(--text);
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
}
.btn-close:hover { border-color: var(--line-strong); }

.timeline-meta {
    padding: 16px 24px;
    border-bottom: 1px solid var(--line);
    display: flex;
    flex-wrap: wrap;
    gap: 14px 24px;
    font-size: 12px;
}

.timeline-meta dt {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    font-size: 10px;
    margin-bottom: 2px;
}
.timeline-meta dd { font-family: var(--font-mono); font-size: 13px; }
.timeline-meta dd a { color: var(--info); }

.timeline-meta-item { min-width: 100px; }

.timeline-content { padding: 20px 24px 60px; }

.update-block {
    position: relative;
    padding: 14px 0 18px 24px;
    border-left: 2px solid var(--line);
    margin-left: 6px;
}

.update-block::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 18px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--info);
    border: 2px solid var(--bg);
}

.update-block.update-initial::before { background: var(--accent); }
.update-block.update-resolution::before { background: var(--success); }

.update-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    align-items: baseline;
}

.update-source {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.update-time {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-faint);
}

.update-text {
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    color: var(--text);
}

.update-media {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 6px;
    margin-top: 10px;
}

.update-media img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    cursor: pointer;
    transition: opacity 0.15s;
}
.update-media img:hover { opacity: 0.85; }

.update-link {
    display: inline-block;
    margin-top: 8px;
    font-size: 12px;
    color: var(--info);
}

/* Severity chip in headers */
.severity-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
    background: var(--bg-card);
    border: 1px solid var(--line);
}

.severity-chip.major { color: var(--sev-major); border-color: var(--sev-major); }
.severity-chip.significant { color: var(--sev-significant); border-color: var(--sev-significant); }
.severity-chip.routine { color: var(--sev-routine); border-color: var(--sev-routine); }
