:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 8px;
    --shadow: 0 4px 20px rgba(0,0,0,.35);
}

[data-theme="light"] {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-light: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --shadow: 0 4px 20px rgba(0,0,0,.1);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.page { min-height: 100vh; }
.hidden { display: none !important; }

/* Login */
#login {
    display: flex;
    align-items: center;
    justify-content: center;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.card h1 { margin: 0 0 8px; font-size: 22px; }
.card p { margin: 0 0 20px; color: var(--text-muted); }

.card label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

input, select, button, textarea {
    font: inherit;
    border-radius: var(--radius);
    border: 1px solid var(--surface-light);
    background: var(--bg);
    color: var(--text);
    padding: 10px 12px;
    outline: none;
}

textarea { resize: vertical; }

input:focus, select:focus, textarea:focus { border-color: var(--primary); }

button {
    cursor: pointer;
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    font-weight: 600;
    transition: .15s;
}
button:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button.secondary {
    background: transparent;
    border-color: var(--surface-light);
    color: var(--text);
}
button.secondary:hover { background: var(--surface-light); }
button.danger {
    background: var(--danger);
    border-color: var(--danger);
}
button.danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.small { padding: 6px 10px; font-size: 12px; }

#loginBtn { width: 100%; margin-top: 12px; }
.error { color: var(--danger); margin-top: 10px; font-size: 14px; }

/* App */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--surface-light);
}

header h1 { margin: 0; font-size: 18px; }

main { padding: 24px; max-width: 1400px; margin: 0 auto; }

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-label { color: var(--text-muted); font-size: 13px; }
.stat-value { font-size: 28px; font-weight: 700; }

.actions { margin-bottom: 24px; }
.generate-box {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
}
.generate-box h3 { margin: 0 0 8px; width: 100%; font-size: 16px; }
.generate-box label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.generate-box input { min-width: 160px; }

.generated-keys {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
}
.generated-keys h3 {
    margin: 0 0 12px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.generated-keys textarea {
    width: 100%;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 13px;
    line-height: 1.6;
}

.filters {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
}
.filters label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.filters select { min-width: 120px; }
.filters input { flex: 1; min-width: 180px; }

.batch-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--surface);
    border-radius: var(--radius);
    flex-wrap: wrap;
}
.check-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
}
.check-label input { width: 16px; height: 16px; }

.table-wrap {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: auto;
    box-shadow: var(--shadow);
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--surface-light); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; }
tbody tr:hover { background: var(--surface-light); opacity: .85; }
td.key-cell { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }

.check-cell { width: 40px; text-align: center; }
.check-cell input { width: 16px; height: 16px; cursor: pointer; }

.status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status.unused { background: rgba(148,163,184,.15); color: var(--text-muted); }
.status.active { background: rgba(34,197,94,.15); color: var(--success); }
.status.disabled { background: rgba(239,68,68,.15); color: var(--danger); }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.actions-cell { display: flex; gap: 6px; }
.actions-cell button { padding: 6px 10px; font-size: 12px; }

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
}

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--surface);
    border-left: 4px solid var(--primary);
    padding: 14px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transform: translateY(120%);
    transition: transform .25s;
    z-index: 100;
    max-width: 360px;
}
.toast.show { transform: translateY(0); }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
}
.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 640px;
    max-height: 80vh;
    overflow: auto;
    padding: 24px;
}
.modal-content h2, .modal-content h3 { margin-top: 0; }
.modal-content pre {
    background: var(--bg);
    padding: 14px;
    border-radius: var(--radius);
    overflow: auto;
    font-size: 12px;
}

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

.captcha-box {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
.captcha-box img {
    height: 44px;
    border-radius: var(--radius);
    border: 1px solid var(--surface-light);
    background: white;
}
.captcha-box input { width: 100px; }
.captcha-box button { padding: 10px; font-size: 12px; }

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.muted { color: var(--text-muted); font-size: 13px; }

.button-like {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    border: 1px solid var(--surface-light);
    background: transparent;
    color: var(--text);
}
.button-like:hover { background: var(--surface-light); }
.button-like.secondary { border-color: var(--surface-light); }

.empty { text-align: center; color: var(--text-muted); padding: 40px; }

@media (max-width: 768px) {
    .header-actions { flex-wrap: wrap; }
    .captcha-box { flex-wrap: wrap; }
    .filters { flex-direction: column; align-items: stretch; }
    .filters input { width: 100%; }
    .batch-bar { flex-direction: column; align-items: flex-start; }
    main { padding: 16px; }
    .actions-cell { flex-wrap: wrap; }
    th, td { padding: 10px; }
}
