:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --border: #e5e9f2;
    --text: #111827;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.06);
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary);
    text-decoration: none;
}

/* ---------------- 侧边栏 ---------------- */

.side {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 232px;
    background: linear-gradient(180deg, #111827 0%, #0f172a 100%);
    color: #cbd5e1;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 20;
}

.side .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 17px;
    font-weight: 600;
    color: #fff;
    padding: 4px 10px 22px;
    letter-spacing: 0.01em;
}

.side .brand::before {
    content: "";
    width: 28px;
    height: 28px;
    border-radius: 9px;
    background: linear-gradient(135deg, #3b82f6, #22d3ee);
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.45);
    flex: 0 0 auto;
}

.side a {
    display: block;
    color: #b6c2d6;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: background 0.15s ease, color 0.15s ease;
}

.side a:hover {
    background: rgba(148, 163, 184, 0.12);
    color: #fff;
}

.side a.active {
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: #fff;
    box-shadow: 0 6px 18px rgba(37, 99, 235, 0.35);
}

.side .side-sep {
    margin: 16px 12px 4px;
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #64748b;
}

.side .side-user {
    margin-top: auto;
    padding: 14px 12px 4px;
    border-top: 1px solid rgba(148, 163, 184, 0.18);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 13px;
    color: #e2e8f0;
}

.side .side-user form {
    margin: 0;
}

.side .side-foot {
    font-size: 11px;
    line-height: 1.6;
    color: #64748b;
    padding: 10px 12px 0;
}

/* ---------------- 主区域 ---------------- */

.main {
    margin-left: 232px;
    padding: 32px 36px 64px;
    max-width: 1360px;
}

h1 {
    font-size: 25px;
    line-height: 1.3;
    margin: 0 0 6px;
    letter-spacing: -0.01em;
}

h2 {
    font-size: 17px;
    line-height: 1.4;
    margin: 0 0 14px;
}

.page-desc {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

/* ---------------- 卡片与面板 ---------------- */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    box-shadow: var(--shadow-md);
    margin-bottom: 20px;
}

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.panel-head h2 {
    margin: 0;
}

.panel-head .muted {
    margin: 4px 0 0;
}

.cards {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    min-width: 180px;
    box-shadow: var(--shadow-sm);
}

.card .label {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 8px;
}

.card .value {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.card .value.small {
    font-size: 14px;
    font-weight: 500;
    word-break: break-all;
}

/* ---------------- 表格 ---------------- */

.panel > table {
    margin-top: 4px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid #eef1f7;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-weight: 500;
    font-size: 12px;
    letter-spacing: 0.02em;
    background: var(--surface-soft);
    white-space: nowrap;
}

th:first-child {
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
}

th:last-child {
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
}

tbody tr {
    transition: background 0.12s ease;
}

tbody tr:hover td {
    background: #f8faff;
}

td form {
    margin: 0;
}

/* ---------------- 表单控件 ---------------- */

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
input[type="datetime-local"],
select,
textarea {
    min-width: 120px;
    height: 40px;
    padding: 8px 12px;
    border: 1px solid #d8deea;
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
    width: 100%;
    min-height: 84px;
    height: auto;
    resize: vertical;
    line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

input::placeholder,
textarea::placeholder {
    color: #9aa3b2;
}

input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

label {
    font-size: 13px;
}

/* ---------------- 按钮 ---------------- */

button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 40px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.22);
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
}

