/* ─── RESET & BASE ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:         #0f1117;
    --bg2:        #1a1d27;
    --bg3:        #222538;
    --border:     #2e3250;
    --accent:     #6c63ff;
    --accent2:    #00d4aa;
    --warn:       #f59e0b;
    --danger:     #ef4444;
    --success:    #22c55e;
    --text:       #e2e8f0;
    --text2:      #94a3b8;
    --text3:      #64748b;
    --sidebar-w:  240px;
    --topbar-h:   58px;
    --nav-h:      60px;
}

body {
    background: var(--bg); color: var(--text);
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 14px; overflow: hidden; height: 100vh;
}

/* ─── LAYOUT ─────────────────────────────────────────────────────────────────*/
.app { display: flex; height: 100vh; overflow: hidden; }

/* ─── SIDEBAR (desktop) ──────────────────────────────────────────────────────*/
.sidebar {
    width: var(--sidebar-w); min-width: var(--sidebar-w);
    background: var(--bg2); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; overflow-y: auto;
    transition: transform 0.25s ease; z-index: 200;
    flex-shrink: 0;
}

.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.6); z-index: 190;
}

.sidebar-logo {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.sidebar-logo-left .brand { font-size: 16px; font-weight: 700; }
.sidebar-logo-left .sub { font-size: 11px; color: var(--text3); margin-top: 2px; }
.sidebar-logo-left .badge {
    display: inline-block; background: var(--accent); color: white;
    font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 3px;
    margin-top: 6px; letter-spacing: 0.5px;
}
.sidebar-close {
    display: none; background: none; border: none; color: var(--text3);
    font-size: 20px; cursor: pointer; padding: 4px;
}

.sidebar-section { padding: 12px 8px 4px; }
.sidebar-section-label {
    font-size: 10px; font-weight: 600; color: var(--text3);
    letter-spacing: 1px; text-transform: uppercase; padding: 0 8px 6px;
}

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: 8px; cursor: pointer;
    color: var(--text2); font-size: 13px; transition: all 0.15s;
    margin-bottom: 2px; position: relative;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent); color: white; }
.nav-item .icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
.nav-item .badge-dot {
    width: 6px; height: 6px; border-radius: 50%; background: var(--danger);
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
}
.nav-item.dynamic { border-left: 2px solid var(--accent2); padding-left: 10px; }

/* ─── MAIN ───────────────────────────────────────────────────────────────────*/
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* ─── TOP BAR ────────────────────────────────────────────────────────────────*/
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px; height: var(--topbar-h);
    border-bottom: 1px solid var(--border); background: var(--bg2);
    flex-shrink: 0; gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.hamburger {
    display: none; background: none; border: none;
    color: var(--text2); font-size: 20px; cursor: pointer;
    padding: 6px; border-radius: 6px; flex-shrink: 0;
}
.hamburger:hover { background: var(--bg3); color: var(--text); }
.topbar-titles { min-width: 0; }
.topbar-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-meta { font-size: 11px; color: var(--text3); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.branch-selector {
    background: var(--bg3); border: 1px solid var(--border);
    color: var(--text); border-radius: 6px; padding: 6px 8px; font-size: 12px; cursor: pointer;
    max-width: 130px;
}
.alert-bell {
    background: var(--bg3); border: 1px solid var(--border);
    border-radius: 6px; padding: 6px 10px; cursor: pointer;
    position: relative; font-size: 15px; flex-shrink: 0;
}
.alert-bell .count {
    position: absolute; top: -4px; right: -4px;
    background: var(--danger); color: white; font-size: 9px; font-weight: 700;
    border-radius: 50%; width: 16px; height: 16px;
    display: flex; align-items: center; justify-content: center;
}

/* ─── CONTENT ────────────────────────────────────────────────────────────────*/
.content {
    flex: 1; overflow-y: auto;
    padding: 16px;
    /* bottom padding for mobile nav bar */
    padding-bottom: calc(var(--nav-h) + 16px);
}

/* ─── STAT CARDS ─────────────────────────────────────────────────────────────*/
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px; margin-bottom: 16px;
}
.stat-card {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 10px; padding: 14px;
}
.stat-label { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 22px; font-weight: 700; margin: 5px 0 3px; }
.stat-change { font-size: 11px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }
.stat-change.warn { color: var(--warn); }
.stat-systems { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; }
.sys-badge {
    font-size: 9px; font-weight: 600; padding: 2px 5px; border-radius: 3px;
    background: var(--bg3); color: var(--text3); border: 1px solid var(--border);
}

