/*
  Teisora operator console.

  Deliberately its own visual language rather than teisoraweb's: an operator
  should never be able to mistake this tab for the customer site, because the
  buttons here rewrite what every MCP client reads. Dense, monospace-leaning,
  and obviously a tool.

  Light and dark both, driven by prefers-color-scheme — an internal tool gets
  used at odd hours and a forced-light console at 2am is its own small hostility.
*/

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --border: #d9d9d3;
  --border-strong: #b9b9b1;
  --text: #1b1b18;
  --text-dim: #6b6b63;
  --accent: #7c3b17;
  --accent-text: #ffffff;
  --danger: #a02216;
  --danger-bg: #fdf0ee;
  --ok: #1f6b3a;
  --warn-bg: #fdf7e3;
  --warn-border: #e6d08a;
  --focus: #1f6feb;
  --radius: 6px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #1e1e23;
    --surface-2: #26262c;
    --border: #33333b;
    --border-strong: #4a4a54;
    --text: #e8e8e3;
    --text-dim: #9a9a92;
    --accent: #c97a4a;
    --accent-text: #1a1a1a;
    --danger: #e5705f;
    --danger-bg: #2a1c1a;
    --ok: #6cc08a;
    --warn-bg: #2b2718;
    --warn-border: #5c5230;
    --focus: #64a0ff;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* A visible focus ring everywhere. Keyboard is how anyone edits text quickly. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-text);
  padding: 0.75rem 1rem;
  z-index: 10;
}
.skip:focus { left: 0; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ---------- masthead ---------- */

.masthead {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.masthead .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 60px;
  flex-wrap: wrap;
}
.brand {
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  font-size: 1rem;
}
.brand span {
  font-family: var(--mono);
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-left: 0.5rem;
}
.masthead-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.who {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main.wrap { padding-top: 1.75rem; padding-bottom: 4rem; }

/* ---------- typography ---------- */

h1 { font-size: 1.5rem; margin: 0 0 0.35rem; letter-spacing: -0.015em; }
h2 { font-size: 1.05rem; margin: 0 0 0.35rem; }
p { margin: 0 0 0.6rem; }
.sub { color: var(--text-dim); max-width: 62ch; margin: 0; }
.dim { color: var(--text-dim); font-size: 0.85rem; }
code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

.crumbs {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}
.crumbs a { color: var(--text-dim); }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.page-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.version-line {
  margin: 0.6rem 0 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* ---------- controls ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  /* 44px minimum target: this gets used on a tablet on a desk, not only a mouse. */
  min-height: 44px;
  padding: 0 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease;
}
.button:hover { background: var(--surface-2); }
.button:active { transform: translateY(1px); }
.button[disabled] { opacity: 0.55; cursor: not-allowed; transform: none; }
.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 550;
}
.button.primary:hover { filter: brightness(1.08); }
.button.ghost { background: transparent; border-color: var(--border); }
.button.block { width: 100%; }
.button.small { min-height: 34px; padding: 0 0.7rem; font-size: 0.82rem; }
.button.danger {
  border-color: var(--danger);
  color: var(--danger);
  background: transparent;
}
.button.danger:hover { background: var(--danger-bg); }

form.inline { display: inline; margin: 0; }

.field { margin-bottom: 0.9rem; }
.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 550;
  margin-bottom: 0.3rem;
  color: var(--text-dim);
}
.element {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
}
.element:focus-visible { border-color: var(--focus); }

.upload {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
/* The native file input is unstyleable and ugly; the label is the control. */
.file-pick {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 0.9rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.86rem;
  cursor: pointer;
  max-width: 22rem;
}
.file-pick:hover { background: var(--surface-2); }
.file-pick:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.file-pick input[type="file"] {
  font: inherit;
  font-size: 0.8rem;
  max-width: 12rem;
  margin-left: 0.5rem;
  color: var(--text-dim);
}
.file-pick-label { font-weight: 550; white-space: nowrap; }

/* ---------- status ---------- */

.notice, .error, .ok {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}
.notice { background: var(--surface-2); border: 1px solid var(--border); }
.notice.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.error { background: var(--danger-bg); border: 1px solid var(--danger); color: var(--danger); }
.ok { background: var(--surface-2); border: 1px solid var(--ok); color: var(--ok); }

.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.74rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  white-space: nowrap;
}
.badge.current { border-color: var(--ok); color: var(--ok); }
.badge.history { border-color: var(--warn-border); color: var(--text-dim); }

