/* mon.iii.ovh — сервис мониторинга. Тёмная тема, без фреймворков. */

:root {
    --bg: #0e1116;
    --panel: #171b22;
    --panel-2: #1e232c;
    --border: #2a3140;
    --text: #dce3ed;
    --muted: #8a94a6;
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #f87171;
    --accent: #60a5fa;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--panel-2); border-radius: 6px; padding: 0.1rem 0.35rem; font-size: 0.9em; }
pre { overflow-x: auto; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.inline { display: inline; }

/* --- Шапка --- */

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.7rem 1.2rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--ok);
    margin-right: 0.3rem;
}
.topbar nav { display: flex; gap: 1rem; flex: 1; flex-wrap: wrap; }
.topbar nav a { color: var(--text); opacity: 0.85; }
.topbar nav a:hover { opacity: 1; }
.userbox { display: flex; align-items: center; gap: 0.8rem; }

.badge {
    display: inline-block;
    min-width: 1.3em;
    padding: 0 0.35em;
    border-radius: 999px;
    background: var(--danger);
    color: #10131a;
    font-size: 0.78rem;
    font-weight: 700;
    text-align: center;
}

/* --- Контент --- */

.container { max-width: 1100px; margin: 0 auto; padding: 1.2rem; }

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
h1 { font-size: 1.5rem; margin: 0.4rem 0; }
h2 { font-size: 1.05rem; margin: 0 0 0.7rem; color: var(--text); }
.subtitle { color: var(--muted); margin-top: 0.2rem; }

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 1.2rem;
    margin: 1rem 0;
}
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
}
.grid .card { margin: 0; }

.empty-state { text-align: center; padding: 2.5rem 1rem; }
.empty-state .code { font-size: 3rem; color: var(--muted); }

/* --- Статусы --- */

.status {
    display: inline-block;
    padding: 0.05rem 0.55rem;
    border-radius: 999px;
    font-size: 0.85rem;
    white-space: nowrap;
}
.status-ok { background: rgba(52, 211, 153, 0.15); color: var(--ok); }
.status-problem { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.status-pending { background: rgba(251, 191, 36, 0.15); color: var(--warn); }

.live { color: var(--ok); font-size: 0.8rem; vertical-align: middle; }
.live.off { color: var(--danger); }

.kind {
    font-family: ui-monospace, monospace;
    font-size: 0.85rem;
    padding: 0.05rem 0.45rem;
    border-radius: 6px;
    background: var(--panel-2);
}
.kind-cpu { color: var(--warn); }
.kind-mem { color: var(--accent); }
.kind-disk { color: var(--warn); }
.kind-unreachable { color: var(--danger); }

.alert-msg {
    background: rgba(248, 113, 113, 0.12);
    border: 1px solid rgba(248, 113, 113, 0.4);
    color: var(--danger);
    border-radius: 8px;
    padding: 0.5rem 0.9rem;
}

/* --- Таблицы --- */

.table-wrap { overflow-x: auto; }
.nodes-table { width: 100%; border-collapse: collapse; }
.nodes-table th, .nodes-table td {
    text-align: left;
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid var(--border);
    word-break: break-word;
}
.nodes-table .status, .nodes-table .kind {
    white-space: nowrap;
}
.nodes-table th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }
.nodes-table tr:last-child td { border-bottom: none; }
.node-link { font-weight: 600; }

/* --- Метрики --- */

.metric-big { font-size: 2rem; font-weight: 700; margin-bottom: 0.4rem; }
.bar {
    height: 8px;
    background: var(--panel-2);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.6rem;
}
.bar.slim { display: inline-block; vertical-align: middle; width: 120px; margin: 0 0.5rem 0 0; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--ok); transition: width 0.6s; }
.bar-fill.cpu { background: var(--accent); }
.bar-fill.mem { background: var(--ok); }

dl { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 1rem; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; text-align: right; }

/* --- Формы --- */

