:root {
    color-scheme: dark;
    --bg: #0f1012;
    --panel: #17191c;
    --panel-soft: #1e2227;
    --text: #eef2f6;
    --muted: #9aa4b2;
    --line: #2b3037;
    --brand: #14b8a6;
    --brand-dark: #0f9487;
    --ok: #35d487;
    --bad: #fb7185;
    --warn: #f59e0b;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
}
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }
button, .button {
    border: 1px solid var(--line);
    background: #22262c;
    color: var(--text);
    height: 34px;
    padding: 0 12px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}
button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.primary:hover { background: var(--brand-dark); }
.danger { background: #be123c; border-color: #be123c; color: #fff; }
.danger:hover { background: #9f1239; }
input, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    background: #101215;
    color: var(--text);
}
input::placeholder, textarea::placeholder { color: #697280; }
label { display: grid; gap: 6px; color: var(--muted); font-weight: 600; }
code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    background: #101215;
    border: 1px solid #2a3038;
    color: #dce7f4;
    padding: 2px 5px;
    border-radius: 4px;
}
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 188px;
    background: #090b0f;
    color: #d6dde7;
    padding: 18px 12px;
    transition: width .18s ease;
    z-index: 20;
}
.nav-state { position: absolute; opacity: 0; pointer-events: none; }
.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 8px 4px 22px;
}
.brand {
    font-size: 19px;
    font-weight: 800;
    color: white;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar-toggle,
.mobile-menu-toggle {
    border: 1px solid #334155;
    border-radius: 6px;
    color: #dbe4f0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    padding: 0 8px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}
.sidebar-toggle:hover { background: #1d222a; color: #fff; }
.mobile-menu-toggle { display: none; color: var(--text); border-color: var(--line); background: #22262c; }
.sidebar nav { display: grid; gap: 4px; }
.sidebar a {
    padding: 11px 12px;
    border-radius: 7px;
    color: #aab3bf;
}
.sidebar a.active, .sidebar a:hover {
    background: #1f2937;
    color: white;
}
.nav-state:checked ~ .sidebar {
    width: 72px;
    padding-inline: 8px;
}
.nav-state:checked ~ .sidebar .brand {
    width: 34px;
    font-size: 0;
    overflow: visible;
}
.nav-state:checked ~ .sidebar .brand::before {
    content: "剪";
    display: inline-flex;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: #1f2937;
    color: #fff;
    font-size: 16px;
}
.nav-state:checked ~ .sidebar .brand-row {
    justify-content: center;
    margin-inline: 0;
}
.nav-state:checked ~ .sidebar .sidebar-toggle {
    width: 42px;
    padding: 0;
    font-size: 0;
}
.nav-state:checked ~ .sidebar .sidebar-toggle::after { content: "开"; font-size: 12px; }
.nav-state:checked ~ .sidebar a {
    padding-inline: 4px;
    text-align: center;
    font-size: 12px;
}
.nav-state:checked ~ .main { margin-left: 72px; }
.main {
    margin-left: 188px;
    padding: 24px;
    min-width: 0;
    transition: margin-left .18s ease;
}
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}
.topbar h1 { margin: 0; font-size: 24px; }
.notice {
    background: #132238;
    border: 1px solid #294766;
    color: #b9d7ff;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
}
.notice.error { background: #36151c; border-color: #743142; color: #fecdd3; }
.notice.success { background: #10281f; border-color: #235c45; color: #bbf7d0; }
.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}
.stats article {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
}
.stats b { display: block; font-size: 30px; margin-bottom: 4px; }
.stats span { color: var(--muted); }
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    overflow: auto;
}
.panel.narrow { max-width: 720px; }
.panel h2 { margin: 0 0 14px; font-size: 17px; }
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}
.panel-head p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 13px;
}
.panel-head.compact {
    margin-bottom: 10px;
}
.panel-head.compact h2 {
    margin: 0;
}
.panel-head.compact a {
    color: var(--brand);
    font-size: 13px;
    font-weight: 700;
}
.code-toolbar {
    display: grid;
    grid-template-columns: minmax(360px, 1fr) minmax(360px, 520px);
    gap: 14px;
    align-items: center;
    margin-bottom: 10px;
}
.filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.filter-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #20242a;
    color: var(--muted);
    font-weight: 700;
    white-space: nowrap;
}
.filter-chip.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #06201d;
}
.search {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    min-width: 0;
}
.search input { min-width: 0; }
.search button { width: 72px; flex: 0 0 72px; }
.search .button { flex: 0 0 auto; }
.list-summary {
    color: var(--muted);
    font-size: 13px;
    margin: 2px 0 8px;
}
.grid-form {
    display: grid;
    grid-template-columns: 120px 220px 1fr auto;
    align-items: end;
    gap: 12px;
}
.stack-form { display: grid; gap: 14px; }
table { width: 100%; border-collapse: collapse; }
th, td {
    border-bottom: 1px solid var(--line);
    text-align: left;
    padding: 10px 8px;
    vertical-align: top;
}
th {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}
td { white-space: nowrap; }
td:nth-child(7) { white-space: normal; min-width: 180px; }
.badge {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    background: #e5e7eb;
}
.badge.ok { background: #123827; color: #78f0af; }
.badge.bad { background: #411620; color: #fda4af; }
.actions { display: flex; gap: 6px; }
.actions form { margin: 0; }
.inline-edit { display: contents; }
.inline-edit input { width: 150px; }
.codes-workbench {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 16px;
    align-items: start;
}
.codes-main {
    min-width: 0;
}
.codes-side {
    min-width: 0;
    display: grid;
    gap: 16px;
    position: sticky;
    top: 24px;
}
.side-card {
    margin-bottom: 0;
    overflow: visible;
}
.codes-table {
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    min-width: 1040px;
}
.codes-table-head,
.codes-row {
    display: grid;
    grid-template-columns: 286px 76px minmax(130px, 1fr) 190px 150px;
    gap: 12px;
    align-items: center;
    min-height: 46px;
    padding: 0 12px;
    border-bottom: 1px solid var(--line);
}
.codes-table-head {
    min-height: 38px;
    background: #20242a;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}
.codes-row {
    color: var(--text);
    font-size: 13px;
    background: #17191c;
}
.codes-row:last-child {
    border-bottom: 0;
}
.codes-row:hover,
.codes-row.selected {
    background: #182b2a;
}
.codes-row span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.codes-table-head span:first-child,
.codes-row span:first-child {
    overflow: visible;
    text-overflow: clip;
}
.codes-row span:first-child code {
    display: inline-block;
    min-width: 252px;
    white-space: nowrap;
}
.side-card .stack-form {
    gap: 10px;
}
.side-card label code {
    min-height: 34px;
    display: flex;
    align-items: center;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}
.side-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}
.side-actions form,
.side-actions button {
    width: 100%;
}
.side-log {
    display: grid;
    gap: 10px;
}
.side-log-item {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 10px;
}
.side-log-item time {
    color: var(--muted);
    font-weight: 800;
    font-size: 12px;
}
.side-log-item p {
    margin: 0;
    line-height: 1.45;
    color: var(--text);
    font-size: 13px;
}
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.empty-state {
    color: var(--muted);
    padding: 16px;
    text-align: center;
}
.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at 20% 10%, #19312e 0, #0f1012 36%, #090b0f 100%);
}
.login-card, .install-card {
    width: min(440px, calc(100vw - 32px));
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 26px;
    display: grid;
    gap: 16px;
    box-shadow: 0 22px 60px rgba(0,0,0,.22);
}
.login-card h1, .install-card h1 { margin: 0 0 4px; }

@media (max-width: 920px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-form { grid-template-columns: 1fr 1fr; }
    .grid-form .wide { grid-column: 1 / -1; }
    .grid-form button { width: 100%; }
    .code-toolbar { grid-template-columns: 1fr; }
    .search { justify-content: stretch; }
    .codes-workbench { grid-template-columns: 1fr; }
    .codes-side {
        position: static;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .codes-side .side-card:last-child {
        grid-column: 1 / -1;
    }
}

@media (max-width: 720px) {
    body { font-size: 13px; }
    .sidebar {
        position: sticky;
        top: 0;
        width: 100%;
        padding: 10px 12px;
        border-bottom: 1px solid #253147;
    }
    .brand-row {
        margin: 0;
    }
    .brand { font-size: 17px; }
    .sidebar-toggle { display: none; }
    .mobile-menu-toggle { display: inline-flex; }
    .sidebar nav {
        display: none;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        margin-top: 10px;
    }
    .nav-state:checked ~ .sidebar {
        width: 100%;
        padding: 10px 12px;
    }
    .nav-state:checked ~ .sidebar .brand {
        width: auto;
        font-size: 17px;
    }
    .nav-state:checked ~ .sidebar .brand::before {
        content: none;
    }
    .nav-state:checked ~ .sidebar .brand-row {
        justify-content: space-between;
    }
    .nav-state:checked ~ .sidebar nav {
        display: grid;
    }
    .nav-state:checked ~ .sidebar a {
        text-align: left;
        font-size: 13px;
        padding: 10px 11px;
    }
    .main,
    .nav-state:checked ~ .main {
        margin-left: 0;
        padding: 14px;
    }
    .topbar {
        gap: 10px;
        margin-bottom: 12px;
    }
    .topbar h1 { font-size: 22px; }
    .panel {
        padding: 12px;
        margin-bottom: 12px;
    }
    .panel-head {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
    }
    .stats { grid-template-columns: 1fr; }
    .grid-form { grid-template-columns: 1fr; }
    .filter-group {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 4px;
    }
    .filter-chip { flex: 0 0 auto; }
    .search {
        display: grid;
        grid-template-columns: 1fr 72px;
    }
    .search .button {
        grid-column: 1 / -1;
        width: 100%;
    }
    th, td { padding: 9px 7px; }
    .actions { gap: 5px; }
    .actions button { padding: 0 10px; }
    .codes-side { grid-template-columns: 1fr; }
    .codes-side .side-card:last-child { grid-column: auto; }
    .codes-table { min-width: 900px; }
    .codes-table-head,
    .codes-row {
        grid-template-columns: 260px 72px minmax(120px, 1fr) 150px 120px;
        gap: 8px;
        padding-inline: 10px;
    }
    .codes-row span:first-child code { min-width: 236px; }
}
