/* Thoth console.
 *
 * One stylesheet, no build step, no framework. Colours are defined as custom
 * properties on :root for the light theme and redefined under
 * prefers-color-scheme: dark, so the console follows the operating system
 * without a toggle to get out of sync.
 */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-alt: #f0f2f5;
  --border: #d8dde4;
  --text: #1a1d21;
  --text-muted: #5f6873;
  --accent: #b4441c;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --ok-bg: #e6f4ea;
  --ok-border: #9ad3ab;
  --ok-text: #10502a;
  --error-bg: #fdecea;
  --error-border: #f0a9a3;
  --error-text: #8c1d18;
  --tag-bg: #e8ebef;
  --radius: 6px;
  --mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --surface: #1d2126;
    --surface-alt: #23282e;
    --border: #333a42;
    --text: #e7eaee;
    --text-muted: #9aa4b0;
    --accent: #e2703a;
    --accent-text: #16191d;
    --danger: #f2837b;
    --ok-bg: #16301f;
    --ok-border: #2f6b45;
    --ok-text: #a6e3bd;
    --error-bg: #3a1c1a;
    --error-border: #7d3a34;
    --error-text: #f5b7b1;
    --tag-bg: #2b3138;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body.centered {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

/* --- top bar -------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 650;
  font-size: 17px;
  letter-spacing: 0.01em;
  color: var(--text);
  text-decoration: none;
}

.nav { display: flex; gap: 4px; flex: 1; }

.navlink {
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
}
.navlink:hover { background: var(--surface-alt); color: var(--text); }
.navlink.active { background: var(--accent); color: var(--accent-text); }

.whoami { display: flex; align-items: center; gap: 12px; }
.who { color: var(--text-muted); font-size: 14px; }

/* --- layout --------------------------------------------------------------- */

.main { padding: 20px; max-width: 1400px; margin: 0 auto; }

.split {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
}

.pane { min-width: 0; }
.pane.wide { max-width: 100%; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 19px; margin: 0 0 8px; }
h3 { font-size: 16px; margin: 0 0 10px; }
h4 { font-size: 14px; margin: 20px 0 8px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

.muted { color: var(--text-muted); font-size: 14px; }
.mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.danger-text { color: var(--danger); }

/* --- cards ---------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card.empty { color: var(--text-muted); text-align: center; padding: 40px 16px; }
.card.danger-zone { border-color: var(--error-border); }

.signin { width: min(400px, 92vw); text-align: center; }
.signin h1 { font-size: 30px; margin-bottom: 0; }

/* --- tree and lists ------------------------------------------------------- */

.tree, .list { list-style: none; margin: 0 0 16px; padding: 0; }

.tree-row, .list-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  border: 1px solid transparent;
}
.tree-row:hover, .list-row:hover { background: var(--surface-alt); }
.tree-row.selected, .list-row.selected {
  background: var(--surface);
  border-color: var(--accent);
}

.list-row { flex-direction: column; gap: 2px; }
.list-title { font-weight: 550; }
.list-sub { color: var(--text-muted); font-size: 13px; }
.tree-name { font-weight: 500; }

/* --- tables --------------------------------------------------------------- */

.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.grid td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.grid tr:last-child td { border-bottom: none; }
.grid.compact td, .grid.compact th { padding: 5px 8px; }
.grid a { color: var(--text); }

/* Wide tables scroll inside their own card rather than pushing the page. */
.card > table { display: block; overflow-x: auto; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 12px 0 0; font-size: 14px; }
.facts dt { color: var(--text-muted); }
.facts dd { margin: 0; }

/* --- forms ---------------------------------------------------------------- */

.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--text-muted); }
.stack label.checkbox { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }

input[type="text"], input[type="email"], select {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.inline { display: inline; }

.button {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  align-self: flex-start;
}
.button:hover { border-color: var(--text-muted); }
.button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }

.linkish {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
}
.linkish.danger { color: var(--danger); }

/* --- tags, flashes, audit ------------------------------------------------- */

.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--tag-bg);
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}
.tag.danger-tag { background: var(--error-bg); color: var(--error-text); }

