/* ------------------------------------------------------------------
 * PeopleCode Web Simulator -- styles
 * ------------------------------------------------------------------ */

:root {
  --bg:            #14161a;
  --bg-panel:      #1a1d23;
  --bg-raised:     #21252d;
  --bg-input:      #12141a;
  --border:        #2b313b;
  --border-strong: #3a424f;
  --text:          #d9dee7;
  --text-dim:      #8d97a7;
  --text-faint:    #667081;
  --accent:        #d0553f;
  --accent-hover:  #e06249;
  --accent-quiet:  rgba(208, 85, 63, 0.14);
  --link:          #6fb3d2;
  --good:          #5fb87a;
  --warn:          #d9a343;
  --bad:           #e06c6c;
  --shadow:        0 8px 24px rgba(0, 0, 0, 0.35);

  --tk-comment:  #6f7885;
  --tk-keyword:  #f08a7c;
  --tk-string:   #9fd0f0;
  --tk-number:   #8fc7ee;
  --tk-variable: #86d99a;
  --tk-sysvar:   #e8ab6a;
  --tk-call:     #cfa8f0;
  --tk-type:     #8fc7ee;
  --tk-defkind:  #e8ab6a;
  --tk-op:       #aab3c0;
  --tk-ident:    #d9dee7;
  /* A compiler-directive marker, and the branch a directive drops: the marker
   * reads as machinery rather than code, and the dropped branch is greyed and
   * italic like a comment, because that is what it is once it is dropped. */
  --tk-directive: #c9a227;
  --tk-inactive:  #5c6673;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --code-size: 13px;
  --code-lh: 20px;
}

:root[data-theme="light"] {
  --bg:            #eef0f4;
  --bg-panel:      #ffffff;
  --bg-raised:     #f5f6f9;
  --bg-input:      #ffffff;
  --border:        #d7dbe3;
  --border-strong: #bcc3ce;
  --text:          #1e232b;
  --text-dim:      #5c6675;
  --text-faint:    #8b95a3;
  --accent:        #c2492f;
  --accent-hover:  #a93c25;
  --accent-quiet:  rgba(194, 73, 47, 0.10);
  --link:          #1f6f96;
  --good:          #2f7d47;
  --warn:          #9a6a12;
  --bad:           #b8382f;
  --shadow:        0 8px 24px rgba(30, 35, 43, 0.14);

  --tk-comment:  #7c8592;
  --tk-keyword:  #b3261e;
  --tk-string:   #0a4f7a;
  --tk-number:   #0b5394;
  --tk-variable: #216e39;
  --tk-sysvar:   #8a5210;
  --tk-call:     #6b3fa0;
  --tk-type:     #0b5394;
  --tk-defkind:  #8a5210;
  --tk-op:       #4a5462;
  --tk-ident:    #1e232b;
  --tk-directive: #8a5210;
  --tk-inactive:  #98a1ae;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body.dragging { cursor: col-resize; user-select: none; }

.mono { font-family: var(--font-mono); }
.spacer { flex: 1 1 auto; }
.dim { color: var(--text-dim); }

/* ---------------- top bar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.logo {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font: 700 13px/1 var(--font-mono);
  letter-spacing: 0.5px;
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.1px;
  white-space: nowrap;
}
.brand p {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
}

.controls { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.sel { display: flex; align-items: center; gap: 6px; }
.sel > span {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

select, input[type="text"], input[type="search"] {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
  font: inherit;
  font-size: 13px;
  max-width: 100%;
}
select:focus, input:focus, textarea:focus {
  outline: 2px solid var(--link);
  outline-offset: -1px;
}

.btn {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--link); }
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.tiny { padding: 3px 8px; font-size: 12px; }
.btn.icon { padding: 6px 9px; font-size: 15px; line-height: 1; }

kbd {
  font: 11px/1 var(--font-mono);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 4px;
  padding: 3px 4px;
}
:root[data-theme="light"] .btn.primary kbd {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.35);
}

/* ---------------- layout ---------------- */
#main {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-panel);
}
#pane-editor { flex: 0 0 50%; }
#pane-out { flex: 1 1 auto; border-left: 1px solid var(--border); }

.splitter {
  flex: 0 0 5px;
  background: var(--bg);
  cursor: col-resize;
  position: relative;
}
.splitter::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--border);
  width: 1px;
  margin: 0 auto;
}
.splitter:hover::after, .splitter:focus::after { background: var(--link); width: 3px; }

.pane-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.pane-head h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.head-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.meta { font-size: 11.5px; color: var(--text-faint); }

/* ---------------- editor ---------------- */
.editor {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  background: var(--bg-input);
  font-family: var(--font-mono);
  font-size: var(--code-size);
  line-height: var(--code-lh);
}

