/* Telescanner console styling, layered on Pico.
 *
 * Loaded after pico.min.css. The overrides target :root[data-theme=light] to
 * match the specificity Pico uses for its own light scheme, and the document is
 * pinned to that theme: this is a single-user tool with one committed look.
 */

:root[data-theme="light"] {
  --pico-font-family:
    system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --pico-font-size: 100%;
  --pico-line-height: 1.55;
  --pico-border-radius: 3px;
  --pico-spacing: 1rem;

  --ground: #111b19;
  --ground-ink: #e6ede9;
  --ground-dim: #93a8a2;
  --paper: #eef1ee;
  --surface: #ffffff;
  --ink: #151b1a;
  --muted: #5b6a67;
  --line: #d3dbd7;
  --signal: #0d6e5a;
  --signal-soft: #e0efe9;
  --veto: #9c3a1f;
  --veto-soft: #f6e4dd;

  --pico-background-color: var(--paper);
  --pico-color: var(--ink);
  --pico-h1-color: var(--ink);
  --pico-h2-color: var(--ink);
  --pico-muted-color: var(--muted);
  --pico-border-color: var(--line);
  --pico-primary: var(--signal);
  --pico-primary-background: var(--signal);
  --pico-primary-hover-background: #0a5849;
  --pico-primary-border: var(--signal);
  --pico-primary-hover-border: #0a5849;
  --pico-primary-underline: rgba(13, 110, 90, 0.4);
  --pico-primary-focus: rgba(13, 110, 90, 0.3);
  --pico-form-element-background-color: var(--surface);
  --pico-form-element-border-color: #c4cec9;
  --pico-form-element-active-border-color: var(--signal);
  --pico-form-element-focus-color: var(--signal);
  --pico-code-background-color: var(--signal-soft);
  --pico-code-color: #0a4a3e;
}

body {
  background: var(--paper);
}

.mono,
code,
textarea,
.normalized {
  font-family: var(--pico-font-family-monospace);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.nowrap {
  white-space: nowrap;
}

/* Shell -------------------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: 14rem minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  padding: 2rem 1.25rem;
  background: var(--ground);
  color: var(--ground-ink);
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
}

.mark {
  display: block;
  text-decoration: none;
  color: inherit;
}

.mark-name {
  display: block;
  font-family: var(--pico-font-family-monospace);
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  color: var(--surface);
}

.mark-sub {
  display: block;
  font-size: 0.8125rem;
  color: var(--ground-dim);
}

.rail-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
}

.rail-nav a {
  display: block;
  padding: 0.4rem 0.6rem;
  margin-left: -0.6rem;
  border-radius: 3px;
  color: var(--ground-dim);
  text-decoration: none;
}

.rail-nav a:hover {
  color: var(--surface);
}

.rail-nav a[aria-current="page"] {
  background: rgba(255, 255, 255, 0.07);
  color: var(--surface);
  box-shadow: inset 2px 0 0 var(--signal);
}

.rail-exit {
  margin: 0;
}

.rail-exit .link-button {
  color: var(--ground-dim);
}

.rail-exit .link-button:hover {
  color: var(--surface);
}

.page {
  padding: 3rem 3rem 6rem;
  max-width: 70rem;
}

.page-head {
  margin-bottom: 2rem;
}

.page-head h1 {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin-bottom: 0.35rem;
}

.lead,
.hint {
  color: var(--muted);
  max-width: 62ch;
}

.hint {
  font-size: 0.8125rem;
  margin-bottom: 0.5rem;
}

.back {
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 3px;
  padding: 1.25rem;
}

/* Buttons and alerts -------------------------------------------------- */

.link-button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  width: auto;
  color: var(--signal);
  font-size: 0.875rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.link-button.danger {
  color: var(--veto);
}

.alert {
  border-left: 3px solid var(--signal);
  background: var(--signal-soft);
  padding: 0.7rem 0.9rem;
  margin-bottom: 1.5rem;
}

.alert-veto {
  border-left-color: var(--veto);
  background: var(--veto-soft);
  color: #6f2814;
}

.field-error {
  color: var(--veto);
  font-size: 0.875rem;
}

.error-list {
  margin: 0.5rem 0 0;
  padding: 0;
  font-size: 0.875rem;
}

.error-list li {
  padding: 0.35rem 0;
  border-top: 1px solid var(--line);
  color: var(--veto);
}

/* Pico sets `ul li { list-style: square }`, which outranks list-style set on
 * the list itself. The marker has to be cleared on the item. */
.verdicts > li,
.error-list > li {
  list-style: none;
}

.line-tag {
  display: inline-block;
  background: var(--veto-soft);
  color: #6f2814;
  padding: 0 0.35rem;
  margin-right: 0.35rem;
}

/* Tables --------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 3px;
}

table {
  margin: 0;
}

/* Without a min-width the table shrinks to the wrapper and the overflow-x on
 * .table-wrap never engages, so columns get squeezed instead of scrolled. */
.rules {
  min-width: 44rem;
}

/* The rule name is the only free-flowing column, so it is the one the table
 * layout starves first. */
.rules th:first-child {
  min-width: 13rem;
}

.chats {
  min-width: 34rem;
}

table th,
table td {
  vertical-align: baseline;
}

thead th {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
}

.rules tbody th a {
  text-decoration: none;
  font-weight: 600;
}

.rules tbody th a:hover {
  text-decoration: underline;
}

.sep {
  color: var(--line);
  padding: 0 0.3rem;
}

.state {
  font-size: 0.8125rem;
  white-space: nowrap;
}

.state-on {
  color: var(--signal);
}

.state-on::before,
.state-off::before {
  content: "";
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  margin-right: 0.4rem;
  background: currentColor;
}

.state-off {
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 1rem;
  align-items: baseline;
}

.actions form {
  margin: 0;
}

.create-row,
.sync-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.create-row input,
.sync-row button,
.create-row button {
  margin: 0;
  width: auto;
}

.create-row input {
  min-width: 18rem;
}

/* Rule form ------------------------------------------------------------ */

.rule-form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1.75rem;
}

