:root {
    color-scheme: light;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f4f6f8;
    color: #17202a;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: inherit; }
.topbar {
    min-height: 64px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #111827;
    color: white;
}
.brand { font-weight: 700; text-decoration: none; }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.container { width: min(1120px, calc(100% - 32px)); margin: 32px auto; }
.card {
    background: white;
    border: 1px solid #dfe4ea;
    border-radius: 14px;
    padding: 24px;
    box-shadow: 0 8px 24px rgba(17, 24, 39, .05);
}
.narrow { max-width: 520px; margin: 64px auto; }
.stack { display: grid; gap: 16px; }
label { display: grid; gap: 7px; font-weight: 600; }
.inline { display: flex; align-items: center; font-weight: 400; }
input, select, button {
    width: 100%;
    min-height: 44px;
    border-radius: 9px;
    border: 1px solid #cbd5e1;
    padding: 10px 12px;
    font: inherit;
}
button {
    border: 0;
    background: #2563eb;
    color: white;
    font-weight: 700;
    cursor: pointer;
}
.link-button { width: auto; min-height: auto; padding: 0; background: transparent; }
.error { margin: -10px 0 0; color: #b42318; }
.muted { color: #667085; }
.hero { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin-bottom: 24px; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; color: #667085; }
h1 { margin: 6px 0 8px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.status {
    border-radius: 999px;
    background: #dcfae6;
    color: #067647;
    padding: 7px 12px;
    font-weight: 700;
}
.status.danger { background: #fee4e2; color: #b42318; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid #eaecf0; }
@media (max-width: 760px) {
    .grid { grid-template-columns: 1fr; }
    .topbar { padding: 0 16px; }
    .container { width: min(100% - 24px, 1120px); margin-top: 20px; }
    .hero { align-items: flex-start; }
}

/* Web installer */
.installer-body { background: #eef2f7; }
.installer-shell { width: min(980px, calc(100% - 28px)); margin: 38px auto 64px; }
.installer-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 22px; }
.installer-header h1 { font-size: clamp(28px, 5vw, 42px); margin-bottom: 0; }
.installer-version { padding: 7px 11px; border-radius: 999px; background: #e0e7ff; color: #3730a3; font-weight: 700; font-size: 13px; }
.installer-card h2 { margin: 0 0 7px; }
.requirements-list { display: grid; border: 1px solid #e2e8f0; border-radius: 12px; overflow: hidden; }
.requirement-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 13px 15px; background: #fff; border-bottom: 1px solid #e2e8f0; }
.requirement-row:last-child { border-bottom: 0; }
.requirement-row div { display: grid; gap: 3px; }
.requirement-row span:not(.status) { color: #64748b; font-size: 14px; }
.status.warn { background: #fef3c7; color: #92400e; }
.status.fail { background: #fee2e2; color: #991b1b; }
.form-grid { display: grid; gap: 16px; }
.form-grid.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid small { color: #64748b; font-weight: 400; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; border-radius: 9px; border: 0; padding: 10px 16px; background: #2563eb; color: #fff; font-weight: 700; text-decoration: none; }
.button.secondary { background: #e2e8f0; color: #1e293b; }
button:disabled, .button[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.installer-actions { display: flex; justify-content: flex-end; gap: 12px; }
.installer-actions.split { justify-content: space-between; }
.alert { border-radius: 11px; padding: 14px 16px; }
.alert p { margin: 6px 0 0; }
.alert ul { margin-bottom: 0; }
.alert-danger { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.database-test-row { display: flex; align-items: center; gap: 14px; }
.database-test-row .button { width: auto; flex: 0 0 auto; }
.database-result { font-size: 14px; }
.database-result.ok { color: #067647; }
.database-result.fail { color: #b42318; }
.database-result.pending { color: #475569; }
.confirm-row { display: flex; align-items: flex-start; gap: 10px; font-weight: 500; }
.confirm-row input { width: 18px; min-height: 18px; margin-top: 2px; }
.success-mark, .failure-mark { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 50%; font-size: 30px; font-weight: 800; }
.success-mark { background: #dcfae6; color: #067647; }
.failure-mark { background: #fee2e2; color: #b42318; }
.summary-list { display: grid; gap: 0; margin: 0; border: 1px solid #e2e8f0; border-radius: 12px; overflow: hidden; }
.summary-list div { display: grid; grid-template-columns: 180px 1fr; gap: 16px; padding: 12px 15px; border-bottom: 1px solid #e2e8f0; }
.summary-list div:last-child { border-bottom: 0; }
.summary-list dt { font-weight: 700; }
.summary-list dd { margin: 0; word-break: break-word; }
pre { white-space: pre-wrap; word-break: break-all; background: #111827; color: #f8fafc; padding: 13px; border-radius: 9px; overflow: auto; }
@media (max-width: 760px) {
    .form-grid.two-columns, .form-grid.three-columns { grid-template-columns: 1fr; }
    .installer-header { align-items: flex-start; }
    .installer-actions, .installer-actions.split { flex-direction: column-reverse; }
    .installer-actions .button, .installer-actions button { width: 100%; }
    .database-test-row { align-items: stretch; flex-direction: column; }
    .summary-list div { grid-template-columns: 1fr; gap: 4px; }
}

/* Application shell */
.app-body { background: #f5f7fb; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 24px 18px;
    background: #111827;
    color: #fff;
}
.sidebar-brand { display: grid; gap: 4px; padding: 0 10px 22px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-brand a { font-size: 20px; font-weight: 800; text-decoration: none; }
.sidebar-brand small { color: #94a3b8; }
.sidebar-nav { display: grid; gap: 5px; padding: 20px 0; }
.sidebar-nav a { padding: 11px 12px; border-radius: 9px; color: #cbd5e1; text-decoration: none; font-weight: 650; }
.sidebar-nav a:hover, .sidebar-nav a.active { background: #1f2937; color: #fff; }
.nav-section { margin: 16px 12px 4px; color: #64748b; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.sidebar-user { margin-top: auto; display: grid; gap: 5px; padding: 18px 10px 0; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-user span { color: #94a3b8; font-size: 13px; overflow-wrap: anywhere; }
.sidebar-user form { margin-top: 8px; }
.app-main { min-width: 0; }
.app-container { width: min(1240px, calc(100% - 48px)); margin: 32px auto 64px; }
.mobile-header { display: none; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-header h1 { margin: 5px 0 7px; font-size: clamp(28px, 4vw, 38px); }
.page-header > .button, .page-header > button { width: auto; min-width: 150px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stats-grid.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-card { display: grid; gap: 6px; min-height: 128px; padding: 20px; border: 1px solid #e2e8f0; border-radius: 14px; background: #fff; box-shadow: 0 6px 18px rgba(15,23,42,.04); }
.stat-card span { color: #64748b; font-weight: 650; }
.stat-card strong { font-size: 32px; line-height: 1; }
.stat-card strong.stat-text { font-size: 19px; line-height: 1.25; }
.stat-card small { color: #94a3b8; }
.content-grid { display: grid; gap: 18px; align-items: start; }
.content-grid.two-thirds { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.card-header h2 { margin: 4px 0 0; }
.card-header .button { width: auto; white-space: nowrap; }
.compact-list { display: grid; gap: 0; margin: 10px 0 0; }
.compact-list div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid #eef2f6; }
.compact-list div:last-child { border-bottom: 0; }
.compact-list dt { color: #64748b; }
.compact-list dd { margin: 0; font-weight: 700; text-align: right; }
.notice { margin-bottom: 20px; padding: 14px 16px; border: 1px solid #dbe4ee; border-radius: 11px; background: #fff; }
.notice p { margin: 5px 0 0; }
.notice ul { margin-bottom: 0; }
.notice.success { background: #ecfdf3; border-color: #abefc6; color: #067647; }
.notice.warning { background: #fffaeb; border-color: #fedf89; color: #93370d; }
.notice.danger { background: #fef3f2; border-color: #fecdca; color: #b42318; }
.status { display: inline-flex; align-items: center; justify-content: center; width: fit-content; border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 800; letter-spacing: .02em; background: #eef2f6; color: #475467; }
.status.success, .status.active { background: #dcfae6; color: #067647; }
.status.warning, .status.pending, .status.pending_connection { background: #fef0c7; color: #b54708; }
.status.error, .status.connection_error, .status.expired { background: #fee4e2; color: #b42318; }
.status.archived, .status.disconnected { background: #eaecf0; color: #475467; }
.button { width: auto; }
.button.secondary { background: #eef2f6; color: #344054; }
.button.ghost { background: transparent; border: 1px solid rgba(255,255,255,.22); color: #fff; }
.button.small { min-height: 36px; padding: 7px 10px; font-size: 13px; }
.button.danger { background: #b42318; }
.text-link { color: #175cd3; font-weight: 700; text-decoration: none; }
.text-link:hover { text-decoration: underline; }
.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
.table-card table { min-width: 760px; }
.table-card th { color: #475467; background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table-card td { vertical-align: middle; }
.cell-subtitle { display: block; margin-top: 4px; color: #667085; font-size: 13px; }
.row-muted { opacity: .65; }
.empty-state { display: grid; justify-items: start; gap: 10px; padding: 48px; }
.empty-state h2, .empty-state p { margin: 0; }
.form-card h2 { margin-top: 0; }
textarea { width: 100%; border-radius: 9px; border: 1px solid #cbd5e1; padding: 10px 12px; font: inherit; resize: vertical; }
label small { color: #667085; font-weight: 400; }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; padding-top: 8px; }
.form-actions button, .form-actions .button { width: auto; min-width: 150px; }
.input-prefix { display: grid; grid-template-columns: 42px minmax(0, 1fr); }
.input-prefix span { display: grid; place-items: center; border: 1px solid #cbd5e1; border-right: 0; border-radius: 9px 0 0 9px; background: #f8fafc; color: #667085; }
.input-prefix input { border-radius: 0 9px 9px 0; }
.check-row { display: flex; align-items: flex-start; gap: 10px; }
.check-row input { width: 18px; min-height: 18px; margin-top: 2px; }
.capability-list { display: grid; gap: 0; }
.capability-list div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid #eef2f6; }
.capability-list div:last-child { border-bottom: 0; }
.capability-list span { overflow-wrap: anywhere; }
.capability-list strong { color: #667085; font-size: 12px; }
.danger-zone { border-color: #fecdca; }
.migration-list { display: grid; gap: 8px; margin: 18px 0; }
.migration-list code { padding: 9px 10px; border-radius: 8px; background: #f2f4f7; overflow-wrap: anywhere; }
.summary-list.clean { margin-bottom: 18px; }
.steps-list { padding-left: 20px; color: #475467; }
.steps-list li { margin-bottom: 9px; }

@media (max-width: 1020px) {
    .app-shell { grid-template-columns: 210px minmax(0, 1fr); }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .content-grid.two-thirds { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar { position: static; height: auto; padding: 16px; }
    .sidebar-brand { border-bottom: 0; padding-bottom: 10px; }
    .sidebar-nav { display: flex; overflow-x: auto; padding: 8px 0; }
    .sidebar-nav a { white-space: nowrap; }
    .nav-section, .sidebar-user { display: none; }
    .app-container { width: min(100% - 24px, 1240px); margin-top: 20px; }
    .page-header { flex-direction: column; }
    .page-header > .button, .page-header > button { width: 100%; }
    .stats-grid, .stats-grid.compact { grid-template-columns: 1fr; }
    .stat-card { min-height: 105px; }
    .card-header { flex-direction: column; }
    .card-header .button { width: 100%; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions button, .form-actions .button { width: 100%; }
    .empty-state { padding: 30px 22px; }
}

/* v3 analytics */
.filter-card { margin-bottom: 20px; }
.filter-row { display: grid; grid-template-columns: minmax(220px, 2fr) minmax(160px, 1fr) auto auto; gap: 14px; align-items: end; }
.filter-row .button, .filter-row button { min-width: 130px; }
.analytics-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.analytics-grid { align-items: start; }
.bar-chart { display: grid; gap: 10px; margin-top: 18px; }
.bar-chart-row { display: grid; grid-template-columns: 96px minmax(120px, 1fr) 90px; align-items: center; gap: 12px; font-size: 13px; }
.bar-chart-row strong { text-align: right; }
.bar-track { height: 12px; border-radius: 999px; background: #e7edf5; overflow: hidden; }
.bar-track i { display: block; height: 100%; border-radius: inherit; background: #2563eb; }
.small-copy { font-size: 13px; line-height: 1.55; }
code { overflow-wrap: anywhere; }
.status.completed { background: #dcfce7; color: #166534; }
.status.partial { background: #fef3c7; color: #92400e; }
.status.failed { background: #fee2e2; color: #991b1b; }
.status.running { background: #dbeafe; color: #1d4ed8; }
@media (max-width: 900px) {
    .filter-row, .analytics-kpis { grid-template-columns: 1fr; }
    .bar-chart-row { grid-template-columns: 78px minmax(100px, 1fr) 70px; }
}
