/* Samastra Central — internal registry.
   Paper ground, field-green ink, digits in mono. Hairline furrows rule the
   ledgers; the ink masthead band is the one bold element on the page. */

:root {
  /* Identity */
  --paper:  #FAFAF7;
  --ink:    #1C2B22;
  --field:  #2E6B4F;
  --furrow: #E2E3DA;
  --dim:    #6B7268;
  --alert:  #A44A3F;

  /* Tones derived from the six above */
  --card:       #FFFFFF;
  --field-deep: #24553F;
  --field-wash: #EDF3EE;
  --alert-deep: #8A3E35;
  --alert-wash: #F7EDEA;
  --on-ink:     rgba(250, 250, 247, 0.72);
  --on-ink-faint: rgba(250, 250, 247, 0.28);

  /* Type */
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Spacing scale — every gap in the app comes from this ladder */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;

  --radius: 4px;
  --rule: 1px solid var(--furrow);
  --measure: 68rem;
  --control-h: 2.375rem;  /* one height for every field and the buttons beside them */
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, p, ul, ol, fieldset, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
fieldset { border: 0; padding: 0; min-width: 0; }

a { color: var(--field); text-underline-offset: 2px; }
a:hover { color: var(--field-deep); }

/* One focus treatment everywhere, always visible */
:focus-visible {
  outline: 2px solid var(--field);
  outline-offset: 2px;
  border-radius: 2px;
}

.mono, code { font-family: var(--mono); font-size: 0.8125rem; font-variant-ligatures: none; }

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

/* ------------------------------------------------------------- Masthead */

.masthead {
  display: flex;
  align-items: center;
  gap: var(--s5);
  flex-wrap: wrap;
  padding: var(--s3) var(--s5);
  background: var(--ink);
  color: var(--paper);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s3);
  font-weight: 650;
  letter-spacing: 0.01em;
}

.brand .mark {
  width: 1.75rem;
  height: 1.75rem;
  flex: none;
  display: block;
}

/* The mark stands in for the name, so only "Central" is ever set in type */
.brand-name {
  font-weight: 650;
  letter-spacing: 0.02em;
}

.masthead nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s4);
  margin-left: auto;
}

.masthead nav a {
  color: var(--on-ink);
  text-decoration: none;
  font-size: 0.875rem;
}

.masthead nav a:hover { color: var(--paper); text-decoration: underline; }
.masthead :focus-visible { outline-color: var(--paper); }
.masthead form { margin: 0; display: inline-flex; }

.masthead .signout {
  background: transparent;
  border-color: var(--on-ink-faint);
  color: var(--on-ink);
  font-size: 0.8125rem;
  padding: 0.28rem 0.7rem;
}

.masthead .signout:hover {
  background: rgba(250, 250, 247, 0.08);
  border-color: var(--paper);
  color: var(--paper);
}

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

main {
  max-width: var(--measure);
  margin: 0 auto;
  padding: var(--s5) var(--s5) var(--s7);
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s3);
  padding-bottom: var(--s3);
  margin-bottom: var(--s5);
  border-bottom: var(--rule);
}

h1 { font-size: 1.375rem; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 1.0625rem; font-weight: 650; }

/* ---------------------------------------------------------------- Flash */

.flashes {
  max-width: var(--measure);
  margin: var(--s4) auto 0;
  padding: 0 var(--s5);
  display: grid;
  gap: var(--s2);
}

.flash {
  padding: var(--s2) var(--s4);
  border-left: 3px solid var(--field);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--field-wash);
  font-size: 0.9375rem;
}

.flash.alert {
  border-left-color: var(--alert);
  background: var(--alert-wash);
  color: var(--alert-deep);
}

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

.table-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.table-scroll > table { min-width: 44rem; }

th {
  text-align: left;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dim);
  font-weight: 600;
  white-space: nowrap;
  padding: 0 var(--s4) var(--s2) 0;
  border-bottom: 2px solid var(--ink);
}

