:root {
  --bg: #070b14;
  --surface: #0f1624;
  --surface2: #161e30;
  --elevated: #1c263c;
  --fg: #e8eef9;
  --muted: #8b9bb8;
  --subtle: #5d6d8a;
  --border: #243047;
  --border-strong: #33415c;
  --primary: #3b82f6;
  --primary-fg: #f8fbff;
  --success: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 10px;
  --shadow: 0 12px 40px rgba(0,0,0,.35);
  --sidebar-w: 280px;
  --sidebar-collapsed: 64px;
  --header-h: 56px;
  font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); }
button, [role="button"] { cursor: pointer; }
button:disabled { opacity: .45; cursor: not-allowed; }
a { color: inherit; text-decoration: none; }
input, select, textarea {
  font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(59,130,246,.25); }
textarea { font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace; min-height: 160px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
label input[type="checkbox"] {width:unset;}
.app { display: flex; flex-direction: column; height: 100dvh; min-height: 0; }
.header {
  height: var(--header-h); flex-shrink: 0; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--surface); z-index: 30;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -.02em; }
.logo img { width: 32px; height: 32px; border-radius: 8px; }
.header-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; transition: width .2s ease;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar-top {
  display: flex; align-items: center; justify-content: space-between; padding: 8px; border-bottom: 1px solid var(--border);
}
.sidebar-top .label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--subtle); padding: 0 8px; }
.sidebar.collapsed .label, .sidebar.collapsed .nav-text, .sidebar.collapsed .tree-text, .sidebar.collapsed .meter-text { display: none; }
.nav { flex: 1; overflow-y: auto; padding: 8px; min-height: 0; }
.nav-item, .tree-link {
  display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 10px; border-radius: 8px;
  color: var(--muted); font-size: 14px; border: none; background: transparent; width: 100%; text-align: left;
}
.nav-item:hover, .tree-link:hover { background: var(--surface2); color: var(--fg); }
.nav-item.active, .tree-link.active { background: rgba(59,130,246,.15); color: #60a5fa; }
.nav-item svg, .tree-link svg { width: 16px; height: 16px; flex-shrink: 0; }
.tree-section { margin-top: 16px; }
.tree-head { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--subtle); padding: 0 10px 6px; display: flex; justify-content: space-between; }
.tree-db { margin-bottom: 4px; }
.tree-children { margin-left: 22px; border-left: 1px solid var(--border); padding-left: 8px; }
.meter {
  flex-shrink: 0; border-top: 1px solid var(--border); padding: 12px; background: var(--surface);
}
.meter .bar { height: 4px; background: var(--elevated); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.meter .fill { height: 100%; background: var(--primary); border-radius: 2px; transition: width .3s; }
.meter-text { font-size: 11px; color: var(--muted); }

.main { flex: 1; min-width: 0; overflow-y: auto; padding: 24px 28px; }
.page-header { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.page-header h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.page-header p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13px; font-weight: 500; background: var(--primary); color: var(--primary-fg);
}
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--surface2); color: var(--fg); border-color: var(--border); }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn.danger { background: rgba(248,113,113,.15); color: var(--danger); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 12px; }
.btn.icon { width: 36px; padding: 0; }

.tabs {
  display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 18px; padding-bottom: 0;
}
.tab {
  flex-shrink: 0; padding: 10px 14px; font-size: 13px; color: var(--muted); border: none; background: transparent;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--fg); }
