* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #333;
    overflow: hidden;
}

.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* 侧边栏 */
.sidebar {
    width: 220px;
    background: #ffffff;
    color: #333;
    flex-shrink: 0;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: #6c63ff;
}

.nav-list {
    list-style: none;
    padding: 10px 0;
}

.nav-item {
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 14px;
    color: #555;
}

.nav-item:hover {
    background: #f0f2ff;
    color: #6c63ff;
}

.nav-item.active {
    background: #eef0ff;
    color: #6c63ff;
    font-weight: 600;
    border-left: 3px solid #6c63ff;
}

/* 主内容 */
.content {
    flex: 1;
    min-width: 0;
    height: 100vh;
    padding: 24px;
    overflow-y: auto;
    padding-bottom: 72px;
}

.content h1 {
    font-size: 22px;
    margin-bottom: 20px;
    color: #1a1a2e;
}

/* ===== 登录页 ===== */
#login-page {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #5b54e6 0%, #6c63ff 45%, #a78bfa 100%);
    overflow: auto;
    z-index: 50;
}
#login-page.hidden { display: none !important; }

/* 背景柔光装饰球 */
#login-page::before,
#login-page::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    background: #ffffff;
    opacity: 0.12;
    pointer-events: none;
}
#login-page::before { width: 460px; height: 460px; top: -140px; right: -90px; }
#login-page::after  { width: 360px; height: 360px; bottom: -120px; left: -70px; }

.login-box {
    position: relative;
    width: 100%;
    max-width: 380px;
    margin: 0;
    background: #fff;
    padding: 40px 36px 30px;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(28, 24, 88, 0.30);
    text-align: center;
    animation: loginFadeIn 0.5s ease both;
}

