:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e6ec;
  --text: #16191f;
  --muted: #5d6675;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --ok: #15803d;
  --ok-bg: #f0fdf4;
  --ok-border: #bbf7d0;
  --warn: #a16207;
  --warn-bg: #fefce8;
  --warn-border: #fde68a;
  --mysql: #0e7490;
  --mysql-bg: #ecfeff;
  --pg: #4338ca;
  --pg-bg: #eef2ff;
  --focus: 0 0 0 3px rgba(37, 99, 235, .25);
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a303b;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --danger: #f87171;
    --danger-bg: #2a1215;
    --danger-border: #5c1d22;
    --ok: #4ade80;
    --ok-bg: #0f2418;
    --ok-border: #1d4d31;
    --warn: #facc15;
    --warn-bg: #2a2410;
    --warn-border: #574a13;
    --mysql: #67e8f9;
    --mysql-bg: #0c2a30;
    --pg: #a5b4fc;
    --pg-bg: #1c1f45;
    --focus: 0 0 0 3px rgba(59, 130, 246, .35);
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; font-weight: 650; }
h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: .75rem; }
.h2 { font-size: 1.25rem; margin-bottom: 1rem; }
code, .mono { font-family: var(--mono); font-size: .9em; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 5px; overflow-wrap: anywhere; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .5rem; }

/* ---- layout ---- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0 1.25rem; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo { width: 22px; height: 22px; color: var(--primary); }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a { padding: .4rem .7rem; border-radius: 7px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.usermenu { display: flex; align-items: center; gap: .75rem; }
.usermenu form { margin: 0; }

.container { max-width: 1120px; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { margin-top: .15rem; }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 2rem; box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; justify-content: center; gap: .5rem; font-weight: 650; font-size: 1.1rem; margin-bottom: 1.5rem; }
.auth-brand .logo { width: 28px; height: 28px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem 1.4rem; margin-bottom: 1.25rem; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.card-danger { border-color: var(--danger-border); }
.card-danger h2 { color: var(--danger); }
.card p { margin: 0 0 .9rem; }

/* ---- forms ---- */
.stack { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .35rem; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-weight: 550; font-size: .9rem; padding: 0; }
.field legend { margin-bottom: .35rem; }
.hint { color: var(--muted); font-size: .8rem; }
.error { color: var(--danger); font-size: .82rem; font-weight: 500; }
input:not([type=radio]):not([type=checkbox]), select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
input[type=radio], input[type=checkbox] { accent-color: var(--primary); width: 1rem; height: 1rem; margin: .2rem 0 0; flex: none; }
.check { display: flex; gap: .55rem; align-items: flex-start; font-size: .92rem; cursor: pointer; }
fieldset[disabled] .check { opacity: .6; cursor: default; }
.choice-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.choice {
  display: flex; align-items: center; gap: .55rem; cursor: pointer;
  border: 1px solid var(--border); border-radius: 9px; padding: .55rem .85rem;
}
.choice:has(input:checked) { border-color: var(--primary); box-shadow: var(--focus); }
.actions { display: flex; gap: .6rem; justify-content: flex-end; }

.toolbar { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar input:not([type=radio]):not([type=checkbox]), .toolbar select { width: auto; flex: 0 1 auto; }
.toolbar input:not([type=radio]):not([type=checkbox])[type=search] { flex: 1 1 220px; }
.toolbar input:not([type=radio]):not([type=checkbox]).w-sm { flex: 0 1 160px; min-width: 120px; }
.radios { display: flex; flex-direction: column; gap: .4rem; }
.input-group { display: flex; gap: .5rem; }
.input-group input:not([type=radio]):not([type=checkbox]) { flex: 1; min-width: 0; }
.input-group .btn { flex: none; }
.grid-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  font: inherit; font-weight: 550; font-size: .9rem; line-height: 1.2;
  padding: .55rem .95rem; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.92); background: var(--danger); }
.btn-ghost { background: transparent; }
.btn-sm { padding: .35rem .65rem; font-size: .84rem; }
.btn-xs { padding: .15rem .45rem; font-size: .75rem; border-radius: 6px; }
.btn-block { width: 100%; }
.btn.is-loading { opacity: .65; cursor: progress; }
.btn.is-copied { color: var(--ok); border-color: var(--ok-border); }

/* ---- feedback ---- */
.alert { padding: .7rem .9rem; border-radius: 8px; border: 1px solid; margin-bottom: 1rem; font-size: .92rem; }
.alert-ok { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok); }
.alert-err { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.alert-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn); }

.tag {
  display: inline-block; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  padding: .1rem .4rem; border-radius: 5px; background: var(--surface-2); color: var(--muted); vertical-align: middle;
}
.tag-warn { background: var(--warn-bg); color: var(--warn); }
.engine { display: inline-block; font-size: .78rem; font-weight: 600; padding: .15rem .5rem; border-radius: 6px; }
.engine-mysql { background: var(--mysql-bg); color: var(--mysql); }
.engine-postgres { background: var(--pg-bg); color: var(--pg); }
.pill {
  display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; font-weight: 500;
  padding: .15rem .55rem; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-ok { color: var(--ok); border-color: var(--ok-border); }
.pill-err { color: var(--danger); border-color: var(--danger-border); }
.engines { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }

/* ---- tables ---- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th {
  text-align: left; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); background: var(--surface-2); padding: .6rem .9rem; border-bottom: 1px solid var(--border);
}
.table td { padding: .7rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table-dense td { padding: .5rem .75rem; font-size: .86rem; }
.table code { white-space: nowrap; overflow-wrap: normal; }
.table .details { max-width: 360px; color: var(--muted); overflow-wrap: anywhere; }
.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1rem; }

/* ---- key/value ---- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .55rem 1.25rem; margin: 0 0 1rem; align-items: center; }
.kv dt { color: var(--muted); font-size: .88rem; }
.kv dd { margin: 0; min-width: 0; }
.copy { display: inline-flex; align-items: center; gap: .4rem; max-width: 100%; }
.copy code { overflow-wrap: anywhere; }
.code {
  margin: 0; padding: .9rem 1rem; background: var(--surface-2); border-radius: 8px;
  font-family: var(--mono); font-size: .85rem; overflow-x: auto; white-space: pre;
}

.error-page { text-align: center; padding: 2rem 0; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--muted); margin: 0; }

@media (max-width: 720px) {
  .topbar { height: auto; flex-wrap: wrap; gap: .5rem 1rem; padding: .6rem 1rem; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .usermenu { margin-left: auto; }
  .container { padding: 1.25rem 1rem 3rem; }
  .kv { grid-template-columns: 1fr; gap: .15rem; }
  .kv dd { margin-bottom: .5rem; }
  .auth-card { padding: 1.5rem; }
}
