:root {
    --bg: #0a0a0f;
    --bg-elevated: #0f1420;
    --border: #1e2530;
    --text: #e6ecf5;
    --text-muted: #94a3b8;
    --accent: #0ea5e9;
    --accent-hover: #0284c7;
    --accent-tint: rgba(14, 165, 233, 0.1);
    --error: #ef4444;
    --radius: 10px;
    --content-width: 1080px;

    --alert-error-bg: rgba(239, 68, 68, 0.1);
    --alert-error-border: rgba(239, 68, 68, 0.35);
    --alert-error-text: #fca5a5;
    --alert-info-bg: rgba(14, 165, 233, 0.1);
    --alert-info-border: rgba(14, 165, 233, 0.35);
    --alert-info-text: #7dd3fc;
    --overlay-bg: rgba(0, 0, 0, 0.6);
    --shadow: rgba(0, 0, 0, 0.45);
}

:root[data-theme="light"] {
    --bg: #f4f6fa;
    --bg-elevated: #ffffff;
    --border: #dbe2ea;
    --text: #101725;
    --text-muted: #5b6779;
    --accent: #0284c7;
    --accent-hover: #036ba1;
    --accent-tint: rgba(2, 132, 199, 0.1);
    --error: #dc2626;

    --alert-error-bg: rgba(220, 38, 38, 0.08);
    --alert-error-border: rgba(220, 38, 38, 0.3);
    --alert-error-text: #b91c1c;
    --alert-info-bg: rgba(2, 132, 199, 0.08);
    --alert-info-border: rgba(2, 132, 199, 0.3);
    --alert-info-text: #036ba1;
    --overlay-bg: rgba(15, 23, 42, 0.35);
    --shadow: rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }

body, .topbar, .footer, .panel, .db-card, .modal, .modal-overlay,
.toast, .field input, .advanced-options, .status-line, code,
.data-table th, .data-table td {
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Manrope", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

.hidden { display: none !important; }

.topbar {
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
}

.topbar-inner {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    font-weight: 600;
    font-size: 17px;
    letter-spacing: 0.2px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.theme-toggle-btn {
    padding: 7px;
}

.theme-toggle-btn svg {
    width: 18px;
    height: 18px;
}

.theme-toggle-btn .icon-moon { display: none; }
:root[data-theme="light"] .theme-toggle-btn .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle-btn .icon-moon { display: block; }

.container {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 32px 24px 64px;
}

.footer {
    border-top: 1px solid var(--border);
    margin-top: 40px;
}

.footer-inner {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 18px 24px;
    color: var(--text-muted);
    font-size: 13px;
}

h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 24px 0 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

.muted { color: var(--text-muted); }
code { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 13px; }

.panel {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}

.panel-narrow { max-width: 420px; margin: 60px auto; }

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.field {
    display: block;
    margin-bottom: 14px;
}

.field span { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-muted); }

.field input, .field select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
}

.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--accent);
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    font-size: 13px;
    color: var(--text-muted);
}

.checkbox-field input { width: auto; }

.advanced-options {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 16px;
}

.advanced-options summary {
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
    user-select: none;
}

.advanced-options[open] summary { margin-bottom: 12px; color: var(--text); }
.advanced-options .field:last-of-type { margin-bottom: 10px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-primary { background: var(--accent); color: #041420; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--accent); }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { color: var(--text); }

.btn-block { width: 100%; margin-top: 4px; }

.alert {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 14px;
    text-wrap: pretty;
}

.alert-error { background: var(--alert-error-bg); border: 1px solid var(--alert-error-border); color: var(--alert-error-text); }
.alert-info { background: var(--alert-info-bg); border: 1px solid var(--alert-info-border); color: var(--alert-info-text); }

.status-line { margin-top: 12px; padding: 10px 12px; border-radius: 8px; font-size: 13px; background: var(--bg); border: 1px solid var(--border); }

.db-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.db-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    cursor: pointer;
    transition: border-color 0.15s ease;
    min-width: 0;
}

.db-card .db-name {
    font-weight: 600;
    margin-bottom: 4px;
    overflow-wrap: anywhere;
}

.db-card:hover { border-color: var(--accent); }
.db-card.selected { border-color: var(--accent); background: var(--accent-tint); }
.db-card .db-meta { font-size: 12px; color: var(--text-muted); }

.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
}

.tab-btn {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    padding: 10px 4px;
    margin-right: 20px;
    font-size: 14px;
    cursor: pointer;
}

.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }

.action-row { display: flex; gap: 10px; margin-bottom: 16px; }

.data-table-wrap {
    overflow-x: auto;
    margin-top: 8px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 500;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.upload-box {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    margin-bottom: 16px;
}

.progress-wrap { margin-bottom: 16px; }

.progress-track {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.1s linear;
}

.progress-meta {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-primary:disabled, .btn-danger:disabled { opacity: 0.5; cursor: not-allowed; }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 440px;
    width: 90%;
}

.modal h2 { margin-bottom: 12px; }
.modal p { margin: 0 0 12px; font-size: 14px; }
.modal .field { margin-top: 16px; }

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

.info-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 16px;
    margin: 0;
}

.info-list dt {
    color: var(--text-muted);
    font-size: 13px;
    white-space: nowrap;
}

.info-list dd {
    margin: 0;
    font-size: 13px;
    word-break: break-word;
}

.restore-proceed-btn {
    margin-top: 12px;
}

.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    z-index: 200;
    max-width: 340px;
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 13px;
    box-shadow: 0 8px 24px var(--shadow);
    cursor: pointer;
    animation: toast-in 0.15s ease-out;
}

.toast:hover { border-color: var(--accent); }
.toast.toast-error { border-left-color: var(--error); }

.toast-title { font-weight: 600; margin-bottom: 4px; }
.toast-body { color: var(--text-muted); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