.form-card form { display: flex; flex-direction: column; gap: 0.8rem; max-width: 420px; }
label { display: flex; flex-direction: column; gap: 0.25rem; color: var(--muted); font-size: 0.9rem; }
label.checkbox { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--text); }

input, select {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 0.5rem 0.7rem;
    font: inherit;
}
input:focus, select:focus { outline: 1px solid var(--accent); }

button {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 0.45rem 0.9rem;
    font: inherit;
    cursor: pointer;
}
button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #0b1220;
    font-weight: 600;
}
button.danger {
    border-color: var(--danger);
    color: var(--danger);
    background: transparent;
}

.btn {
    display: inline-block;
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 0.45rem 0.9rem;
    font: inherit;
    cursor: pointer;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0b1220; font-weight: 600; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 0.2rem 0.6rem; font-size: 0.85rem; }
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }

button.link {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font: inherit;
    padding: 0;
}

/* --- Блок видимости в форме --- */

.access-box {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.7rem 0.9rem;
    margin: 0;
}
.access-box legend {
    color: var(--muted);
    font-size: 0.9rem;
    padding: 0 0.3rem;
}
.access-box .checkbox { margin: 0.25rem 0; }

/* --- Ключ узла --- */

.key-block {
    background: #0a0d12;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.7rem 0.9rem;
    font-family: ui-monospace, monospace;
    font-size: 0.85rem;
    word-break: break-all;
    white-space: pre-wrap;
}

/* --- Оповещения --- */

.notif-list { list-style: none; margin: 0; padding: 0; }
.notif {
    display: flex;
    gap: 0.7rem;
    padding: 0.6rem 0.4rem;
    border-bottom: 1px solid var(--border);
    align-items: flex-start;
}
.notif:last-child { border-bottom: none; }
.notif.unread { background: rgba(96, 165, 250, 0.06); border-radius: 8px; }
.notif-dot {
    width: 9px; height: 9px;
    border-radius: 50%;
    margin-top: 0.45rem;
    flex: none;
}
.notif-problem .notif-dot { background: var(--danger); }
.notif-resolved .notif-dot { background: var(--ok); }

/* --- Графики --- */

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.chart-box h3 { margin: 0 0 0.3rem; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
canvas { width: 100%; height: 120px; background: #0a0d12; border-radius: 8px; }

@media (max-width: 640px) {
    dd, dt { text-align: left; }
    .page-head { flex-direction: column; align-items: flex-start; }
}

/* --- Мобильная версия: таблицы превращаются в карточки --- */

@media (max-width: 700px) {
    .container { padding: 0.8rem; }
    .card { padding: 0.8rem 0.9rem; border-radius: 9px; }
    h1 { font-size: 1.25rem; }
    h2 { font-size: 1rem; }

    .topbar {
        padding: 0.55rem 0.8rem;
        gap: 0.5rem 1rem;
    }
    .topbar nav {
        order: 3;
        flex: 1 0 100%;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 0.9rem;
        padding-bottom: 0.1rem;
        scrollbar-width: none;
    }
    .topbar nav::-webkit-scrollbar { display: none; }
    .topbar nav a { white-space: nowrap; font-size: 0.92rem; }
    .userbox { margin-left: auto; }

    .metric-big { font-size: 1.55rem; }
    .btn-group { width: 100%; }
    .btn, button { padding: 0.5rem 0.8rem; }

    /* таблица → набор карточек */
    .nodes-table { display: block; }
    .nodes-table thead { display: none; }
    .nodes-table tbody { display: block; }
    .nodes-table tr {
        display: block;
        background: var(--panel-2);
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 0.65rem 0.8rem;
        margin: 0.6rem 0;
    }
    .nodes-table tr:last-child { margin-bottom: 0; }
    .nodes-table td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 1rem;
        padding: 0.18rem 0;
        border: none;
        white-space: normal;
    }
    .nodes-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 0.8rem;
        flex: none;
    }
    .nodes-table td:not([data-label])::before { content: none; }
    .nodes-table td.wide {
        flex-direction: column;
        gap: 0.15rem;
        align-items: flex-start;
        padding-bottom: 0.35rem;
    }
    .nodes-table td.wide::before { margin-bottom: 0.1rem; }

    .table-wrap { overflow-x: visible; }
    .key-block { font-size: 0.78rem; }
    .charts { grid-template-columns: 1fr; }
    .chart-box canvas { height: 100px; }
    .login-card { padding: 1.6rem 1.4rem; }
}

