:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-soft: #eef4ff;
  --card: rgba(255, 255, 255, .93);
  --card-solid: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #dbe4f0;
  --line-strong: #cbd5e1;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #16a34a;
  --shadow: 0 20px 70px rgba(15, 23, 42, .10);
  --shadow-soft: 0 12px 28px rgba(15, 23, 42, .06);
  --radius: 22px;
  --radius-sm: 14px;
  --focus: 0 0 0 4px rgba(37, 99, 235, .14);
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #09111f;
  --bg-soft: #0f1b31;
  --card: rgba(15, 23, 42, .88);
  --card-solid: #111827;
  --text: #e5edf8;
  --muted: #9fb0c8;
  --line: #26344a;
  --line-strong: #334155;
  --primary: #60a5fa;
  --primary-strong: #3b82f6;
  --primary-soft: rgba(96, 165, 250, .12);
  --danger: #f87171;
  --warning: #fbbf24;
  --success: #4ade80;
  --shadow: 0 24px 80px rgba(0, 0, 0, .30);
  --shadow-soft: 0 12px 30px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, .22), transparent 34rem),
    radial-gradient(circle at top right, rgba(34, 197, 94, .13), transparent 26rem),
    linear-gradient(135deg, var(--bg), var(--bg-soft));
  font-size: 16px;
  line-height: 1.5;
}

a { color: inherit; }
form { margin: 0; }
code, .kbd {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  overflow-wrap: anywhere;
  background: var(--primary-soft);
  border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--line));
  border-radius: 10px;
  padding: 2px 7px;
  color: var(--primary-strong);
  font-weight: 800;
}

.app-shell {
  width: min(1420px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 18px;
  padding: 22px;
  border: 1px solid rgba(219, 228, 240, .75);
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(255,255,255,.80), rgba(255,255,255,.55));
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
}
:root[data-theme='dark'] .topbar { background: linear-gradient(145deg, rgba(15,23,42,.86), rgba(15,23,42,.62)); }
.brand-row { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 54px;
  height: 54px;
  display: inline-grid;
  place-items: center;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #22c55e);
  box-shadow: 0 16px 36px rgba(37, 99, 235, .22);
  font-size: 26px;
}
.topbar h1 { margin: 2px 0 5px; font-size: clamp(28px, 3vw, 40px); letter-spacing: -.045em; line-height: 1.08; }
.topbar p { margin: 0; color: var(--muted); font-size: 16px; max-width: 760px; }
.eyebrow { text-transform: uppercase; font-weight: 900; letter-spacing: .14em; color: var(--primary-strong); font-size: 12px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.tabs {
  position: sticky;
  top: 10px;
  z-index: 30;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 18px 0;
  padding: 8px;
  border: 1px solid rgba(219, 228, 240, .85);
  border-radius: 999px;
  background: rgba(255, 255, 255, .78);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
}
:root[data-theme='dark'] .tabs { background: rgba(15, 23, 42, .78); }
.tabs a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  padding: 11px 15px;
  border-radius: 999px;
  font-weight: 900;
  transition: .16s ease;
}
.tabs a:hover { background: var(--primary-soft); color: var(--primary-strong); }
.tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); box-shadow: 0 12px 24px rgba(37, 99, 235, .22); }

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}
.quick-action {
  min-height: 112px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  text-decoration: none;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow-soft);
  transition: .16s ease;
}
.quick-action:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); }
.quick-action .icon { width: 42px; height: 42px; flex: 0 0 42px; display: grid; place-items: center; border-radius: 15px; background: var(--primary-soft); font-size: 22px; }
.quick-action b { display: block; margin-bottom: 4px; font-size: 16px; }
.quick-action span { display: block; color: var(--muted); font-size: 13px; line-height: 1.35; }

.card {
  background: var(--card);
  border: 1px solid rgba(219, 228, 240, .90);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
  backdrop-filter: blur(12px);
}
.card.compact { padding: 18px; }
.card-header { margin-bottom: 18px; }
.card-header h2 { margin: 0 0 7px; font-size: clamp(22px, 2vw, 27px); letter-spacing: -.035em; }
.card-header h3 { margin: 0; }
.card-header p { margin: 0; color: var(--muted); }
.split { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid.single { grid-template-columns: 1fr; }
.span-2 { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 8px; font-weight: 900; color: var(--text); }
.field-hint { color: var(--muted); font-size: 12px; font-weight: 700; margin-top: -3px; }
.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row input { flex: 1; }
input, select, textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line-strong);
  background: var(--card-solid);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font: inherit;
  color: var(--text);
  outline: none;
  transition: .15s ease;
}
textarea { resize: vertical; min-height: 118px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: var(--focus); }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 72%, transparent); }