td {
  padding: var(--s3) var(--s4) var(--s3) 0;
  border-bottom: var(--rule);
  vertical-align: top;
}

th:last-child, td:last-child { padding-right: 0; }
tbody tr:hover { background: rgba(46, 107, 79, 0.035); }

/* Columns that hold controls shrink to their contents; text columns take the rest */
.col-app { width: 1%; }
.col-actions { width: 1%; white-space: nowrap; }

td.empty { color: var(--dim); font-style: italic; }

/* Telegram link state: a ring that fills once an identity is paired */
.status {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  white-space: nowrap;
  color: var(--dim);
  font-size: 0.875rem;
}

.status::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  border: 1px solid var(--dim);
  flex: none;
}

.status.connected { color: var(--ink); }
.status.connected::before { background: var(--field); border-color: var(--field); }

/* Minted deep link: the URL wraps, its expiry sits under it, button below */
.link-token {
  display: grid;
  gap: var(--s1);
  margin-bottom: var(--s2);
}

/* A fixed measure so the URL wraps to a predictable block: the column claims
   this width only on rows that actually carry a token. */
.link-token code {
  display: block;
  width: 15rem;
  word-break: break-all;
  color: var(--ink);
  background: var(--field-wash);
  padding: 0.15rem 0.35rem;
  border-radius: var(--radius);
}

.expiry { font-size: 0.75rem; color: var(--dim); }

/* Row actions travel together on one line, never stacking raggedly */
.actions {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: var(--s2);
}

.actions form { margin: 0; display: inline-flex; }

/* ------------------------------------------------------------ Link card */

/* The card is a drawing, not a document: it carries its own palette and its
   own rules inside the <svg>, because it gets lifted into a canvas where no
   stylesheet follows it. Nothing below reaches inside — this only stages it. */
.card-stage {
  display: grid;
  justify-items: center;
  gap: var(--s5);
}

.link-card {
  width: 100%;
  max-width: 24rem;
  height: auto;
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(28, 43, 34, 0.06), 0 10px 28px rgba(28, 43, 34, 0.09);
}

.card-note {
  max-width: 30rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--dim);
}

/* -------------------------------------------------------------- Buttons */

/* Held in :where() so it carries no specificity — every modifier class below
   wins over it, even on <input type="submit">, which out-weighs a bare class. */
:where(button, input[type="submit"], .btn-primary, .btn-quiet) {
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.25;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--furrow);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--field);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

:where(button, input[type="submit"], .btn-quiet):hover {
  border-color: var(--field);
  background: var(--field-wash);
  color: var(--field-deep);
}

.btn-primary {
  background: var(--field);
  border-color: var(--field);
  color: var(--paper);
  font-weight: 550;
}

.btn-primary:hover {
  background: var(--field-deep);
  border-color: var(--field-deep);
  color: var(--paper);
}

.btn-danger { color: var(--alert); }

.btn-danger:hover {
  border-color: var(--alert);
  background: var(--alert-wash);
  color: var(--alert-deep);
}

/* App access: on reads as filled, off as an outline */
.toggle {
  min-width: 3.5rem;
  padding: 0.3rem 0.6rem;
  font-size: 0.6875rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.toggle.is-on {
  background: var(--field);
  border-color: var(--field);
  color: var(--paper);
}

.toggle.is-on:hover {
  background: var(--field-deep);
  border-color: var(--field-deep);
  color: var(--paper);
}

.toggle.is-off {
  background: transparent;
  border-color: var(--furrow);
  color: var(--dim);
}

.toggle.is-off:hover {
  background: var(--card);
  border-color: var(--dim);
  color: var(--ink);
}

/* ---------------------------------------------------------------- Forms */

label {
  display: block;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--dim);
  margin-bottom: var(--s1);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
select {
  font-family: inherit;
  font-size: 0.9375rem;
  line-height: 1.5;
  width: 100%;
  height: var(--control-h);
  padding: 0 0.6rem;
  border: 1px solid var(--furrow);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
}

/* Wins over the type-selector rule above, so mono fields stay mono */
input.mono { font-family: var(--mono); font-size: 0.875rem; }

input::placeholder { color: var(--dim); opacity: 0.7; font-family: var(--sans); }

input[type="text"]:hover,
input[type="email"]:hover,
input[type="password"]:hover,
select:hover { border-color: var(--dim); }

select {
  appearance: none;
  padding-right: var(--s6);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--dim) 50%),
    linear-gradient(135deg, var(--dim) 50%, transparent 50%);
  background-position: right 1rem center, right 0.7rem center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.field { display: block; }