button:hover,
.btn:hover {
    background: linear-gradient(135deg, #1d4ed8, #2563eb);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3);
    transform: translateY(-1px);
}

button:active,
.btn:active {
    transform: translateY(0);
}

button.ghost,
.btn.ghost {
    background: #eef4ff;
    color: var(--primary);
    border-color: #dbe7ff;
    box-shadow: none;
}

button.ghost:hover,
.btn.ghost:hover {
    background: #e2ecff;
    box-shadow: none;
}

button.danger {
    background: linear-gradient(135deg, #dc2626, #ef4444);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.2);
}

button.danger:hover {
    background: linear-gradient(135deg, #b91c1c, #dc2626);
}

button.danger-ghost {
    background: #fff1f2;
    color: var(--danger);
    border-color: #ffe0e3;
    box-shadow: none;
}

button.danger-ghost:hover {
    background: #ffe4e6;
    box-shadow: none;
}

button.mini,
.btn.mini {
    height: 30px;
    padding: 0 10px;
    font-size: 12px;
    border-radius: 8px;
}

a.btn {
    text-decoration: none;
}

/* ---------------- 布局工具 ---------------- */

.row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.row > input[type="text"],
.row > input[type="datetime-local"],
.row > input[type="file"],
.row > select {
    flex: 0 1 auto;
}

.muted {
    color: var(--muted);
    font-size: 13px;
}

.flash-wrap:empty {
    display: none;
}

.flash {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid transparent;
}

.flash.ok {
    background: #ecfdf3;
    color: #067647;
    border-color: #abefc6;
}

.flash.err {
    background: #fef3f2;
    color: #b42318;
    border-color: #fecdca;
}

.poster {
    width: 54px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    background: #e8ecf5;
}

.poster.large {
    width: 180px;
    height: 270px;
}

.tag {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    background: #eef4ff;
    color: var(--primary);
}

.tag.warn {
    background: #fff4e5;
    color: #b54708;
}

.tag.gray {
    background: #f1f3f7;
    color: var(--muted);
}

.pager {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 16px;
    font-size: 14px;
}

.pager a {
    padding: 6px 12px;
    border-radius: 8px;
    background: #eef4ff;
}

.pager a:hover {
    background: #e2ecff;
}

.empty {
    padding: 32px 18px;
    text-align: center;
    color: #8a93a6;
    font-size: 14px;
    border: 1px dashed #dfe5ef;
    border-radius: var(--radius-md);
    background: var(--surface-soft);
}

code,
.mono {
    font-family: "JetBrains Mono", Consolas, "Courier New", monospace;
    background: #f1f4fa;
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 13px;
    word-break: break-all;
}

/* ---------------- 表单栅格 ---------------- */

.form-grid {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 12px 16px;
    align-items: center;
    max-width: 760px;
}

.form-grid label {
    color: var(--muted);
    font-size: 14px;
}

.form-grid .full {
    grid-column: 1 / -1;
}

.form-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    align-items: end;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
}

.field > span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
}

.field > small {
    color: #9aa3b2;
    font-size: 12px;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    min-width: 0;
}

.form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.form-actions button,
.form-actions .btn {
    min-width: 96px;
}

/* ---------------- 密钥页 ---------------- */

.key-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.key-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: #fbfcff;
    padding: 16px 18px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.key-card:hover {
    border-color: #cfdbf5;
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.07);
}

.key-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.key-title {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 0;
}

.key-code {
    font-size: 13px;
    padding: 4px 9px;
    background: #eef2f9;
    color: #334155;
}

.key-meta {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 10px;
    color: var(--muted);
    font-size: 13px;
}

.key-meta b {
    color: var(--text);
    font-weight: 500;
}

.key-edit {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(190px, 1fr) auto auto;
    gap: 12px;
    align-items: end;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px dashed #e3e8f2;
}

.key-edit .form-actions {
    padding-bottom: 1px;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 10px;
    border: 1px solid #d8deea;
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--muted);
    white-space: nowrap;
    cursor: pointer;
}

.switch input {
    margin: 0;
}

/* ---------------- 其他 ---------------- */

.split {
    display: flex;
    gap: 26px;
    align-items: flex-start;
}

.split .left {
    flex: 0 0 220px;
}

.split .right {
    flex: 1;
    min-width: 0;
}

.list-narrow {
    max-height: 320px;
    overflow: auto;
    font-size: 13px;
}

/* ---------------- 登录页 ---------------- */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at 15% 15%, rgba(59, 130, 246, 0.28), transparent 45%),
        radial-gradient(circle at 85% 20%, rgba(34, 211, 238, 0.18), transparent 40%),
        linear-gradient(160deg, #0f172a 0%, #111827 55%, #0b1220 100%);
}

.login-card {
    width: 400px;
    max-width: 100%;
    background: var(--surface);
    border-radius: 20px;
    padding: 34px 32px;
    box-shadow: 0 24px 70px rgba(2, 6, 23, 0.5);
}

.login-card h1 {
    margin: 0 0 6px;
    font-size: 24px;
}

.login-card .muted {
    margin: 0 0 4px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 22px;
}

.login-form label {
    display: flex;
    flex-direction: column;
    gap: 7px;
    font-size: 13px;
    color: var(--muted);
}

.login-form input {
    width: 100%;
    min-width: 0;
    height: 44px;
    padding: 10px 12px;
}

.login-form button {
    height: 46px;
    margin-top: 4px;
    font-size: 15px;
}

/* ---------------- 响应式 ---------------- */

@media (max-width: 900px) {
    .side {
        position: sticky;
        top: 0;
        width: auto;
        flex-direction: row;
        align-items: center;
        gap: 4px;
        padding: 10px 12px;
        overflow-x: auto;
    }

    .side .brand {
        padding: 0 12px 0 0;
        white-space: nowrap;
    }

    .side .brand::before {
        width: 24px;
        height: 24px;
        border-radius: 8px;
    }

    .side a {
        padding: 8px 12px;
        white-space: nowrap;
    }

    .side .side-sep,
    .side .side-foot {
        display: none;
    }

    .side .side-user {
        margin: 0 0 0 auto;
        padding: 0 0 0 8px;
        border-top: 0;
        white-space: nowrap;
    }

    .main {
        margin-left: 0;
        padding: 20px 16px 48px;
    }

    .main h1 {
        font-size: 22px;
    }

    .panel {
        padding: 18px;
    }

    .key-edit {
        grid-template-columns: 1fr;
    }

    .key-edit .form-actions {
        justify-content: flex-start;
    }
}
