:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --brand-soft: #eef2ff;
  --ok: #12b76a;
  --danger: #d92d20;
  --shadow: 0 10px 30px rgba(16, 24, 40, .08);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

.wrap { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }

/* ---------- header ---------- */
.hero {
  background: radial-gradient(1200px 400px at 10% -20%, #6d5efc 0%, transparent 60%),
              linear-gradient(120deg, #312e81, #4f46e5 55%, #7c3aed);
  color: #fff;
  padding: 28px 0 64px;
}

.hero-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.brand { display: flex; gap: 14px; align-items: center; }

.logo {
  width: 52px; height: 52px; border-radius: 15px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .28);
  font-weight: 800; letter-spacing: .5px;
  backdrop-filter: blur(4px);
}

.hero h1 { margin: 0; font-size: 26px; letter-spacing: -.3px; }
.sub { margin: 2px 0 0; color: rgba(255, 255, 255, .78); font-size: 13.5px; }

.status {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .24);
  padding: 8px 14px; border-radius: 999px;
  font-size: 13px; white-space: nowrap;
}

.status .dot { width: 9px; height: 9px; border-radius: 50%; background: #fdb022; }
.status.ok .dot { background: #32d583; box-shadow: 0 0 0 4px rgba(50, 213, 131, .18); }
.status.err .dot { background: #f97066; }

/* ---------- stats ---------- */
.stats {
  display: grid; gap: 14px;
  grid-template-columns: repeat(4, 1fr);
  margin-top: -42px;
  margin-bottom: 18px;
}

.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}

.stat .k { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; }
.stat .v { font-size: 28px; font-weight: 750; margin-top: 4px; letter-spacing: -.5px; }
.stat .h { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

/* ---------- card ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}

.tabs { display: flex; gap: 4px; padding: 12px 14px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }

.tab {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; padding: 10px 16px; cursor: pointer;
  border-bottom: 3px solid transparent; white-space: nowrap;
  border-radius: 10px 10px 0 0;
}

.tab:hover { color: var(--ink); background: #f9fafb; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.toolbar {
  display: flex; gap: 10px; padding: 14px 16px; flex-wrap: wrap; align-items: center;
  border-bottom: 1px solid var(--line);
}

.toolbar input[type="search"] { flex: 1 1 220px; }

input, select {
  font: inherit; color: var(--ink);
  background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px; outline: none;
  min-height: 40px;
}

input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 10px; padding: 9px 14px; min-height: 40px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}

.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 4px 9px; min-height: 0; font-size: 12px; }
.btn.danger { color: var(--danger); border-color: #fecdca; background: #fffbfa; }
.btn.danger:hover { background: #fef3f2; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th, td { padding: 11px 16px; text-align: left; border-bottom: 1px solid #f2f4f7; white-space: nowrap; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; background: #fcfcfd; }
tbody tr:hover { background: #f9faff; }
td.num, th.num { text-align: right; }
td.actions { text-align: right; }

.icon-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  width: 32px; height: 32px; cursor: pointer; margin-left: 6px;
  display: inline-grid; place-items: center;
}
.icon-btn:hover { background: #f2f4f7; }
.icon-btn.del:hover { background: #fef3f2; border-color: #fecdca; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  background: var(--brand-soft); color: #4338ca; font-size: 12px; font-weight: 600;
}

.empty { padding: 36px; text-align: center; color: var(--muted); }

/* ---------- sql ---------- */
.sql-panel { border-top: 1px solid var(--line); background: #0b1020; color: #d7dcf5; }
.sql-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; font-size: 12px; letter-spacing: .05em;
  text-transform: uppercase; color: #9aa4d2; border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sql-head .btn { color: #d7dcf5; border-color: rgba(255, 255, 255, .18); background: transparent; }
.sql-head .btn:hover { background: rgba(255, 255, 255, .08); }
.sql-panel pre { margin: 0; padding: 16px; overflow-x: auto; }
.sql-panel code { font: 13px/1.55 Consolas, "Cascadia Mono", monospace; }
.sql-panel .kw { color: #93c5fd; }
.sql-panel .str { color: #86efac; }
.sql-panel .num { color: #fca5a5; }

/* ---------- learn ---------- */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 18px 0 28px; }
.mini { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.mini h3 { margin: 0 0 6px; font-size: 15px; color: var(--brand); }
.mini p { margin: 0; color: var(--muted); font-size: 13.5px; }
code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; background: #f2f4f7; padding: 1px 5px; border-radius: 5px; }
.sql-panel code { background: none; padding: 0; }

.foot { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12.5px; padding-bottom: 28px; flex-wrap: wrap; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(16, 24, 40, .55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 18px; width: min(520px, 100%); box-shadow: 0 24px 60px rgba(16, 24, 40, .3); animation: pop .16s ease-out; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
.form { padding: 16px 18px; display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.field { display: grid; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.field input, .field select { width: 100%; }
.field .err { color: var(--danger); font-size: 12px; min-height: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #101828; color: #fff; padding: 11px 18px; border-radius: 12px;
  box-shadow: 0 12px 30px rgba(16, 24, 40, .35); font-size: 14px; z-index: 60;
  max-width: calc(100% - 32px);
}
.toast[hidden] { display: none; }
.toast.err { background: #b42318; }

/* ---------- sql console ---------- */
.console { margin-top: 18px; scroll-margin-top: 16px; }
.console-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.console-head h2 { margin: 0; font-size: 17px; }
.console-head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.chip {
  background: var(--brand-soft); color: #4338ca; border-radius: 999px;
  padding: 5px 12px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.samples { display: flex; gap: 8px; padding: 12px 18px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.samples button {
  font: inherit; font-size: 12.5px; cursor: pointer;
  background: #f9fafb; border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; color: #344054;
}
.samples button:hover { background: var(--brand-soft); border-color: #c7d2fe; color: #4338ca; }

.console-editor { padding: 14px 18px; background: #0b1020; }
.console-editor textarea {
  width: 100%; resize: vertical; min-height: 96px;
  background: #111832; color: #e6e9ff;
  border: 1px solid #2a3358; border-radius: 12px;
  padding: 12px 14px; outline: none;
  font: 13.5px/1.6 Consolas, "Cascadia Mono", monospace;
}
.console-editor textarea:focus { border-color: #6d5efc; box-shadow: 0 0 0 3px rgba(109, 94, 252, .22); }
.console-actions { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.console-actions .btn.ghost { color: #d7dcf5; border-color: #2a3358; }
.console-actions .btn.ghost:hover { background: rgba(255, 255, 255, .06); }
.console-actions .hint { color: #8b94c4; font-size: 12px; margin-left: auto; }

.console-output { padding: 14px 18px 18px; overflow-x: auto; min-height: 54px; }
.console-output .muted { color: var(--muted); font-size: 13.5px; }
.console-output .msg { font-size: 13.5px; margin-bottom: 10px; font-weight: 600; }
.console-output .msg.ok { color: #067647; }
.console-output .msg.err { color: var(--danger); }
.console-output table { font-size: 13px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.console-output th, .console-output td { padding: 8px 12px; }
.console-output .err-box {
  background: #fef3f2; border: 1px solid #fecdca; color: #b42318;
  border-radius: 10px; padding: 10px 12px; font-size: 13.5px;
}
.console-output code { background: #f2f4f7; }

.console-table-wrap { max-height: 320px; overflow: auto; border-radius: 10px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .cards { grid-template-columns: 1fr; }
  .hero { padding-bottom: 56px; }
}
@media (max-width: 560px) {
  .hero h1 { font-size: 22px; }
  .form { grid-template-columns: 1fr; }
  .toolbar input[type="search"] { flex-basis: 100%; }
}
