/* SQL Practice — styling adapted from sqlite-lite-editor (DB Browser look). */

:root {
  --bg: #f0f0f0;
  --panel: #fff;
  --border: #c0c0c0;
  --toolbar: #f5f5f5;
  --tab-active: #fff;
  --tab-inactive: #e0e0e0;
  --tab-border: #a0a0a0;
  --text: #1a1a1a;
  --muted: #666;
  --accent: #0060c0;
  --tree: #fafafa;
  --grid-header: #e8ecf0;
  --grid-alt: #f6f8fa;
  --grid-border: #dde1e6;
  --error-bg: #fff0f0;
  --error-text: #c00000;
  --success-bg: #f0fff0;
  --success-text: #006000;
  --info-bg: #f0f6ff;
  --info-text: #0b4a8f;
  --warn-bg: #fffbe6;
  --warn-text: #7a5200;
  --btn-bg: #e8e8e8;
  --btn-border: #b0b0b0;
  --check: #1f7a35;
  --mono: 'Consolas', 'Liberation Mono', 'DejaVu Sans Mono', 'Courier New', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Segoe UI', 'Liberation Sans', 'DejaVu Sans', Tahoma, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 11px; }

/* ---------- Loading / fatal error ---------- */
.fullscreen-msg {
  height: 100vh; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px; padding: 20px; font-size: 14px;
}

/* ---------- App shell ---------- */
.app { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px;
  padding: 4px 8px; background: var(--toolbar);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; color: var(--accent); padding: 0 4px; }
.tool-sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }
.tool-label { font-size: 12px; font-weight: 600; }
.tool-btn, .btn-primary, .btn-check {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border: 1px solid var(--btn-border); border-radius: 3px;
  background: var(--btn-bg); color: var(--text); cursor: pointer;
  font-size: 12px; font-family: inherit; white-space: nowrap; min-height: 26px;
}
.tool-btn:hover:not(:disabled) { background: #dedede; }
.tool-btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { padding: 4px 14px; border-color: var(--accent); background: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #0052a6; }
.btn-check { padding: 4px 14px; border-color: var(--check); background: var(--check); color: #fff; font-weight: 600; }
.btn-check:hover { background: #18652b; }
.tool-select, .tool-input {
  padding: 3px 8px; border: 1px solid var(--btn-border); border-radius: 3px;
  font-size: 12px; background: #fff; color: var(--text); font-family: inherit; min-height: 26px;
}
.tool-input { flex: 1; min-width: 120px; max-width: 400px; font-family: var(--mono); }
.toolbar-right {
  margin-left: auto; font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 340px;
}

/* ---------- Tabs ---------- */
.tabbar { display: flex; padding: 6px 8px 0; background: var(--bg); flex-shrink: 0; }
.tab {
  padding: 6px 16px; border: 1px solid var(--tab-border); border-radius: 4px 4px 0 0;
  background: var(--tab-inactive); cursor: pointer; font-size: 12.5px; color: var(--text);
  margin-bottom: -1px; position: relative; z-index: 1; font-family: inherit;
}
.tab.active { background: var(--tab-active); border-bottom-color: var(--tab-active); font-weight: 600; z-index: 2; }

/* ---------- Main panel ---------- */
.main {
  flex: 1; display: flex; min-height: 0;
  background: var(--panel); border: 1px solid var(--tab-border);
  margin: 0 8px 0 8px; border-radius: 0 0 4px 4px; overflow: hidden;
}

/* Schema side panel (styled like "Database Structure") */
.schema-panel {
  width: 270px; flex-shrink: 0; display: flex; flex-direction: column;
  border-right: 1px solid var(--grid-border); background: var(--tree); min-height: 0;
}
.schema-header {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 6px 10px; font-weight: 600; font-size: 12px; color: var(--text);
  background: var(--toolbar); border: none; border-bottom: 1px solid var(--grid-border);
  text-align: left; font-family: inherit; cursor: default;
}
.schema-ds { margin-left: auto; font-weight: 400; color: var(--muted); font-size: 11px; }
.schema-header .chev { display: none; }
.schema-tree { flex: 1; overflow-y: auto; padding-bottom: 8px; }
.tree-table {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 4px 10px; font-size: 12px; font-weight: 600; color: var(--text);
  border: none; background: none; cursor: pointer; text-align: left; font-family: inherit;
  border-bottom: 1px solid var(--grid-border);
}
.tree-table:hover { background: #eef3f9; }
.tree-table .count { color: var(--muted); font-size: 11px; font-weight: 400; margin-left: auto; }
.chev-icon { transition: transform 0.15s; flex-shrink: 0; }
.tree-table.open .chev-icon { transform: rotate(90deg); }
.tree-cols { list-style: none; padding: 2px 0 4px; }
.tree-cols li {
  display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap;
  padding: 2px 10px 2px 30px; font-size: 11.5px; color: var(--text);
}
.tree-cols .ctype { color: #888; font-size: 10.5px; }
.tree-cols .pk { color: #b07800; font-size: 10px; font-weight: 600; }
.tree-cols .fk { color: var(--accent); font-size: 10.5px; }
.tree-note { padding: 8px 10px; font-size: 11px; color: var(--muted); line-height: 1.5; }

/* Work area */
.work { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }

.question {
  padding: 10px 12px; background: #fafbfc; border-bottom: 1px solid var(--grid-border);
  flex-shrink: 0; max-height: 40%; overflow-y: auto;
}
.question-meta { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.question-meta .badge {
  display: inline-block; padding: 0 6px; border-radius: 3px; margin-right: 6px;
  background: var(--grid-header); color: var(--text); font-weight: 600; text-transform: capitalize;
}
.question-prompt { font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.hints { margin: 8px 0 0 0; padding: 0; list-style: none; }
.hints li {
  margin-top: 6px; padding: 6px 10px; border-radius: 4px; font-size: 12.5px; line-height: 1.45;
  background: var(--warn-bg); color: var(--warn-text); border: 1px solid #f0e0a0;
}
.hints li b { margin-right: 4px; }

.sql-toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 4px 8px;
  background: var(--toolbar); border-bottom: 1px solid var(--grid-border); flex-shrink: 0;
}

.editor { height: 30%; min-height: 110px; flex-shrink: 0; border-bottom: 1px solid var(--grid-border); overflow: hidden; }

/* Feedback / messages */
.feedback, .msg {
  margin: 8px 10px; padding: 9px 12px; border-radius: 4px; font-size: 12.5px; line-height: 1.5;
  flex-shrink: 0; white-space: pre-wrap; overflow-wrap: anywhere;
}
.feedback { max-height: 35%; overflow-y: auto; }
.msg-error, .feedback.error { background: var(--error-bg); color: var(--error-text); border: 1px solid #f0c0c0; }
.msg-success, .feedback.success { background: var(--success-bg); color: var(--success-text); border: 1px solid #c0f0c0; }
.msg-info, .feedback.info { background: var(--info-bg); color: var(--info-text); border: 1px solid #c4d8f2; }
.feedback.warn { background: var(--warn-bg); color: var(--warn-text); border: 1px solid #f0e0a0; }
.feedback .title { font-weight: 700; display: block; margin-bottom: 2px; }
.feedback .raw, .msg .raw { font-family: var(--mono); font-size: 12px; display: block; margin-top: 4px; }
.feedback .next-link {
  margin-top: 8px; display: inline-flex; color: #fff; background: var(--check); border: none;
  padding: 4px 12px; border-radius: 3px; cursor: pointer; font-size: 12px; font-family: inherit; font-weight: 600;
}

/* Results grid */
.results { flex: 1; overflow: auto; min-height: 80px; }
.placeholder { padding: 20px; color: var(--muted); text-align: center; font-size: 12px; }
.result-label { padding: 4px 10px; font-size: 11px; color: var(--muted); background: var(--toolbar); border-bottom: 1px solid var(--grid-border); }
.grid { width: 100%; border-collapse: collapse; font-size: 12px; }
.grid th {
  position: sticky; top: 0; background: var(--grid-header); padding: 5px 10px; text-align: left;
  font-weight: 600; border-bottom: 2px solid var(--grid-border); border-right: 1px solid var(--grid-border);
  white-space: nowrap; z-index: 1;
}
.grid th.rownum, .grid td.rownum { width: 50px; text-align: center; color: var(--muted); }
.grid td {
  padding: 3px 10px; border-bottom: 1px solid var(--grid-border); border-right: 1px solid var(--grid-border);
  white-space: nowrap; max-width: 300px; overflow: hidden; text-overflow: ellipsis;
}
.grid tbody tr:nth-child(even) { background: var(--grid-alt); }
.grid .null { color: #aaa; font-style: italic; }
.grid-more { padding: 6px 10px; font-size: 11px; color: var(--muted); }

/* Execution log (like DB Browser's message pane) */
.exec-log {
  padding: 8px 12px; background: #f5f5f0; border-top: 1px solid var(--grid-border);
  font-family: var(--mono); font-size: 12px; line-height: 1.6; flex-shrink: 0;
  white-space: pre-wrap; max-height: 90px; overflow-y: auto;
}
.exec-log .err { color: var(--error-text); }

/* Status bars */
.statusbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 3px 10px; background: var(--toolbar); font-size: 11px; color: var(--muted); flex-shrink: 0;
}
.statusbar.inner { border-top: 1px solid var(--grid-border); }
.statusbar.outer { margin: 0 8px 4px 8px; border: 1px solid var(--grid-border); border-top: none; border-radius: 0 0 4px 4px; }

/* CodeMirror theme from sqlite-lite-editor */
.cm-s-db-browser.CodeMirror { background: #fff; color: #1a1a1a; font-size: 13px; line-height: 1.5; font-family: var(--mono); }
.cm-s-db-browser .CodeMirror-gutters { background: #f0f0f0; border-right: 1px solid #d0d0d0; }
.cm-s-db-browser .CodeMirror-linenumber { color: #888; font-size: 12px; }
.cm-s-db-browser .CodeMirror-cursor { border-left-color: #1a1a1a; }
.cm-s-db-browser .CodeMirror-selected { background: #c8ddf8; }
.cm-s-db-browser .cm-keyword { color: #0000ff; font-weight: bold; }
.cm-s-db-browser .cm-builtin { color: #800080; }
.cm-s-db-browser .cm-string { color: #a31515; }
.cm-s-db-browser .cm-string-2 { color: #a31515; }
.cm-s-db-browser .cm-number { color: #098658; }
.cm-s-db-browser .cm-comment { color: #008000; font-style: italic; }
.cm-s-db-browser .cm-operator { color: #1a1a1a; }
.cm-s-db-browser .cm-def { color: #795e26; }
.cm-s-db-browser .cm-variable-2 { color: #1a1a1a; }
.cm-s-db-browser .cm-type { color: #267f99; font-weight: bold; }
.cm-s-db-browser .CodeMirror-activeline-background { background: #f5f5dc; }
.editor .CodeMirror { height: 100%; }

/* ---------- Narrow screens (phones, small tablets) ---------- */
@media (max-width: 760px) {
  html, body { height: auto; overflow: auto; }
  .app { height: auto; min-height: 100vh; overflow: visible; }
  .toolbar { gap: 6px; padding: 6px 8px; }
  .toolbar .tool-sep { display: none; }
  .toolbar-right { margin-left: 0; width: 100%; max-width: none; }
  .tool-btn, .btn-primary, .btn-check, .tool-select { min-height: 34px; font-size: 13px; }
  .kbd-help { display: none; }
  .main { flex-direction: column; overflow: visible; }
  .work { overflow: visible; }
  .schema-panel { width: auto; border-right: none; border-bottom: 1px solid var(--grid-border); order: 0; }
  .schema-header { cursor: pointer; padding: 10px; font-size: 13px; }
  .schema-header .chev {
    display: inline-block; width: 0; height: 0; border-style: solid;
    border-width: 5px 0 5px 7px; border-color: transparent transparent transparent currentColor;
    transition: transform 0.15s;
  }
  .schema-panel:not(.collapsed-mobile) .schema-header .chev { transform: rotate(90deg); }
  .schema-panel.collapsed-mobile .schema-tree { display: none; }
  .schema-tree { max-height: 50vh; }
  .question { max-height: none; }
  .question-prompt { font-size: 15px; }
  .editor { height: 200px; }
  .feedback { max-height: none; }
  .results { max-height: 60vh; min-height: 60px; }
  .exec-log { max-height: none; }
  .tool-input { max-width: none; }
}