/* ---------- empty states ---------- */

.empty {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text-dim);
  background: var(--surface);
}
.empty h2 { color: var(--text); }
.empty p { max-width: 48ch; margin: 0.5rem auto 0; }
.empty.small { padding: 3rem 1rem; }

/* ---------- catalogue ---------- */

.cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.card:hover { border-color: var(--border-strong); }
.card-link { text-decoration: none; color: inherit; }
.card-link h2 { font-family: var(--mono); font-size: 1rem; }
.card .desc {
  color: var(--text-dim);
  font-size: 0.88rem;
  margin: 0.3rem 0 0;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.meta {
  display: flex;
  gap: 1.1rem;
  margin: auto 0 0;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
}
.meta dt { color: var(--text-dim); margin: 0; }
.meta dd { margin: 0; font-family: var(--mono); }

/* ---------- editor ---------- */

.editor-grid {
  display: grid;
  grid-template-columns: minmax(200px, 260px) 1fr;
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 760px) {
  .editor-grid { grid-template-columns: 1fr; }
}

.pane-title {
  font-family: var(--mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin: 0 0 0.6rem;
}

.files {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  position: sticky;
  top: 76px;
}
.files ul { list-style: none; margin: 0; padding: 0; }
.file {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  min-height: 40px;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  text-decoration: none;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.8rem;
}
.file:hover { background: var(--surface-2); }
.file.current {
  background: var(--surface-2);
  box-shadow: inset 2px 0 0 var(--accent);
  font-weight: 600;
}
.file-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--text-dim); font-size: 0.72rem; flex-shrink: 0; }
.pane-foot {
  margin: 0.8rem 0 0;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--text-dim);
}

.editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.editor-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.editor-head .pane-title { text-transform: none; font-size: 0.9rem; color: var(--text); }
textarea.code {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.65;
  padding: 0.8rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  min-height: 24rem;
  tab-size: 2;
}
.editor-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.9rem;
  flex-wrap: wrap;
}
.inline-field { flex: 1 1 20rem; margin: 0; }

/* ---------- history ---------- */

.history { margin-top: 2rem; }
.versions { list-style: none; margin: 0; padding: 0; }
.version {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 0.4rem;
}
.version.is-current { border-color: var(--ok); }
.version-open {
  flex: 1;
  display: grid;
  grid-template-columns: 3.5rem 1fr auto;
  gap: 0.75rem;
  align-items: center;
  text-decoration: none;
  color: inherit;
  min-height: 36px;
  overflow: hidden;
}
.version .v { font-family: var(--mono); font-weight: 600; font-size: 0.85rem; }
.version .note {
  color: var(--text-dim);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.version .when { font-family: var(--mono); font-size: 0.76rem; color: var(--text-dim); }
@media (max-width: 620px) {
  .version-open { grid-template-columns: 3rem 1fr; }
  .version .when { grid-column: 2; }
}

/* ---------- danger zone ---------- */

.danger {
  margin-top: 2.5rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--danger);
  border-radius: var(--radius);
  background: var(--surface);
}
.danger p { color: var(--text-dim); font-size: 0.86rem; max-width: 62ch; }

/* ---------- sign-in ---------- */

.auth-main {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
}
.auth-card {
  width: 100%;
  max-width: 26rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
}
.auth-head { margin-bottom: 1.5rem; }
.auth-head h1 { font-size: 1.25rem; }
.auth-head p { color: var(--text-dim); font-size: 0.88rem; margin: 0; }

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