.pattern-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.pattern-field textarea {
  font-size: 0.875rem;
  line-height: 1.6;
  margin-bottom: 0;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-top: 1.5rem;
}

.form-actions button {
  width: auto;
  margin: 0;
}

/* Tester ---------------------------------------------------------------- */

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

.tester-input textarea {
  font-size: 0.875rem;
}

.tester-input button {
  width: auto;
}

.normalized {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 0.75rem;
  font-size: 0.8125rem;
  word-break: break-word;
}

.verdicts {
  margin: 0;
  padding: 0;
}

.verdict {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-left-color: var(--line);
  padding: 0.85rem 1rem;
  margin-bottom: 0.5rem;
}

.verdict-head {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.verdict-head a {
  font-weight: 600;
  text-decoration: none;
  color: var(--ink);
}

.verdict-tag {
  font-family: var(--pico-font-family-monospace);
  font-size: 0.8125rem;
  color: var(--muted);
}

.verdict-line {
  margin: 0.4rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.verdict-line code {
  margin-right: 0.35rem;
}

.verdict-matched {
  border-left-color: var(--signal);
}

.verdict-matched .verdict-tag {
  color: var(--signal);
}

.verdict-vetoed {
  border-left-color: #b98900;
}

.verdict-broken {
  border-left-color: var(--veto);
}

.verdict-broken .verdict-tag {
  color: var(--veto);
}

/* Matches ---------------------------------------------------------------- */

.matches {
  list-style: none;
  margin: 0;
  padding: 0;
}

.match {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1rem 1.15rem;
  margin-bottom: 0.6rem;
}

.match-head {
  display: flex;
  gap: 0.9rem;
  align-items: baseline;
  flex-wrap: wrap;
  font-size: 0.875rem;
  color: var(--muted);
}

.match-rule {
  font-weight: 600;
  color: var(--ink);
}

.match-excerpt {
  margin: 0.5rem 0;
  white-space: pre-wrap;
}

.match-meta {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
  display: flex;
  gap: 0.9rem;
  align-items: baseline;
  flex-wrap: wrap;
}

.pager {
  display: flex;
  gap: 1.5rem;
  align-items: baseline;
  margin-top: 1.5rem;
  font-size: 0.875rem;
  color: var(--muted);
}

/* Login ------------------------------------------------------------------ */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  background: var(--ground);
}

.gate-card {
  background: var(--surface);
  border-radius: 3px;
  padding: 2.5rem;
  width: min(24rem, 100%);
}

.gate-card h1 {
  font-family: var(--pico-font-family-monospace);
  font-size: 1.25rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.gate-lead {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

.gate-card button {
  margin-bottom: 0;
}

/* Narrow screens ---------------------------------------------------------- */

@media (max-width: 55rem) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 1.25rem;
    padding: 1rem 1.25rem;
    flex-wrap: wrap;
  }

  .rail-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.75rem;
    flex: 1;
  }

  .rail-nav a {
    margin-left: 0;
  }

  .rail-nav a[aria-current="page"] {
    box-shadow: inset 0 -2px 0 var(--signal);
  }

  .page {
    padding: 2rem 1.25rem 4rem;
  }

  .tester {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Phone: the data tables become cards ------------------------------------- */

/* Same breakpoint as the rail: once the layout is one column, a table this
 * wide can only be read by scrolling sideways, and the actions end up off
 * screen. Each row becomes a card, in the same idiom as the alert list, with
 * the column head repeated on each cell as its label. */
@media (max-width: 55rem) {
  .table-wrap {
    overflow-x: visible;
    background: none;
    border: 0;
  }

  /* Label and value sit close together, so the card is capped at a
   * readable measure instead of stretching across the whole column. */
  .rules,
  .chats {
    min-width: 0;
    max-width: 42rem;
  }

  .rules thead,
  .chats thead {
    display: none;
  }

  .rules,
  .rules tbody,
  .rules tr,
  .rules th,
  .rules td,
  .chats,
  .chats tbody,
  .chats th,
  .chats td {
    display: block;
  }

  .rules tr,
  .chats tr {
    border: 1px solid var(--line);
    border-radius: 3px;
    padding: 0.9rem 1rem;
    margin-bottom: 0.6rem;
    background: var(--surface);
  }

  .rules th,
  .rules td,
  .chats th,
  .chats td {
    padding: 0;
    border: 0;
    background: var(--surface);
  }

  .rules tbody th,
  .chats tbody th {
    font-size: 1rem;
    padding-bottom: 0.6rem;
  }

  .rules td,
  .chats td[data-label] {
    position: relative;
    padding: 0.4rem 0 0.4rem 8.5rem;
    border-top: 1px solid var(--line);
    font-size: 0.875rem;
  }

  .rules td::before,
  .chats td[data-label]::before {
    content: attr(data-label);
    position: absolute;
    left: 0;
    top: 0.45rem;
    width: 8rem;
    color: var(--muted);
    font-family: var(--pico-font-family);
    font-size: 0.8125rem;
  }

  .rules .actions {
    display: inline-flex;
  }

  .chats tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 0.75rem;
  }

  .chats tbody th {
    grid-column: 2;
  }

  .chats td[data-label] {
    grid-column: 1 / -1;
  }

  .chats tbody td:first-child {
    padding-bottom: 0.6rem;
  }

  .chats tbody td:first-child input {
    margin: 0;
  }
}