.tab.active { color: #60a5fa; border-bottom-color: var(--primary); }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--primary); transform: translateY(-1px); }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card .meta { color: var(--muted); font-size: 13px; }
.card-icon {
  width: 40px; height: 40px; border-radius: 10px; background: rgba(59,130,246,.15); color: var(--primary);
  display: flex; align-items: center; justify-content: center; margin-bottom: 12px;
}
.card.dashed {
  border-style: dashed; border-color: var(--border-strong); background: transparent; display: flex;
  flex-direction: column; align-items: center; justify-content: center; min-height: 140px; color: var(--muted);
}
.card.dashed:hover { color: var(--primary); border-color: var(--primary); }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; max-width: 720px;
}
.panel h2 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.panel .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
table.data th {
  text-align: left; padding: 10px 12px; background: var(--surface2); color: var(--muted); font-weight: 500;
  border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none;
}
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-family: "IBM Plex Mono", monospace; font-size: 12px; }
table.data tr:hover td { background: rgba(59,130,246,.05); }
table.data tr:last-child td { border-bottom: none; }
.null { color: var(--subtle); }
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 500;
  background: var(--elevated); color: var(--muted); font-family: inherit;
}
.badge.ok { background: rgba(52,211,153,.15); color: var(--success); }
.badge.primary { background: rgba(59,130,246,.15); color: #60a5fa; }
.badge.warn { background: rgba(251,191,36,.15); color: var(--warn); }
.badge.danger { background: rgba(248,113,113,.15); color: var(--danger); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.search { flex: 1; min-width: 160px; position: relative; }
.search input { padding-left: 36px; }
.search::before {
  content: ""; position: absolute; left: 12px; top: 50%; width: 14px; height: 14px; transform: translateY(-50%);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='%235d6d8a' stroke-width='2' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3-3'/%3E%3C/svg%3E") center/contain no-repeat;
}

.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.format-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 14px; }
.format-btn {
  text-align: left; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--fg);
}
.format-btn.active { border-color: var(--primary); background: rgba(59,130,246,.1); }
.format-btn .t { font-weight: 600; font-size: 13px; }
.format-btn .h { font-size: 11px; color: var(--muted); margin-top: 4px; }

.dropzone {
  border: 2px dashed var(--border-strong); border-radius: 12px; padding: 36px 16px; text-align: center;
  color: var(--muted); cursor: pointer; transition: border-color .15s, color .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); color: var(--fg); }
.dropzone input { display: none; }

.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 100; background: var(--surface2); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; max-width: 360px;
  transform: translateY(120%); opacity: 0; transition: transform .25s ease, opacity .25s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.err { border-color: rgba(248,113,113,.4); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(7,11,20,.72); z-index: 80; display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal {
  width: min(520px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; box-shadow: var(--shadow); max-height: 85dvh; overflow: auto;
}
.modal h2 { margin: 0 0 12px; font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.schema-row {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); margin-bottom: 8px;
}
.schema-row .name { font-weight: 600; min-width: 100px; font-family: "IBM Plex Mono", monospace; font-size: 13px; }
.schema-row .type { color: var(--muted); font-size: 13px; min-width: 90px; }
.flags { display: flex; flex-wrap: wrap; gap: 4px; }

.console-layout { display: grid; grid-template-columns: 1fr 260px; gap: 16px; }
.console-out {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  font-family: "IBM Plex Mono", monospace; font-size: 12px; max-height: 320px; overflow: auto; white-space: pre-wrap;
}
.saved-list button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: none; background: transparent;
  color: var(--muted); border-radius: 6px; font-size: 13px;
}
.saved-list button:hover { background: var(--surface2); color: var(--fg); }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-size: 16px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }

.activity { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden; }
.activity li {
  list-style: none; display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.activity ul { margin: 0; padding: 0; }
.activity li:last-child { border-bottom: none; }
.activity time { color: var(--subtle); font-size: 11px; flex-shrink: 0; font-variant-numeric: tabular-nums; }

.chart-bars { display: flex; align-items: flex-end; gap: 8px; height: 180px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.chart-bars .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: 6px; }
.chart-bars .bar { width: 100%; max-width: 48px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 4px; }
.chart-bars .lbl { font-size: 10px; color: var(--muted); text-align: center; max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.designer { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 20px; }
.designer .tbl {
  width: 200px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden;
}
.designer .tbl-h { padding: 10px 12px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13px; color: #60a5fa; }
.designer .tbl-c { padding: 6px 12px; font-size: 11px; font-family: "IBM Plex Mono", monospace; color: var(--muted); display: flex; justify-content: space-between; }

.empty {
  text-align: center; padding: 48px 16px; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: 12px;
}
.pager { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }

.backdrop-nav {
  display: none; position: fixed; inset: 0; background: rgba(7,11,20,.55); z-index: 40;
}
.menu-btn { display: none; }

@media (max-width: 860px) {
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed; top: var(--header-h); bottom: 0; left: 0; z-index: 50; width: var(--sidebar-w) !important;
    transform: translateX(-105%); transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.collapsed { width: var(--sidebar-w) !important; }
  .sidebar.collapsed .label, .sidebar.collapsed .nav-text, .sidebar.collapsed .tree-text, .sidebar.collapsed .meter-text { display: initial; }
  .backdrop-nav.show { display: block; }
  .main { padding: 16px; }
  .console-layout { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
