/* ===========================================================================
   SSClash-Go — web UI. Calm-grey design system with light / dark / auto themes.
   Self-contained, no external fonts.
   =========================================================================== */

:root {
    --bg-page: #f2f3f5;
    --bg-surface: #ffffff;
    --bg-surface-2: #f7f8fa;
    --bg-nav: #2b2f33;
    --bg-code: #1e2227;

    --text-primary: #2c3035;
    --text-secondary: #555b61;
    --text-muted: #868d94;
    --text-nav: #c4c9ce;
    --text-nav-hover: #ffffff;

    --border-color: #e1e4e8;
    --border-strong: #cdd2d8;
    --accent: #5b7083;
    --accent-hover: #44535f;
    --accent-soft: #eef1f4;
    --link: #3f6079;

    --ok: #2e8457;
    --ok-hover: #27704a;
    --err: #b3473a;
    --err-hover: #9c3d31;
    --warn: #b9810c;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 2px 10px rgba(0, 0, 0, 0.08);
    --shadow-btn: 0 1px 2px rgba(15, 23, 42, 0.08);

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius: var(--radius-md);
    --control-h: 36px;
    --control-h-sm: 32px;
    --topbar-control-h: 36px;
    --gap: 18px;
    --sidebar-w: 232px;
    --topbar-h: 56px;
    --editor-h: 640px;
}

[data-theme="dark"] {
    --bg-page: #15171a;
    --bg-surface: #1e2125;
    --bg-surface-2: #24282d;
    --bg-nav: #101214;
    --bg-code: #0c0e10;
    --text-primary: #e3e6e9;
    --text-secondary: #b3b9bf;
    --text-muted: #828a91;
    --border-color: #2e333a;
    --border-strong: #3a4048;
    --accent: #7e95a8;
    --accent-hover: #98abbb;
    --accent-soft: #262b31;
    --link: #8fb0c9;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 12px rgba(0, 0, 0, 0.5);
    --shadow-btn: 0 1px 2px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: dark) {
    [data-theme="auto"] {
        --bg-page: #15171a; --bg-surface: #1e2125; --bg-surface-2: #24282d;
        --bg-nav: #101214; --bg-code: #0c0e10;
        --text-primary: #e3e6e9; --text-secondary: #b3b9bf; --text-muted: #828a91;
        --border-color: #2e333a; --border-strong: #3a4048;
        --accent: #7e95a8; --accent-hover: #98abbb; --accent-soft: #262b31; --link: #8fb0c9;
        --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow-md: 0 2px 12px rgba(0,0,0,.5);
        --shadow-btn: 0 1px 2px rgba(0,0,0,.35);
    }
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px; line-height: 1.55;
    color: var(--text-secondary); background: var(--bg-page);
    display: flex; flex-direction: column; min-height: 100vh;
    transition: background-color .25s ease, color .25s ease;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { color: var(--text-primary); font-weight: 600; line-height: 1.25; }
code, .mono { font-family: 'Monaco','Menlo','Ubuntu Mono','Consolas',monospace; }

/* ---- Topbar ---- */
.topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 30;
    height: var(--topbar-h); min-height: var(--topbar-h);
    background: var(--bg-nav); box-shadow: var(--shadow-md);
    display: flex; align-items: center; gap: 10px; padding: 0 14px;
}
.brand {
    display: flex; align-items: center; gap: 11px;
    color: #fff; text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; flex: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #e8eef2;
}
.brand-mark img,
.brand-mark svg { width: 28px; height: 28px; display: block; }
.brand-text { display: flex; flex-direction: column; gap: 1px; line-height: 1.1; min-width: 0; }
.brand-name { font-weight: 400; font-size: 1.02rem; letter-spacing: 0; color: #fff; white-space: nowrap; }
.brand-ver { font-weight: 500; font-size: .68rem; color: rgba(255, 255, 255, 0.52); letter-spacing: 0.02em; }
.topbar-spacer { flex: 1; }

.logout-form { display: contents; margin: 0; }

/* Toolbar — single segmented bar (service + theme + logout) */
.topbar-svc {
    display: inline-flex; align-items: stretch; flex: none;
    height: var(--topbar-control-h);
    min-height: var(--topbar-control-h);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 0;
    background: rgba(0, 0, 0, 0.22);
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.svc-seg {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--topbar-control-h);
    padding: 0 14px;
    font-size: .8125rem; font-weight: 600; line-height: 1; white-space: nowrap;
    font-family: inherit;
    border: 0; background: transparent;
    color: rgba(255, 255, 255, 0.9);
    transition: background .15s ease, color .15s ease;
}
.topbar-svc > .svc-seg ~ .svc-seg,
.topbar-svc > form .svc-seg {
    box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.14);
}
.svc-action {
    cursor: pointer; height: 100%;
}
.svc-action:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.svc-action:active { background: rgba(255, 255, 255, 0.06); }
.svc-action#btn-stop:hover { background: rgba(179, 71, 58, 0.22); color: #ffe8e4; }
.svc-action:disabled { opacity: .45; cursor: not-allowed; }
.svc-action[hidden] { display: none !important; }
.svc-icon {
    padding: 0;
    width: var(--topbar-control-h);
    min-width: var(--topbar-control-h);
}
.svc-icon svg { width: 18px; height: 18px; flex: none; }