.gutter {
  flex: 0 0 auto;
  overflow: hidden;
  padding: 12px 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  user-select: none;
}
/* Scroll sync happens by transform; deliberately no will-change here, since
 * promoting these to their own layer leaves them stale on a theme switch. */
.gutter-inner { transform: translateY(0); }
.ln {
  height: var(--code-lh);
  padding: 0 10px 0 14px;
  text-align: right;
  color: var(--text-faint);
  font-size: 12px;
  min-width: 48px;
}
.ln.err {
  color: #fff;
  background: var(--bad);
  font-weight: 700;
}

.code {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
}

.highlight {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
  padding: 12px 16px;
  white-space: pre;
  pointer-events: none;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  tab-size: 3;
}
.highlight code { font: inherit; }

.code textarea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 12px 16px;
  border: 0;
  resize: none;
  overflow: auto;
  white-space: pre;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  tab-size: 3;
}
.code textarea::selection { background: rgba(111, 179, 210, 0.32); }

.err-band {
  position: absolute;
  left: 0;
  right: 0;
  background: rgba(224, 108, 108, 0.13);
  border-left: 2px solid var(--bad);
  pointer-events: none;
}

/* ---------------- completion list ---------------- */
/* Positioned inside .code, which is the caret's own coordinate space, so the
 * list follows the caret without any measuring of the text itself. */
.ac {
  position: absolute;
  z-index: 5;
  min-width: 260px;
  max-width: 520px;
  /* Ten rows of about 26px, plus the padding: enough that the list never shows
   * half a row, which is what a smaller cap did. */
  max-height: 300px;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  box-shadow: var(--shadow);
  font-family: var(--font-ui);
  font-size: 12.5px;
  padding: 3px;
}
.ac[hidden] { display: none; }

.ac-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 7px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.ac-row:hover { background: var(--bg-raised); }
.ac-row.ac-sel { background: var(--accent-quiet); }
.ac-row.ac-sel .ac-label { color: var(--accent); font-weight: 600; }

.ac-kind {
  flex: 0 0 auto;
  width: 34px;
  font: 10px/1.6 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
}
/* The kind carries the colour the token would have in the editor, so the list
 * and the code agree about what a thing is. */
.ac-kind.ac-func, .ac-kind.ac-meth { color: var(--tk-call); }
.ac-kind.ac-sysv { color: var(--tk-sysvar); }
.ac-kind.ac-keyw { color: var(--tk-keyword); }
.ac-kind.ac-vari { color: var(--tk-variable); }
.ac-kind.ac-reco, .ac-kind.ac-fiel, .ac-kind.ac-defk { color: var(--tk-defkind); }
.ac-kind.ac-prop { color: var(--tk-type); }
.ac-kind.ac-unsu { color: var(--warn); }

.ac-label {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  color: var(--text);
}
.ac-detail {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
  color: var(--text-faint);
  font-size: 11.5px;
}

/* token colours */
.tk-comment  { color: var(--tk-comment); font-style: italic; }
.tk-keyword  { color: var(--tk-keyword); }
.tk-string   { color: var(--tk-string); }
.tk-number   { color: var(--tk-number); }
.tk-variable { color: var(--tk-variable); }
.tk-sysvar   { color: var(--tk-sysvar); }
.tk-call     { color: var(--tk-call); }
.tk-type     { color: var(--tk-type); }
.tk-defkind  { color: var(--tk-defkind); }
.tk-op       { color: var(--tk-op); }
.tk-ident    { color: var(--tk-ident); }
.tk-directive { color: var(--tk-directive); font-weight: 600; }
.tk-inactive  { color: var(--tk-inactive); font-style: italic; }

/* ---------------- tabs ---------------- */
.tabs {
  display: flex;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: 10px 14px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  font: 10.5px/1 var(--font-mono);
}
.badge.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
/* `display` from .badge would otherwise beat the user-agent [hidden] rule. */
.badge[hidden] { display: none; }

.tab-panels { flex: 1 1 auto; min-height: 0; position: relative; }
.panel {
  display: none;
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 0 0 24px;
}
.panel.active { display: block; }

.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  z-index: 2;
}
.panel-toolbar .search { flex: 1 1 auto; }

.empty {
  padding: 28px 20px;
  color: var(--text-faint);
  font-size: 13px;
  max-width: 60ch;
}
.empty p { margin: 0; }

.section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 14px 14px 6px;
  flex-wrap: wrap;
}
.section-head h3 {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

/* ---------------- output list ---------------- */
.out-list { padding: 4px 0; }

.out-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 3px 14px;
  border-left: 2px solid transparent;
}
.out-row:hover { background: var(--bg-raised); }

