:root {
    --bg: #0f172a;
    --panel: #1e293b;
    --panel-2: #273449;
    --border: #334155;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --ok: #22c55e;
    --fail: #ef4444;
    --pending: #eab308;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: linear-gradient(180deg, #0b1222 0%, #0f172a 100%);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
    font-size: 13px;
    min-height: 100vh;
}

.wrap {
    max-width: 1700px;
    margin: 0 auto;
    padding: 0 20px;
}

/* progress bar (top of page during ops) */
#progress-bar {
    position: fixed;
    top: 0; left: 0;
    height: 3px;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), #8b5cf6);
    z-index: 9999;
    transition: width 0.3s ease;
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.6);
}
#progress-bar.active {
    width: 90%;
    transition: width 18s cubic-bezier(0.05, 0.5, 0.1, 1);
}
#progress-bar.done {
    width: 100%;
    transition: width 0.25s ease;
}

.topbar {
    background: rgba(15, 23, 42, 0.85);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(8px);
    padding: 14px 0;
    margin-bottom: 18px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .logo { font-size: 20px; }
.brand .title { font-weight: 700; font-size: 18px; letter-spacing: 0.3px; }
.brand .subtitle { color: var(--muted); font-size: 12px; }

.health {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    font-size: 11.5px;
}
.health-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--panel-2);
    border: 1px solid var(--border);
}
.health-item .dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--muted);
}
.health-item.ok .dot { background: var(--ok); box-shadow: 0 0 6px rgba(34, 197, 94, 0.6); }
.health-item.fail .dot { background: var(--fail); box-shadow: 0 0 6px rgba(239, 68, 68, 0.6); }
.health-item.ok .val { color: #86efac; }
.health-item.fail .val { color: #fca5a5; font-weight: 600; }
.health-item.neutral { background: transparent; border-color: transparent; }
.health-item .lbl { color: var(--muted); }
.health-item .val { font-variant-numeric: tabular-nums; }
.cnt-ok { color: #86efac; font-weight: 600; }
.cnt-fail { color: #fca5a5; font-weight: 600; }
.cnt-pending { color: #fde68a; font-weight: 600; }

/* toolbar */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 12px;
}
.toolbar h2 { margin: 0; font-size: 16px; font-weight: 600; }
.toolbar .right { display: flex; gap: 8px; }
.toolbar .left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* state pills in the toolbar — visual alerts that double as one-click filters */
.state-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    cursor: pointer;
    user-select: none;
    border: 1px solid transparent;
    transition: filter 0.12s, transform 0.05s;
}
.state-pill[hidden] { display: none; }
.state-pill:hover { filter: brightness(1.15); }
.state-pill:active { transform: translateY(1px); }
.state-pill .dot { width: 7px; height: 7px; border-radius: 50%; }
.state-pill b { font-weight: 700; font-variant-numeric: tabular-nums; }

.state-pill.bad {
    background: rgba(239, 68, 68, 0.14);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.45);
}
.state-pill.bad .dot { background: var(--fail); box-shadow: 0 0 6px rgba(239, 68, 68, 0.55); }
.state-pill.warn {
    background: rgba(234, 179, 8, 0.14);
    color: #fde68a;
    border-color: rgba(234, 179, 8, 0.45);
}
.state-pill.warn .dot { background: var(--pending); box-shadow: 0 0 6px rgba(234, 179, 8, 0.6); }
.state-pill.muted {
    background: rgba(148, 163, 184, 0.12);
    color: var(--muted);
    border-color: rgba(148, 163, 184, 0.4);
}
.state-pill.muted .dot { background: var(--muted); }
.state-pill.outdated {
    background: rgba(234, 179, 8, 0.16);
    color: #fde68a;
    border-color: rgba(234, 179, 8, 0.45);
}
.state-pill.outdated .dot { background: var(--pending); box-shadow: 0 0 6px rgba(234, 179, 8, 0.6); }
.state-pill.locked {
    background: rgba(245, 158, 11, 0.14);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.45);
}
.state-pill.locked .dot { background: #f59e0b; box-shadow: 0 0 6px rgba(245, 158, 11, 0.6); }
.state-pill.active-filter {
    outline: 2px solid currentColor;
    outline-offset: 1px;
}

/* card */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
}
.card.no-pad { padding: 0; overflow: hidden; }

/* buttons */
.btn {
    border: 0;
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 7px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 500;
    transition: background 0.12s, border-color 0.12s, transform 0.05s;
    line-height: 1.1;
}
.btn:hover { background: #334155; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* .is-blocked: visually disabled but the click still reaches our JS handler
   so we can show an explanatory toast (used on Undeploy for locked domains
   — the button stays discoverable but won't actually invoke the action). */
.btn.is-blocked {
    opacity: 0.45;
    cursor: not-allowed;
    text-decoration: line-through;
    text-decoration-thickness: 1px;
}
.btn.is-blocked:hover { background: transparent; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn.danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn.warn {
    background: rgba(234, 179, 8, 0.14);
    border-color: rgba(234, 179, 8, 0.55);
    color: #fde68a;
}
.btn.warn:hover { background: rgba(234, 179, 8, 0.24); border-color: rgba(234, 179, 8, 0.85); }
.btn.ok {
    background: rgba(34, 197, 94, 0.14);
    border-color: rgba(34, 197, 94, 0.55);
    color: #86efac;
}
.btn.ok:hover { background: rgba(34, 197, 94, 0.24); border-color: rgba(34, 197, 94, 0.85); }
.btn.cyan {
    background: rgba(6, 182, 212, 0.14);
    border-color: rgba(6, 182, 212, 0.55);
    color: #67e8f9;
}
.btn.cyan:hover { background: rgba(6, 182, 212, 0.26); border-color: rgba(6, 182, 212, 0.85); color: #a5f3fc; }
.btn.violet {
    background: rgba(168, 85, 247, 0.14);
    border-color: rgba(168, 85, 247, 0.55);
    color: #d8b4fe;
}
.btn.violet:hover { background: rgba(168, 85, 247, 0.26); border-color: rgba(168, 85, 247, 0.85); color: #e9d5ff; }
.btn.xs { padding: 4px 8px; font-size: 11.5px; border-radius: 5px; }

/* table */
table.domains {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}
table.domains th {
    text-align: left;
    padding: 10px 10px;
    font-weight: 600;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    /* Сплошной фон без sticky: иначе при пустой таблице/коротком списке
       полупрозрачные заголовки накрывают строки. */
    background: #1a2438;
}
table.domains th.sortable-th {
    cursor: pointer;
    user-select: none;
    padding-right: 22px;
    position: relative;
}
table.domains th.sortable-th:hover { color: var(--text); }
table.domains th.sortable-th::after {
    content: "⇅";
    position: absolute;
    right: 6px;
    color: var(--border);
    font-size: 11px;
}
table.domains th.sort-asc::after  { content: "▲"; color: var(--primary); font-size: 9px; }
table.domains th.sort-desc::after { content: "▼"; color: var(--primary); font-size: 9px; }
table.domains td {
    padding: 7px 10px;
    border-bottom: 1px solid rgba(51, 65, 85, 0.45);
    vertical-align: middle;
}
table.domains tbody tr.row-clickable { cursor: pointer; }
table.domains tbody tr:hover { background: rgba(99, 102, 241, 0.07); }
table.domains tbody tr.active { background: rgba(99, 102, 241, 0.12); }

table.domains td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
table.domains td.mono .dom-name { color: var(--text); }
table.domains td.xs { font-size: 11.5px; }

/* Domain-name cell: laid out as a flex row so a long .dom-name can ellipsis
   without pushing the lock-pin / copy / edit / spinner icons onto a second
   line. .dom-name shrinks and clips, the icon group stays a no-shrink chip. */
table.domains td.col-name {
    max-width: 320px;
}
table.domains td.col-name > .name-row {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}
table.domains td.col-name .dom-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
table.domains td.col-name .name-icons {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

/* tiny copy button next to each domain name */
.copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 0;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    color: var(--muted);
    font-size: 11px;
    line-height: 1;
    vertical-align: middle;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    flex: 0 0 auto;
}
.copy-btn:hover {
    background: var(--panel-2);
    border-color: var(--primary);
    color: var(--primary);
}
.copy-btn .copy-icon { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.copy-btn.copied {
    background: rgba(34, 197, 94, 0.18);
    border-color: rgba(34, 197, 94, 0.7);
    color: #86efac;
}

/* tiny edit button next to each domain name (same shape as .copy-btn) */
.edit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 0;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    color: var(--muted);
    font-size: 11px;
    line-height: 1;
    vertical-align: middle;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    flex: 0 0 auto;
}
.edit-btn:hover {
    background: var(--panel-2);
    border-color: #a78bfa;
    color: #a78bfa;
}
.edit-btn .edit-icon { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* lock-pin: "config locked" indicator next to the domain name. Same 18×18
   footprint as .copy-btn / .edit-btn so all three icons line up cleanly
   without bumping each other onto a second line. Inert (no click handler);
   the flag is toggled from Edit-domain modal or via bulk Lock/Unlock. */
.lock-pin {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 0;
    padding: 0;
    border: 1px solid rgba(245, 158, 11, 0.45);
    border-radius: 4px;
    background: rgba(245, 158, 11, 0.12);
    color: #fbbf24;
    font-size: 11px;
    line-height: 1;
    vertical-align: middle;
    cursor: help;
    user-select: none;
    flex: 0 0 auto;
}

/* Quick-actions row inside the Edit-domain modal — mirrors the per-row
   action buttons in the domains table. Compact, wrap-friendly. */
.domain-actions-field { margin-top: 4px; }
.domain-actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.domain-actions-row .btn {
    flex: 0 0 auto;
}

/* tiny "open log" button at the right of the error column.
   Aligned to the right so the error text takes precedence visually. */
table.domains td.err {
    position: relative;
    padding-right: 28px; /* room for the floating icon button */
}
.err-text {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}
.logs-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    color: var(--muted);
    font-size: 12px;
    line-height: 1;
    opacity: 0.55;
    transition: opacity 0.12s, background 0.12s, border-color 0.12s, color 0.12s;
}
.logs-btn:hover {
    opacity: 1;
    background: var(--panel-2);
    border-color: var(--primary);
    color: var(--primary);
}
.logs-btn .logs-icon { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
table.domains td.center { text-align: center; }
table.domains td.pad { padding: 22px; }

.tag {
    display: inline-block;
    padding: 2px 8px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 11px;
    color: var(--muted);
}
/* dir-tag — colored chip for direction name in domain table.
   Inline background/border/color applied by app.js (deterministic HSL hash). */
.tag.dir-tag {
    font-weight: 600;
    letter-spacing: 0.2px;
}
.dir-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
    background: var(--muted);
}
/* dir-chip-preview — chip in settings/add-domain modals showing the picked
   direction's color. Same coloring rules as .dir-tag, slightly bigger. */
.dir-chip-preview {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 70px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: 0.2px;
    flex: 0 0 auto;
}
.dir-select-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.dir-select-row select { flex: 1 1 auto; }

/* validate-banner — status row above template editor.
   Variants: v-checking (neutral), v-ok (green), v-warn (amber), v-error (red).
   When v-error is active, Save / Save&redeploy are disabled in JS. */
.validate-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--panel-2);
    font-size: 12.5px;
    line-height: 1.4;
}
.validate-banner .vb-icon {
    display: inline-flex;
    width: 22px;
    height: 22px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    background: rgba(255,255,255,0.04);
    flex: 0 0 auto;
}
.validate-banner .vb-text {
    flex: 1 1 auto;
    word-break: break-word;
}
.validate-banner .vb-toggle { flex: 0 0 auto; }
.validate-banner .vb-details {
    flex-basis: 100%;
    margin: 6px 0 0 0;
    padding: 8px 10px;
    background: rgba(0,0,0,0.35);
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11.5px;
    color: var(--fg);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 220px;
    overflow: auto;
}
.validate-banner.v-checking { border-color: rgba(120,160,255,0.45); background: rgba(40,80,140,0.18); color: #a8c2ff; }
.validate-banner.v-checking .vb-icon { color: #a8c2ff; animation: spin 1.1s linear infinite; }
.validate-banner.v-ok       { border-color: rgba(80,200,120,0.55); background: rgba(40,120,60,0.18);  color: #b6f0c2; }
.validate-banner.v-ok .vb-icon { color: #b6f0c2; }
.validate-banner.v-warn     { border-color: rgba(255,200,90,0.55); background: rgba(140,100,30,0.20); color: #ffd789; }
.validate-banner.v-warn .vb-icon { color: #ffd789; }
.validate-banner.v-error    { border-color: rgba(255,90,100,0.65); background: rgba(150,40,50,0.22);  color: #ffb1b8; }
.validate-banner.v-error .vb-icon { color: #ffb1b8; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
.btn.xs.ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
}
.btn.xs.ghost:hover { color: var(--fg); border-color: var(--muted); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

/* ---------- login page ---------- */
.login-body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    min-height: 100vh;
}
.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px 28px 22px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.45);
}
.login-brand {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 20px;
}
.login-brand .logo  { font-size: 26px; line-height: 1; }
.login-brand .title { font-size: 20px; font-weight: 700; letter-spacing: 0.2px; }
.login-brand .subtitle { color: var(--muted); font-size: 12px; margin-left: 2px; }
.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 6px;
}
.login-form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.login-form input {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--fg);
    outline: none;
    transition: border-color 0.15s ease;
}
.login-form input:focus { border-color: rgba(120,160,255,0.65); }
.login-form button {
    margin-top: 4px;
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 600;
}
.login-error {
    margin-bottom: 12px;
    padding: 8px 12px;
    border: 1px solid rgba(255,90,100,0.55);
    background: rgba(150,40,50,0.18);
    color: #ffb1b8;
    font-size: 13px;
    border-radius: 6px;
}
.login-note { margin-top: 14px; text-align: center; }

/* ---------- topbar user/logout ---------- */
.topbar-user {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-left: 16px;
    color: var(--muted);
    font-size: 12px;
}
.topbar-user .uname {
    color: var(--fg);
    font-weight: 600;
}
.topbar-user form { display: inline; margin: 0; }
.topbar-user .logout-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 4px 10px;
    border-radius: 5px;
    font-size: 11px;
    cursor: pointer;
}
.topbar-user .logout-btn:hover { color: var(--fg); border-color: var(--muted); }

.status {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.status-ok      { background: rgba(34, 197, 94, 0.16); color: #86efac; }
.status-fail    { background: rgba(239, 68, 68, 0.16); color: #fca5a5; }
.status-pending { background: rgba(234, 179, 8, 0.16); color: #fde68a; }
.status-running { background: rgba(99, 102, 241, 0.16); color: #c7d2fe; }

.badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 5px;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge.ok { background: rgba(34, 197, 94, 0.16); color: #86efac; }
.badge.no { background: rgba(148, 163, 184, 0.16); color: var(--muted); }

.muted { color: var(--muted); }
.xs { font-size: 11.5px; }
.small { font-size: 11.5px; }
.err {
    color: #fca5a5;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.actions { white-space: nowrap; text-align: right; }
.actions .btn + .btn { margin-left: 4px; }

/* row spinner — индикатор активной операции */
.row-spinner {
    display: inline-block;
    margin-left: 8px;
    width: 11px;
    height: 11px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
}
/* атрибут [hidden] не сработает без этого — наш display:inline-block перебивает UA */
.row-spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.foot {
    margin-top: 24px;
    padding: 12px 20px 20px;
    color: var(--muted);
    font-size: 11.5px;
    text-align: center;
}

/* ---------- modals ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadein 0.15s ease;
}
.modal[hidden] { display: none; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
}
.modal-window {
    position: relative;
    width: 95%;
    max-width: 540px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}
.modal-window.wide { max-width: 920px; }
.modal-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; flex: 1; }
.modal-x {
    background: transparent;
    border: 0;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}
.modal-x:hover { color: var(--text); }
.modal-body {
    padding: 16px 18px;
    overflow: auto;
    /* В flex-колонке modal-window (max-height: 90vh) modal-body должен
       честно ужиматься до доступного пространства, иначе высокий контент
       (textarea на 50vh + несколько секций) распирает .modal-window и
       вылезает ниже его видимой границы. min-height:0 разрешает шринк
       внутри flex, а flex:1 даёт телу расти/сжиматься, так что
       overflow:auto реально клипает содержимое, и любой нижний footer
       (Close + per-tab actions у settings) гарантированно виден без
       наложения на форму. */
    flex: 1 1 auto;
    min-height: 0;
}
.modal-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid var(--border);
}
.modal-foot .muted { margin-right: auto; }

/* error banner внутри модалки лога */
.error-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0 18px;
    margin-top: 14px;
    padding: 10px 12px;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.45);
    border-left: 3px solid var(--fail);
    border-radius: 7px;
}
.error-banner[hidden] { display: none; }
.error-banner-label {
    flex-shrink: 0;
    background: rgba(239, 68, 68, 0.22);
    color: #fecaca;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 4px;
    line-height: 1.6;
}
.error-banner-text {
    color: #fecaca;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

/* form fields inside modal */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.field input, .field select {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 9px 11px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.12s, box-shadow 0.12s;
}
.field input:focus, .field select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}
.hint { margin: 6px 0 0 0; color: var(--muted); font-size: 11.5px; }
.hint code {
    background: var(--panel-2);
    padding: 1px 5px;
    border-radius: 3px;
    border: 1px solid var(--border);
    font-size: 11px;
}

/* template editor */
.tpl-body { display: flex; flex-direction: column; gap: 10px; min-height: 60vh; }
.tpl-toolbar {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.field.inline {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin: 0;
}
.field.inline .lbl {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.tpl-editor {
    flex: 1 1 auto;
    min-height: 50vh;
    width: 100%;
    background: #0b1325;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.55;
    resize: vertical;
    outline: none;
    tab-size: 4;
}
.tpl-editor:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}
.tpl-status-ok   { color: #86efac; }
.tpl-status-fail { color: #fca5a5; }

/* event log */
.event-log {
    background: #0b1325;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.55;
    max-height: 60vh;
    overflow: auto;
    min-height: 120px;
}
.event {
    display: grid;
    grid-template-columns: 90px 56px 1fr;
    gap: 10px;
    padding: 3px 6px;
    border-radius: 4px;
}
.event:hover { background: rgba(99, 102, 241, 0.06); }
.event .ev-time { color: var(--muted); }
.event .ev-level {
    text-transform: uppercase;
    font-weight: 700;
    font-size: 10px;
    letter-spacing: 0.4px;
    align-self: center;
    text-align: center;
    padding: 1px 6px;
    border-radius: 3px;
}
.event .ev-msg { color: var(--text); word-break: break-word; }
.event.lvl-info  .ev-level { background: rgba(99, 102, 241, 0.18); color: #c7d2fe; }
.event.lvl-ok    .ev-level { background: rgba(34, 197, 94, 0.16);  color: #86efac; }
.event.lvl-warn  .ev-level { background: rgba(234, 179, 8, 0.16);  color: #fde68a; }
.event.lvl-error .ev-level { background: rgba(239, 68, 68, 0.18);  color: #fca5a5; }
.event.lvl-error .ev-msg   { color: #fecaca; }

/* ---------- selection / bulk bar ---------- */
.bulk-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 10px;
    padding: 8px 14px;
    border: 1px solid var(--primary);
    background: rgba(99, 102, 241, 0.08);
    border-radius: 8px;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.06);
    flex-wrap: wrap;
}
.bulk-bar[hidden] { display: none; }
.bulk-bar .bulk-label { font-size: 12.5px; color: var(--text); }
.bulk-bar .bulk-label b { color: #c7d2fe; font-weight: 700; }
.bulk-bar .bulk-actions { display: flex; gap: 6px; flex-wrap: wrap; }

table.domains th.col-sel,
table.domains td.col-sel {
    width: 28px;
    padding-left: 12px;
    padding-right: 4px;
}
table.domains input[type="checkbox"] {
    accent-color: var(--primary);
    width: 14px;
    height: 14px;
    cursor: pointer;
    margin: 0;
    vertical-align: middle;
}
table.domains tbody tr.sel-row {
    background: rgba(99, 102, 241, 0.10);
}
table.domains tbody tr.sel-row:hover { background: rgba(99, 102, 241, 0.16); }

/* template badges */
.tpl-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 5px;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.tpl-badge.current  { background: rgba(34, 197, 94, 0.16); color: #86efac; }
.tpl-badge.outdated { background: rgba(234, 179, 8, 0.18); color: #fde68a; }
.tpl-badge.unknown  { background: rgba(148, 163, 184, 0.16); color: var(--muted); }

/* textarea (form fields) */
.field textarea {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 9px 11px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.12s, box-shadow 0.12s;
    resize: vertical;
}
.field textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* confirm dialog */
.confirm-body {
    margin: 0 0 8px 0;
    color: var(--text);
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
}
.confirm-list {
    background: #0b1325;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 8px 10px;
    max-height: 220px;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    color: var(--muted);
}
.confirm-list[hidden] { display: none; }
.confirm-list .ci { padding: 1px 0; color: var(--text); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: white; }

/* toast notifications */
.toast-stack {
    position: fixed;
    bottom: 22px;
    right: 22px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 380px;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    border-radius: 8px;
    padding: 10px 32px 10px 12px;
    box-shadow: var(--shadow);
    font-size: 12.5px;
    line-height: 1.4;
    position: relative;
    animation: toast-in 0.18s ease;
}
.toast.ok    { border-left-color: var(--ok);   color: #d1fae5; }
.toast.fail  { border-left-color: var(--fail); color: #fecaca; }
.toast.warn  { border-left-color: var(--pending); color: #fde68a; }
.toast.info  { border-left-color: var(--primary); }
.toast .toast-x {
    position: absolute;
    top: 4px; right: 6px;
    background: transparent;
    border: 0;
    color: var(--muted);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 4px;
}
.toast .toast-x:hover { color: var(--text); }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.toast.fading { opacity: 0; transition: opacity 0.25s ease; }

/* ---------- filter bar ---------- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 10px;
    padding: 8px 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.filter-bar .f-item { display: flex; align-items: center; }
.filter-bar .f-item.right { margin-left: auto; }
.filter-bar input[type="search"],
.filter-bar select {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 9px;
    font-size: 12px;
    outline: none;
    height: 28px;
}
.filter-bar input[type="search"]:focus,
.filter-bar select:focus {
    border-color: var(--primary);
}

/* ---------- health cell ---------- */
.health-cell {
    display: inline-block;
    min-width: 38px;
    text-align: center;
    padding: 1px 7px;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 600;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: var(--panel-2);
    color: var(--muted);
    border: 1px solid var(--border);
}
.health-cell[data-health="200"] { background: rgba(34, 197, 94, 0.16); color: #86efac; border-color: rgba(34, 197, 94, 0.45); }
.health-cell[data-health="other"] { background: rgba(239, 68, 68, 0.16); color: #fca5a5; border-color: rgba(239, 68, 68, 0.45); }
.health-cell[data-health="fail"] { background: rgba(239, 68, 68, 0.16); color: #fca5a5; border-color: rgba(239, 68, 68, 0.55); }
.health-cell[data-health="nocors"] { background: rgba(234, 179, 8, 0.16); color: #fde68a; border-color: rgba(234, 179, 8, 0.55); cursor: help; }
.health-cell[data-health="checking"] { color: var(--muted); }
.health-cell[data-health="pending"]  { color: var(--muted); }

/* hide rows filtered out by the filter-bar */
table.domains tbody tr.f-hidden { display: none !important; }

/* ---------- settings modal: tabs & layouts ---------- */
.tabs {
    display: flex;
    gap: 4px;
}
.tabs .tab {
    background: transparent;
    border: 1px solid transparent;
    color: var(--muted);
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.tabs .tab:hover { color: var(--text); }
.tabs .tab.active {
    color: #c7d2fe;
    background: rgba(99, 102, 241, 0.14);
    border-color: rgba(99, 102, 241, 0.4);
}
.tab-pane[hidden] { display: none; }

/* settings modal — sections, picker rows, grid forms */
.settings-section {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 12px;
}
.settings-section.grow { display: flex; flex-direction: column; gap: 10px; }
.section-label {
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    margin-bottom: 10px;
}
.dir-picker-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.dir-picker-row .right { margin-left: auto; }
.dir-picker {
    flex: 1 1 240px;
    min-width: 220px;
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 9px 12px;
    font-size: 13.5px;
    font-weight: 500;
    outline: none;
    transition: border-color 0.12s, box-shadow 0.12s;
}
.dir-picker:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}
.dir-stats-row {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
}
.dir-stats-row:empty { display: none; }

/* grid for direction & host-group property forms */
.dir-form-grid {
    display: grid;
    grid-template-columns: minmax(200px, 1fr) minmax(220px, 1.4fr);
    gap: 12px 16px;
}
.hg-form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(160px, 1fr));
    gap: 10px 14px;
}
.hg-form-grid .field.narrow { grid-column: span 1; }
.hg-form-grid .field.checkbox {
    grid-column: span 1;
    align-self: end;
    padding-bottom: 9px;
}
.hg-form-grid .field.checkbox label {
    text-transform: none;
    font-size: 12.5px;
    color: var(--text);
    letter-spacing: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}
.hg-form-grid .field { margin-bottom: 0; }
.dir-form-grid .field { margin-bottom: 0; }

.hg-hosts-area {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 9px 11px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.5;
    outline: none;
    width: 100%;
    resize: vertical;
}
.hg-hosts-area:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2); }

@media (max-width: 700px) {
    .dir-form-grid, .hg-form-grid { grid-template-columns: 1fr; }
}
.modal-foot .grow { flex: 1; }

/* Settings modal — единая нижняя плашка под обоими табами.
   Содержит per-tab status слева, per-tab actions и общую Close справа.
   Кнопки конкретного таба показываются/скрываются JS-ом через [hidden]. */
.modal-foot.settings-foot {
    flex-wrap: wrap;
    gap: 10px;
}
.modal-foot.settings-foot .foot-status {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 0;
}
.modal-foot.settings-foot .foot-status[hidden] { display: none; }
.modal-foot.settings-foot .foot-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
.modal-foot.settings-foot .foot-actions[hidden] { display: none; }

/* ---------- pagination ---------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.4);
    flex-wrap: wrap;
}
.pagination[hidden] { display: none; }
.pagination .page-size {
    display: flex; align-items: center; gap: 8px;
    color: var(--muted); font-size: 12px;
}
.pagination .page-size select {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    height: 28px;
    outline: none;
}
.pagination .page-size select:focus { border-color: var(--primary); }
.pagination .page-nav {
    display: flex; align-items: center; gap: 6px;
}
.pagination .page-info {
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    min-width: 110px;
    text-align: center;
}

/* responsive adjustments — column layout: sel(1) name(2) dir(3) status(4) health(5) onapps(6) tpl(7) reg(8) iss(9) exp(10) err(11) act(12) */
@media (max-width: 1400px) {
    table.domains .col-tpl { display: none; }
    table.domains td:nth-child(7) { display: none; }
}
@media (max-width: 1200px) {
    table.domains .col-reg, table.domains .col-iss { display: none; }
    table.domains td:nth-child(8), table.domains td:nth-child(9) { display: none; }
}
@media (max-width: 900px) {
    table.domains .col-app, table.domains .col-err { display: none; }
    table.domains td:nth-child(6), table.domains td:nth-child(11) { display: none; }
}
@media (max-width: 720px) {
    table.domains .col-hl { display: none; }
    table.domains td:nth-child(5) { display: none; }
}
