:root {
    color-scheme: dark;
    --bg: #0a0f1f;
    --bg-soft: #11182b;
    --panel: #111a2f;
    --panel-2: #17233d;
    --text: #e8edf7;
    --muted: #9aa7bf;
    --line: #2a3655;
    --primary: #47c89a;
    --primary-2: #2fa47b;
    --danger: #f97066;
    --warning: #f5a524;
    --info: #50b6ff;
    --radius: 14px;
}

html[data-theme="light"] {
    color-scheme: light;
    --bg: #f2f5fb;
    --bg-soft: #ffffff;
    --panel: #ffffff;
    --panel-2: #f8fbff;
    --text: #17233b;
    --muted: #4f607f;
    --line: #dce5f3;
    --primary: #1e8e67;
    --primary-2: #176f51;
    --danger: #cc3340;
    --warning: #a66f00;
    --info: #145da9;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    background:
        radial-gradient(1200px 500px at 20% -10%, rgba(71, 200, 154, 0.15), transparent 45%),
        radial-gradient(1000px 460px at 90% 0%, rgba(80, 182, 255, 0.12), transparent 44%),
        var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.container-fluid {
    width: 100%;
    padding-left: 12px;
    padding-right: 12px;
}

a { color: inherit; text-decoration: none; }

.app-header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(8, 13, 25, 0.85);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(8px);
}
html[data-theme="light"] .app-header { background: rgba(255,255,255,0.82); }
.row {
    margin: 0;
    padding: 10px 14px;
    display: flex;
    gap: 12px;
    align-items: center;
}
.brand {
    font-weight: 700;
    letter-spacing: 0.3px;
    color: var(--primary);
}
.top-nav { display: flex; gap: 6px; }
.top-nav a {
    padding: 7px 10px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
}
.top-nav a.on, .top-nav a:hover { background: var(--panel-2); color: var(--text); }
.header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}
.search {
    min-width: 210px;
    background: var(--bg-soft);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
}

.icon-btn {
    background: var(--bg-soft);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
}

.btn {
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    border-radius: 10px;
    padding: 8px 12px;
    cursor: pointer;
}
.btn.primary { background: var(--primary); color: #04271d; border-color: transparent; font-weight: 700; }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { background: #3c1c26; color: #ffcad0; border-color: #6f2838; }
.btn.w100 { width: 100%; }

.app-main {
    margin: 0;
    padding: 16px 14px 44px;
}

.page-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.page-head h1 {
    margin: 0;
    font-size: 20px;
}
.filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
select, input, textarea {
    background: var(--bg-soft);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 8px 10px;
    min-height: 38px;
}
textarea { width: 100%; }

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}
.card {
    background: linear-gradient(155deg, var(--panel), var(--panel-2));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    min-height: 90px;
}
.card .label { color: var(--muted); font-size: 12px; display: block; margin-bottom: 6px; }
.card strong { font-size: 22px; line-height: 1; }

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