.out-kind {
  flex: 0 0 auto;
  width: 42px;
  margin-top: 2px;
  font: 10px/14px var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: right;
  color: var(--text-faint);
}
.out-text {
  flex: 1 1 auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  min-width: 0;
}
.out-line {
  flex: 0 0 auto;
  background: none;
  border: 0;
  color: var(--text-faint);
  font: 11px/1.4 var(--font-mono);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}
.out-line:hover { color: var(--link); background: var(--bg-raised); }

.kind-warning { border-left-color: var(--warn); background: rgba(217, 163, 67, 0.07); }
.kind-warning .out-kind, .kind-warning .out-text { color: var(--warn); }
.kind-error { border-left-color: var(--bad); background: rgba(224, 108, 108, 0.09); }
.kind-error .out-kind, .kind-error .out-text { color: var(--bad); }
.kind-info { border-left-color: var(--link); }
.kind-info .out-kind, .kind-info .out-text { color: var(--link); }

.error-box {
  margin: 14px;
  padding: 12px 14px;
  border: 1px solid var(--bad);
  border-left-width: 3px;
  border-radius: 6px;
  background: rgba(224, 108, 108, 0.08);
}
.error-box strong {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--bad);
  margin-bottom: 5px;
}
.error-box p {
  margin: 0 0 9px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  white-space: pre-wrap;
}

/* ---------------- grids ---------------- */
.grid-scroll { overflow-x: auto; }

table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
table.grid th {
  text-align: left;
  padding: 6px 10px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border-strong);
  border-top: 1px solid var(--border);
  font: 600 11px/1.4 var(--font-mono);
  color: var(--text-dim);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
table.grid th.key { color: var(--accent); }
table.grid td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  white-space: nowrap;
}
table.grid tbody tr:hover { background: var(--bg-raised); }
table.grid td.num { text-align: right; }
table.grid td.name { color: var(--tk-variable); }
table.grid td.val { color: var(--text); white-space: pre-wrap; word-break: break-word; }
table.grid .mono { font-family: var(--font-mono); font-size: 12px; }

/* ---------------- database browser ---------------- */
.db-wrap { display: flex; align-items: stretch; min-height: 0; }
.db-list {
  flex: 0 0 210px;
  border-right: 1px solid var(--border);
  padding: 6px 0;
  overflow-y: auto;
}
.db-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: 0;
  border-left: 2px solid transparent;
  color: var(--text-dim);
  font: 12px/1.5 var(--font-mono);
  padding: 5px 10px;
  cursor: pointer;
  text-align: left;
}
.db-item:hover { background: var(--bg-raised); color: var(--text); }
.db-item.active {
  background: var(--accent-quiet);
  border-left-color: var(--accent);
  color: var(--text);
}
.db-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }
.db-count {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--text-faint);
  background: var(--bg-raised);
  border-radius: 8px;
  padding: 1px 6px;
}
.db-count.changed { background: var(--accent); color: #fff; }
.db-detail { flex: 1 1 auto; min-width: 0; overflow: auto; }
.db-detail .meta { padding: 0 14px; }

/* ---------------- SQL console ---------------- */
.sql-console { border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.sql-console[hidden] { display: none; }

.sql-input {
  display: block;
  width: calc(100% - 28px);
  margin: 0 14px;
  min-height: 96px;
  resize: vertical;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
  tab-size: 3;
}
.sql-input::placeholder { color: var(--text-faint); }

.sql-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 4px;
  flex-wrap: wrap;
}

.sql-out { padding: 2px 14px 0; }
.sql-out .section-head, .sql-out .error-box { padding-left: 0; margin-left: 0; }
.sql-out .error-box { margin: 10px 0; }
.sql-hint { margin: 4px 0 0; max-width: 70ch; }

.sql-outline {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.sql-outnum { flex: 0 0 auto; color: var(--text-faint); font: 11px/1.6 var(--font-mono); }
.sql-outsql {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--tk-string);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sql-outmsg { flex: 0 0 auto; color: var(--good); font-size: 12px; }

.btn.tiny.on { border-color: var(--accent); color: var(--accent); }

/* ---------------- SQL log ---------------- */
.sql-list { margin: 0; padding: 8px 14px 8px 40px; }
.sql-list li { margin-bottom: 12px; }
.sql-text {
  margin: 0;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: 12px/1.55 var(--font-mono);
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--tk-string);
}
.sql-binds { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.sql-source {
  display: inline-block;
  margin-bottom: 4px;
  font: 10px/1.4 var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.chip {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  font: 11px/1.5 var(--font-mono);
  color: var(--text-dim);
}
.chips { display: flex; flex-wrap: wrap; gap: 5px; padding: 4px 14px 12px; }

/* ---------------- session form ---------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  padding: 4px 14px 12px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label {
  font: 600 11.5px/1.4 var(--font-mono);
  color: var(--tk-sysvar);
}
.field-hint { font-size: 11px; color: var(--text-faint); }

.clock-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 14px 14px;
  flex-wrap: wrap;
}
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; }
.clock-input { font-family: var(--font-mono); min-width: 220px; }
.clock-input:disabled { opacity: 0.5; }

.kv { padding: 4px 14px 12px; display: grid; gap: 4px; max-width: 420px; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; }
.kv-key { color: var(--text-dim); }
.kv-val { color: var(--text); }

/* ---------------- reference ---------------- */
.ref-body { padding: 4px 0 20px; }
.ref-section { padding: 10px 14px 4px; }
.ref-section h3 {
  margin: 10px 0 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}
.ref-section > p.meta { margin: 0 0 8px; max-width: 70ch; }

.ref-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}
.ref-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 12px;
}
.ref-card h4 {
  margin: 0 0 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}
.ref-card pre {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-dim);
  white-space: pre-wrap;
}

