/* ===== CSS VARIABLES & THEMES ===== */
:root {
    --navy: #0d1117;
    --navy-mid: #161b22;
    --navy-light: #1e2530;
    --gold: #c9972c;
    --gold-light: #e8b94a;
    --gold-pale: #f5e9c8;
    --sidebar-w: 260px;

    /* Light mode */
    --bg: #f5f0e8;
    --surface: #ffffff;
    --surface2: #f8f5ef;
    --text: #0a1628;
    --text-muted: #3d4d63;
    --border: #ddd8cc;
    --topbar-bg: #ffffff;
    --card-bg: #ffffff;
    --input-bg: #ffffff;
    --hover-row: #fafaf8;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

/* ===== RESET & BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html { scroll-behavior: smooth; }

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background 0.25s ease, color 0.25s ease;
    line-height: 1.6;
}

/* ===== TYPOGRAPHY ===== */
h1, h2, h3, h4, h5, h6 {
    font-family: 'DM Serif Display', serif;
    font-weight: 600;
    line-height: 1.2;
}

h1 { font-size: 2.125rem; }
h2 { font-size: 1.875rem; }
h3 { font-size: 1.5rem; }

p { color: var(--text-muted); font-size: 0.9375rem; }

/* ===== BUTTONS ===== */
.btn {
    padding: 0.625rem 1rem;
    border: none;
    border-radius: 0.5rem;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

.btn-primary { background: var(--navy); color: #ffffff; }
.btn-primary:hover { background: var(--navy-light); }

.btn-secondary {
    background: var(--surface2);
    color: var(--text);
    border: 1.5px solid var(--border);
}
.btn-secondary:hover { border-color: var(--gold); background: var(--surface); }

.btn-danger {
    background: rgba(192, 57, 43, 0.1);
    color: #c0392b;
    border: 1px solid rgba(192, 57, 43, 0.2);
}
.btn-danger:hover { background: rgba(192, 57, 43, 0.18); }

.btn-sm { padding: 0.5rem 1rem; font-size: 0.8125rem; }

/* ===== LOGIN PAGE ===== */
.login-page { min-height: 100vh; display: flex; align-items: stretch; }

.login-left {
    width: 52%;
    background: var(--navy);
    padding: 3.75rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}

.login-left::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    border: 1px solid rgba(201, 168, 76, 0.15);
    top: -200px;
    left: -200px;
}

.login-left::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    border: 1px solid rgba(201, 168, 76, 0.1);
    bottom: -100px;
    right: -100px;
}

.login-logo { display: flex; align-items: center; gap: 0.75rem; z-index: 1; }

.login-logo-icon {
    width: 44px;
    height: 44px;
    background: var(--gold);
    border-radius: 0.625rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--navy);
    font-family: 'DM Serif Display', serif;
}

.login-logo-text {
    font-family: 'DM Serif Display', serif;
    font-size: 1.375rem;
    color: #ffffff;
    font-weight: 600;
}

.login-hero { z-index: 1; }
.login-hero h1 { font-size: 3.25rem; color: #ffffff; line-height: 1.1; margin-bottom: 1.25rem; }
.login-hero h1 em { color: var(--gold); font-style: italic; }
.login-hero p { color: rgba(255, 255, 255, 0.6); font-size: 1rem; line-height: 1.7; max-width: 380px; }

.login-stats { display: flex; gap: 2.5rem; z-index: 1; }
.login-stat span { display: block; font-size: 1.75rem; font-family: 'DM Serif Display', serif; color: var(--gold); }
.login-stat small { color: rgba(255, 255, 255, 0.5); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.0625rem; }

.login-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3.75rem;
    background: var(--bg);
    position: relative;
}

.login-form-box { width: 100%; max-width: 400px; }
.login-form-box h2 { font-size: 2rem; color: var(--text); margin-bottom: 0.5rem; }
.login-form-box p { color: var(--text-muted); margin-bottom: 2.5rem; font-size: 0.875rem; }

