:root {
    --bg: #eef1f2;
    --surface: #ffffff;
    --surface-muted: #f6f8f8;
    --line: #d7ddde;
    --line-strong: #bcc6c7;
    --ink: #172022;
    --muted: #687476;
    --green: #24765b;
    --green-dark: #185943;
    --green-soft: #e4f1ec;
    --amber: #9a6514;
    --amber-soft: #fff3da;
    --red: #ad3c34;
    --red-soft: #fae9e7;
    --shadow: 0 8px 24px rgba(23, 32, 34, 0.08);
    --radius: 6px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
    margin: 0;
    color: var(--ink);
    background: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    letter-spacing: 0;
}

button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible {
    outline: 3px solid rgba(36, 118, 91, 0.22);
    outline-offset: 1px;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 216px minmax(0, 1fr);
    grid-template-rows: 64px minmax(0, 1fr);
}

.topbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    color: #f7fbfa;
    background: #172022;
    border-bottom: 1px solid #293638;
}

.brand-mark {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    color: #10231c;
    background: #6bc39f;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 800;
}

.brand-copy { display: flex; flex-direction: column; line-height: 1.15; }
.brand-copy strong { font-size: 15px; }
.brand-copy span { margin-top: 3px; color: #9babab; font-size: 11px; }
.mod-switcher { width: min(260px, 24vw); margin-left: 22px; }
.mod-switcher > span { margin: 0 0 3px; color: #8fa09e; font-size: 9px; }
.mod-switcher select { height: 30px; color: #edf5f2; background: #263234; border-color: #415052; }
.topbar-status { margin-left: auto; display: flex; align-items: center; gap: 8px; color: #b7c6c4; font-size: 12px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #6bc39f; box-shadow: 0 0 0 3px rgba(107, 195, 159, 0.14); }
.topbar-status.offline .status-dot { background: #d86559; box-shadow: none; }
.account-menu { display: flex; align-items: center; gap: 5px; padding-left: 10px; border-left: 1px solid #394648; color: #b7c6c4; font-size: 11px; }
.account-menu .mini-button { color: #b7c6c4; }
.account-menu .mini-button:hover { color: white; background: #293638; border-color: #415052; }

.sidebar {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    padding: 20px 12px 16px;
    background: #202a2c;
    border-right: 1px solid #303c3e;
}

.sidebar nav { display: grid; gap: 4px; }
.nav-button {
    width: 100%;
    height: 44px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px;
    color: #b8c3c4;
    background: transparent;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    text-align: left;
}
.nav-button:hover { color: #fff; background: #293638; }
.nav-button.active { color: #fff; background: #334244; }
.nav-index { width: 22px; color: #6f8183; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.nav-button.active .nav-index { color: #6bc39f; }
.sidebar-meta { margin-top: auto; display: grid; gap: 5px; padding: 12px; color: #718183; font-size: 11px; border-top: 1px solid #334042; }

.main-content {
    grid-column: 2;
    grid-row: 2;
    min-width: 0;
    padding: 26px;
    overflow: auto;
}

.view { display: none; max-width: 1480px; margin: 0 auto; }
.view.active { display: block; }
.view-heading { min-height: 58px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.view-heading h1 { margin: 2px 0 0; font-size: 24px; line-height: 1.2; }
.eyebrow { margin: 0; color: var(--green); font-size: 10px; font-weight: 800; letter-spacing: 1.4px; }
.heading-stat { align-self: center; color: var(--muted); font-variant-numeric: tabular-nums; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.full-panel { overflow: hidden; }
.panel-toolbar { min-height: 68px; display: flex; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.split-toolbar { justify-content: space-between; gap: 20px; }
.toolbar-note { color: var(--muted); font-size: 12px; }

.button {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 14px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.button:hover { background: var(--surface-muted); border-color: #9facad; }
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button.primary { color: white; background: var(--green); border-color: var(--green); }
.button.primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.button.danger { color: white; background: var(--red); border-color: var(--red); }
.button.danger:hover { background: #8f302a; border-color: #8f302a; }
.button.secondary { background: var(--surface-muted); }
.button.quiet { min-height: 30px; padding: 0 10px; color: var(--muted); background: transparent; border-color: transparent; }
.button.quiet:hover { color: var(--ink); background: var(--surface-muted); border-color: var(--line); }
.button.danger-text { color: var(--red); background: transparent; border-color: transparent; }
.button.danger-text:hover { background: var(--red-soft); border-color: #e6bbb7; }
.link-button { line-height: 34px; }

label > span, .search-field > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
input, textarea, select {
    width: 100%;
    color: var(--ink);
    background: white;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
}
input, select { height: 38px; padding: 0 10px; }
textarea { padding: 10px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #9aa4a6; }
input[readonly] { color: var(--muted); background: var(--surface-muted); }
.search-field { width: 100%; }
.search-field > span { margin-bottom: 5px; }
.wide-search { max-width: 520px; }

.player-layout { display: grid; grid-template-columns: 310px minmax(560px, 1fr); gap: 14px; min-height: calc(100vh - 166px); }
.player-browser, .player-editor { min-height: 620px; overflow: hidden; }
.player-browser { display: flex; flex-direction: column; }
.result-summary { padding: 9px 14px; color: var(--muted); background: var(--surface-muted); border-bottom: 1px solid var(--line); font-size: 12px; }
.player-list { flex: 1; min-height: 0; overflow: auto; }
.player-row {
    width: 100%;
    min-height: 68px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    color: var(--ink);
    background: white;
    border: 0;
    border-bottom: 1px solid var(--line);
    cursor: pointer;
    text-align: left;
}
.player-row:hover { background: var(--surface-muted); }
.player-row.active { background: var(--green-soft); box-shadow: inset 3px 0 var(--green); }
.player-row-main { min-width: 0; display: grid; gap: 5px; }
.player-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.player-row small { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.player-row-meta { display: grid; justify-items: end; gap: 5px; color: var(--muted); font-size: 11px; }

.empty-state { min-height: 620px; display: grid; place-content: center; justify-items: center; gap: 7px; color: var(--muted); }
.empty-state strong { color: var(--ink); font-size: 16px; }
.player-editor form { padding: 22px; }
.editor-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.editor-header h2 { margin: 3px 0 0; font-size: 20px; }
.record-state { padding: 6px 9px; color: var(--muted); background: var(--surface-muted); border: 1px solid var(--line); border-radius: 4px; font-size: 11px; }
.record-state.issued { color: var(--green-dark); background: var(--green-soft); border-color: #b8dbcd; }
.form-grid { display: grid; gap: 14px; }
.player-fields { grid-template-columns: minmax(220px, 0.8fr) minmax(260px, 1.2fr); }

.switch-row { position: relative; min-height: 62px; display: flex; align-items: center; margin: 16px 0; padding: 10px 12px; background: var(--surface-muted); border: 1px solid var(--line); border-radius: 4px; cursor: pointer; }
.switch-copy { min-width: 0; display: grid; gap: 3px; padding-right: 54px; }
.switch-copy strong { font-size: 13px; }
.switch-copy small { color: var(--muted); font-size: 11px; }
.switch-row input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-control { position: absolute; top: 50%; right: 12px; width: 38px; height: 22px; background: #aeb8b9; border-radius: 11px; transform: translateY(-50%); transition: background 120ms ease; }
.switch-control::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: white; border-radius: 50%; transition: transform 120ms ease; box-shadow: 0 1px 3px rgba(0,0,0,.22); }
.switch-row input:checked + .switch-control { background: var(--green); }
.switch-row input:checked + .switch-control::after { transform: translateX(16px); }

.grant-section, .cdk-section { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.section-title-row { min-height: 34px; display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.section-title-row h3 { margin: 0 0 4px; font-size: 14px; }
.section-title-row span { color: var(--muted); font-size: 11px; }
.inline-actions { display: flex; gap: 2px; }
.grant-tools { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(180px, .55fr); gap: 12px; margin: 12px 0; }
.input-action { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.table-wrap { width: 100%; overflow: auto; }
.grant-table-wrap { max-height: 315px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { position: sticky; top: 0; z-index: 1; padding: 10px 12px; color: var(--muted); background: #f1f4f4; border-bottom: 1px solid var(--line-strong); font-size: 11px; text-align: left; white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-muted); }
.check-column { width: 64px; text-align: center; }
.action-column { width: 150px; text-align: right; }
.grant-check { width: 16px; height: 16px; accent-color: var(--green); }
.type-label { display: inline-flex; align-items: center; min-height: 24px; padding: 0 7px; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); background: var(--surface-muted); font-size: 11px; }
.type-label.private { color: var(--amber); background: var(--amber-soft); border-color: #ead2a6; }
.covered-label { color: var(--green); font-size: 11px; }
.table-empty { height: 90px; color: var(--muted); text-align: center; }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.mini-button { min-height: 28px; padding: 0 8px; color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: 3px; cursor: pointer; }
.mini-button:hover { color: var(--ink); background: var(--surface-muted); border-color: var(--line); }
.mini-button.delete:hover { color: var(--red); background: var(--red-soft); border-color: #e6bbb7; }
.mini-button:disabled { opacity: .35; cursor: not-allowed; }
#authors-view .action-column { width: 220px; }

.cdk-section textarea { min-height: 86px; margin-top: 10px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; line-height: 1.55; word-break: break-all; }
.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.action-spacer { flex: 1; }

.catalog-table-wrap, .history-table-wrap { max-height: calc(100vh - 230px); min-height: 500px; }
.catalog-table-wrap td:nth-child(1) { width: 90px; font-weight: 700; }
.history-table-wrap { font-size: 12px; }
.history-table-wrap td:nth-child(4) { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pagination-bar { min-height: 54px; display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 8px 14px; background: var(--surface-muted); border-top: 1px solid var(--line); }
.pagination-bar .page-summary { min-width: 150px; color: var(--muted); font-size: 12px; text-align: center; }
.pagination-bar .page-size { width: auto; min-width: 92px; height: 32px; }
.pagination-bar .button { min-height: 32px; }
.grant-pagination { min-height: 48px; padding: 7px 10px; border: 1px solid var(--line); border-top: 0; }
.compact-pagination {
    min-height: 76px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(80px, 1.25fr);
    grid-template-areas:
        "summary summary summary"
        "previous next size";
    gap: 6px;
    padding: 7px 10px;
}
.compact-pagination .page-summary { grid-area: summary; min-width: 0; }
.compact-pagination .page-previous { grid-area: previous; }
.compact-pagination .page-next { grid-area: next; }
.compact-pagination .page-size { grid-area: size; width: 100%; min-width: 0; }
.compact-pagination .button { width: 100%; padding: 0 8px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.metric { min-height: 104px; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto 1fr; align-items: end; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.metric span { grid-column: 1 / -1; align-self: start; color: var(--muted); font-size: 12px; }
.metric strong { font-size: 30px; line-height: 1; }
.metric small { margin: 0 0 2px 6px; color: var(--muted); }
.data-layout { display: grid; grid-template-columns: minmax(520px, 1.2fr) minmax(320px, .8fr); gap: 14px; }
.data-panel { overflow: hidden; }
.data-section { padding: 18px; border-bottom: 1px solid var(--line); }
.data-section h2, .data-section h3 { margin: 0 0 7px; font-size: 15px; }
.data-section p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.data-section code { display: block; padding: 10px; overflow-wrap: anywhere; color: #334648; background: var(--surface-muted); border: 1px solid var(--line); border-radius: 4px; }
.action-section { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.import-mode { display: block; padding: 18px; }
.backup-panel { overflow: hidden; }
.panel-heading-row { min-height: 74px; display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-heading-row h2 { margin: 3px 0 0; font-size: 16px; }
.panel-heading-row > span { color: var(--muted); font-size: 12px; }
.backup-list { max-height: 420px; overflow: auto; }
.backup-row { min-height: 58px; display: grid; align-content: center; gap: 4px; padding: 9px 18px; border-bottom: 1px solid var(--line); }
.backup-row:last-child { border-bottom: 0; }
.backup-row strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; overflow-wrap: anywhere; }
.backup-row span { color: var(--muted); font-size: 11px; }

.settings-layout { display: grid; grid-template-columns: minmax(420px, 1fr) minmax(360px, .8fr); gap: 14px; margin-bottom: 14px; }
.settings-panel { padding-bottom: 18px; overflow: hidden; }
.settings-panel > label, .settings-panel > .form-actions, .settings-panel > .key-facts, .settings-panel > .key-actions { margin-left: 18px; margin-right: 18px; }
.settings-panel > label { display: block; margin-top: 14px; }
.settings-panel > label.switch-row { display: flex; }
.key-facts { display: grid; gap: 12px; margin-top: 16px; margin-bottom: 18px; }
.key-facts code { display: block; padding: 9px; overflow-wrap: anywhere; color: #334648; background: var(--surface-muted); border: 1px solid var(--line); border-radius: 4px; font-size: 11px; }
.key-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.member-tools { display: grid; grid-template-columns: minmax(220px, 1fr) 150px auto; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-top: 14px; padding: 18px; border-color: #e6bbb7; box-shadow: none; }
.danger-zone h2 { margin: 3px 0 6px; font-size: 16px; }
.danger-zone p:last-child { margin: 0; color: var(--muted); font-size: 12px; }
.dialog-note { margin: 0; color: var(--muted); line-height: 1.55; }

dialog { width: min(480px, calc(100vw - 32px)); padding: 0; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 22px 60px rgba(0,0,0,.24); }
dialog::backdrop { background: rgba(17, 25, 27, .56); }
#skin-form, #password-form, #new-mod-form, #author-form, #private-key-form { display: grid; gap: 15px; padding: 20px; }
#private-key-result label { display: block; }
#private-key-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 3px; }
.dialog-heading h2 { margin: 3px 0 0; font-size: 20px; }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; color: var(--muted); background: transparent; border: 0; border-radius: 3px; cursor: pointer; font-size: 24px; line-height: 1; }
.icon-button:hover { color: var(--ink); background: var(--surface-muted); }
.compact-switch { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; padding-top: 16px; border-top: 1px solid var(--line); }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; max-width: min(420px, calc(100vw - 44px)); padding: 11px 14px; color: white; background: #253234; border-radius: 4px; box-shadow: 0 12px 34px rgba(0,0,0,.22); opacity: 0; transform: translateY(8px); pointer-events: none; transition: 140ms ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }
.busy-overlay { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(238, 241, 242, .74); backdrop-filter: blur(2px); }
.busy-overlay[hidden] { display: none; }
.busy-box { min-width: 190px; display: flex; align-items: center; justify-content: center; gap: 12px; padding: 18px; background: white; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.spinner { width: 18px; height: 18px; border: 2px solid #c9d2d3; border-top-color: var(--green); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: #172022; }
.login-shell { width: min(860px, 100%); display: grid; grid-template-columns: 1fr 390px; overflow: hidden; background: white; border: 1px solid #344144; border-radius: 6px; box-shadow: 0 26px 80px rgba(0,0,0,.34); }
.login-brand { min-height: 470px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; padding: 52px; color: white; background: #202a2c; }
.login-brand .brand-mark { width: 46px; height: 46px; margin-bottom: 34px; }
.login-brand h1 { margin: 8px 0 14px; font-size: 30px; }
.login-brand > p:last-child { max-width: 370px; margin: 0; color: #a9b8b7; line-height: 1.8; }
.login-form { display: grid; align-content: center; gap: 18px; padding: 42px; }
.login-form h2 { margin: 5px 0 0; font-size: 24px; }
.login-form .button { margin-top: 4px; }
.login-form > small { color: var(--muted); line-height: 1.5; }
.login-error { padding: 10px 12px; color: var(--red); background: var(--red-soft); border: 1px solid #e6bbb7; border-radius: 4px; }

@media (max-width: 1040px) {
    .app-shell { grid-template-columns: 1fr; grid-template-rows: 64px auto minmax(0, 1fr); }
    .topbar { grid-column: 1; grid-row: 1; }
    .sidebar { grid-column: 1; grid-row: 2; min-height: auto; padding: 7px 12px; border-right: 0; border-bottom: 1px solid #303c3e; }
    .sidebar nav { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); overflow-x: auto; }
    .sidebar-meta { display: none; }
    .main-content { grid-column: 1; grid-row: 3; }
    .player-layout { grid-template-columns: 270px minmax(520px, 1fr); overflow-x: auto; }
    .data-layout { grid-template-columns: 1fr; }
    .settings-layout { grid-template-columns: 1fr; }
    .topbar-status { display: none; }
}

@media (max-width: 720px) {
    .topbar { padding: 0 14px; }
    .brand-copy, .account-menu > span { display: none; }
    .mod-switcher { width: min(210px, 42vw); margin-left: 0; }
    .account-menu { margin-left: auto; }
    .main-content { padding: 16px 12px; }
    .sidebar nav { grid-template-columns: repeat(6, minmax(92px, 1fr)); }
    .nav-button { justify-content: center; padding: 0 8px; }
    .nav-index { display: none; }
    .view-heading h1 { font-size: 21px; }
    .player-layout { display: block; min-height: 0; overflow: visible; }
    .player-browser { min-height: 0; max-height: 330px; margin-bottom: 12px; }
    .player-editor, .empty-state { min-height: 420px; }
    .player-editor form { padding: 15px; }
    .player-fields, .grant-tools { grid-template-columns: 1fr; }
    .form-actions { flex-wrap: wrap; }
    .action-spacer { display: none; }
    .form-actions .button { flex: 1 1 140px; }
    .metric-grid { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
    .data-layout { grid-template-columns: 1fr; }
    .action-section { align-items: flex-start; flex-direction: column; }
    .action-section .button { width: 100%; }
    .split-toolbar { align-items: flex-start; flex-direction: column; }
    .toolbar-note { display: none; }
    .member-tools { grid-template-columns: 1fr; }
    .pagination-bar { flex-wrap: wrap; justify-content: center; }
    .pagination-bar .page-summary { order: -1; flex: 1 0 100%; }
    .danger-zone { align-items: stretch; flex-direction: column; }
    .login-page { padding: 14px; }
    .login-shell { grid-template-columns: 1fr; }
    .login-brand { min-height: auto; padding: 28px; }
    .login-brand .brand-mark { margin-bottom: 18px; }
    .login-brand h1 { font-size: 24px; }
    .login-form { padding: 28px; }
}
