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

:root {
    --bg: #f5f5f5;
    --card-bg: #fff;
    --text: #333;
    --text-muted: #888;
    --border: #ddd;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --info: #0ea5e9;
    --radius: 6px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Navbar */
.navbar {
    background: #1e293b;
    color: #fff;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
}
.nav-brand a { color: #fff; text-decoration: none; font-weight: 600; font-size: 1.1rem; }
.nav-links { display: flex; align-items: center; gap: 1rem; }
.nav-links a { color: #cbd5e1; text-decoration: none; font-size: 0.9rem; }
.nav-links a:hover { color: #fff; }
.nav-user { color: #94a3b8; font-size: 0.85rem; }

/* Container */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

/* Page header */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; }
.page-actions { display: flex; gap: 0.5rem; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
    color: var(--text);
    text-decoration: none;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.15s;
}
.btn:hover { background: #f0f0f0; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
.btn-full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; }
.stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-label { font-size: 0.85rem; color: var(--text-muted); }
.stat-success .stat-value { color: var(--success); }
.stat-danger .stat-value { color: var(--danger); }

/* Sites grid */
.sites-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; }
.site-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.site-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.site-header h3 { font-size: 1rem; }
.site-header h3 a { color: var(--text); text-decoration: none; }
.site-header h3 a:hover { color: var(--primary); }
.site-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.meta-item { font-size: 0.8rem; color: var(--text-muted); }
.site-actions { display: flex; gap: 0.5rem; }

/* Badges */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 500; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-running { background: #dbeafe; color: #1d4ed8; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-none { background: #f1f5f9; color: #64748b; }
.badge-info { background: #e0f2fe; color: #0369a1; }
.badge-default { background: #f1f5f9; color: #475569; }

/* Tables */
.table { width: 100%; border-collapse: collapse; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th { background: #f8fafc; text-align: left; padding: 0.6rem 0.75rem; font-size: 0.8rem; color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border); }
.table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid #f1f5f9; font-size: 0.875rem; }
.table tr:last-child td { border-bottom: none; }
.actions-cell { white-space: nowrap; }
.actions-cell .btn { margin-right: 0.25rem; }

/* Forms */
.form-container { max-width: 700px; }
.form-section { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.form-section h2 { font-size: 1rem; margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid #f1f5f9; }
.form-group { margin-bottom: 0.75rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 0.25rem; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 0.9rem; font-family: inherit;
}
.form-group small { color: var(--text-muted); font-size: 0.8rem; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; }
.form-actions { margin-top: 1rem; display: flex; gap: 0.5rem; }
.form-inline { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.form-inline input, .form-inline select { width: auto; min-width: 150px; padding: 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); }

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }

/* Login */
.login-container { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.login-box { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; width: 100%; max-width: 380px; }
.login-box h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }

/* Info grid */
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 0.5rem; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.5rem; }
.info-item { font-size: 0.875rem; }
.info-item strong { color: var(--text-muted); }

/* File browser */
.breadcrumbs { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem; margin-bottom: 1rem; font-size: 0.875rem; }
.breadcrumbs a { color: var(--primary); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }

/* Code viewer */
.code-block { background: #1e293b; color: #e2e8f0; padding: 1rem; border-radius: var(--radius); overflow-x: auto; font-size: 0.8rem; line-height: 1.6; max-height: 80vh; }
.file-info { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1rem; }

/* Users Layout */
.users-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 1.5rem;
    align-items: start;
}
.users-sidebar .form-section { position: sticky; top: 1rem; }
.users-main h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.user-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    overflow: hidden;
}
.user-card-header {
    padding: 0.75rem 1rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.user-identity { display: flex; align-items: center; gap: 0.5rem; }
.user-name { font-size: 0.95rem; }
.user-email { font-size: 0.8rem; color: var(--text-muted); }
.user-card-body { padding: 1rem; }
.user-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}
.user-fields .form-group { margin-bottom: 0; }
.user-fields .form-group label { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 0.15rem; }
.user-fields .form-group input,
.user-fields .form-group select { padding: 0.4rem 0.5rem; font-size: 0.85rem; }
.toggle-label { display: flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; cursor: pointer; padding-top: 0.3rem; }
.user-sites { border-top: 1px solid #f1f5f9; padding-top: 0.75rem; }
.user-sites > label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; display: block; margin-bottom: 0.35rem; }
.site-checks { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; }
.site-check { font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; gap: 0.3rem; }
.user-card-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    background: #fafafa;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Empty state */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state .btn { margin-top: 1rem; }

/* Section */
.section { margin-bottom: 2rem; }
.section h2 { font-size: 1.1rem; margin-bottom: 1rem; }

/* Error text */
.error-text { color: var(--danger); font-size: 0.8rem; cursor: help; }

/* File Changes Panel */
.changes-panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 1rem;
}
.changes-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}
.changes-header h3 { font-size: 1rem; margin: 0; }
.changes-summary { padding: 0.75rem 1rem; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.changes-list { padding: 0 1rem 1rem; }
.change-item {
    padding: 0.3rem 0.5rem;
    font-size: 0.82rem;
    font-family: 'SF Mono', SFMono-Regular, Consolas, monospace;
    border-radius: 3px;
    margin-bottom: 2px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.change-added { background: #f0fdf4; color: #166534; }
.change-removed { background: #fef2f2; color: #991b1b; }
.change-modified { background: #fffbeb; color: #92400e; }

/* DB Browser Layout */
.db-browser {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 1rem;
    min-height: calc(100vh - 140px);
}
.db-sidebar {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.db-sidebar-header {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}
.db-sidebar-header input {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
}
.db-table-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.25rem 0;
}
.db-table-item {
    padding: 0.35rem 0.75rem;
    font-size: 0.82rem;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-left: 3px solid transparent;
}
.db-table-item:hover { background: #f8fafc; }
.db-table-item.active { background: #eff6ff; border-left-color: var(--primary); font-weight: 500; }
.db-table-icon {
    display: inline-block;
    width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    background: #e2e8f0;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    color: #64748b;
    vertical-align: middle;
    margin-right: 0.25rem;
}

/* DB Main Area */
.db-main {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.db-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}
.db-tab {
    padding: 0.6rem 1.25rem;
    border: none;
    background: none;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.db-tab:hover { color: var(--text); }
.db-tab.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--card-bg); }
.db-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.db-toolbar {
    padding: 0.5rem 0.75rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    border-bottom: 1px solid #f1f5f9;
    flex-wrap: wrap;
}
.db-toolbar input {
    flex: 1;
    min-width: 150px;
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
}
.db-grid-wrap {
    flex: 1;
    overflow: auto;
}
.db-data-table {
    font-size: 0.8rem;
    border: none;
    border-radius: 0;
}
.db-data-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    white-space: nowrap;
}
.db-data-table th.sortable { cursor: pointer; user-select: none; }
.db-data-table th.sortable:hover { background: #eef2ff; }
.db-data-table td {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.db-data-table td.null-val { color: #94a3b8; font-style: italic; }
.db-pagination {
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--border);
}
.db-page-controls {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    flex-wrap: wrap;
}

/* SQL Query Panel */
.db-sql-input {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}
.db-sql-input textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: 'SF Mono', SFMono-Regular, Consolas, monospace;
    font-size: 0.85rem;
    resize: vertical;
    min-height: 80px;
}
.db-sql-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
}

/* Loading Overlay */
.db-loading {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.db-loading-inner { text-align: center; }
.db-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 768px) {
    .navbar { padding: 0 1rem; }
    .nav-links { gap: 0.5rem; }
    .container { padding: 1rem; }
    .sites-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
    .db-browser { grid-template-columns: 1fr; min-height: auto; }
    .db-sidebar { max-height: 200px; }
    .users-layout { grid-template-columns: 1fr; }
    .users-sidebar .form-section { position: static; }
    .bp-stages { flex-direction: column; gap: 0.5rem; }
}

/* Backup Progress Panel */
.backup-progress {
    background: var(--card-bg);
    border: 1px solid var(--primary);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    animation: bp-fadein 0.3s ease;
}
@keyframes bp-fadein { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

.bp-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.bp-header h3 { font-size: 1rem; font-weight: 600; color: var(--text); }
.bp-elapsed {
    font-family: monospace;
    font-size: 0.9rem;
    color: var(--text-muted);
    background: var(--bg);
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius);
}

.bp-stages {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.bp-stage {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    opacity: 0.35;
    transition: opacity 0.3s ease;
}
.bp-stage.bp-done, .bp-stage.bp-active, .bp-stage.bp-error { opacity: 1; }

.bp-stage-icon { flex-shrink: 0; width: 20px; display: flex; justify-content: center; }

.bp-stage-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--border);
    transition: all 0.3s ease;
}
.bp-stage.bp-active .bp-stage-dot {
    background: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.25);
    animation: bp-pulse 1.5s ease infinite;
}
@keyframes bp-pulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(37,99,235,0.25); }
    50% { box-shadow: 0 0 0 6px rgba(37,99,235,0.1); }
}
.bp-stage.bp-done .bp-stage-dot { background: var(--success); }
.bp-stage.bp-error .bp-stage-dot { background: var(--danger); }

.bp-stage-content { flex: 1; min-width: 0; }
.bp-stage-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.25rem;
}
.bp-stage-label { font-size: 0.8rem; font-weight: 500; color: var(--text); }
.bp-stage-info { font-size: 0.75rem; color: var(--text-muted); font-family: monospace; }

.bp-bar-wrap {
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
}
.bp-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.5s ease;
    width: 0%;
}
.bp-bar.bp-bar-done { background: var(--success); }
.bp-bar.bp-bar-error { background: var(--danger); }
.bp-bar.bp-bar-indeterminate {
    animation: bp-indeterminate 1.5s ease infinite;
    background: linear-gradient(90deg, var(--primary), rgba(37,99,235,0.4), var(--primary));
    background-size: 200% 100%;
}
@keyframes bp-indeterminate {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.bp-message {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.backup-progress.bp-complete { border-left-color: var(--success); border-color: var(--success); }
.backup-progress.bp-complete .bp-header h3 { color: var(--success); }
.backup-progress.bp-warning { border-left-color: var(--warning); border-color: var(--warning); }
.backup-progress.bp-warning .bp-header h3 { color: var(--warning); }
.backup-progress.bp-failed { border-left-color: var(--danger); border-color: var(--danger); }
.backup-progress.bp-failed .bp-header h3 { color: var(--danger); }

/* Site Groups */
.site-group { margin-bottom: 1.5rem; }
.site-group-name {
    font-size: 1.1rem; font-weight: 600; color: var(--text-muted);
    margin-bottom: .5rem; padding-bottom: .25rem;
    border-bottom: 2px solid var(--border);
}
.site-group-cards {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

/* Progress Card */
.progress-card {
    background: var(--card-bg);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.1);
}
.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.progress-stage {
    font-weight: 600;
    font-size: 0.95rem;
}
.progress-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.progress-bar-track {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.25rem;
}
.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.5s ease;
}
.progress-bar-indeterminate {
    width: 30% !important;
    animation: indeterminate 1.5s infinite ease-in-out;
}
@keyframes indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}
.progress-pct {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: right;
}

/* Changes Panel */
.changes-panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 1rem;
}
.changes-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}
.changes-summary {
    padding: 0.5rem 1rem;
}
.change-item {
    padding: 0.25rem 1rem;
    font-family: monospace;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--bg);
}
.change-added { color: var(--success); }
.change-removed { color: var(--danger); }
.change-modified { color: var(--warning); }

/* Mini progress (dashboard cards) */
.progress-mini {
    padding: 0.25rem 0 0.5rem;
}
.progress-mini-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}
