/* Trigger codes are printed on flyers and typed into a chat, so the interface
   is built around those two artifacts: codes are stamped in monospace, replies
   are shown as the bubble the visitor actually receives. */

:root {
  --ink: #171a2b;
  --ink-70: #4a4e63;
  --ink-45: #7e8296;
  --paper: #e8ece7;
  --card: #ffffff;
  --edge: #d3d9d2;
  --edge-soft: #e7ebe6;
  --live: #0f8a6a;
  --live-soft: #dff0e9;
  --halt: #9c3a5a;
  --halt-soft: #f6e7ec;

  --mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --r-card: 10px;
  --r-bubble: 14px;
  --r-stamp: 3px;
}

* { box-sizing: border-box; }

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

a { color: var(--ink); text-decoration-color: var(--ink-45); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--live);
  outline-offset: 2px;
  border-radius: 2px;
}

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

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.85rem 1.5rem;
  background: var(--ink);
  color: var(--paper);
}

.brand {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--paper);
  text-decoration: none;
  white-space: nowrap;
}

.topnav { display: flex; gap: 1.25rem; margin-right: auto; flex-wrap: wrap; }

.topnav a {
  color: rgba(232, 236, 231, 0.72);
  text-decoration: none;
  font-size: 0.95rem;
}
.topnav a:hover { color: var(--paper); }
.topnav a[aria-current="page"] {
  color: var(--paper);
  box-shadow: inset 0 -2px 0 var(--live);
}

.topbar form { margin: 0; }

.topbar button {
  background: none;
  border: 1px solid rgba(232, 236, 231, 0.3);
  color: rgba(232, 236, 231, 0.85);
  font: inherit;
  font-size: 0.9rem;
  padding: 0.3rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
}
.topbar button:hover { border-color: var(--paper); color: var(--paper); }

/* ---------- page frame ---------- */

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

.page--narrow { max-width: 560px; }

.pagehead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-45);
  margin: 0 0 0.4rem;
}

h1 {
  font-size: 1.9rem;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0;
}

h2 {
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  margin: 2.5rem 0 0.75rem;
}

.lede { color: var(--ink-70); margin: 0.5rem 0 0; max-width: 52ch; }

/* ---------- buttons ---------- */

.btn {
  display: inline-block;
  font: inherit;
  font-size: 0.95rem;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--ink);
  background: none;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: rgba(23, 26, 43, 0.06); }

.btn--primary { background: var(--ink); color: var(--paper); }
.btn--primary:hover { background: #262a44; }

.btn--quiet { border-color: var(--edge); color: var(--ink-70); }
.btn--quiet:hover { border-color: var(--ink-45); color: var(--ink); background: none; }

.btn--danger { border-color: transparent; color: var(--halt); padding-left: 0.7rem; padding-right: 0.7rem; }
.btn--danger:hover { background: var(--halt-soft); }

/* ---------- rules list ---------- */

.rules { display: flex; flex-direction: column; gap: 0.75rem; }

.rule {
  display: grid;
  grid-template-columns: 8.5rem 1fr auto;
  align-items: center;
  gap: 1.5rem;
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: var(--r-card);
  padding: 1.1rem 1.25rem;
}

.rule__code {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: var(--r-stamp);
  padding: 0.4rem 0.6rem;
  text-align: center;
  overflow-wrap: anywhere;
}

.rule__excerpt {
  margin: 0;
  color: var(--ink-70);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.rule__meta { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.45rem; }

.rule__actions { display: flex; align-items: center; gap: 0.35rem; }
.rule__actions form { margin: 0; }

.status {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}
.status--live { background: var(--live-soft); color: var(--live); }
.status--paused { background: var(--halt-soft); color: var(--halt); }

.chip {
  font-size: 0.82rem;
  color: var(--ink-70);
  background: var(--paper);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
}

.empty {
  background: var(--card);
  border: 1px dashed var(--edge);
  border-radius: var(--r-card);
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--ink-70);
}
.empty p { margin: 0 0 1.25rem; }

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

.editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 22rem);
  gap: 2.5rem;
  align-items: start;
}

.editor form { margin: 0; }

.field { display: block; margin-bottom: 1.6rem; }

.field__label {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
}

.field__hint {
  display: block;
  color: var(--ink-70);
  font-size: 0.85rem;
  margin-top: 0.35rem;
}

input[type="text"],
input[type="password"],
textarea,
input[type="file"] {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: 0.6rem 0.7rem;
}

textarea { min-height: 11rem; resize: vertical; line-height: 1.5; }

input[name="code"] {
  font-family: var(--mono);
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

input[type="file"] { padding: 0.5rem; color: var(--ink-70); }

.switch {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: var(--r-card);
  padding: 0.85rem 1rem;
  margin-bottom: 1.6rem;
}
.switch input { width: 1.1rem; height: 1.1rem; accent-color: var(--live); margin: 0; }
.switch span { font-weight: 600; }
.switch small { display: block; color: var(--ink-70); font-weight: 400; }

.actions { display: flex; align-items: center; gap: 0.75rem; }

/* ---------- conversation preview (the signature element) ---------- */

.preview { position: sticky; top: 2rem; }

.preview__title {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-45);
  margin: 0 0 0.75rem;
}

.thread {
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: var(--r-card);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-height: 32rem;
  overflow-y: auto;
}

.bubble {
  position: relative;
  max-width: 85%;
  padding: 0.65rem 0.85rem;
  border-radius: var(--r-bubble);
  font-size: 0.92rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble--in {
  align-self: flex-start;
  background: var(--paper);
  border-bottom-left-radius: 4px;
}

.bubble--out {
  align-self: flex-end;
  background: var(--live-soft);
  border-bottom-right-radius: 4px;
}

.bubble--empty { color: var(--ink-45); font-style: italic; }

/* Highlighting the code inside the incoming message shows the operator why it
   matched: any occurrence anywhere in the text, upper or lower case. */
mark {
  background: #f6dd8e;
  color: var(--ink);
  font-family: var(--mono);
  font-weight: 600;
  border-radius: var(--r-stamp);
  padding: 0 0.15em;
}

.attachment {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.5rem;
  font-size: 0.82rem;
  color: var(--ink-70);
  white-space: normal;
}
.attachment b { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }

/* ---------- messages, tables (shared with the other pages) ---------- */

.error {
  background: var(--halt-soft);
  color: var(--halt);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  margin: 0 0 1.5rem;
}

.notice {
  background: var(--live-soft);
  color: var(--live);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  margin: 0 0 1.5rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: var(--r-card);
  overflow: hidden;
}

th, td { text-align: left; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--edge-soft); }

th {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-45);
  font-weight: 500;
}

tr:last-child td { border-bottom: none; }

/* Standalone forms on the login / settings pages. */
form label { display: block; margin-bottom: 1rem; }
form label input { max-width: 26rem; }

button {
  font: inherit;
  cursor: pointer;
}

form > button {
  font-size: 0.95rem;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
}

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .editor { grid-template-columns: minmax(0, 1fr); gap: 1.75rem; }
  .preview { position: static; }
  .thread { max-height: none; }

  .rule { grid-template-columns: minmax(0, 1fr); gap: 0.85rem; }
  .rule__code { text-align: left; justify-self: start; min-width: 6rem; }
  .rule__actions { justify-content: flex-start; }
}

@media (max-width: 560px) {
  .page { padding: 1.75rem 1rem 3rem; }
  .topbar { gap: 1rem; padding: 0.75rem 1rem; }
  h1 { font-size: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