dl.ref-list { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
dl.ref-list dt {
  font-size: 12px;
  color: var(--tk-call);
  margin-top: 8px;
  word-break: break-word;
}
dl.ref-list dd {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
  max-width: 78ch;
}
dl.ref-list dt[hidden], dl.ref-list dd[hidden] { display: none; }

/* ---------------- status bar ---------------- */
.statusbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  font-size: 11.5px;
  color: var(--text-dim);
}
#status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#status.good { color: var(--good); }
#status.bad { color: var(--bad); }
#status-right { font-family: var(--font-mono); color: var(--text-faint); white-space: nowrap; }

/* ---------------- scrollbars ---------------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 6px;
  border: 3px solid var(--bg-panel);
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ---------------- sign-in gate and account menu ---------------- */
/* Both are inert unless a Supabase project is configured in
 * js/auth/supabase-config.js -- src/auth/auth-gate.ts unhides them. */

/* `display: grid` below would otherwise beat the user-agent [hidden]
 * rule, the same trap .badge has. */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.auth-gate[hidden] { display: none; }

.auth-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 380px;
  padding: 32px 28px;
  text-align: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.auth-card .logo { width: 40px; height: 40px; border-radius: 9px; font-size: 15px; }
.auth-card h2 { margin: 0; font-size: 17px; font-weight: 600; }
.auth-card p { margin: 0; font-size: 13px; color: var(--text-dim); }
.auth-card .btn { margin-top: 4px; }
.auth-card .btn:disabled { opacity: 0.55; cursor: not-allowed; }

.auth-error {
  width: 100%;
  padding: 9px 11px;
  border-radius: 6px;
  background: var(--accent-quiet);
  border: 1px solid var(--bad);
  color: var(--bad) !important;
  font-size: 12.5px;
  text-align: left;
}
.auth-note { font-size: 11.5px; color: var(--text-faint) !important; }

/* While the gate is up the shell must not be reachable behind it --
 * app.ts has not booted, so these are empty frames in any case. */
body.auth-locked #main,
body.auth-locked .statusbar,
body.auth-locked .controls { visibility: hidden; }

.account { position: relative; }

.account-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 200px;
  padding: 5px 8px 5px 5px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.account-btn:hover { border-color: var(--link); }
.account-btn:disabled { opacity: 0.6; cursor: default; }

.avatar {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font: 700 10.5px/1 var(--font-ui);
  flex: 0 0 auto;
}

.account-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-btn .caret { color: var(--text-faint); font-size: 10px; flex: 0 0 auto; }

.account-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 90;
  min-width: 220px;
  padding: 6px;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.account-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 9px 9px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 5px;
  text-align: left;
}
.account-meta strong { font-size: 12.5px; font-weight: 600; }
.account-meta span { font-size: 11px; color: var(--text-faint); word-break: break-all; }

.account-item {
  display: block;
  width: 100%;
  padding: 7px 9px;
  background: none;
  border: 0;
  border-radius: 5px;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.account-item:hover { background: var(--bg-raised); color: var(--link); }
#auth-signout-ms { color: var(--text-dim); font-size: 11.5px; }

/* ---------------- narrow screens ---------------- */
@media (max-width: 900px) {
  #main { flex-direction: column; }
  #pane-editor { flex: 0 0 45%; }
  #pane-out { border-left: 0; border-top: 1px solid var(--border); }
  .splitter { flex: 0 0 7px; cursor: row-resize; }
  .splitter::after { width: auto; height: 1px; margin: auto 0; }
  body.dragging { cursor: row-resize; }
  .db-wrap { flex-direction: column; }
  .db-list { flex: 0 0 auto; max-height: 150px; border-right: 0; border-bottom: 1px solid var(--border); }
}

@media (max-width: 700px) {
  .brand p { display: none; }
  .account-name { display: none; }
  .account-btn { max-width: none; padding: 5px; }
  .sel > span { display: none; }
  .topbar { gap: 10px; padding: 8px 10px; }
  .btn.primary kbd { display: none; }
}