/* ─── CHART CARDS ────────────────────────────────────────────────────────────*/
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.chart-grid.full { grid-template-columns: 1fr; }
.chart-wrap { position: relative; height: 200px; }
.chart-card {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 10px; padding: 14px;
}
.chart-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.chart-title { font-size: 12px; font-weight: 600; }
.chart-subtitle { font-size: 11px; color: var(--text3); margin-top: 2px; }
.chart-badge { font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.chart-badge.warn { background: rgba(245,158,11,0.15); color: var(--warn); border: 1px solid rgba(245,158,11,0.3); }
.chart-badge.ok { background: rgba(34,197,94,0.15); color: var(--success); border: 1px solid rgba(34,197,94,0.3); }
.chart-badge.info { background: rgba(108,99,255,0.15); color: var(--accent); border: 1px solid rgba(108,99,255,0.3); }

/* ─── INSIGHTS ───────────────────────────────────────────────────────────────*/
.insight-list { display: flex; flex-direction: column; gap: 10px; }
.insight-card {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 10px; padding: 12px 14px;
    display: flex; gap: 12px; align-items: flex-start;
    cursor: pointer; transition: border-color 0.15s;
}
.insight-card:hover { border-color: var(--accent); }
.insight-card.critical { border-left: 3px solid var(--danger); }
.insight-card.warning { border-left: 3px solid var(--warn); }
.insight-card.opportunity { border-left: 3px solid var(--accent2); }
.insight-icon { font-size: 18px; }
.insight-body { flex: 1; min-width: 0; }
.insight-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.insight-text { font-size: 12px; color: var(--text2); line-height: 1.5; }
.insight-meta { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.insight-tag { font-size: 10px; padding: 2px 6px; border-radius: 3px; }
.insight-tag.systems { background: var(--bg3); color: var(--text3); }
.insight-tag.variance { background: rgba(245,158,11,0.1); color: var(--warn); }
.insight-tag.saving { background: rgba(34,197,94,0.1); color: var(--success); }
.insight-right { text-align: right; min-width: 70px; flex-shrink: 0; }
.insight-variance { font-size: 16px; font-weight: 700; }
.insight-variance.up { color: var(--danger); }
.insight-variance.down { color: var(--warn); }
.insight-variance.opp { color: var(--accent2); }
.add-alert-btn { font-size: 11px; color: var(--accent); cursor: pointer; margin-top: 4px; display: inline-block; }
.add-alert-btn:hover { text-decoration: underline; }

/* ─── ALERTS ─────────────────────────────────────────────────────────────────*/
.alerts-grid { display: grid; gap: 10px; }
.alert-row {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 10px; padding: 12px 14px;
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.alert-row.triggered { border-left: 3px solid var(--danger); }
.alert-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.alert-dot.active.triggered { background: var(--danger); }
.alert-dot.active { background: var(--success); }
.alert-dot.inactive { background: var(--text3); }
.alert-info { flex: 1; min-width: 0; }
.alert-name { font-weight: 600; font-size: 13px; }
.alert-condition { font-size: 12px; color: var(--text2); margin-top: 2px; }
.alert-channel { font-size: 11px; color: var(--accent); }
.alert-status { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 4px; white-space: nowrap; }
.alert-status.triggered { background: rgba(239,68,68,0.15); color: var(--danger); }
.alert-status.ok { background: rgba(34,197,94,0.15); color: var(--success); }
.alert-status.inactive { background: var(--bg3); color: var(--text3); }

.add-alert-form {
    background: var(--bg2); border: 1px dashed var(--border);
    border-radius: 10px; padding: 14px; margin-top: 12px;
}
.form-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.form-input, .form-select {
    background: var(--bg3); border: 1px solid var(--border);
    color: var(--text); border-radius: 6px; padding: 8px 10px;
    font-size: 13px; flex: 1; min-width: 120px;
}
.btn { padding: 8px 14px; border-radius: 6px; border: none; font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.15s; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { opacity: 0.85; }
.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn-success { background: var(--accent2); color: var(--bg); }
.btn-outline { background: transparent; color: var(--text2); border: 1px solid var(--border); }

/* ─── TABLE ──────────────────────────────────────────────────────────────────*/
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; min-width: 500px; }
.data-table th { font-size: 10px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.5px; padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 12px; }
.data-table tr:hover td { background: var(--bg3); }
.margin-bar { height: 4px; border-radius: 2px; background: var(--accent); display: inline-block; }

/* ─── CHATBOT ────────────────────────────────────────────────────────────────*/
.chat-container {
    position: fixed; bottom: 80px; right: 16px; z-index: 300;
}
.chat-toggle {
    width: 50px; height: 50px; border-radius: 50%;
    background: var(--accent); border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; color: white; box-shadow: 0 4px 20px rgba(108,99,255,0.4);
    transition: transform 0.2s;
}
.chat-toggle:hover { transform: scale(1.05); }
.chat-panel {
    display: none; position: absolute; bottom: 62px; right: 0;
    width: min(360px, calc(100vw - 32px));
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 14px; box-shadow: 0 8px 40px rgba(0,0,0,0.4);
    overflow: hidden; flex-direction: column;
}
.chat-panel.open { display: flex; }
.chat-header {
    padding: 12px 14px; background: var(--bg3); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.chat-header-icon { font-size: 16px; }
.chat-header-info .title { font-weight: 600; font-size: 13px; }
.chat-header-info .sub { font-size: 10px; color: var(--accent2); }
.chat-messages {
    flex: 1; overflow-y: auto; padding: 12px;
    display: flex; flex-direction: column; gap: 8px; max-height: 300px;
}
.msg { max-width: 85%; }
.msg.user { align-self: flex-end; }
.msg.ai { align-self: flex-start; }
.msg-bubble { padding: 8px 12px; border-radius: 10px; font-size: 13px; line-height: 1.5; }
.msg.user .msg-bubble { background: var(--accent); color: white; border-radius: 10px 10px 2px 10px; }
.msg.ai .msg-bubble { background: var(--bg3); color: var(--text); border-radius: 10px 10px 10px 2px; }
.msg-time { font-size: 10px; color: var(--text3); margin-top: 2px; padding: 0 4px; }
.msg.user .msg-time { text-align: right; }
.chat-suggestions { padding: 8px 12px; display: flex; gap: 6px; overflow-x: auto; border-top: 1px solid var(--border); -webkit-overflow-scrolling: touch; }
.suggestion-chip {
    font-size: 11px; padding: 4px 8px; border-radius: 20px; white-space: nowrap;
    background: var(--bg3); border: 1px solid var(--border);
    color: var(--text2); cursor: pointer; transition: all 0.15s; flex-shrink: 0;
}
.suggestion-chip:hover { border-color: var(--accent); color: var(--accent); }
.chat-input-row { padding: 10px 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.chat-input {
    flex: 1; background: var(--bg3); border: 1px solid var(--border);
    color: var(--text); border-radius: 8px; padding: 8px 10px;
    font-size: 13px; resize: none; outline: none; font-family: inherit;
}
.chat-input:focus { border-color: var(--accent); }
.chat-send { background: var(--accent); border: none; color: white; border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 16px; }

/* ─── BOTTOM NAV (mobile) ────────────────────────────────────────────────────*/
.bottom-nav {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--nav-h); background: var(--bg2);
    border-top: 1px solid var(--border);
    z-index: 150;
    justify-content: space-around; align-items: center;
    padding: 0 4px;
}
.bottom-nav-item {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 10px; border-radius: 8px; cursor: pointer;
    color: var(--text3); font-size: 10px; flex: 1; transition: all 0.15s;
    position: relative;
}
.bottom-nav-item .icon { font-size: 18px; }
.bottom-nav-item.active { color: var(--accent); }
.bottom-nav-item .badge-dot {
    position: absolute; top: 4px; right: 12px;
    width: 6px; height: 6px; border-radius: 50%; background: var(--danger);
}

/* ─── TYPING ─────────────────────────────────────────────────────────────────*/
.typing { display: flex; gap: 4px; align-items: center; padding: 4px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text3); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100% { opacity: 0.2; } 40% { opacity: 1; } }

/* ─── SCROLLBAR ──────────────────────────────────────────────────────────────*/
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ─── MISC ───────────────────────────────────────────────────────────────────*/
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-title { font-size: 13px; font-weight: 600; }
.section-sub { font-size: 11px; color: var(--text3); margin-top: 2px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.page-header { margin-bottom: 16px; }
.page-header h2 { font-size: 17px; font-weight: 700; }
.page-header p { font-size: 12px; color: var(--text2); margin-top: 3px; }
.highlight-box {
    background: rgba(108,99,255,0.1); border: 1px solid rgba(108,99,255,0.3);
    border-radius: 8px; padding: 10px 14px; margin-bottom: 14px;
    font-size: 12px; line-height: 1.6;
}
.generated-badge {
    display: inline-flex; align-items: center;
    font-size: 10px; padding: 2px 6px; border-radius: 4px;
    background: rgba(0,212,170,0.15); color: var(--accent2);
    border: 1px solid rgba(0,212,170,0.3); margin-left: 6px;
}

/* ─── RESPONSIVE ─────────────────────────────────────────────────────────────*/
@media (max-width: 768px) {
    body { overflow: auto; }
    .app { overflow: hidden; }

    /* Sidebar slides in as drawer */
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0;
        transform: translateX(-100%);
        z-index: 200; box-shadow: 4px 0 20px rgba(0,0,0,0.4);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
    .sidebar-close { display: block; }
    .hamburger { display: flex; align-items: center; justify-content: center; }

    /* Hide desktop topbar meta on small screens */
    .topbar-meta { display: none; }
    .topbar { padding: 0 12px; }

    /* Content fills full width, bottom padding for nav */
    .content { padding: 12px 12px calc(var(--nav-h) + 12px); }

    /* Stat cards: 2 columns */
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-value { font-size: 18px; }

    /* Charts: 1 column */
    .chart-grid { grid-template-columns: 1fr; }
    .chart-wrap { height: 180px; }

    /* Insights: hide right variance on very small screens */
    .insight-right { display: none; }

    /* Chat panel full width on mobile */
    .chat-container { bottom: calc(var(--nav-h) + 8px); right: 12px; }

    /* Bottom nav visible */
    .bottom-nav { display: flex; }
}

@media (max-width: 420px) {
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 10px 12px; }
    .stat-value { font-size: 16px; }
    .stat-label { font-size: 9px; }
    .chart-wrap { height: 160px; }
    .branch-selector { display: none; }
    .page-header h2 { font-size: 15px; }
}