.btn {
  appearance: none;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  min-height: 44px;
  font-weight: 950;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  line-height: 1;
  background: #e2e8f0;
  color: #0f172a;
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease, background .15s ease;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-soft); }
.btn:disabled, .btn.disabled { opacity: .58; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-strong); }
.btn-ghost { background: var(--card-solid); color: var(--text); border: 1px solid var(--line); }
.btn-soft { background: var(--primary-soft); color: var(--primary-strong); border: 1px solid color-mix(in srgb, var(--primary) 26%, var(--line)); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-lg { padding: 15px 22px; font-size: 16px; min-height: 52px; }
.btn.loading { pointer-events: none; opacity: .82; }
.btn.loading::before { content: ''; width: 15px; height: 15px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.actions.vertical { flex-direction: column; align-items: stretch; }
.actions.compact .btn { padding: 9px 11px; min-height: 36px; border-radius: 12px; font-size: 13px; }
.mini-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0 14px; }

.alert {
  padding: 14px 18px;
  border-radius: 17px;
  margin-bottom: 16px;
  border: 1px solid;
  font-weight: 800;
}
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-success { background: #ecfdf5; border-color: #bbf7d0; color: #166534; }
.alert-danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
:root[data-theme='dark'] .alert-warning { background: rgba(217,119,6,.14); border-color: rgba(251,191,36,.32); color: #fde68a; }
:root[data-theme='dark'] .alert-success { background: rgba(22,163,74,.14); border-color: rgba(74,222,128,.35); color: #bbf7d0; }
:root[data-theme='dark'] .alert-danger { background: rgba(220,38,38,.16); border-color: rgba(248,113,113,.35); color: #fecaca; }

.codeblock {
  display: block;
  width: 100%;
  background: var(--card-solid);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  overflow: auto;
  color: var(--text);
}
.login-card { max-width: 560px; margin: 44px auto; }
.login-aside { max-width: 720px; margin: -20px auto 36px; }

.database-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  margin: 10px 0 16px;
  max-height: 320px;
  overflow: auto;
  padding: 4px;
}
.check-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--card-solid);
  padding: 12px;
  transition: .15s ease;
}
.check-card:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); box-shadow: var(--shadow-soft); }
.check-card input { width: auto; min-height: auto; }
.check-card span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 16px 0; }
.toggle {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  background: var(--card-solid);
  border: 1px solid var(--line);
  padding: 12px 14px;
  border-radius: 15px;
  min-height: 48px;
}
.toggle input { width: auto; min-height: auto; }
.section-title { font-size: 18px; font-weight: 950; margin: 22px 0 10px; display: flex; align-items: center; gap: 8px; }
.section-title::before { content: ''; width: 8px; height: 22px; border-radius: 999px; background: linear-gradient(180deg, var(--primary), #22c55e); }

.mini-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.mini-stats span, .badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--line));
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 950;
}
.badge.ok { background: #ecfdf5; color: #166534; border-color: #bbf7d0; }
.badge.warn { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.badge.danger { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
:root[data-theme='dark'] .badge.ok { background: rgba(22,163,74,.16); color: #bbf7d0; border-color: rgba(74,222,128,.34); }
:root[data-theme='dark'] .badge.warn { background: rgba(217,119,6,.16); color: #fde68a; border-color: rgba(251,191,36,.34); }
:root[data-theme='dark'] .badge.danger { background: rgba(220,38,38,.16); color: #fecaca; border-color: rgba(248,113,113,.34); }

.table-search { margin: 0; max-width: 360px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 18px; background: var(--card-solid); }
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 760px; }
th, td { text-align: left; padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); background: color-mix(in srgb, var(--card-solid) 86%, var(--primary-soft)); position: sticky; top: 0; z-index: 1; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--primary-soft) 45%, transparent); }
.details-row pre { white-space: pre-wrap; font-size: 13px; background: var(--bg-soft); border-radius: 14px; padding: 14px; }
.table-wrap small, small { color: var(--muted); }

.progress-panel {
  position: sticky;
  bottom: 18px;
  z-index: 40;
  border-color: color-mix(in srgb, var(--primary) 35%, var(--line));
}
.progress { height: 18px; background: color-mix(in srgb, var(--line) 70%, var(--card-solid)); border-radius: 999px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: linear-gradient(90deg, #2563eb, #22c55e); transition: width .25s ease; }
#progressPercent { font-size: 28px; }
#progressDetails { margin-top: 12px; }
.progress-detail-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.muted { color: var(--muted); }
.warn { color: var(--warning); }
.empty { color: var(--muted); background: var(--card-solid); border: 1px dashed var(--line-strong); border-radius: 16px; padding: 16px; }
.hidden { display: none !important; }
.help-text, .callout {
  background: var(--card-solid);
  border: 1px dashed var(--line-strong);
  border-radius: 15px;
  padding: 12px 14px;
  color: var(--muted);
  font-weight: 750;
  line-height: 1.45;
}
.help-text b, .callout b { color: var(--text); }

.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.status-grid div, .stat, .step-card {
  background: var(--card-solid);
  border: 1px solid var(--line);
  border-radius: 17px;
  padding: 16px;
}
.status-grid b, .stat span, .step-card span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.status-grid span, .stat strong { display: block; font-size: 20px; font-weight: 950; overflow-wrap: anywhere; }
.stat strong { letter-spacing: -.025em; }
.stats-row .card { margin-bottom: 0; }
.step-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.step-card { display: flex; gap: 13px; align-items: flex-start; }
.step-card .step-num { flex: 0 0 34px; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 12px; background: var(--primary); color: #fff; font-weight: 950; }
.step-card h3 { margin: 0 0 4px; font-size: 17px; }
.step-card p { margin: 0; color: var(--muted); font-size: 14px; }

.profile-list { display: flex; flex-direction: column; gap: 12px; }
.profile-main { min-width: 0; }
.profile-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 16px; border: 1px solid var(--line); background: var(--card-solid); border-radius: 18px; padding: 16px; }
.profile-card h3 { margin: 0 0 4px; }
.profile-card p { margin: 0 0 8px; color: var(--muted); overflow-wrap: anywhere; }
.profile-edit { grid-column: 1 / -1; background: color-mix(in srgb, var(--card-solid) 92%, var(--primary-soft)); border: 1px solid var(--line); border-radius: 16px; padding: 12px; margin-top: 4px; }
.profile-edit summary { cursor: pointer; font-weight: 950; color: var(--primary-strong); list-style: none; }
.profile-edit summary::-webkit-details-marker { display: none; }
.profile-edit summary::before { content: '✎'; display: inline-flex; width: 26px; height: 26px; align-items: center; justify-content: center; margin-right: 8px; border-radius: 999px; background: var(--primary-soft); border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--line)); }
.profile-edit[open] summary { margin-bottom: 14px; }
.profile-edit .form-grid { border-top: 1px dashed var(--line); padding-top: 14px; }
.profile-card small .badge { padding: 4px 8px; font-size: 12px; vertical-align: middle; }

.danger-zone { border-color: color-mix(in srgb, var(--danger) 36%, var(--line)); }
.restore-result pre { background: #0f172a; color: #e2e8f0; border-radius: 16px; padding: 16px; overflow: auto; }
.checklist { margin: 0; padding-left: 22px; color: var(--text); }
.checklist li { margin: 10px 0; }
.connection-result { background: var(--card-solid); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-top: 4px; }
.connection-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 12px 0; }
.connection-meta span { display: block; background: color-mix(in srgb, var(--card-solid) 92%, var(--primary-soft)); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; color: var(--text); font-weight: 850; overflow-wrap: anywhere; }
.connection-meta b { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.connection-table { margin-top: 12px; }
.connection-table table { min-width: 680px; }
.connection-view-list { margin-top: 6px; color: var(--muted); font-size: 12px; max-width: 360px; line-height: 1.35; }

.toast-stack { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { max-width: min(420px, calc(100vw - 36px)); border-radius: 16px; padding: 13px 15px; border: 1px solid var(--line); background: var(--card-solid); color: var(--text); box-shadow: var(--shadow); font-weight: 850; animation: toast-in .18s ease-out; }
.toast.success { border-color: #bbf7d0; }
.toast.error { border-color: #fecaca; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1100px) {
  .quick-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .step-grid, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .grid-2, .grid-4, .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .topbar, .split { flex-direction: column; }
  .topbar-actions { justify-content: flex-start; }
  .app-shell { width: min(100% - 24px, 1420px); padding-top: 14px; }
  .tabs { position: static; border-radius: 20px; }
  .tabs a { flex: 1 1 auto; justify-content: center; }
  .profile-card { grid-template-columns: 1fr; }
  .profile-card .actions.vertical { flex-direction: row; }
  .profile-edit { grid-column: 1; }
  .database-grid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .quick-actions { grid-template-columns: 1fr; }
  .brand-row { align-items: flex-start; }
  .brand-mark { width: 46px; height: 46px; border-radius: 15px; }
  .card, .topbar { padding: 18px; border-radius: 20px; }
  .btn { width: 100%; }
  .actions .btn, .topbar-actions .btn { width: auto; }
  .actions.compact .btn { width: 100%; }
  .input-row { flex-direction: column; }
}
.quick-action-current {
  border-color: color-mix(in srgb, var(--primary) 50%, var(--line));
  background: linear-gradient(145deg, var(--primary-soft), var(--card));
}