.btn-cognito {
    width: 100%;
    padding: 0.9375rem;
    background: #0066CC;
    color: #ffffff;
    border: none;
    border-radius: 0.5rem;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    transition: all 0.3s ease;
    margin-bottom: 1.25rem;
    box-shadow: 0 4px 12px rgba(0, 102, 204, 0.3);
}
.btn-cognito:hover {
    background: #0052A3;
    box-shadow: 0 6px 16px rgba(0, 102, 204, 0.4);
    transform: translateY(-2px);
}

/* ===== PORTAL LAYOUT ===== */
.portal { display: none; }
.portal.active { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-w);
    background: var(--navy);
    min-height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.sidebar-logo {
    padding: 1.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.sidebar-logo-icon {
    width: 36px;
    height: 36px;
    background: var(--gold);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'DM Serif Display', serif;
    font-size: 1rem;
    font-weight: 700;
    color: var(--navy);
    flex-shrink: 0;
}

.sidebar-logo-text { font-family: 'DM Serif Display', serif; font-size: 1.125rem; color: #ffffff; font-weight: 600; }

.sidebar-nav { flex: 1; padding: 1.25rem 0.75rem; overflow-y: auto; }

.nav-section { margin-bottom: 1.75rem; }
.nav-section-label {
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.09375rem;
    color: rgba(255, 255, 255, 0.3);
    padding: 0 0.75rem;
    margin-bottom: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: 0.5rem;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.125rem;
    text-decoration: none;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #ffffff; }
.nav-item.active { background: rgba(201, 168, 76, 0.15); color: var(--gold-light); }

.nav-icon { width: 18px; text-align: center; font-size: 1rem; flex-shrink: 0; }

.sidebar-user {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--gold);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--navy);
    flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 0.8125rem; font-weight: 600; color: #ffffff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.6875rem; color: var(--gold); font-weight: 500; }

/* ===== MAIN CONTENT ===== */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; overflow-x: hidden; max-width: 100%; }

.topbar {
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    transition: background 0.25s ease, border-color 0.25s ease;
    box-shadow: var(--shadow-sm);
}

.topbar-title { font-family: 'DM Serif Display', serif; font-size: 1.25rem; color: var(--text); font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 0.625rem; }

.page-content { padding: 2rem; flex: 1; overflow-y: auto; overflow-x: hidden; max-width: 100%; }

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.75rem;
}
.page-header h1 { margin-bottom: 0.25rem; }
.page-header p { font-size: 0.875rem; color: var(--text-muted); }

/* ===== STATS GRID ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
    transition: all 0.25s ease;
    box-shadow: var(--shadow-sm);
}
.stat-card:hover { border-color: var(--gold); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gold);
}

.stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05rem; color: var(--text-muted); font-weight: 600; margin-bottom: 0.75rem; }
.stat-value { font-family: 'DM Serif Display', serif; font-size: 2.375rem; color: var(--text); line-height: 1; margin-bottom: 0.5rem; }
.stat-sub { font-size: 0.75rem; color: var(--text-muted); }
.stat-icon { position: absolute; top: 1.25rem; right: 1.25rem; font-size: 1.75rem; opacity: 0.12; }

/* ===== ZONE STAT CARDS — full colored background ===== */
.stat-card.zone-card {
    min-height: 200px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    text-decoration: none;
    box-shadow: 0 4px 16px rgba(0,0,0,0.18);
}
.stat-card.zone-card::before { display: none; }
.stat-card.zone-card:hover { transform: translateY(-3px); filter: brightness(1.08); border-color: transparent; }