@keyframes loginFadeIn {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* 品牌头 */
.login-brand { margin-bottom: 28px; }
.login-logo {
    width: 64px;
    height: 64px;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    border-radius: 18px;
    background: linear-gradient(135deg, #6c63ff, #a78bfa);
    box-shadow: 0 10px 22px rgba(108, 99, 255, 0.40);
}
.login-title {
    font-size: 22px;
    font-weight: 700;
    color: #1a1a2e;
    letter-spacing: 0.5px;
}
.login-subtitle {
    margin-top: 6px;
    font-size: 13px;
    color: #94a3b8;
}

.login-box input {
    width: 100%;
    padding: 13px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 14px;
    margin-bottom: 16px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.login-box input:focus {
    border-color: #6c63ff;
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.15);
}

.login-challenge-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.login-challenge-question {
    flex: 1;
    padding: 11px 12px;
    border: 1px dashed #c7d2fe;
    background: #f5f3ff;
    color: #4338ca;
    border-radius: 10px;
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    letter-spacing: 6px;
    font-family: 'Consolas', 'Courier New', monospace;
}

.login-refresh-btn {
    width: auto !important;
    flex-shrink: 0;
    padding: 11px 14px !important;
    margin-bottom: 0 !important;
    background: #eef2ff !important;
    color: #4338ca !important;
    border: 1px solid #c7d2fe !important;
    border-radius: 10px !important;
    font-size: 13px !important;
    cursor: pointer;
    box-shadow: none !important;
    transition: background 0.2s !important;
}

.login-refresh-btn:hover {
    background: #e0e7ff !important;
    filter: none !important;
    transform: none !important;
}

.login-help {
    margin: -4px 0 14px;
    font-size: 12px;
    color: #64748b;
}

.login-trusted-hint {
    display: none !important;
}

.login-box button {
    width: 100%;
    padding: 13px;
    background: linear-gradient(135deg, #6c63ff, #5a52d5);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(108, 99, 255, 0.35);
    transition: transform 0.15s, box-shadow 0.2s, filter 0.2s;
}

.login-box button:hover {
    filter: brightness(1.06);
    box-shadow: 0 10px 24px rgba(108, 99, 255, 0.45);
}

.login-box button:active {
    transform: translateY(1px);
    box-shadow: 0 4px 12px rgba(108, 99, 255, 0.35);
}

/* 统计卡片 */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.stat-card .label {
    font-size: 13px;
    color: #888;
    margin-bottom: 8px;
}

.stat-card .value {
    font-size: 28px;
    font-weight: 700;
    color: #1a1a2e;
}

.stat-card.green .value { color: #22c55e; }
.stat-card.blue .value { color: #3b82f6; }
.stat-card.orange .value { color: #f59e0b; }
.stat-card.red .value { color: #ef4444; }

.dashboard-panels {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}

.dashboard-panel {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    padding: 18px;
}

.dashboard-panel h3 {
    font-size: 16px;
    margin-bottom: 14px;
    color: #1f2937;
}

.mode-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.mode-stat-card {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 12px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.mode-stat-title {
    font-size: 14px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 8px;
}

.mode-stat-main {
    font-size: 18px;
    font-weight: 700;
    color: #4f46e5;
    margin-bottom: 6px;
}

.mode-stat-sub {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 8px;
}

.mode-stat-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.mini-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    background: #eef2ff;
    color: #4338ca;
}

.mini-tag.warning {
    background: #fef3c7;
    color: #b45309;
}

.mini-tag.danger {
    background: #fee2e2;
    color: #b91c1c;
}

.metric-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 12px;
}

.metric-list div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #f8fafc;
    font-size: 13px;
}

.metric-list span {
    color: #64748b;
}

.metric-list strong {
    color: #111827;
    font-size: 16px;
}

/* 工具栏 */
.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    align-items: center;
    flex-wrap: wrap;
}

.toolbar select, .toolbar input[type="text"] {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
}

/* 按钮 */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
}

.btn-primary {
    background: #6c63ff;
    color: #fff;
}

.btn-primary:hover { background: #5a52d5; }

.btn-secondary {
    background: #e5e7eb;
    color: #333;
}

.btn-secondary:hover { background: #d1d5db; }

.btn-sm {
    padding: 4px 10px;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 500;
    color: #fff;
    transition: background 0.18s ease, color 0.18s ease, opacity 0.18s ease, transform 0.18s ease;
}

.btn-red { background: #ef4444; }
.btn-red:hover { background: #dc2626; }
.btn-green { background: #22c55e; }
.btn-green:hover { background: #16a34a; }
.btn-orange { background: #f59e0b; color: #fff; }
.btn-orange:hover { background: #d97706; }
.btn-purple { background: #8b5cf6; color: #fff; }
.btn-purple:hover { background: #7c3aed; }
.btn-blue { background: #3b82f6; color: #fff; }
.btn-blue:hover { background: #2563eb; }
.btn-sm.btn-secondary { background: #e5e7eb; color: #333; }
.btn-sm.btn-secondary:hover { background: #d1d5db; }
.btn-pending,
.btn-pending:hover {
    background: #dbeafe !important;
    color: #1d4ed8 !important;
}
.btn-pending-danger,
.btn-pending-danger:hover {
    background: #fee2e2 !important;
    color: #b91c1c !important;
}
.btn-pending-success,
.btn-pending-success:hover {
    background: #dcfce7 !important;
    color: #166534 !important;
}
.btn:disabled,
.btn-sm:disabled {
    cursor: not-allowed;
    opacity: 0.78;
}

.table-selectionbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 14px;
    margin: 10px 0 12px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
}

.table-selectionbar.hidden {
    display: none;
}

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

.selectionbar-count {
    color: #1d4ed8;
    font-size: 13px;
    font-weight: 600;
}

.selectionbar-hint {
    color: #64748b;
    font-size: 12px;
}

.selectionbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.table-shell {
    position: relative;
    width: 100%;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 8px;
}

.table-scroll::-webkit-scrollbar,
.floating-table-scrollbar::-webkit-scrollbar {
    height: 12px;
}

.table-scroll::-webkit-scrollbar-thumb,
.floating-table-scrollbar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

.table-scroll::-webkit-scrollbar-track,
.floating-table-scrollbar::-webkit-scrollbar-track {
    background: #e5e7eb;
    border-radius: 999px;
}

/* 数据表格 */
.data-table {
    width: 100%;
    background: #fff;
    border-radius: 8px;
    overflow: visible;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border-collapse: collapse;
    font-size: 13px;
    min-width: max-content;
}

.data-table th {
    background: #f8f9fa;
    padding: 6px 8px;
    text-align: left;
    font-weight: 600;
    color: #666;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
    font-size: 12px;
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
}
.data-table th.sortable:hover {
    background: #e5e7eb;
    color: #333;
}
.data-table th.sortable::after {
    content: ' ⇅';
    opacity: 0.4;
    font-size: 11px;
}

.data-table td.copyable {
    cursor: pointer;
    position: relative;
}
.data-table td.copyable:hover {
    background: #eef2ff;
}
.data-table td.copyable:hover::after {
    content: '点击复制';
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a2e;
    color: #fff;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
}
.data-table td.no-copy {
    cursor: not-allowed;
    user-select: none;
    color: #999;
}

.data-table td {
    padding: 5px 8px;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
    vertical-align: top;
}
.data-table tbody tr:hover {
    background: #f8fafc;
}
.data-table tbody tr.row-selected {
    background: #eff6ff;
}
.data-table td.col-machine {
    max-width: 130px;
}

.row-select-col,
.row-select-cell {
    width: 42px;
    min-width: 42px;
    max-width: 42px;
    text-align: center !important;
}

.row-select-col input,
.row-select-cell input {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    min-width: max-content;
    white-space: nowrap;
}

.secret-cell,
.secret-render {
    display: block;
    min-width: 0;
}

.secret-value-row {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.secret-toggle-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 4px 7px;
    color: #4f46e5;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
}

.secret-toggle-btn:hover {
    background: #e0e7ff;
}

.secret-value {
    display: inline-block;
    max-width: 220px;
    padding: 6px 10px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    color: #0f172a;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

.secret-value.expanded {
    max-width: none;
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
}

.secret-copyable {
    cursor: pointer;
}

.secret-copyable:hover {
    background: #eef2ff;
    border-color: #c7d2fe;
}

.secret-empty {
    color: #9ca3af;
}

.secret-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.data-table td.col-apikey,
.data-table td.col-summary,
.data-table td.col-version,
.data-table td.col-actions {
    max-width: none;
    overflow: visible;
    text-overflow: clip;
}

.data-table td.col-apikey {
    word-break: normal;
    white-space: nowrap;
}

.summary-compact {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    min-width: max-content;
}

.summary-compact-line,
.summary-compact-meta,
.summary-compact-text,
.summary-compact-error {
    display: inline-block;
    white-space: nowrap;
    line-height: 1.35;
}

.summary-compact-line,
.summary-compact-text {
    color: #111827;
}

.summary-compact-meta {
    color: #6b7280;
    font-size: 11px;
}

.summary-compact-error {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 4px;
}

.floating-table-scrollbar {
    position: fixed;
    bottom: 0;
    height: 14px;
    overflow-x: auto;
    overflow-y: hidden;
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid #cbd5e1;
    box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.08);
    z-index: 950;
}

.floating-table-scrollbar.hidden {
    display: none;
}

#floating-table-scrollbar-inner {
    height: 1px;
}


/* 状态标签 */
.status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
}

.status-free, .status-unused { background: #dcfce7; color: #166534; }
.status-bound, .status-active { background: #dbeafe; color: #1e40af; }
.status-expired { background: #fee2e2; color: #991b1b; }
.status-disabled { background: #f3f4f6; color: #6b7280; }
.status-mode, .status-pooled, .status-rotated { background: #ede9fe; color: #6d28d9; }
.status-normal, .status-monitor_only, .status-unlimited { background: #dcfce7; color: #166534; }
.status-warning, .status-awaiting_rotation { background: #fef3c7; color: #b45309; }
.status-exhausted, .status-quota_exhausted, .status-retired { background: #fee2e2; color: #b91c1c; }
.status-unknown { background: #e5e7eb; color: #4b5563; }

.summary-stack {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 170px;
    white-space: normal;
}

.summary-line {
    font-size: 12px;
    color: #111827;
    line-height: 1.45;
}

.summary-meta {
    font-size: 11px;
    color: #6b7280;
    line-height: 1.45;
    white-space: normal;
    word-break: break-word;
}

.muted-text {
    color: #9ca3af;
}

.text-danger {
    color: #dc2626;
}

.empty-hint {
    color: #94a3b8;
    font-size: 13px;
    padding: 10px 0;
}

/* 分页 */
.pagination {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    justify-content: center;
}

.pagination button {
    padding: 6px 12px;
    border: 1px solid #ddd;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.pagination button.active {
    background: #6c63ff;
    color: #fff;
    border-color: #6c63ff;
}

/* 弹窗 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: #fff;
    border-radius: 12px;
    padding: 28px;
    width: 480px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.modal-wide {
    width: min(980px, calc(100vw - 48px));
}

.modal-content h3 {
    margin-bottom: 16px;
    color: #1a1a2e;
}

.modal-content textarea {
    width: 100%;
    height: 160px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-family: monospace;
    font-size: 13px;
    resize: vertical;
}

.form-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.form-row label {
    width: 80px;
    font-size: 14px;
    color: #555;
}

.form-row input, .form-row select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    justify-content: flex-end;
}

.detail-toolbar {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 18px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.detail-cell {
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.detail-cell span {
    font-size: 12px;
    color: #64748b;
}

.detail-cell strong {
    font-size: 13px;
    color: #111827;
    word-break: break-word;
}

.detail-cell-wide {
    grid-column: span 2;
}

.detail-section {
    margin-top: 18px;
}

.detail-section h4 {
    font-size: 14px;
    margin-bottom: 10px;
    color: #1f2937;
}

.summary-card,
.detail-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.detail-item {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 12px;
    background: #fff;
}

.gen-result {
    margin-top: 16px;
    padding: 12px;
    background: #f0fdf4;
    border-radius: 8px;
    font-family: monospace;
    font-size: 12px;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
}

.perm-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 16px;
}
.perm-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}
.perm-label input[type="checkbox"] {
    margin: 0;
}

.hidden { display: none !important; }

/* 提示 */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    z-index: 2000;
    animation: slideIn 0.3s ease;
}

.toast.success { background: #22c55e; }
.toast.error { background: #ef4444; }
.toast.info { background: #3b82f6; }
.toast.warning { background: #f59e0b; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