.svc-status { cursor: default; user-select: none; }
.svc-status .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.svc-status.on {
    color: #d8f5e8;
    background: rgba(46, 132, 87, 0.22);
}
.svc-status.on .dot { background: #3ecf7a; box-shadow: 0 0 0 3px rgba(52, 199, 123, 0.2); }
.svc-status.off {
    color: #ffd8d2;
    background: rgba(179, 71, 58, 0.18);
}
.svc-status.off .dot { background: #e0604f; box-shadow: 0 0 0 3px rgba(224, 96, 79, 0.16); }

.icon-btn {
    background: rgba(255, 255, 255, 0.08); color: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md); cursor: pointer;
    font-size: 1.05rem; display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.18); color: #fff; }
.nav-toggle { display: none; }
.nav-toggle.icon-btn {
    width: var(--topbar-control-h); min-width: var(--topbar-control-h);
    height: var(--topbar-control-h); min-height: var(--topbar-control-h);
}
.icon-btn svg { width: 18px; height: 18px; }
.theme-float { position: fixed; top: 16px; right: 16px; background: var(--bg-surface-2); color: var(--text-secondary); border: 1px solid var(--border-color); }
.theme-float:hover { background: var(--accent-soft); color: var(--text-primary); }

/* ---- App shell (topbar + sidebar + content) ---- */
.shell { display: flex; align-items: flex-start; flex: 1; padding-top: var(--topbar-h); }
.sidebar {
    position: sticky; top: var(--topbar-h); align-self: flex-start;
    width: var(--sidebar-w); flex: none; height: calc(100vh - var(--topbar-h));
    background: var(--bg-surface); border-right: 1px solid var(--border-color);
    padding: 14px 10px; overflow-y: auto;
}
.side-nav { display: flex; flex-direction: column; gap: 3px; }
.side-link {
    display: flex; align-items: center; gap: 11px; padding: 10px 12px;
    border-radius: var(--radius); color: var(--text-secondary); font-weight: 600; font-size: .92rem;
}
.side-link svg { width: 18px; height: 18px; flex: none; opacity: .8; }
.side-link:hover { background: var(--accent-soft); color: var(--text-primary); text-decoration: none; }
.side-link.active { background: var(--accent-soft); color: var(--accent); }
.side-link.active svg { opacity: 1; }

/* ---- Layout ---- */
.content { width: 100%; padding: var(--gap); flex: 1; min-width: 0; }

/* ---- Overview strip ---- */
.overview {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: var(--gap);
}
.ov-item {
    background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius);
    padding: 10px 14px; display: flex; flex-direction: column; gap: 2px;
}
.ov-k { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.ov-v { font-weight: 700; color: var(--text-primary); font-size: .95rem; }
.ov-v.is-on { color: var(--ok); }
.ov-v.is-off { color: var(--text-muted); }

/* ---- Nav drawer scrim (mobile) ---- */
.nav-scrim { display: none; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0,0,0,.45); z-index: 32; }
/* Page-level action bar (title + primary action for a whole multi-card page) */
.page-bar {
    display: flex; align-items: center; gap: 12px; margin-bottom: var(--gap);
    position: sticky; top: var(--topbar-h); z-index: 25;
    background: var(--bg-page); padding: 8px 0;
}
.page-bar h2 { font-size: 1.15rem; margin: 0; }
.page-bar .hint { margin-top: 2px; }
.page-bar .spacer { flex: 1; }

.card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: var(--gap); }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.card-head-text {
    display: flex;
    min-width: 0;
    flex-direction: row;
    align-items: baseline;
    flex-wrap: nowrap;
    gap: 8px 12px;
    overflow: hidden;
}
.card-head-text h2 { flex: none; margin: 0; }
.card-head-text .sub {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.card-head-log .card-head-text {
    flex: 1 1 auto;
}
.card-head-actions { flex: none; margin-left: auto; }
.card-head h2 { font-size: 1.05rem; margin: 0; }
.card-head .sub { color: var(--text-muted); font-size: .85rem; }
.card-head .spacer { flex: 1; }
/* Sticky card toolbar (Configuration, Rule lists, System Log) */
.card-head-sticky {
    position: sticky;
    top: var(--topbar-h);
    z-index: 25;
    background: var(--bg-surface);
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
}
.log-autoscroll {
    display: inline-flex; align-items: center; gap: 8px;
    min-height: var(--control-h-sm);
    border: 0; padding: 0; margin: 0; cursor: pointer; user-select: none;
}
.log-autoscroll-label { font-weight: 600; font-size: .8125rem; color: var(--text-primary); white-space: nowrap; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px; cursor: pointer;
    border: 1px solid var(--border-strong); background: var(--bg-surface);
    color: var(--text-primary);
    min-height: var(--control-h); padding: 0 16px;
    border-radius: var(--radius-md); font-size: .875rem; font-weight: 600; line-height: 1;
    transition: background .15s ease, border-color .15s ease, box-shadow .15s ease, opacity .15s ease;
    box-shadow: var(--shadow-btn);
}
.btn:hover { background: var(--accent-soft); border-color: var(--border-strong); text-decoration: none; }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary {
    background: var(--accent); border-color: var(--accent); color: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.1); }
