/* ============================================
   opencode-zen-proxy — 简洁白配色样式
   ============================================ */

/* ── CSS Variables ── */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --bg: #ffffff;
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --bg-hover: #f8fafc;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --success: #22c55e;
    --success-bg: #dcfce7;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.07), 0 10px 15px rgba(0, 0, 0, 0.05);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg-body);
    line-height: 1.6;
    min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

/* ── Layout ── */
.app-layout {
    display: flex;
    min-height: 100vh;
}
.sidebar {
    width: 240px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 1.5rem 0;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
}
.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 2rem;
    max-width: 1200px;
    width: 100%;
}

/* ── Sidebar ── */
.sidebar-logo {
    padding: 0 1.5rem 1.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.sidebar-logo span { color: var(--primary); }
.sidebar-nav { list-style: none; padding: 0; }
.sidebar-nav li { margin: 0; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s;
    text-decoration: none;
}
.sidebar-nav a:hover {
    background: var(--bg-hover);
    color: var(--text);
    text-decoration: none;
}
.sidebar-nav a.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}
.sidebar-nav a .icon { font-size: 1.1rem; width: 1.5rem; text-align: center; }
.sidebar-footer {
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ── Top bar ── */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 0.875rem; color: var(--text-secondary); margin-top: 0.25rem; }

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}
.card-title { font-size: 1rem; font-weight: 600; color: var(--text); }

/* ── Stat Cards ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    margin-top: 0.25rem;
}
.stat-card .stat-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ── Login Page ── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-body);
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}
.login-card h1 {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.5rem;
}
.login-card p {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.375rem;
}
.form-input, .form-select {
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    font-family: var(--font);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}
.form-input:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.form-input::placeholder { color: var(--text-muted); }
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
textarea.form-input { min-height: 80px; resize: vertical; font-family: "SFMono-Regular", Consolas, monospace; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    background: var(--bg);
    color: var(--text);
    text-decoration: none;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ── Table ── */
.table-wrapper { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
th, td {
    padding: 0.75rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: var(--bg-body);
}
tr:hover { background: var(--bg-hover); }

/* ── Badge ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
}
.badge-success { background: var(--success-bg); color: #166534; }
.badge-danger { background: var(--danger-bg); color: #991b1b; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* ── Pagination ── */
.pagination {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    justify-content: center;
}
.pagination a, .pagination span {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
}
.pagination a:hover { background: var(--bg-hover); text-decoration: none; }
.pagination .active { background: var(--primary); color: white; border-color: var(--primary); }

/* ── Alert / Message ── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}
.alert-error { background: var(--danger-bg); color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: var(--success-bg); color: #166534; border: 1px solid #bbf7d0; }

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 500px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}
.modal h2 { font-size: 1.125rem; margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.5rem; }

/* ── Code Blocks ── */
.code-block {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: var(--radius);
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.8rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 400px;
    overflow-y: auto;
}

/* ── Key Display ── */
.key-display {
    font-family: "SFMono-Regular", Consolas, monospace;
    background: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    word-break: break-all;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

/* ── Filters ── */
.filters {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.filters .form-group { margin-bottom: 0; }

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state p { font-size: 0.9rem; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; padding: 1rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .filters { flex-direction: column; }
    .top-bar { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
}

/* ── Utility ── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-sm { font-size: 0.875rem; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; display: inline-block; vertical-align: middle; }

/* ── Checkbox Toggle ── */
.toggle {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #cbd5e1;
    border-radius: 22px;
    transition: 0.2s;
}
.toggle-slider::before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ── Copy Key Button ── */
.btn-copy-key {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 2px 4px;
    margin-left: 4px;
    vertical-align: middle;
    border-radius: 3px;
    display: inline-flex;
    align-items: center;
    transition: color 0.15s, background 0.15s;
}
.btn-copy-key:hover { color: var(--primary); background: var(--bg-body); }

/* ── Forwarding Trace ── */
.trace-container {
    padding: 0.5rem 0;
}
.trace-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.trace-entry {
    padding: 0.625rem 0.75rem;
    background: var(--bg-body);
    border-radius: var(--radius);
    font-size: 0.875rem;
    line-height: 1.5;
    border-left: 3px solid transparent;
}
.trace-entry:has(🟢) {
    border-left-color: var(--success);
}
.trace-entry:has(🔴) {
    border-left-color: var(--danger);
}
.trace-error {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 0.125rem;
    font-family: "SFMono-Regular", Consolas, monospace;
}