/* --- Страница входа --- */

.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background:
        radial-gradient(800px 400px at 20% 0%, rgba(96, 165, 250, 0.12), transparent 60%),
        radial-gradient(700px 380px at 85% 100%, rgba(52, 211, 153, 0.10), transparent 60%),
        var(--bg);
}

.login-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 2.2rem 2.4rem;
    width: min(380px, 100%);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.login-card h1 {
    font-size: 1.35rem;
    margin: 0 0 0.15rem;
}

.login-card .subtitle {
    margin: 0 0 1.5rem;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.login-card button.primary {
    margin-top: 0.4rem;
    padding: 0.6rem;
    background: var(--accent);
    border-color: var(--accent);
    color: #0b1220;
    font-weight: 600;
}

.login-footer {
    position: fixed;
    bottom: 1rem;
    left: 0;
    right: 0;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
}

/* --- Полоса истории инцидентов --- */

.nodes-table tr[data-node-id] td { border-bottom: none; }
.strip-row td { padding-top: 0; }
.strip-head {
    display: flex;
    align-items: baseline;
    gap: 0.9rem;
}
.strip-uptime { font-weight: 600; font-size: 0.85rem; color: var(--ok); }
.strip-toggle .arr { display: inline-block; transition: transform 0.15s; }
.strip-toggle.open .arr { transform: rotate(180deg); }
.strip {
    display: flex;
    gap: 2px;
    height: 10px;
    margin-top: 0.3rem;
}
.seg {
    flex: 1 1 0;
    min-width: 2px;
    border-radius: 2px;
    background: var(--panel-2);
}
.seg-ok { background: var(--ok); opacity: 0.8; }
.seg-warn { background: var(--warn); }
.seg-down { background: var(--danger); }
.seg:hover { filter: brightness(1.35); }
.seg-none:hover { filter: none; outline: 1px solid var(--border); }

#seg-tip {
    position: fixed;
    z-index: 60;
    max-width: 280px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.35rem 0.6rem;
    font-size: 0.8rem;
    line-height: 1.45;
    pointer-events: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    white-space: pre-line;
}
#seg-tip .tip-state-down { color: var(--danger); font-weight: 600; }
#seg-tip .tip-state-warn { color: var(--warn); font-weight: 600; }
#seg-tip .tip-state-ok { color: var(--ok); }
#seg-tip .tip-state-none { color: var(--muted); }

.incident-list { margin-top: 0.45rem; }
.incident {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.2rem 0.9rem;
    padding: 0.35rem 0;
    border-top: 1px dashed var(--border);
}
.inc-open { color: var(--danger); font-weight: 600; }

.strip-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1.2rem;
    margin-top: 0.7rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.78rem;
}
.strip-legend i {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    margin-right: 0.35rem;
    vertical-align: -1px;
}
.strip-legend .seg-ok { opacity: 0.8; }

@media (max-width: 700px) {
    /* строка-полоска визуально приклеивается к карточке узла */
    .nodes-table tr[data-node-id] {
        margin-bottom: 0;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
    .nodes-table tr.strip-row {
        margin: 0 0 0.6rem;
        border-top: none;
        border-top-left-radius: 0;
        border-top-right-radius: 0;
        padding-top: 0;
    }
    .strip-row td {
        display: block;
        padding: 0;
        border: none;
    }
    .strip-row td::before { content: none; }
    .strip-head { flex-wrap: wrap; gap: 0.4rem 0.9rem; }
    .strip { gap: 1px; }
    .seg { min-width: 1px; }
    .incident { gap: 0.15rem 0.7rem; }
}