.btn-ok:hover { background: var(--ok-hover); border-color: var(--ok-hover); }
.btn-danger { background: var(--err); border-color: var(--err); color: #fff; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.1); }
.btn-danger:hover { background: var(--err-hover); border-color: var(--err-hover); }
.btn-sm { min-height: var(--control-h-sm); padding: 0 12px; font-size: .8125rem; border-radius: var(--radius-sm); }
.btn-icon {
    width: var(--control-h-sm);
    min-width: var(--control-h-sm);
    padding: 0;
}
.btn-icon svg { width: 18px; height: 18px; flex: none; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.card-head .btn-row { gap: 6px; }
.card-head.card-head-log .btn-row.card-head-actions-log {
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 8px;
}
.card-head .cfg-io { margin-left: 2px; gap: 3px; }

/* Config profiles — compact picker beside page title */
.cfg-profile {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 2px;
}
.cfg-profile-select {
    appearance: none;
    -webkit-appearance: none;
    height: 28px;
    max-width: 148px;
    padding: 0 26px 0 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 8px center;
    color: var(--text-primary);
    font: inherit;
    font-size: .82rem;
    line-height: 1;
    cursor: pointer;
    transition: border-color .15s, color .15s, background-color .15s;
}
.cfg-profile-select:hover,
.cfg-profile-select:focus {
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border-color));
    color: var(--text-primary);
    outline: none;
}
.cfg-profile-add,
.cfg-profile-more {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    color: var(--text-muted);
    min-width: 28px;
    padding: 0;
}
.cfg-profile-add svg { width: 14px; height: 14px; opacity: .85; }
.cfg-profile-add:hover,
.cfg-profile-more:hover {
    background: var(--accent-soft);
    border-color: transparent;
    color: var(--text-primary);
}
.cfg-profile-add:hover svg { opacity: 1; }
.cfg-profile-menu {
    left: 0;
    right: auto;
    min-width: 168px;
}
.cfg-io .btn-icon {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    color: var(--text-secondary);
    border-radius: var(--radius);
}
.cfg-io .btn-icon svg { opacity: .8; }
.cfg-io .btn-icon:hover {
    background: var(--accent-soft);
    border-color: transparent;
    color: var(--text-primary);
}
.cfg-io .btn-icon:hover svg { opacity: 1; }
.cfg-io .btn-icon:active { transform: none; box-shadow: none; }
.btn-row-sep {
    width: 1px;
    height: 20px;
    margin: 0 2px;
    background: var(--border-color);
    flex: none;
}

#cfg-dashboard[hidden] {
    display: none !important;
}

/* Split button (Save & Reload + dropdown) */
.btn-split {
    position: relative;
    display: inline-flex;
    align-items: stretch;
}
.btn-split-main {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: 0;
    box-shadow: none;
}
.btn-split-toggle {
    min-width: 0;
    padding: 0 9px;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: 1px solid var(--border-strong);
    box-shadow: none;
}
.btn-primary.btn-split-toggle {
    border-left: 1px solid color-mix(in srgb, #fff 22%, transparent);
}
.btn-split .btn:active { transform: none; }
.btn-split-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 30;
    min-width: 220px;
    padding: 4px;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}
.btn-split-menu[hidden] { display: none; }
.btn-split-menu button {
    display: block;
    width: 100%;
    margin: 0;
    padding: 8px 12px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    font-size: .8125rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: background .15s ease;
}
.btn-split-menu button:hover { background: var(--accent-soft); }
.btn-split.is-busy .btn-split-toggle { pointer-events: none; }

/* ---- Forms ---- */
.field { margin-bottom: 16px; }
.card-body > .field:last-child { margin-bottom: 0; }
.field > label { display: block; font-weight: 600; color: var(--text-primary); margin-bottom: 5px; }
.field .hint { color: var(--text-muted); font-size: .82rem; margin-top: 4px; }
input[type=text], input[type=password], input[type=number], select, textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius);
    background: var(--bg-surface); color: var(--text-primary); font-size: .9rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.switch-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border-color); }
.switch-row.switch-row-last { border-bottom: 0; padding-bottom: 0; }
.switch-row.switch-row-inactive { opacity: 0.5; }
.switch-row .label { flex: 1; }
.switch-row .label b { color: var(--text-primary); font-weight: 600; }
.switch-row .label .hint { color: var(--text-muted); font-size: .82rem; }

/* toggle */
.toggle { position: relative; width: 42px; height: 23px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: .2s; cursor: pointer; }
.toggle .slider::before { content: ""; position: absolute; height: 17px; width: 17px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(19px); }
.toggle input:disabled + .slider { opacity: 0.45; cursor: not-allowed; }

