/* === 基础重置与变量 === */
:root {
    color-scheme: light dark;
    --canvas: #f3f6f2;
    --surface: #ffffff;
    --surface-soft: #f8faf6;
    --ink: #18231d;
    --muted: #647268;
    --line: #dce4dc;
    --line-strong: #c4d1c6;
    --nav: #21342b;
    --nav-2: #2d4639;
    --accent: #2f7d62;
    --accent-strong: #226149;
    --amber: #c8892d;
    --danger: #b84a3d;
    --shadow: 0 18px 46px rgba(24, 35, 29, .10);
    --font-ui: "IBM Plex Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-data: "IBM Plex Mono", "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font-ui); background: var(--canvas); color: var(--ink); }
a { color: inherit; text-decoration: none; }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* === 管理布局 === */
.admin-layout { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); background: var(--canvas); }
.admin-sidebar { grid-column: 1; grid-row: 1; background: linear-gradient(180deg, var(--nav) 0%, #17251e 100%); color: #f3f8f1; display: grid; grid-template-rows: auto 1fr auto; min-width: 0; box-shadow: inset 0 5px 0 var(--amber); }
.sidebar-brand { height: 68px; padding: 14px 16px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid rgba(255,255,255,.09); }
.brand-mark { width: 34px; height: 34px; border-radius: 6px; display: grid; place-items: center; background: var(--amber); color: #17251e; font-weight: 900; font-family: var(--font-data); letter-spacing: 0; }
.sidebar-brand strong { display: block; font-size: 14px; letter-spacing: 0; }
.sidebar-brand small { display: block; margin-top: 2px; color: #aebdaf; font-size: 12px; }
.sidebar-menu { padding: 10px; display: grid; gap: 4px; align-content: start; }
.sidebar-item { min-height: 38px; padding: 0 12px; border-radius: 6px; display: flex; align-items: center; justify-content: space-between; gap: 10px; color: #cfdbcf; font-size: 13px; font-weight: 760; }
.sidebar-item:hover { background: rgba(255,255,255,.07); color: #ffffff; }
.sidebar-item.is-active { background: var(--nav-2); color: #ffffff; box-shadow: inset 3px 0 0 var(--amber); }
.sidebar-item small { min-width: 22px; height: 20px; border-radius: 999px; display: grid; place-items: center; background: rgba(255,255,255,.10); font-size: 11px; font-family: var(--font-data); }
.sidebar-footer { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.10); color: #aebdaf; font-size: 12px; }

.admin-main { grid-column: 2; grid-row: 1; min-width: 0; background: var(--canvas); display: grid; grid-template-rows: auto auto auto minmax(0, 1fr); }
.admin-topbar { min-height: 56px; padding: 0 20px; display: flex; align-items: center; justify-content: space-between; gap: 18px; background: rgba(255,255,255,.86); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.mobile-menu-button, .mobile-nav-backdrop { display: none; }
.admin-topbar .mobile-menu-button { display: none; }
.breadcrumb { color: var(--muted); font-size: 12px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

.page-heading { min-height: 58px; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
.page-heading h1 { margin: 0; font-size: 19px; font-weight: 820; letter-spacing: 0; }
.page-heading p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.admin-id { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.logout-form { margin: 0; }

.content { padding: 12px 16px 16px; min-width: 0; }
.content.content-single { display: block; }
.license-content { display: block; }

/* === 面板组件 === */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; box-shadow: none; }
.panel-header { min-height: 46px; display: flex; justify-content: space-between; gap: 16px; padding: 10px 12px; align-items: center; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font-size: 15px; font-weight: 820; }
.panel-header p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.notice { margin: 10px 16px 0; padding: 11px 13px; border-radius: 4px; background: #ecf7ef; color: #23633f; border: 1px solid #cfe2d5; }

/* === 汇总栏 === */
.summary-bar { margin-bottom: 12px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border: 1px solid var(--line); border-left: 4px solid var(--amber); border-radius: 4px; background: var(--surface); overflow: hidden; }
.summary-item { min-height: 92px; padding: 16px 18px; border-right: 1px solid var(--line); white-space: nowrap; }
.summary-item:last-child { border-right: 0; }
.summary-item span { display: block; color: var(--muted); font-size: 13px; font-weight: 760; }
.summary-item strong { display: block; margin-top: 8px; font-family: var(--font-data); font-size: 30px; line-height: 1; }
.summary-item.is-warning strong { color: var(--amber); }

/* === 授权过滤器 === */
.license-list-panel { min-width: 0; }
.license-filter-toolbar { margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-width: 0 0 1px; border-radius: 0; background: var(--surface); display: grid; grid-template-columns: minmax(320px, 1fr) auto auto; gap: 12px; align-items: end; }
.filter-search, .filter-group { display: grid; gap: 6px; min-width: 0; }
.filter-search span, .filter-group span { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .02em; }
.filter-search input { height: 36px; padding-left: 12px; background: #ffffff; }
.filter-search::before { content: ""; display: none; }
.filter-selects { display: flex; gap: 10px; align-items: end; }
.filter-group { width: 128px; }
.filter-actions { display: flex; gap: 8px; align-items: end; }
.filter-actions .button, .filter-actions button { min-height: 38px; }

/* === 表单元素 === */
.section-body { padding: 14px 16px 16px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-full { grid-column: 1 / -1; }
label { display: grid; gap: 6px; color: #4b5563; font-size: 13px; }
input, textarea, select { width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 5px; background: #ffffff; color: var(--ink); font: inherit; min-height: 36px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,125,98,.12); }
textarea { min-height: 96px; resize: vertical; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 16px 10px; }
.bulk-actions { display: flex; flex-wrap: nowrap; align-items: center; gap: 8px; }
.bulk-actions select { width: 148px; flex: 0 0 148px; }

.button, button { border: 0; border-radius: 5px; min-height: 32px; padding: 8px 12px; display: inline-flex; align-items: center; justify-content: center; font: inherit; font-size: 13px; font-weight: 780; cursor: pointer; text-decoration: none; background: var(--accent); color: #ffffff; white-space: nowrap; }
.button:hover, button:hover { background: var(--accent-strong); }
.button.primary, button.primary { background: var(--accent); }
.button.secondary, button.secondary { background: var(--nav-2); }
.button.danger, button.danger { background: var(--danger); }
.button.ghost, button.ghost { background: #ffffff; color: var(--ink); border: 1px solid var(--line-strong); }
.button.ghost:hover, button.ghost:hover { background: #f5f8f4; }

/* === 表格组件 === */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px; border-bottom: 1px solid #e8eee7; font-size: 13px; vertical-align: top; }
.table th { background: #f3f7f2; color: var(--muted); font-size: 12px; font-weight: 780; }
.table-wrap { overflow-x: auto; }

.pagination { padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; color: #6b7788; font-size: 13px; border-top: 1px solid var(--line); }
.pagination-actions { display: flex; gap: 8px; }

.empty { margin: 0; color: #6b7788; font-size: 13px; }
.empty-state { padding: 28px 18px; display: grid; gap: 12px; justify-items: start; color: #6b7788; }
.text-link { display: inline-flex; color: #2f80ed; font-size: 13px; font-weight: 700; }

/* === 授权列表 === */
.license-table { border-top: 1px solid var(--line); overflow-x: auto; }
.license-table-head, .license-row { min-width: 760px; display: grid; grid-template-columns: 1.65fr 1fr .55fr .7fr 78px; gap: 10px; align-items: center; }
.license-table-head { padding: 8px 16px; background: #eef3ed; color: var(--muted); border-bottom: 1px solid #dce3ea; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
.license-row { position: relative; padding: 10px 16px; border-bottom: 1px solid #e8eee7; color: #17202a; font-size: 13px; }
.license-row::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: transparent; }
.license-row:hover, .license-row.is-active { background: #f5f9f4; }
.license-row.is-active::before { background: var(--amber); }

.license-key { min-width: 0; font-family: var(--font-data); font-size: 12px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.license-select { width: 14px; height: 14px; min-height: 0; padding: 0; margin: 0 8px 0 0; vertical-align: -2px; }

.status-badge { width: max-content; max-width: 100%; padding: 3px 7px; border-radius: 999px; font-size: 11px; border: 1px solid #b9dbc6; background: #eaf7ef; color: #23633f; white-space: nowrap; font-weight: 760; }
.status-badge.is-disabled { border-color: #e7c0ba; background: #fff2ef; color: var(--danger); }

.row-action { width: max-content; min-height: 28px; padding: 5px 9px; pointer-events: none; }

/* === 抽屉组件 === */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(19, 28, 40, .24); z-index: 20; }
.license-detail-drawer { position: fixed; top: 0; right: 0; width: 408px; max-width: 92%; height: 100vh; background: #ffffff; border-left: 1px solid var(--line-strong); box-shadow: -20px 0 54px rgba(24,35,29,.18); display: grid; grid-template-rows: auto 1fr auto; z-index: 21; }
.drawer-header { padding: 16px; display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); }
.drawer-header h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: 0; }
.drawer-header code { display: block; max-width: 330px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; font-family: var(--font-data); }
.drawer-close { width: 32px; height: 32px; flex: 0 0 auto; border-radius: 5px; display: grid; place-items: center; border: 1px solid var(--line-strong); color: #536173; font-size: 20px; line-height: 1; }
.drawer-body { padding: 16px; overflow: auto; }
.drawer-section { margin-bottom: 20px; }
.drawer-section h3 { margin: 0 0 12px; font-size: 14px; }
.drawer-kv { margin: 0; display: grid; gap: 10px; }
.drawer-kv div { display: grid; grid-template-columns: 76px 1fr; gap: 10px; font-size: 13px; line-height: 1.45; }
.drawer-kv dt { color: #6b7788; }
.drawer-kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.recent-activation { display: grid; gap: 3px; margin-bottom: 8px; padding: 9px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface-soft); font-size: 12px; }
.recent-activation span { color: #6b7788; }
.local-badge { width: max-content; border-radius: 999px; padding: 2px 6px; background: #fff7e8; color: #b7791f; border: 1px solid #f0d9ac; font-size: 11px; }
.drawer-actions { padding: 14px 18px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid #e3e9ef; background: #f9fbfc; }
.drawer-actions form { margin: 0; display: contents; }

/* === 账号设置 === */
.form-panel { width: 100%; }
.table-panel { width: 100%; }
.account-settings-panel { width: 100%; }
.account-settings-panel .section-body { display: grid; gap: 18px; }
.account-form-row { display: grid; grid-template-columns: 150px minmax(0, 1fr) auto; gap: 12px; align-items: end; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.account-form-row:last-child { padding-bottom: 0; border-bottom: 0; }
.account-form-title { align-self: center; }
.account-form-title h3 { margin: 0 0 4px; font-size: 14px; }
.account-form-title p { margin: 0; color: #6b7788; font-size: 12px; line-height: 1.45; }
.account-form-fields { display: grid; gap: 12px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.danger-zone { margin-top: 16px; padding-top: 16px; border-top: 1px solid #dce3ea; display: flex; flex-wrap: wrap; gap: 10px; }

/* === 审计日志 === */
.audit-grid { display: grid; gap: 10px; }
.audit-entry { padding: 12px; border: 1px solid var(--line); border-radius: 5px; display: grid; gap: 4px; font-size: 13px; background: var(--surface-soft); }
.audit-entry small { color: #6b7788; }

/* === 诊断与导出 === */
.diagnostic-grid, .export-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.diagnostic-item, .export-item { padding: 14px; border: 1px solid var(--line); border-radius: 5px; display: grid; gap: 8px; background: var(--surface-soft); }
.diagnostic-item span, .export-item span { color: #6b7788; font-size: 12px; }
.diagnostic-item code { overflow-wrap: anywhere; }

/* === 登录页面 === */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-box { width: min(360px, 100%); padding: 24px; border: 1px solid var(--line); border-top: 5px solid var(--amber); border-radius: 6px; background: var(--surface); box-shadow: 0 22px 60px rgba(24, 35, 29, .12); }
.login-box h1 { margin: 0 0 6px; font-size: 23px; font-weight: 840; letter-spacing: 0; }
.login-box p { margin: 0 0 18px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.login-box form { display: grid; gap: 12px; }
.login-box label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 760; }
.login-box input { width: 100%; padding: 10px 12px; min-height: 38px; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--ink); font: inherit; }
.login-box input:focus { outline: 2px solid var(--amber); outline-offset: 2px; border-color: var(--accent); }
.login-box button { border: 0; border-radius: 5px; min-height: 38px; padding: 10px 14px; font: inherit; font-weight: 800; cursor: pointer; background: var(--accent); color: #ffffff; }
.login-box button:hover { background: var(--accent-strong); }

/* === 发码密钥提示 === */
.secret-banner {
    margin: 0 0 16px;
    padding: 14px 16px;
    border: 2px solid var(--amber);
    border-radius: 8px;
    background: color-mix(in srgb, var(--amber) 8%, var(--surface));
    color: var(--ink);
}

.secret-copy-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.secret-copy-row code {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--canvas);
    font-family: ui-monospace, monospace;
    font-size: 14px;
    word-break: break-all;
}

/* === 响应式布局 === */
@media (max-width: 900px) {
    .admin-layout { display: block; min-height: 100vh; }
    .admin-sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: min(280px, 84vw); height: 100vh; z-index: 31; transform: translateX(-100%); transition: transform .18s ease; box-shadow: 22px 0 60px rgba(19, 28, 40, .22); }
    .admin-sidebar:target { transform: translateX(0); }
    .admin-sidebar:target + .mobile-nav-backdrop { display: block; position: fixed; top: 0; right: 0; bottom: 0; left: min(280px, 84vw); z-index: 30; background: rgba(19, 28, 40, .34); }
    .sidebar-brand { height: auto; }
    .sidebar-footer { display: none; }
    .admin-main { min-height: 100vh; grid-column: auto; grid-row: auto; }
    .admin-topbar { min-height: 58px; padding: 10px 16px; align-items: center; flex-direction: row; }
    .mobile-menu-button { display: inline-flex; flex: 0 0 auto; }
    .breadcrumb { flex: 1; min-width: 0; }
    .topbar-actions { justify-content: flex-start; flex-wrap: wrap; }
    .page-heading { padding: 16px; align-items: flex-start; flex-direction: column; }
    .content { padding: 0 16px 16px; }
    .summary-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .license-filter-toolbar { grid-template-columns: 1fr; margin: 14px 16px; }
    .filter-selects, .filter-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
    .filter-group { width: auto; }
    .form-grid, .account-form-row, .account-form-fields { grid-template-columns: 1fr; }
    .diagnostic-grid, .export-grid { grid-template-columns: 1fr; }
    .drawer-actions { flex-wrap: wrap; justify-content: flex-start; }
    .license-detail-drawer { width: 100%; max-width: 100%; }
}

@media (max-width: 560px) {
    .summary-bar { grid-template-columns: 1fr; }
    .filter-selects, .filter-actions { grid-template-columns: 1fr; }
    .page-heading { align-items: stretch; }
}

/* === 暗色模式 === */
@media (prefers-color-scheme: dark) {
    :root {
        --canvas: #111318;
        --surface: #1a1f27;
        --surface-soft: #15191f;
        --ink: #e9eef6;
        --muted: #8f9bab;
        --line: #2a3140;
        --line-strong: #3a4252;
        --nav: #161b25;
        --nav-2: #1f2635;
    }

    body { background: var(--canvas); color: var(--ink); }

    .admin-topbar { background: var(--surface); border-color: var(--line); }
    .panel { background: var(--surface); border-color: var(--line); }
    .panel-header { border-color: var(--line); }

    input, textarea, select {
        background: var(--surface);
        color: var(--ink);
        border-color: var(--line-strong);
    }

    .filter-search input { background: var(--surface); }

    .button.ghost, button.ghost {
        background: var(--surface);
        color: var(--ink);
        border-color: var(--line-strong);
    }
    .button.ghost:hover, button.ghost:hover { background: var(--surface-soft); }

    .license-table-head { background: var(--surface-soft); }
    .license-row:hover, .license-row.is-active { background: var(--surface-soft); }

    .table th { background: var(--surface-soft); }

    .drawer-backdrop { background: rgba(0, 0, 0, .6); }
    .license-detail-drawer { background: var(--surface); border-color: var(--line); }
    .drawer-header { border-color: var(--line); }
    .drawer-actions { background: var(--surface-soft); border-color: var(--line); }
    .drawer-close { border-color: var(--line-strong); color: var(--ink); }

    .recent-activation { background: var(--surface-soft); border-color: var(--line); }

    .login-box { background: var(--surface); border-color: var(--line); box-shadow: 0 22px 60px rgba(0, 0, 0, .4); }

    .notice { background: #2a3d2f; border-color: #3a5540; color: #9fd4b0; }

    .secret-banner {
        background: color-mix(in srgb, var(--amber) 15%, var(--surface));
        border-color: var(--amber);
    }

    .secret-copy-row code {
        background: var(--canvas);
        border-color: var(--line);
    }

    .audit-entry, .diagnostic-item, .export-item {
        background: var(--surface-soft);
        border-color: var(--line);
    }
}
