* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #1a5276; --primary-d: #14425e; --accent: #2e86c1;
  --bg: #f4f6f9; --card: #ffffff; --line: #dbe3ec; --text: #1f2937;
  --muted: #6b7280; --ok: #1e8449; --err: #c0392b; --radius: 10px;
  --shadow: 0 2px 10px rgba(15,40,60,.08);
}
body { font-family: 'Segoe UI', Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--accent); }
code { background:#eef2f7; padding:1px 5px; border-radius:4px; font-size:12px; }
.hidden { display: none !important; }
.req { color: var(--err); }

/* ---------- buttons / inputs ---------- */
.btn { display:inline-block; border:1px solid var(--line); background:#fff; color:var(--text);
  padding:8px 16px; border-radius:8px; cursor:pointer; font-size:13px; transition:.15s; text-decoration:none; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--primary); border-color: var(--primary); color:#fff; }
.btn-primary:hover { background: var(--primary-d); color:#fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-block { width:100%; margin-top:12px; }
.btn-xs { padding:3px 9px; font-size:12px; }
.input-sm { width:100px; padding:5px 8px; border:1px solid var(--line); border-radius:6px; }
label { display:block; margin:12px 0 4px; font-weight:600; font-size:13px; color:#374151; }
input[type=text], input[type=email], input[type=password], input[type=search],
input[type=number], textarea, select {
  width:100%; padding:9px 12px; border:1px solid var(--line); border-radius:8px; font-size:14px;
  background:#fff; font-family:inherit; }
input:focus, textarea:focus, select:focus { outline:2px solid var(--accent); outline-offset:-1px; }

/* ---------- top nav ---------- */
.topnav { display:flex; align-items:center; gap:24px; background: var(--primary); color:#fff;
  padding:0 24px; height:56px; position:sticky; top:0; z-index:50; box-shadow: var(--shadow); }
.topnav .brand { font-weight:700; font-size:16px; white-space:nowrap; }
.navlinks { display:flex; gap:6px; flex:1; }
.navlinks a { color:#d7e5ef; text-decoration:none; padding:8px 14px; border-radius:8px; font-size:13px; }
.navlinks a:hover { background: rgba(255,255,255,.12); color:#fff; }
.navlinks a.active { background: rgba(255,255,255,.18); color:#fff; font-weight:600; }
.userbox { display:flex; align-items:center; gap:12px; font-size:13px; }
.userbox .btn-ghost { color:#d7e5ef; }

/* ---------- auth pages ---------- */
.auth-wrap { min-height:calc(100vh - 56px); display:flex; align-items:center; justify-content:center; padding:32px 16px; }
.auth-card { background:var(--card); border-radius:14px; box-shadow:var(--shadow); width:100%; max-width:420px; padding:32px; }
.auth-head h1 { font-size:20px; color:var(--primary); margin-bottom:4px; }
.auth-head p { color:var(--muted); font-size:13px; margin-bottom:16px; }
.tabs { display:flex; gap:8px; border-bottom:1px solid var(--line); margin-bottom:16px; }
.tab { flex:1; background:none; border:none; padding:10px; cursor:pointer; font-size:14px; color:var(--muted); border-bottom:2px solid transparent; }
.tab.active { color:var(--primary); font-weight:700; border-bottom-color: var(--primary); }
.tabpane { display:none; }
.tabpane.active { display:block; }
.hint { font-size:12px; color:var(--muted); margin-top:12px; text-align:center; }

.msg { padding:10px 14px; border-radius:8px; margin:12px 0; font-size:13px; }
.msg.ok { background:#e8f8ef; color:var(--ok); border:1px solid #b7e4c7; }
.msg.err { background:#fdecea; color:var(--err); border:1px solid #f5b7b1; }
.msg.warn { background:#fef9e7; color:#8a6d0b; border:1px solid #f8e08e; }

/* ---------- dashboard ---------- */
.page { max-width:1200px; margin:0 auto; padding:28px 24px 60px; }
.page-full { max-width:none; }
.page-title { font-size:22px; color:var(--primary); }
.page-sub { color:var(--muted); margin:4px 0 20px; }
.badge { font-size:11px; background:#eef2f7; color:var(--primary); border-radius:20px; padding:3px 10px; vertical-align:middle; font-weight:600; }
.kpi-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(210px,1fr)); gap:16px; margin-bottom:24px; }
.kpi { background:var(--card); border-radius:var(--radius); padding:20px; box-shadow:var(--shadow); }
.kpi-num { display:block; font-size:32px; font-weight:700; color:var(--primary); }
.kpi-label { color:var(--muted); font-size:13px; }
.kpi-label em { color:var(--ok); font-style:normal; }
.chart-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(440px,1fr)); gap:16px; }
.chart-card { background:var(--card); border-radius:var(--radius); padding:18px; box-shadow:var(--shadow); }
.chart-card h3 { font-size:14px; color:#374151; margin-bottom:12px; }

/* ---------- query builder ---------- */
.qb-toolbar { display:flex; align-items:center; gap:10px; margin-bottom:14px; flex-wrap:wrap; }
.qb-status { font-size:12px; color:var(--muted); }
.qb-layout { display:grid; grid-template-columns:230px 1fr 280px; gap:14px; align-items:start; }
@media (max-width:1100px){ .qb-layout { grid-template-columns:1fr; } }
.qb-palette { background:var(--card); border-radius:var(--radius); box-shadow:var(--shadow); padding:12px; position:sticky; top:70px; }
.table-list { list-style:none; max-height:70vh; overflow:auto; margin-top:8px; }
.table-list li { padding:7px 10px; border-radius:6px; cursor:grab; font-size:13px; display:flex; justify-content:space-between; gap:6px; }
.table-list li:hover { background:#eef4fa; }
.table-list li small { color:var(--muted); }
.qb-canvas-wrap { display:flex; flex-direction:column; gap:12px; min-width:0; }
#qb-canvas { position:relative; height:460px; background:
  linear-gradient(#eef2f7 1px,transparent 1px) 0 0/24px 24px,
  linear-gradient(90deg,#eef2f7 1px,transparent 1px) 0 0/24px 24px, #fff;
  border:1px solid var(--line); border-radius:var(--radius); overflow:auto; }
.canvas-hint { position:absolute; inset:0; display:flex; align-items:center; justify-content:center; color:#b6c2cf; pointer-events:none; font-size:15px; }
#qb-links { position:absolute; top:0; left:0; pointer-events:none; }
.qtable { position:absolute; width:220px; background:#fff; border:1px solid var(--line); border-radius:8px;
  box-shadow:var(--shadow); font-size:12px; user-select:none; }
.qtable-head { background:var(--primary); color:#fff; padding:6px 10px; border-radius:8px 8px 0 0;
  font-weight:600; cursor:move; display:flex; justify-content:space-between; align-items:center; }
.qtable-head .x { cursor:pointer; opacity:.8; } .qtable-head .x:hover { opacity:1; }
.qtable-cols { max-height:210px; overflow:auto; }
.qcol { padding:4px 10px; display:flex; align-items:center; gap:6px; border-bottom:1px solid #f1f5f9; cursor:pointer; }
.qcol:hover { background:#f0f7fd; }
.qcol .ctype { margin-left:auto; color:var(--muted); font-size:10px; }
.qcol.join-src { background:#fdebd0; }
.qcol .jdot { width:8px; height:8px; border-radius:50%; background:#d5dbe3; flex:none; }
.qtable.join-target .jdot { background:var(--accent); }
.qb-sql { background:#0f202c; color:#a9d6f5; border-radius:var(--radius); padding:14px 16px; }
.qb-sql-head { color:#7fb8dc; font-size:12px; margin-bottom:8px; display:flex; justify-content:space-between; }
#qb-sql-text { font-family:Consolas,monospace; font-size:12.5px; white-space:pre-wrap; max-height:180px; overflow:auto; }
.qb-side { display:flex; flex-direction:column; gap:12px; }
.side-sec { background:var(--card); border-radius:var(--radius); box-shadow:var(--shadow); padding:12px; }
.side-sec h4 { font-size:13px; margin-bottom:8px; display:flex; justify-content:space-between; align-items:center; }
.count { background:#eef2f7; border-radius:12px; padding:1px 8px; font-size:11px; color:var(--primary); }
.mini-list { list-style:none; font-size:12px; max-height:180px; overflow:auto; }
.mini-list li { padding:4px 6px; border-bottom:1px solid #f1f5f9; display:flex; gap:6px; align-items:center; }
.mini-list select { padding:2px 4px; font-size:11px; width:auto; margin-left:auto; }
.flt-row, .sort-row { display:grid; grid-template-columns:1fr auto; gap:5px; margin-bottom:6px; font-size:12px; }
.flt-row .fl-top { grid-column:1/-1; display:flex; gap:5px; }
.flt-row .conj { width:70px; }
.x-btn { background:none; border:none; color:var(--err); cursor:pointer; font-size:14px; }

.qb-results { margin-top:18px; background:var(--card); border-radius:var(--radius); box-shadow:var(--shadow); padding:14px; }
.results-head { display:flex; justify-content:space-between; align-items:center; margin-bottom:10px; }
.table-scroll { overflow:auto; max-height:480px; border:1px solid var(--line); border-radius:8px; }
.res-table { border-collapse:collapse; width:100%; font-size:12.5px; }
.res-table th, .res-table td { border-bottom:1px solid #eef2f7; padding:7px 10px; text-align:left; white-space:nowrap; }
.res-table th { background:#f8fafc; position:sticky; top:0; font-size:11.5px; color:#475569; }
.res-table tr:hover td { background:#f6fafd; }

.modal { position:fixed; inset:0; background:rgba(15,32,44,.5); display:flex; align-items:center; justify-content:center; z-index:100; }
.modal-card { background:#fff; border-radius:12px; padding:24px; width:90%; max-width:420px; box-shadow:0 10px 40px rgba(0,0,0,.25); }
.modal-card h3 { color:var(--primary); margin-bottom:10px; }
.modal-card p { color:var(--muted); font-size:13px; margin-bottom:14px; }
.modal-btns { display:flex; gap:8px; margin-top:16px; flex-wrap:wrap; }