.seg {
    display: inline-flex; flex-wrap: wrap; gap: 4px;
    padding: 4px; max-width: 100%;
    background: var(--bg-surface-2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}
.seg button {
    border: 0; background: transparent; color: var(--text-secondary);
    min-height: var(--control-h); padding: 0 16px;
    border-radius: var(--radius-md); cursor: pointer;
    font-weight: 600; font-size: .875rem; line-height: 1;
    transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.seg button:hover:not(.active) { background: rgba(127, 127, 127, 0.08); color: var(--text-primary); }
.seg button.active {
    background: var(--accent); color: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.14);
}

/* ---- Editor (always dark, fixed height) ---- */
.cfg-editor-wrap {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-surface-2);
}
.cfg-editor-surface {
    overflow: hidden;
    background: #000;
    border-bottom-left-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
}
.cfg-editor-wrap:not(.has-outline) .cfg-editor-surface {
    border-radius: var(--radius);
}
.cfg-editor-wrap .editor {
    width: 100%;
    height: var(--editor-h);
    min-height: 360px;
    border: 0;
    border-radius: 0;
    overflow: hidden;
    background: #000;
    color: #dedede;
}
.cfg-editor-wrap.has-outline .editor {
    height: calc(var(--editor-h) - 32px);
    min-height: 328px;
}
.editor { width: 100%; height: var(--editor-h); min-height: 360px; border: 1px solid var(--border-color); border-radius: var(--radius); overflow: hidden; background: #000; color: #dedede; }
/* Ace find bar: below sticky card headers (z-index 25) and split menus (30) */
.card-body .ace_search,
.editor .ace_search { z-index: 20 !important; }

/* Config YAML jump bar — single row on top of the editor */
.cfg-outline {
    position: relative;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 4px 3px 6px;
    background: var(--bg-surface-2);
    border-bottom: 1px solid var(--border-color);
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
}
.cfg-outline[hidden] { display: none !important; }
.cfg-outline.is-jump-only .cfg-outline-rail { display: none; }
.cfg-outline.is-jump-only .cfg-outline-jump-wrap {
    flex: 1 1 auto;
    max-width: none;
}
.cfg-outline-rail {
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 1px 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.cfg-outline-rail::-webkit-scrollbar { display: none; }
.cfg-outline-chips {
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 3px;
    min-width: min-content;
}
.cfg-outline-chip {
    appearance: none;
    display: inline-flex;
    align-items: center;
    height: 24px;
    min-height: 24px;
    padding: 0 7px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .01em;
    line-height: 1.25;
    cursor: pointer;
    white-space: nowrap;
    transition: color .12s, background-color .12s, border-color .12s;
}
.cfg-outline-chip:hover {
    color: var(--text-primary);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.cfg-outline-chip.is-active,
.cfg-outline-chip[aria-current="true"] {
    border-color: color-mix(in srgb, var(--accent) 45%, var(--border-color));
    background: var(--accent-soft);
    color: var(--text-primary);
}
.cfg-outline-jump-wrap {
    position: relative;
    flex: 0 1 auto;
    min-width: 0;
    max-width: min(280px, 34vw);
}
.cfg-outline-jump-wrap[hidden] { display: none !important; }
.cfg-outline-jump-wrap::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 8px;
    width: 0;
    height: 0;
    margin-top: -1px;
    border: 4px solid transparent;
    border-top-color: var(--text-muted);
    pointer-events: none;
}
.cfg-outline-jump {
    appearance: none;
    -webkit-appearance: none;
    display: block;
    width: 100%;
    height: 24px;
    min-height: 24px;
    padding: 0 22px 1px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font: inherit;
    font-size: .68rem;
    line-height: 22px;
    cursor: pointer;
}
.cfg-outline-jump:hover,
.cfg-outline-jump:focus {
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border-color));
    outline: none;
    box-shadow: none;
}
.cfg-outline-goto {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: color .12s, border-color .12s, background-color .12s;
}
.cfg-outline-goto svg { width: 12px; height: 12px; opacity: .85; }
.cfg-outline-goto:hover,
.cfg-outline-goto[aria-expanded="true"] {
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border-color));
    background: var(--accent-soft);
    color: var(--text-primary);
}
.cfg-outline-goto:focus-visible,
.cfg-outline-chip:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
    outline-offset: 1px;
}
.cfg-outline-jump:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
    outline-offset: 1px;
    box-shadow: none;
}
.cfg-outline-palette {
    position: absolute;
    top: calc(100% + 3px);
    right: 0;
    left: auto;
    z-index: 40;
    width: min(320px, calc(100vw - 48px));
    padding: 5px;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}