.flash {
  margin: 0;
  padding: 10px 20px;
  border-bottom: 1px solid transparent;
  font-size: 14px;
}
.flash-ok { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-text); }
.flash-error { background: var(--error-bg); border-color: var(--error-border); color: var(--error-text); }

.verb { font-weight: 600; }
.verb.create { color: var(--ok-text); }
.verb.delete { color: var(--danger); }
.verb.update, .verb.login { color: var(--text-muted); }

code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-alt);
  padding: 1px 5px;
  border-radius: 3px;
}
code.struck { text-decoration: line-through; opacity: 0.75; }
.arrow { color: var(--text-muted); margin: 0 2px; }
.yes { color: var(--ok-text); font-weight: 700; }
.no { color: var(--text-muted); }

/* --- tickets -------------------------------------------------------------- */

textarea {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  width: 100%;
  resize: vertical;
}

/* The detail screen puts the ticket itself first on a narrow window, and the
 * side panel second. Reversing with direction rather than order keeps the DOM
 * in reading order for a screen reader. */
.split.reversed { grid-template-columns: 1fr minmax(280px, 340px); }
@media (max-width: 900px) {
  .split.reversed { grid-template-columns: 1fr; }
}

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > label { flex: 1; min-width: 140px; }

.filters { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--text-muted); }
.filters label.checkbox { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.filters select { min-width: 160px; }

.tallies { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 16px; }
.tally {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 14px;
  min-width: 84px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}
.tally:hover { border-color: var(--accent); }
.tally-n { font-size: 20px; font-weight: 650; }
.tally-label { font-size: 12px; color: var(--text-muted); }

.ticket-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.ticket-head .ref { color: var(--text-muted); font-size: 13px; }

/* Ticket bodies are stored and rendered as plain text. pre-wrap preserves the
 * line breaks somebody typed without any markup being parsed, which is what
 * lets the console render untrusted content with no sanitiser in the stack. */
.body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 8px 0 0;
}
.body.compact { font-size: 14px; }

.followup, .solution {
  border-top: 1px solid var(--border);
  padding: 12px 0;
}
.followup:first-of-type, .solution:first-of-type { border-top: none; }
.followup > header, .solution > header {
  display: flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
  font-size: 14px;
}
.followup.private {
  background: var(--surface-alt);
  border-left: 3px solid var(--danger);
  padding-left: 10px;
  margin-left: -13px;
}
.solution-accepted { border-left: 3px solid var(--ok-border); padding-left: 10px; margin-left: -13px; }
.solution-rejected { opacity: 0.7; }

.task-edit { display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
.task-edit select { width: auto; min-width: 110px; }
.task-edit input[type="text"] { width: 62px; }

.tag.status-new { background: var(--accent); color: var(--accent-text); }
.tag.status-pending { background: var(--error-bg); color: var(--error-text); }
.tag.status-solved, .tag.status-closed { background: var(--ok-bg); color: var(--ok-text); }
.tag.prio-5 { background: var(--error-bg); color: var(--error-text); font-weight: 600; }
.tag.prio-4 { background: var(--error-bg); color: var(--error-text); }

/* --- portal ---------------------------------------------------------------
 *
 * The customer-facing pages. --brand comes from /portal/brand.css, which is
 * generated per tenant; the fallback keeps the portal usable if a deployment
 * has never been branded. */

.portal .topbar.branded { border-bottom: 3px solid var(--brand, var(--accent)); }
.portal .brand { color: var(--brand, var(--accent)); font-size: 18px; }
.portal .navlink.active { background: var(--brand, var(--accent)); color: #fff; }
.portal .button.primary { background: var(--brand, var(--accent)); border-color: transparent; color: #fff; }
.portal .linkish { color: var(--brand, var(--accent)); }

/* Wider than the console's split view: the portal is one column of prose and
 * forms, and a 1400px line length is unreadable. */
.portal-main { max-width: 820px; }

.welcome { border-left: 3px solid var(--brand, var(--accent)); }

.portal-foot {
  max-width: 820px;
  margin: 0 auto;
  padding: 8px 20px 32px;
}

.solution-decision { border-color: var(--brand, var(--accent)); }
