:root {
    --bg: #f7f7f5;
    --surface: #ffffff;
    --border: #ebebea;
    --text: #37352f;
    --muted: #787774;
    --accent: #2383e2;
    --accent-soft: rgba(35, 131, 226, 0.12);
    --danger: #eb5757;
    --sidebar-width: 220px;
    --radius: 4px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #191919;
        --surface: #202020;
        --border: #2f2f2f;
        --text: #e3e2e0;
        --muted: #9b9a97;
        --accent-soft: rgba(35, 131, 226, 0.18);
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.45;
    background: var(--bg);
    color: var(--text);
}

a { color: inherit; text-decoration: none; }

button, .btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 6px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}

button.secondary {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}

button.ghost {
    background: transparent;
    color: var(--muted);
    padding: 4px 8px;
}

button.ghost:hover { background: var(--bg); color: var(--text); }

input, select, textarea {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
}

.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 10px 8px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.sidebar-brand .logo {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    background: var(--text);
    color: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
}

.sidebar-meta {
    padding: 0 8px 6px;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.org-switcher {
    width: calc(100% - 16px);
    margin: 0 8px 6px;
    padding: 4px 6px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
}

.page-meta {
    margin: -6px 0 12px;
    font-size: 12px;
    color: var(--muted);
}

.card-text {
    margin: 6px 0 0;
    font-size: 13px;
    color: var(--muted);
}

.sidebar-section {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 10px 8px 4px;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}

.nav-item:hover { background: var(--bg); }

.nav-item.active {
    background: var(--accent-soft);
    color: var(--text);
    font-weight: 500;
}

.nav-item .icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--muted);
}

.nav-item.active .icon { color: var(--accent); }

.sidebar-spacer { flex: 1; min-height: 12px; }

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding-top: 8px;
    margin-top: 4px;
}

.user-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    font-size: 12px;
    color: var(--muted);
}

.user-avatar {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    color: var(--text);
    flex-shrink: 0;
}

.user-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.main { flex: 1; min-width: 0; }

.content {
    padding: 20px 28px 28px;
    max-width: 1100px;
}

.page-title {
    margin: 0 0 12px;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 10px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 10px;
}

.kpi {
    padding: 10px 12px;
    margin-bottom: 0;
}

.kpi .value {
    font-size: 20px;
    font-weight: 600;
    line-height: 1.2;
}

.kpi .label {
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 2px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th, td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--muted);
    font-weight: 500;
    font-size: 12px;
}

.toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar input { flex: 1; min-width: 160px; }

.login-wrap {
    max-width: 360px;
    margin: 64px auto;
    padding: 20px;
}

.login-wrap h2 {
    margin: 0 0 14px;
    font-size: 20px;
}

.login-wrap p { margin: 0 0 10px; }

.error { color: var(--danger); font-size: 13px; }

.chat-box {
    min-height: 160px;
    max-height: 320px;
    overflow-y: auto;
    margin-bottom: 10px;
    font-size: 13px;
}

.chat-msg {
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

.badge {
    display: inline-block;
    font-size: 11px;
    color: var(--muted);
    margin-left: 4px;
}

.severity-warning { color: #d9730d; }
.severity-critical { color: var(--danger); }
.severity-info { color: var(--muted); }

.nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 8px;
    min-width: 16px;
    text-align: center;
}

.card.unread { border-left: 3px solid var(--accent); }

.delta-up { color: #0f7b3a; }
.delta-down { color: var(--danger); }

@media (max-width: 768px) {
    .layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .sidebar nav {
        flex-direction: row;
        flex-wrap: wrap;
    }
    .content { padding: 16px; }
}