.stat-card.zone-card.zone-FAILURE     { background: #7b0000; border-color: #7b0000; }
.stat-card.zone-card.zone-CRITICAL    { background: #c0392b; border-color: #c0392b; }
.stat-card.zone-card.zone-DEGRADATION { background: #e67e22; border-color: #e67e22; }
.stat-card.zone-card.zone-DRIFT       { background: #f1c40f; border-color: #e6b800; }
.stat-card.zone-card.zone-STABLE      { background: #2d7a4f; border-color: #2d7a4f; }

/* text on dark cards → white */
.stat-card.zone-card.zone-FAILURE     .zone-card-count,
.stat-card.zone-card.zone-FAILURE     .zone-card-label,
.stat-card.zone-card.zone-FAILURE     .zone-card-desc,
.stat-card.zone-card.zone-CRITICAL    .zone-card-count,
.stat-card.zone-card.zone-CRITICAL    .zone-card-label,
.stat-card.zone-card.zone-CRITICAL    .zone-card-desc,
.stat-card.zone-card.zone-DEGRADATION .zone-card-count,
.stat-card.zone-card.zone-DEGRADATION .zone-card-label,
.stat-card.zone-card.zone-DEGRADATION .zone-card-desc,
.stat-card.zone-card.zone-STABLE      .zone-card-count,
.stat-card.zone-card.zone-STABLE      .zone-card-label,
.stat-card.zone-card.zone-STABLE      .zone-card-desc { color: #ffffff; }

/* text on light yellow card → dark */
.stat-card.zone-card.zone-DRIFT .zone-card-count,
.stat-card.zone-card.zone-DRIFT .zone-card-label,
.stat-card.zone-card.zone-DRIFT .zone-card-desc { color: #0d1117; }

.zone-card-count {
    font-family: 'DM Serif Display', serif;
    font-size: 4rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.5rem;
}
.zone-card-count.muted { opacity: 0.55; }
.zone-card-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    margin-bottom: auto;
}
.zone-card-desc {
    font-size: 0.8125rem;
    margin-top: 1.25rem;
    opacity: 0.88;
    line-height: 1.4;
}

/* ===== RISK GRID (dashboard zone cards) ===== */
.risk-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 1.5rem;
    max-width: 100%;
}
.zone-risk-card {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-decoration: none;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    min-width: 0;
}
.zone-risk-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.zone-risk-card.zero-count { opacity: 0.55; }
.zone-label { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.zone-count { font-size: 3.5rem; font-weight: 300; line-height: 1; }
.zone-desc { font-size: 0.75rem; line-height: 1.6; }
@media (max-width: 900px) {
    .risk-grid { grid-template-columns: repeat(2, 1fr); gap: 10px !important; }
}

/* ===== CARD ===== */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    overflow: hidden;
    transition: all 0.25s ease;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
    max-width: 100%;
}
.card:hover { border-color: var(--gold); box-shadow: var(--shadow-md); }

.card-header {
    padding: 1.125rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.card-title { font-family: 'DM Serif Display', serif; font-size: 1.0625rem; color: var(--text); font-weight: 600; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

thead th {
    padding: 0.6875rem 1.5rem;
    text-align: left;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05rem;
    color: var(--text-muted);
    font-weight: 600;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
}

tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s ease; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--hover-row); }

td { padding: 0.875rem 1.5rem; font-size: 0.875rem; color: var(--text); }

/* ===== BADGES ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.1875rem 0.625rem;
    border-radius: 20px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02rem;
}
.badge.active { background: rgba(46, 125, 94, 0.15); color: #2e7d5e; }
.badge.inactive { background: rgba(100, 116, 139, 0.1); color: var(--text-muted); }

/* ===== ZONE BADGES ===== */
.zone-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.03rem;
}
.zone-FAILURE     { background: #7b0000; color: #fff; }
.zone-CRITICAL    { background: #c0392b; color: #fff; }
.zone-DEGRADATION { background: #e67e22; color: #fff; }
.zone-DRIFT       { background: #f1c40f; color: #1a1a1a; }
.zone-STABLE      { background: #2d7a4f; color: #fff; }
.zone-UNKNOWN { background: rgba(100, 116, 139, 0.15); color: var(--text-muted); }

/* ===== ERI SCORE ===== */
.eri-score { font-family: 'DM Serif Display', serif; font-size: 3.5rem; line-height: 1; }
.eri-FAILURE     { color: #7b0000; }
.eri-CRITICAL    { color: #c0392b; }
.eri-DEGRADATION { color: #e67e22; }
.eri-DRIFT       { color: #b38a00; }
.eri-STABLE      { color: #2d7a4f; }
.eri-UNKNOWN { color: var(--text-muted); }

/* ===== COMPONENT SCORES ===== */
.components-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.component-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.component-label { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.05rem; color: var(--text-muted); font-weight: 600; margin-bottom: 0.5rem; }
.component-value { font-family: 'DM Serif Display', serif; font-size: 2rem; color: var(--text); }

/* ===== INFO BLOCK ===== */
.info-block {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}
.info-block h3 { font-size: 1rem; color: var(--text); margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border); }

.info-row { display: flex; justify-content: space-between; margin-bottom: 0.75rem; font-size: 0.8125rem; }
.info-row span:first-child { color: var(--text-muted); }
.info-row span:last-child { color: var(--text); font-weight: 500; }

/* ===== GRAFANA PANEL ===== */
.grafana-panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.75rem;
    margin-bottom: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
}
.grafana-logo { font-size: 2.5rem; margin-bottom: 0.75rem; }
.grafana-panel h3 { font-size: 1.25rem; color: var(--text); margin-bottom: 0.5rem; }
.grafana-panel p { font-size: 0.8125rem; color: var(--text-muted); margin-bottom: 1.25rem; }

/* ===== ID CHIP ===== */
.id-chip {
    font-size: 0.6875rem;
    font-family: 'Courier New', monospace;
    color: var(--text-muted);
    background: var(--surface2);
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    border: 1px solid var(--border);
    display: inline-block;
}

/* ===== NOTIFICATION ===== */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--navy);
    color: #ffffff;
    padding: 0.875rem 1.25rem;
    border-radius: 0.625rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    z-index: 1000;
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    max-width: 320px;
    border-left: 4px solid var(--gold);
    box-shadow: var(--shadow-lg);
}
.notification.show { transform: translateX(0); opacity: 1; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .components-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .page-content { padding: 1rem; }
    .stats-grid { grid-template-columns: 1fr; }
    .login-page { flex-direction: column; }
    .login-left { width: 100%; padding: 1.75rem 1.5rem 1.5rem; min-height: auto; display: flex; flex-direction: column; }
    .login-logo { display: block; margin-bottom: 16px !important; }
    .login-right { padding: 2rem 1.25rem; }
    .login-stats { display: none; }
    .login-logo svg { display: block; max-width: 100%; height: auto; }
    .login-hero h1 { font-size: 1.875rem; margin-bottom: 0.875rem; line-height: 1.15; }
    .login-hero p { display: none; }
    .topbar { flex-wrap: wrap; padding: 0 1rem; }
}

@media (max-width: 640px) {
    .page-header { flex-direction: column; gap: 1rem; }
    .card-header { flex-direction: column; align-items: flex-start; }
    table { font-size: 0.75rem; }
    td, th { padding: 0.5rem 0.75rem; }
    .login-stats { justify-content: space-between; gap: 0; }
    .login-stat span { font-size: 1.375rem; }
    .login-stat small { font-size: 0.6875rem; letter-spacing: 0.04em; }
    .components-grid { grid-template-columns: 1fr 1fr; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--surface2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== PRINT ===== */
@media print {
    .sidebar, .topbar, .btn { display: none; }
    .main { margin-left: 0; }
    .card, .stat-card { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; }
}

/* ===== TRIAGE ROW ZONE COLORS ===== */
tbody tr.row-FAILURE     { background: rgba(123,0,0,0.07); }
tbody tr.row-CRITICAL    { background: rgba(192,57,43,0.06); }
tbody tr.row-DEGRADATION { background: rgba(230,126,34,0.06); }
tbody tr.row-DRIFT       { background: rgba(241,196,15,0.05); }
tbody tr.row-STABLE      { background: rgba(45,122,79,0.04); }
tbody tr.row-FAILURE:hover     { background: rgba(123,0,0,0.14); }
tbody tr.row-CRITICAL:hover    { background: rgba(192,57,43,0.13); }
tbody tr.row-DEGRADATION:hover { background: rgba(230,126,34,0.13); }
tbody tr.row-DRIFT:hover       { background: rgba(241,196,15,0.11); }
tbody tr.row-STABLE:hover      { background: rgba(45,122,79,0.09); }

/* ===== FILTER BAR ===== */
.filter-bar { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-bottom: 1.25rem; }
.filter-select {
    padding: 0.5rem 0.75rem; border: 1.5px solid var(--border); border-radius: 0.5rem;
    font-family: 'DM Sans', sans-serif; font-size: 0.875rem;
    background: var(--input-bg); color: var(--text);
    outline: none; transition: border-color 0.2s ease; cursor: pointer;
}
.filter-select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,151,44,0.1); }

/* ===== TREND INDICATORS ===== */
.trend-up     { color: #c0392b; font-weight: 700; }
.trend-down   { color: #2d7a4f; font-weight: 700; }
.trend-stable { color: var(--text-muted); }

/* ===== STAT CARD ZONE VARIANTS (non-dashboard use — top border only) ===== */
.stat-card:not(.zone-card).zone-FAILURE::before     { background: #7b0000; }
.stat-card:not(.zone-card).zone-CRITICAL::before    { background: #c0392b; }
.stat-card:not(.zone-card).zone-DEGRADATION::before { background: #e67e22; }
.stat-card:not(.zone-card).zone-DRIFT::before       { background: #f1c40f; }
.stat-card:not(.zone-card).zone-STABLE::before      { background: #2d7a4f; }

/* ===== ERI INLINE (table cells) ===== */
.eri-inline { font-family: 'DM Serif Display', serif; font-size: 1.125rem; font-weight: 700; }
.eri-inline.eri-FAILURE     { color: #7b0000; }
.eri-inline.eri-CRITICAL    { color: #c0392b; }
.eri-inline.eri-DEGRADATION { color: #e67e22; }
.eri-inline.eri-DRIFT       { color: #b38a00; }
.eri-inline.eri-STABLE      { color: #2d7a4f; }
.eri-inline.eri-UNKNOWN { color: var(--text-muted); }

@media (max-width: 768px) {
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-select { width: 100%; }
}

/* ===== FLAG FEATURE ===== */

/* Priority colours */
:root {
    --flag-high:        #c0392b;
    --flag-high-bg:     rgba(192,57,43,0.09);
    --flag-high-border: rgba(192,57,43,0.3);
    --flag-med:         #e67e22;
    --flag-med-bg:      rgba(230,126,34,0.09);
    --flag-med-border:  rgba(230,126,34,0.3);
    --flag-low:         #f39c12;
    --flag-low-bg:      rgba(243,156,18,0.08);
    --flag-low-border:  rgba(243,156,18,0.3);
}

/* ── Flag badge (table cells) ── */
.flag-badge {
    display: inline-flex; align-items: center; gap: 0.25rem;
    font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.03em;
    padding: 0.1875rem 0.5rem; border-radius: 0.375rem;
    white-space: nowrap; user-select: none;
}
.flag-badge.priority-HIGH   { background: var(--flag-high-bg);  color: var(--flag-high);  border: 1px solid var(--flag-high-border); }
.flag-badge.priority-MEDIUM { background: var(--flag-med-bg);   color: var(--flag-med);   border: 1px solid var(--flag-med-border);  }
.flag-badge.priority-LOW    { background: var(--flag-low-bg);   color: var(--flag-low);   border: 1px solid var(--flag-low-border);  }

/* ── Flag banner (detail page) ── */
.flag-banner {
    border-radius: 0.625rem;
    padding: 1.125rem 1.375rem;
    border: 1.5px solid;
    animation: flagBannerIn 0.3s ease;
}
.flag-banner.priority-HIGH   { background: var(--flag-high-bg);  border-color: var(--flag-high-border);  color: var(--flag-high);  }
.flag-banner.priority-MEDIUM { background: var(--flag-med-bg);   border-color: var(--flag-med-border);   color: var(--flag-med);   }
.flag-banner.priority-LOW    { background: var(--flag-low-bg);   border-color: var(--flag-low-border);   color: var(--flag-low);   }

@keyframes flagBannerIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0);    }
}

/* ── Priority pill inside banner ── */
.flag-priority-pill {
    display: inline-flex; align-items: center; gap: 0.25rem;
    font-size: 0.75rem; font-weight: 700; letter-spacing: 0.03em;
    padding: 0.25rem 0.625rem; border-radius: 999px; border: 1.5px solid;
}
.flag-priority-pill.priority-HIGH   { background: var(--flag-high-bg);  color: var(--flag-high);  border-color: var(--flag-high-border);  }
.flag-priority-pill.priority-MEDIUM { background: var(--flag-med-bg);   color: var(--flag-med);   border-color: var(--flag-med-border);   }
.flag-priority-pill.priority-LOW    { background: var(--flag-low-bg);   color: var(--flag-low);   border-color: var(--flag-low-border);   }

/* ── Modal overlay ── */
.flag-modal-overlay {
    position: fixed; inset: 0; z-index: 3000;
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(3px);
    animation: overlayFadeIn 0.2s ease;
}
@keyframes overlayFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Modal card ── */
.flag-modal {
    position: relative;
    background: var(--surface);
    border-radius: 1rem;
    width: min(520px, 94vw);
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 24px 64px rgba(0,0,0,0.28), 0 4px 12px rgba(0,0,0,0.12);
    animation: modalSlideIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid var(--border);
}
@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

.flag-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1.375rem 1.5rem 1.125rem;
    border-bottom: 1px solid var(--border);
}
.flag-modal-icon {
    width: 40px; height: 40px; border-radius: 0.5rem;
    background: rgba(192,57,43,0.1);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.125rem; flex-shrink: 0;
}
.flag-modal-close {
    background: none; border: none; cursor: pointer;
    font-size: 1.375rem; line-height: 1; color: var(--text-muted);
    padding: 0.125rem 0.25rem; border-radius: 0.25rem;
    transition: color 0.15s, background 0.15s;
}
.flag-modal-close:hover { color: var(--text); background: var(--surface2); }

.flag-modal-body  { padding: 1.375rem 1.5rem; display: flex; flex-direction: column; gap: 1.125rem; }
.flag-modal-footer {
    padding: 1rem 1.5rem 1.375rem;
    border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 0.75rem;
}

/* ── Flag form fields ── */
.flag-form-field { display: flex; flex-direction: column; gap: 0.375rem; }
.flag-form-label { font-size: 0.8125rem; font-weight: 600; color: var(--text); }
.flag-form-select, .flag-form-textarea {
    width: 100%; padding: 0.5625rem 0.75rem;
    border: 1.5px solid var(--border); border-radius: 0.5rem;
    font-family: 'DM Sans', sans-serif; font-size: 0.875rem;
    background: var(--input-bg); color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}
.flag-form-select:focus, .flag-form-textarea:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201,151,44,0.12);
}
.flag-form-textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

/* ── Priority radio options ── */
.flag-priority-options { display: flex; gap: 0.75rem; }
.flag-priority-opt {
    flex: 1; cursor: pointer;
    border: 1.5px solid var(--border); border-radius: 0.5rem;
    padding: 0.625rem; text-align: center;
    transition: border-color 0.2s, background 0.2s;
    user-select: none;
}
.flag-priority-opt input[type="radio"] { display: none; }
.flag-priority-opt:hover { border-color: var(--gold); background: var(--surface2); }
.flag-priority-opt.selected[data-priority="HIGH"]   { border-color: var(--flag-high);  background: var(--flag-high-bg);  }
.flag-priority-opt.selected[data-priority="MEDIUM"] { border-color: var(--flag-med);   background: var(--flag-med-bg);   }
.flag-priority-opt.selected[data-priority="LOW"]    { border-color: var(--flag-low);   background: var(--flag-low-bg);   }
.flag-priority-label { font-size: 0.8125rem; font-weight: 600; }
.flag-priority-label.high   { color: var(--flag-high); }
.flag-priority-label.medium { color: var(--flag-med);  }
.flag-priority-label.low    { color: var(--flag-low);  }

/* ── Modal error ── */
.flag-modal-error {
    background: rgba(192,57,43,0.08); border: 1px solid rgba(192,57,43,0.25);
    color: #c0392b; border-radius: 0.5rem; padding: 0.625rem 0.875rem;
    font-size: 0.8125rem; line-height: 1.5;
}
@keyframes flagErrorShake {
    0%, 100% { transform: translateX(0); }
    20%       { transform: translateX(-5px); }
    40%       { transform: translateX(5px); }
    60%       { transform: translateX(-3px); }
    80%       { transform: translateX(3px); }
}
.flag-error-shake { animation: flagErrorShake 0.45s ease; }

/* ── Loading spinner inside button ── */
.flag-spinner {
    display: inline-block; width: 13px; height: 13px;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: flagSpin 0.7s linear infinite;
    vertical-align: middle;
}
@keyframes flagSpin {
    to { transform: rotate(360deg); }
}

/* ── Toast notification ── */
.flag-toast {
    position: fixed; bottom: 1.5rem; right: 1.5rem;
    z-index: 4000;
    background: var(--navy); color: #fff;
    padding: 0.75rem 1.25rem; border-radius: 0.625rem;
    font-size: 0.875rem; font-weight: 500;
    border-left: 4px solid var(--gold);
    box-shadow: var(--shadow-lg);
    transform: translateY(120%); opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
    max-width: 340px;
    pointer-events: none;
}
.flag-toast.show { transform: translateY(0); opacity: 1; }
.flag-toast.flag-toast-error { border-left-color: #c0392b; background: #2d0a0a; }

/* ── Analytics dashboard section ── */
.analytics-section {
    margin: 1.5rem 0;
    padding: 1.25rem 1.5rem;
    background: rgba(201, 151, 44, 0.08);
    border: 1px solid rgba(201, 151, 44, 0.3);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}
.btn-analytics {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    background: #c9972c;
    color: #0d1117;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 6px;
    text-decoration: none;
    transition: background 0.2s ease;
    white-space: nowrap;
}
.btn-analytics:hover { background: #e0aa38; color: #0d1117; }
.analytics-note {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.4;
}

/* ===== HAMBURGER & MOBILE DRAWER ===== */
/* Breakpoints: mobile ≤600px | tablet 601-900px | desktop >900px */

.hamburger-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 5px;
    z-index: 1001;
    flex-shrink: 0;
}

.hamburger-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ── Triage priority queue rows ─────────────────────────────── */
.triage-card {
    gap: 12px !important;
    padding: 12px 16px !important;
    flex-wrap: nowrap !important;
    overflow: hidden !important;
}
.triage-card .list-card-col-primary {
    flex: 1 !important;
    min-width: 0;
    overflow: hidden;
}
.triage-card .list-card-col-primary .item-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
}
.triage-card .list-card-col:not(.list-card-col-hide):not(.triage-col-eri-zone):not(.triage-col-arrow) {
    flex: 0 0 auto;
    white-space: nowrap;
}
.triage-col-eri-zone {
    flex: 0 0 auto !important;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    min-width: 0;
}
.triage-col-eri-zone .eri-inline {
    flex-shrink: 0;
    font-weight: 700;
    white-space: nowrap;
    min-width: 44px;
    text-align: right;
}
.triage-col-eri-zone .zone-badge {
    flex-shrink: 0;
    white-space: nowrap;
}
.triage-col-arrow {
    flex: 0 0 28px !important;
    text-align: right;
    min-width: 0;
}
@media (max-width: 600px) {
    .triage-card {
        padding: 10px 12px !important;
    }
}

@media (max-width: 900px) {
    /* Show hamburger */
    .hamburger-btn {
        display: flex;
    }

    /* Sidebar becomes a slide-in drawer */
    .sidebar {
        width: 280px !important;
        height: 100vh !important;
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        z-index: 1000 !important;
        transform: translateX(-280px);
        transition: transform 0.25s ease;
        box-shadow: none;
    }

    .sidebar.sidebar-open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    /* Main content full width */
    .main {
        margin-left: 0 !important;
        width: 100%;
    }

    /* Topbar */
    .topbar {
        padding: 0 1rem !important;
        height: auto !important;
        min-height: 64px;
    }

    .portal.active {
        overflow: hidden;
    }

    .page-content {
        padding: 16px !important;
        width: 100%;
    }

    /* ERI stat cards: 5-col → 2-col at tablet */
    .eri-stat-cards {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    /* Exec list: hide non-primary, non-actions columns */
    .exec-card .list-card-col:not(.list-card-col-hide) {
        display: none;
    }
}

@media (max-width: 600px) {
    body {
        overflow-x: hidden;
    }

    .page-content {
        padding: 16px !important;
    }

    .topbar-actions {
        gap: 0.375rem;
        flex-wrap: wrap;
    }

    /* Page header stacks */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    /* Dashboard zone cards: 1 column */
    .stats-grid {
        grid-template-columns: 1fr !important;
    }

    /* Zone risk grid: 1 column */
    .risk-grid {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    /* Components grid: 2 columns */
    .components-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Form panel full width */
    .form-panel {
        max-width: 100% !important;
    }

    /* Card header stacks */
    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    /* Tabs: equal split */
    .tabs {
        gap: 0;
    }

    .tab {
        flex: 1;
        text-align: center;
        padding: 0.625rem 0.5rem;
    }

    /* Search input full width */
    .search-input {
        width: 100% !important;
    }

    /* Filter bar stacks */
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-select {
        width: 100%;
    }

    /* Tables: allow horizontal scroll */
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Touch targets: 44px min height */
    .btn {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 44px;
    }

    /* Typography scaling */
    h1 { font-size: 22px !important; }
    h2 { font-size: 18px !important; }
    .item-title { font-size: 13px; }
    .eri-score { font-size: 36px; }

    /* ERI stat cards (exec detail — 5-col → 1-col on mobile) */
    .eri-stat-cards {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    /* Source connectivity strip (exec detail) */
    .source-connect-grid {
        grid-template-columns: 1fr !important;
    }

    /* ERI score card columns (exec detail) */
    .eri-score-card-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ===== PROGRESS BAR ===== */
#progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  opacity: 0;
  z-index: 9999;
  pointer-events: none;
  background: var(--gold);
  transition: width 0.3s ease, opacity 0.4s ease;
}
#progress-bar.loading {
  opacity: 1;
  width: 85%;
}
#progress-bar.done {
  width: 100%;
  opacity: 0;
  transition: width 0.1s ease, opacity 0.5s ease 0.1s;
}

/* ===== BUTTON LOADING STATE ===== */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.btn-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(26, 26, 46, 0.55);
  animation: pulse-dot 1s ease-in-out infinite;
}
.btn-dots span:nth-child(2) { animation-delay: 0.15s; }
.btn-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse-dot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%            { transform: scale(1);   opacity: 1;   }
}

/* ===== SKELETON SCREEN ===== */
.skeleton {
  background: #e0e0e0;
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255,255,255,0.5) 50%,
    transparent 100%
  );
  animation: shimmer 1.4s infinite;
  transform: translateX(-100%);
}
@keyframes shimmer {
  100% { transform: translateX(100%); }
}
.skeleton-card {
  height: 120px;
  margin-bottom: 16px;
}
.skeleton-row {
  height: 16px;
  margin-bottom: 10px;
  width: 100%;
}
.skeleton-row.short { width: 60%; }