.cfg-outline-palette[hidden] { display: none !important; }
.cfg-outline-palette input[type=search] {
    width: 100%;
    height: 28px;
    min-height: 28px;
    padding: 0 8px;
    margin-bottom: 4px;
    font-size: .78rem;
    border-radius: var(--radius-sm);
}
.cfg-outline-palette-list {
    max-height: 280px;
    overflow-y: auto;
}
.cfg-outline-palette-group {
    padding: 6px 8px 2px;
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.cfg-outline-palette-item {
    display: flex;
    align-items: baseline;
    gap: 6px;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 5px 8px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    font-size: .78rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}
.cfg-outline-palette-item > span:first-child {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cfg-outline-palette-item:hover,
.cfg-outline-palette-item.is-active {
    background: var(--accent-soft);
}
.cfg-outline-palette-item .hint {
    margin: 0;
    flex: 0 1 auto;
    max-width: 42%;
    font-size: .68rem;
    font-weight: 500;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cfg-outline-palette-empty {
    padding: 8px 10px;
    font-size: .78rem;
    color: var(--text-muted);
}
.ace_marker-layer .cfg-outline-flash {
    position: absolute;
    background: color-mix(in srgb, var(--accent) 28%, transparent);
}

/* ---- Status / flash ---- */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-weight: 600; }
.flash-ok { background: rgba(58,138,95,.12); color: var(--ok); border: 1px solid rgba(58,138,95,.3); }
.flash-err { background: rgba(179,71,58,.12); color: var(--err); border: 1px solid rgba(179,71,58,.3); }
.toast-wrap { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 1000; }
.toast { background: var(--bg-surface); border: 1px solid var(--border-color); border-left: 4px solid var(--accent); box-shadow: var(--shadow-md); border-radius: var(--radius); padding: 12px 16px; min-width: 260px; max-width: 380px; color: var(--text-primary); animation: slidein .2s ease; }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Interface picker ---- */
.iface-group { margin-bottom: 14px; }
.iface-group h4 { color: var(--text-muted); text-transform: uppercase; font-size: .72rem; letter-spacing: .04em; margin-bottom: 8px; }
.iface-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.iface {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px;
    border: 1px solid var(--border-strong); border-radius: var(--radius); cursor: pointer; background: var(--bg-surface);
}
.iface:hover { background: var(--accent-soft); }
.iface.sel { border-color: var(--accent); background: var(--accent-soft); }
.iface.auto-det { border-color: var(--ok); background: rgba(46, 132, 87, 0.12); }
.iface.auto-det:hover { background: rgba(46, 132, 87, 0.18); }
.iface .name { font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.iface .iface-icon {
    display: inline-flex;
    flex: none;
    color: var(--text-muted);
}
.iface .iface-icon svg { width: 18px; height: 18px; }
.iface.sel .iface-icon { color: var(--accent); }
.iface.auto-det .iface-icon { color: var(--ok); }
.iface .det { font-size: .7rem; color: var(--ok); font-weight: 700; margin-left: auto; flex-shrink: 0; white-space: nowrap; }

/* ---- Log ---- */
.logbox { background: var(--bg-code); color: #e6e9ec; border-radius: var(--radius); padding: 12px; height: var(--editor-h); min-height: 360px; overflow-y: auto; font-family: 'Monaco','Menlo','Consolas',monospace; font-size: .82rem; line-height: 1.5; }
.logline { white-space: pre-wrap; word-break: break-word; }
.logline .t { color: #6b7783; }
.logline .s { font-weight: 700; }
.logline.s-clash .s { color: #6fb1ff; }
.logline.s-gateway .s { color: #c792ea; }
.logline.s-ssclash .s { color: #f0c674; }
.logline.lv-warn { color: #f0c674; }
.logline.lv-error { color: #ff8b7a; }

/* ---- Misc ---- */
.kernel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kernel-head-actions { flex-wrap: nowrap; align-items: center; }
.kernel-channel {
    width: auto; flex: none; box-sizing: border-box;
    height: var(--control-h-sm); min-height: var(--control-h-sm);
    padding: 0 22px 0 10px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--bg-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 8px center;
    color: var(--text-primary); font: inherit; font-size: .8125rem; line-height: 1;
    cursor: pointer; appearance: none; -webkit-appearance: none;
}
.kernel-channel:hover,
.kernel-channel:focus {
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border-strong));
    outline: none;
}
.hwid-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; }
.hwid-grid .field { margin-bottom: 0; }
.cfg-subs-body { padding-top: 10px; padding-bottom: 10px; }
.cfg-subs-row {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 10px 12px; border: 1px solid var(--border-color); border-radius: var(--radius);
    background: var(--bg-surface); margin-bottom: 8px;
}
.cfg-subs-row:last-child { margin-bottom: 0; }
.cfg-subs-name { font-weight: 700; color: var(--text-primary); }
.cfg-subs-meta { font-size: .82rem; color: var(--text-muted); }
.cfg-subs-actions { display: flex; gap: 6px; margin-left: auto; }
.cfg-subs-row.cfg-subs-disabled { opacity: .72; }
.cfg-subs-row.cfg-subs-disabled .cfg-subs-name { color: var(--text-muted); }
.kv { background: var(--bg-surface-2); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 10px 12px; }
.kv .k { font-size: .72rem; text-transform: uppercase; color: var(--text-muted); letter-spacing: .04em; }
.kv .val { font-weight: 700; color: var(--text-primary); font-size: 1rem; margin-top: 2px; }
.count-badge { font-size: .7rem; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: rgba(127,127,127,.16); color: var(--text-secondary); white-space: nowrap; }

/* Reserved network CIDR chips (Settings → Options) */
.cidr-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 36px;
    max-height: 148px;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-surface-2);
}
.cidr-chips.reserved-chips:empty::after {
    content: "No networks — add a CIDR or reset to defaults";
    color: var(--text-muted);
    font-size: .82rem;
    padding: 4px 2px;
}
.cidr-chips.port-chips:empty::after {
    content: "None — leave empty for default (bypass off / all ports)";
}
.cidr-chips-placeholder {
    color: var(--text-muted);
    font-size: .82rem;
    padding: 4px 2px;
}
.cidr-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 100%;
    padding: 3px 4px 3px 8px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: .75rem;
    line-height: 1.35;
}
.cidr-chip.is-cgnat {
    border-color: color-mix(in srgb, var(--warn) 45%, var(--border-color));
    background: color-mix(in srgb, var(--warn) 10%, var(--bg-surface));
}
.cidr-chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cidr-chip-x {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 20px;
    height: 20px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}
.cidr-chip-x svg {
    display: block;
    width: 10px;
    height: 10px;
    flex: none;
}
.cidr-chip-x:hover { background: var(--accent-soft); color: var(--err); }
.cidr-chip-x:hover svg { stroke: var(--err); }
.cidr-chips-add {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: center;
}
.cidr-chips-add input {
    flex: 1;
    min-width: 0;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: .82rem;
}

.cidr-details { margin: 0; }
.cidr-details > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    list-style: none;
    padding: 9px 0;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-weight: 600;
    font-size: .92rem;
}
.cidr-details > summary::-webkit-details-marker { display: none; }
.cidr-details > summary::before {
    content: '▸';
    display: inline-block;
    width: 1em;
    color: var(--text-muted);
    font-weight: 400;
    transition: transform .15s ease;
}
.cidr-details[open] > summary::before { transform: rotate(90deg); }
.cidr-details[open] > summary { border-bottom-color: transparent; }
.cidr-details-title { flex: 1; min-width: 0; }
.cidr-details-body { padding: 0 0 4px; }

.empty-state { padding: 26px 16px; border: 1px dashed var(--border-strong); border-radius: var(--radius); text-align: center; color: var(--text-muted); font-size: .9rem; }
.code-example { margin-bottom: 14px; font-family: 'Monaco','Menlo','Consolas',monospace; font-size: .8rem; background: var(--bg-surface-2); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 10px 12px; white-space: pre; overflow-x: auto; color: var(--text-secondary); }

/* ---- Rule list accordion (collapsible) ---- */
.rs-prefix-details { margin: 0; }
.rs-prefix-details summary {
    cursor: pointer;
    font-size: .82rem;
    color: var(--text-muted);
    user-select: none;
    list-style: none;
}
.rs-prefix-details summary::-webkit-details-marker { display: none; }
.rs-prefix-details summary::before {
    content: '▸';
    display: inline-block;
    width: 1em;
    margin-right: 2px;
    transition: transform .15s ease;
}
.rs-prefix-details[open] summary::before { transform: rotate(90deg); }
.rs-prefix-details[open] summary { color: var(--text-secondary); margin-bottom: 6px; }
.rs-prefix-details .hint { margin: 0 0 8px; font-size: .8rem; }
.rs-prefix-legend {
    margin: 0;
    padding: 8px 10px;
    font-size: .74rem;
    line-height: 1.4;
}

.rs-item { border: 1px solid var(--border-color); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.rs-item-head { display: flex; align-items: center; gap: 10px; padding: 11px 14px; cursor: pointer; user-select: none; background: var(--bg-surface-2); }
.rs-item-head:hover { background: var(--accent-soft); }
.rs-caret { width: 0; height: 0; border-left: 6px solid var(--text-muted); border-top: 5px solid transparent; border-bottom: 5px solid transparent; transition: transform .18s ease; flex: none; }
.rs-item.open .rs-caret { transform: rotate(90deg); }
.rs-name { flex: 1; min-width: 0; font-size: .95rem; font-weight: 700; color: var(--text-primary); }
.rs-head-end { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: none; }
.rs-item-head .rs-add-config {
    cursor: pointer;
    background: transparent;
    border-color: var(--border-color);
    box-shadow: none;
    color: var(--text-secondary);
}
.rs-item-head .rs-add-config svg { opacity: .85; }
.rs-item-head .rs-add-config:hover {
    background: var(--border-color);
    border-color: var(--border-color);
    color: var(--text-primary);
}
.rs-item-head .rs-add-config:hover svg { opacity: 1; }
.rs-item-head .rs-add-config:active { transform: none; box-shadow: none; }
.rs-item-body { display: none; padding: 14px; }
.rs-item.open .rs-item-body { display: block; }
/* Card body: uniform vertical rhythm — stack via margin-top, no trailing margin-bottom */
.card-body > * { margin-bottom: 0; }
.card-body > * + * { margin-top: 16px; }
/* Hidden/empty remote hint must not push the editor (sibling margin still applies). */
.card-body > .cfg-remote-hint[hidden] + *,
.card-body > .cfg-remote-hint:empty + * { margin-top: 0; }
.card-body > .cfg-remote-hint[hidden] + .cfg-editor-wrap,
.card-body > .cfg-remote-hint:empty + .cfg-editor-wrap { margin-top: 0; }
.card-body > .cfg-remote-hint:not([hidden]) {
  margin: 0;
  color: var(--text-muted);
  font-size: .82rem;
  line-height: 1.4;
  cursor: pointer;
  border-radius: 6px;
  padding: 8px 10px;
  background: rgba(127, 127, 127, 0.08);
  transition: background .15s ease, color .15s ease;
}
.card-body > .cfg-remote-hint:not([hidden]):hover {
  color: var(--text-primary);
  background: rgba(127, 127, 127, 0.14);
}
.card-body > .cfg-remote-hint:not([hidden]):focus-visible {
  outline: 2px solid var(--accent, #3b82f6);
  outline-offset: 2px;
}
.modal-wide .cfg-remote-interval {
  margin-top: 14px;
  margin-bottom: 0;
}
.modal-wide .cfg-remote-interval > label {
  display: block;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.modal-wide .cfg-remote-interval .seg { margin: 0 0 8px; }
.modal-wide .cfg-remote-interval > .hint { margin: 0; }
.modal-wide .cfg-remote-interval-hours {
  margin-top: 12px;
  max-width: 140px;
}
.modal-wide .cfg-remote-interval-hours > label {
  display: block;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 5px;
}
.modal-wide .cfg-remote-interval[hidden],
.modal-wide .cfg-remote-interval-hours[hidden] { display: none !important; }
.card-body > .hint:empty { display: none; }
.card-body > .switch-row + .switch-row { margin-top: 0; }
.card-body .field,
.card-body .kernel-grid { margin-bottom: 0; }
.card-body > .switch-row:first-child { padding-top: 0; }
.card-body > .rs-item { margin-top: 14px; margin-bottom: 0; }
.card-body > .rs-item:first-child { margin-top: 0; }
.card-body #iface-picker .iface-group:last-child,
.card-body #rs-lists .rs-item:last-child { margin-bottom: 0; }
.rs-item-body .editor { height: 480px; min-height: 320px; margin-bottom: 12px; }
.rs-prefix-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}
.rs-prefix-btn {
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 11px;
    padding: 4px 8px;
    line-height: 1.2;
}
.rs-actions { justify-content: center; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid color-mix(in srgb, currentColor 35%, transparent); border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; }

.icon-btn:focus-visible, .tab:focus-visible, .seg button:focus-visible, .btn:focus-visible, .svc-action:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.footer {
    margin-top: 32px;
    padding-bottom: 14px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px 10px;
    font-size: .72rem;
    color: var(--text-muted);
    line-height: 1.4;
    letter-spacing: 0.01em;
}
.footer a { color: var(--text-muted); text-decoration: none; font-weight: 500; transition: color .15s ease; }
.footer a:hover { color: var(--text-secondary); text-decoration: none; }
.footer .f-name {
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: -0.01em;
}
.footer .f-meta { color: var(--text-muted); }
.footer .f-sep {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--text-muted) 40%, transparent);
    flex: none;
}
.footer .f-update[hidden] { display: none !important; }
.footer .f-update.is-unavailable,
.footer .f-update.is-dev { color: var(--text-muted); font-size: .7rem; }
.footer .f-update a {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: .7rem;
    text-decoration: none;
    border-bottom: 1px solid color-mix(in srgb, var(--warn) 55%, transparent);
}
.footer .f-update a:hover { color: var(--warn); border-bottom-color: var(--warn); }
.footer .f-update.is-current {
    color: var(--ok);
    font-weight: 600;
    font-size: .7rem;
}
.version-footer {
    margin-top: 20px; padding: 10px 0; border-top: 1px solid rgba(127,127,127,0.15);
    text-align: center; color: var(--text-muted); font-size: 11px;
}
.version-footer a { color: var(--text-muted); }
.version-footer a:hover { color: var(--link); }
.version-footer .dot { margin: 0 6px; opacity: 0.35; }

.cfg-profile-menu {
    left: 0;
    right: auto;
    min-width: 168px;
}

/* ---- Modal ---- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal[hidden] { display: none; }
.modal-scrim {
    position: absolute;
    inset: 0;
    background: rgba(15, 18, 22, 0.45);
    backdrop-filter: blur(2px);
}
[data-theme="dark"] .modal-scrim,
[data-theme="auto"] .modal-scrim { background: rgba(0, 0, 0, 0.62); }
.modal-dialog {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    max-height: min(88vh, 560px);
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    animation: modal-in .18s ease;
}
.modal-dialog:has(.modal-wide) {
    max-width: 520px;
}
@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px) scale(.98); }
    to { opacity: 1; transform: none; }
}
.modal-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px 12px;
    border-bottom: 1px solid var(--border-color);
}
.modal-head h3 {
    flex: 1;
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}
.modal-close {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    color: var(--text-muted);
    min-width: 30px;
    padding: 0;
}
.modal-close svg { width: 16px; height: 16px; }
.modal-close:hover {
    background: var(--accent-soft);
    border-color: transparent;
    color: var(--text-primary);
}
.modal-body {
    padding: 16px 18px;
    overflow: auto;
    flex: 1;
    min-height: 0;
}
.modal-body .field:last-child { margin-bottom: 0; }
.modal-hint {
    color: var(--text-muted);
    font-size: .84rem;
    line-height: 1.45;
    margin-bottom: 14px;
}
.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px 16px;
    border-top: 1px solid var(--border-color);
}
.modal-foot #app-modal-secondary[hidden] { display: none !important; }
.profile-pick-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: .82rem;
}
.profile-pick-toolbar .link-btn {
    border: 0;
    background: none;
    padding: 0;
    color: var(--link);
    font: inherit;
    font-size: inherit;
    cursor: pointer;
}
.profile-pick-toolbar .link-btn:hover { text-decoration: underline; }
.profile-pick-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    max-height: 240px;
    overflow-y: auto;
}
.profile-pick-list li + li { border-top: 1px solid var(--border-color); }
.profile-pick-list label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background .15s ease;
}
.profile-pick-list label:hover { background: var(--accent-soft); }
.profile-pick-list input[type=checkbox] {
    width: auto;
    margin: 0;
    flex: none;
    accent-color: var(--accent);
}
.profile-pick-list .name {
    flex: 1;
    color: var(--text-primary);
    font-weight: 600;
    font-size: .88rem;
}
.profile-pick-list .badge {
    font-size: .72rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 2px 7px;
    border-radius: 999px;
}
.profile-pick-list li.is-disabled label {
    cursor: default;
    opacity: .72;
}
.profile-pick-list li.is-disabled label:hover { background: transparent; }
.profile-pick-list .badge.mono {
    font-family: var(--mono, ui-monospace, monospace);
    letter-spacing: -.02em;
}
.keenetic-policy-list {
    margin: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius, 8px);
    overflow: hidden;
}
.keenetic-policy-list .hint {
    color: var(--text-muted);
    font-size: .78rem;
}
.profile-pick-empty {
    padding: 18px 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: .86rem;
}

body.modal-open { overflow: hidden; }

/* ---- Auth ---- */
.auth-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius); box-shadow: var(--shadow-md); width: 100%; max-width: 380px; padding: 28px; }
.auth-card h1 { text-align: center; margin-bottom: 6px; }
.auth-card .sub { text-align: center; color: var(--text-muted); margin-bottom: 20px; }

@media (max-width: 980px) {
    .overview { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 820px) {
    .nav-toggle { display: inline-flex; }
    .sidebar {
        position: fixed; top: var(--topbar-h); left: 0; z-index: 35;
        height: calc(100vh - var(--topbar-h));
        transform: translateX(-100%); transition: transform .2s ease;
        box-shadow: var(--shadow-md);
    }
    body.nav-open .sidebar { transform: none; }
    body.nav-open .nav-scrim { display: block; }
    .svc-status .txt { display: none; }
    .svc-seg { padding: 0 11px; }
    .topbar .brand-text { display: none; }
    .iface-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
    .hwid-grid { grid-template-columns: repeat(2, 1fr); }

    /* Page bar (Settings): title block + full-width primary action */
    .page-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 10px 0;
    }
    .page-bar .spacer { display: none; }
    .page-bar > .btn { width: 100%; }

    /* Card headers: structured rows instead of random flex-wrap */
    .card-head {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 10px;
        align-items: center;
        padding: 12px 14px;
    }
    .card-head .spacer { display: none; }
    .card-head-text { grid-column: 1 / -1; }
    .card-head > h2 { grid-column: 1; min-width: 0; }
    .card-head > .sub { grid-column: 1 / -1; margin-top: -4px; }
    .card-head > h2 + .sub { grid-column: 1 / -1; }
    .card-head-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
        justify-content: flex-end;
        margin-left: 0;
    }
    .card-head > h2 + .card-head-actions:has(.btn:only-child) {
        grid-column: 2;
        grid-row: 1;
    }
    .card-head-actions:not(:has(.btn:only-child)) {
        grid-column: 1 / -1;
        justify-content: space-between;
    }
    .card-head-log .card-head-actions-log {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }
    .kernel-head-actions {
        flex-direction: column;
        align-items: stretch;
        justify-content: stretch;
    }
    .kernel-head-actions .kernel-channel,
    .kernel-head-actions .btn {
        width: 100%;
        flex: 1 1 auto;
    }
    .card-head-actions .btn { min-width: 0; }
    .card-head:not(.card-head-log) .card-head-actions:not(:has(.btn:only-child)) .btn {
        flex: 1 1 calc(50% - 4px);
    }
    .card-head-log .card-head-actions-log {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        gap: 8px;
    }
    .card-head-log .card-head-actions-log .btn {
        flex: none;
        width: auto;
    }

    /* Configuration: profile on title row, icons + actions stacked below */
    .card-head-config > h2 { grid-column: 1; grid-row: 1; }
    .card-head-config .cfg-profile {
        grid-column: 2;
        grid-row: 1;
        margin-left: 0;
        justify-self: end;
    }
    .card-head-config .cfg-io {
        grid-column: 1 / -1;
        margin-left: 0;
        gap: 6px;
        justify-content: flex-start;
    }
    .cfg-outline-rail { display: none; }
    .cfg-outline.is-jump-only .cfg-outline-jump-wrap,
    .cfg-outline-jump-wrap {
        flex: 1 1 auto;
        max-width: none;
    }
    .cfg-outline-palette {
        left: 0;
        right: 0;
        width: auto;
    }
    .card-head-config > .cfg-actions {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        width: 100%;
    }
    .card-head-config > .cfg-actions .btn-row-sep { display: none; }
    .card-head-config > .cfg-actions > .btn,
    .card-head-config > .cfg-actions > .btn-split {
        width: 100%;
        min-width: 0;
    }
    .card-head-config > .cfg-actions .btn-split {
        display: flex;
    }
    .card-head-config > .cfg-actions .btn-split-main {
        flex: 1;
        min-width: 0;
        padding-left: 8px;
        padding-right: 8px;
    }
    .card-head-config > .cfg-actions .btn-split-toggle {
        flex: none;
        padding: 0 7px;
    }
}

@media (max-width: 480px) {
    .overview { grid-template-columns: 1fr 1fr; }
    .hwid-grid { grid-template-columns: 1fr; }
    .card-head:not(.card-head-log) .card-head-actions:not(:has(.btn:only-child)) {
        flex-direction: column;
    }
    .card-head:not(.card-head-log) .card-head-actions:not(:has(.btn:only-child)) .btn {
        flex: 1 1 auto;
        width: 100%;
    }
}