.field + .field { margin-top: var(--s4); }

/* A stacked form for one record at a time */
.stack-form {
  max-width: 28rem;
  display: grid;
  gap: var(--s4);
}

.checks {
  display: grid;
  gap: var(--s2);
  padding: var(--s3) var(--s4);
  border: var(--rule);
  border-radius: var(--radius);
  background: var(--card);
}

.checks legend {
  padding: 0 var(--s2);
  margin-left: calc(var(--s2) * -1);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--dim);
}

.check { display: flex; align-items: center; gap: var(--s2); }

.check input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--field);
  flex: none;
}

.check label {
  margin: 0;
  font-size: 0.9375rem;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--ink);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding-top: var(--s1);
}

/* A one-line form that opens a record; sits above the ledger it feeds */
.inline-form {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: var(--s3);
  padding: var(--s4);
  margin-bottom: var(--s5);
  border: var(--rule);
  border-radius: var(--radius);
  background: var(--card);
}

.inline-form .field { flex: 1 1 12rem; min-width: 0; }
.inline-form input[type="submit"] { flex: none; height: var(--control-h); }

.errors {
  padding: var(--s3) var(--s4);
  border-left: 3px solid var(--alert);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--alert-wash);
  color: var(--alert-deep);
  font-size: 0.9375rem;
}

.errors p { font-weight: 600; margin-bottom: var(--s1); }
.errors ul { padding-left: var(--s4); list-style: disc; }

/* --------------------------------------------------------------- Sign in */

.signin {
  max-width: 22rem;
  margin: var(--s7) auto;
  padding: var(--s5);
  background: var(--card);
  border: var(--rule);
  border-top: 3px solid var(--field);
  border-radius: var(--radius);
}

.signin h1 { font-size: 1.125rem; }
.signin-note { color: var(--dim); font-size: 0.875rem; margin-top: var(--s1); }
.signin-form { display: grid; gap: var(--s4); margin-top: var(--s5); }
.signin-form input[type="submit"] { width: 100%; padding: 0.55rem 0.75rem; }

/* ------------------------------------------------------- Boards accounts */

.account {
  padding: var(--s5);
  margin-bottom: var(--s5);
  border: var(--rule);
  border-radius: var(--radius);
  background: var(--card);
}

.account-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--s3);
  margin-bottom: var(--s4);
}

.external-id {
  color: var(--dim);
  background: var(--paper);
  border: var(--rule);
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius);
}

.account .table-scroll > table { min-width: 32rem; }

.add-member {
  margin: var(--s4) 0 0;
  padding: var(--s3) var(--s4);
  background: var(--paper);
}

.add-member .field { flex: 0 1 18rem; }

.account .empty { margin-top: var(--s4); }

.empty { color: var(--dim); font-size: 0.9375rem; }

/* ----------------------------------------------------------- Narrow view */

@media (max-width: 40rem) {
  .masthead { gap: var(--s3); padding: var(--s3) var(--s4); }
  .masthead nav { margin-left: 0; width: 100%; gap: var(--s3); }
  main { padding: var(--s4) var(--s4) var(--s6); }
  .flashes { padding: 0 var(--s4); }
  .signin { margin-top: var(--s5); }
  .account { padding: var(--s4); }
  .inline-form .field { flex-basis: 100%; }
  .inline-form input[type="submit"] { width: 100%; }
}

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