.two-col {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
@media (min-width: 900px) {
    .two-col { grid-template-columns: 1fr 1fr; }
}

.list > div {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 7px;
    background: var(--bg-soft);
}
.api-widgets {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 8px;
}
.api-widget {
    border: 1px solid var(--line);
    background: var(--bg-soft);
    border-radius: 12px;
    padding: 10px;
}
.api-widget .head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.api-widget .name {
    font-weight: 700;
    font-size: 14px;
}
.state-pill {
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 700;
    border: 1px solid var(--line);
}
.state-pill.up { background: #123a2b; color: #9ef0ca; border-color: #1c664b; }
.state-pill.down { background: #4a1d24; color: #ffc6d0; border-color: #7c2c39; }
.state-pill.degraded { background: #4a3614; color: #ffe09b; border-color: #6d4f1c; }
.api-widget .meta {
    color: var(--muted);
    font-size: 12px;
    display: grid;
    gap: 2px;
}
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}
.chips span, .badge {
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--bg-soft);
    padding: 5px 10px;
    font-size: 12px;
}
.badge.warn { background: #3a2a11; color: #fdd789; border-color: #664915; }
.badge.danger { background: #3f1b23; color: #ffc8d2; border-color: #6a2634; }
.badges { display: flex; flex-direction: column; gap: 6px; }

.table-wrap { overflow: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
th, td {
    border-bottom: 1px solid var(--line);
    padding: 8px;
    text-align: left;
    vertical-align: top;
}
th { color: var(--muted); font-weight: 600; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 10px; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
}
.grid .full { grid-column: 1 / -1; }

.chat { max-height: 320px; overflow: auto; margin-bottom: 10px; }
.chat-item {
    border: 1px solid var(--line);
    background: var(--bg-soft);
    border-radius: 10px;
    padding: 8px 10px;
    margin-bottom: 8px;
}
.chat-item header { color: var(--muted); margin-bottom: 6px; }
.chat-item p { margin: 0; }

.toast-container {
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 90;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(380px, calc(100vw - 24px));
}
.toast {
    border: 1px solid var(--line);
    background: var(--panel-2);
    border-left: 5px solid var(--primary);
    border-radius: 12px;
    padding: 10px 12px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warning); }

.loading {
    opacity: 0.7;
    pointer-events: none;
}
.is-hidden {
    display: none !important;
}
.skeleton {
    background: linear-gradient(90deg, rgba(255,255,255,0.06), rgba(255,255,255,0.15), rgba(255,255,255,0.06));
    background-size: 200% 100%;
    animation: sk 1.2s infinite linear;
    color: transparent !important;
    border-radius: 8px;
}
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.auth-body {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 18px;
}
.auth-card h1 { margin-top: 0; }
.auth-card p { color: var(--muted); margin-top: 0; }
.auth-card label { display: block; margin: 10px 0 4px; color: var(--muted); }
.auth-card small { color: var(--muted); display: block; margin-top: 10px; }
.alert.error {
    border: 1px solid #6f2838;
    background: #3f1b23;
    color: #ffc8d2;
    border-radius: 10px;
    padding: 8px;
}

.mobile-drawer {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 85vw);
    background: var(--panel);
    border-right: 1px solid var(--line);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 80;
}
.mobile-drawer.open { transform: translateX(0); }
.drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    padding: 12px;
}
.drawer-nav { display: grid; gap: 2px; padding: 8px; }
.drawer-nav a {
    padding: 10px;
    border-radius: 8px;
    color: var(--muted);
}
.drawer-nav a:hover { background: var(--panel-2); color: var(--text); }
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 70;
    display: none;
}
.drawer-backdrop.show { display: block; }

.show-mobile { display: inline-flex; }
.hide-mobile { display: none; }
@media (min-width: 980px) {
    .show-mobile { display: none; }
    .hide-mobile { display: flex; }
}

@media (max-width: 760px) {
    .table-wrap table,
    .table-wrap thead,
    .table-wrap tbody,
    .table-wrap tr,
    .table-wrap th,
    .table-wrap td {
        display: block;
        width: 100%;
    }
    .table-wrap thead {
        position: absolute;
        left: -9999px;
        top: -9999px;
        height: 0;
        overflow: hidden;
    }
    .table-wrap tr {
        border: 1px solid var(--line);
        border-radius: 12px;
        background: var(--bg-soft);
        padding: 6px;
        margin-bottom: 8px;
    }
    .table-wrap td {
        border: 0;
        border-bottom: 1px dashed var(--line);
        padding: 8px 6px;
        min-height: 34px;
        display: grid;
        grid-template-columns: 110px 1fr;
        gap: 8px;
        align-items: start;
    }
    .table-wrap td:last-child {
        border-bottom: 0;
    }
    .table-wrap td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        font-weight: 600;
    }
}
