/*
 * CellTree operator console.
 *
 * Dark by default. This is a tool people sit in front of for hours — a campaign
 * office at night, a ward lead's laptop the evening before a rally — and a page
 * that glows white in a dim room is a page nobody wants to keep open. Light is
 * available for anyone who prefers it, or for printing a roll-up.
 *
 * Neutrals are biased green rather than pure grey, so they read as chosen
 * against the accent instead of inherited from a reset.
 */

:root {
  color-scheme: dark;

  --ground:  #0F1613;
  --surface: #161F1A;
  --raised:  #1D2822;
  --line:    #2B3831;
  --line-soft: #222D27;

  --ink:       #E6EDE8;
  --ink-soft:  #A5B5AC;
  --ink-faint: #75857C;

  --green:      #5FB98D;
  --green-deep: #8FD3B0;
  --green-wash: #162C22;

  --gold: #D9AE55;
  --red:  #E08262;
  --blue: #7FA9CC;

  --gold-wash: #2E2410;
  --red-wash:  #2E1C15;

  --display: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --body: ui-sans-serif, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-mono, ui-monospace, 'Cascadia Code', Consolas, 'Liberation Mono', monospace;

  --rail: 15rem;
}

:root[data-theme='light'] {
  color-scheme: light;

  --ground:  #F2F4F1;
  --surface: #FFFFFF;
  --raised:  #F7F9F6;
  --line:    #D7DED8;
  --line-soft: #E4E9E4;

  --ink:       #16211C;
  --ink-soft:  #48584F;
  --ink-faint: #6D7D74;

  --green:      #2E7D5B;
  --green-deep: #1F5C42;
  --green-wash: #E6F0EA;

  --gold: #A9781C;
  --red:  #A84524;
  --blue: #3E6588;

  --gold-wash: #F7EFDC;
  --red-wash:  #F7E8E2;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------------------
   Shell: a fixed left rail and a scrolling main column.
   Only the content scrolls, so the navigation never walks off the top of the
   screen on a long settings page.
   --------------------------------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }

.rail {
  width: var(--rail);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 1.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0 0.6rem;
}

.brand h1 {
  font-family: var(--display);
  font-size: 1.3rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--green-deep);
}

.tabs { display: flex; flex-direction: column; gap: 0.15rem; }

.tabs button {
  appearance: none;
  background: none;
  border: none;
  border-radius: 7px;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 550;
  text-align: left;
  padding: 0.6rem 0.7rem;
  min-height: 2.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.tabs button:hover { background: var(--raised); color: var(--ink); }

.tabs button.active {
  background: var(--green-wash);
  color: var(--green-deep);
}

.tabs button::before {
  content: '';
  width: 3px;
  height: 1rem;
  border-radius: 2px;
  background: transparent;
  flex: none;
}

.tabs button.active::before { background: var(--green); }

.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 0.5rem; }

.session {
  font-size: 0.8rem;
  color: var(--ink-faint);
  padding: 0 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.session button, .theme-toggle {
  appearance: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.82rem;
  padding: 0.45rem 0.6rem;
  min-height: 2.25rem;
  cursor: pointer;
  text-align: left;
}

.session button:hover, .theme-toggle:hover { border-color: var(--green); color: var(--ink); }

main { flex: 1; min-width: 0; padding: 2rem 2.25rem 4rem; }

/* --- panels: the long page, split ----------------------------------------- */

.subtabs {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin: 0 0 1.5rem;
  padding-bottom: 0;
}

.subtabs button {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-faint);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.55rem 0.85rem;
  min-height: 2.5rem;
  cursor: pointer;
  margin-bottom: -1px;
}

.subtabs button:hover { color: var(--ink); }
.subtabs button.active { color: var(--green-deep); border-bottom-color: var(--green); }

.panel[hidden] { display: none; }

/* --- typography ----------------------------------------------------------- */

h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.65rem;
  letter-spacing: -0.01em;
  margin: 0 0 0.3rem;
  text-wrap: balance;
}

h3 {
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--green-deep);
  margin: 0 0 0.5rem;
}

/* A sub-tab shows one h3 group, so its heading is the tab label already. */
.panel > h3:first-child { display: none; }

h4 {
  font-size: 0.88rem;
  font-weight: 650;
  margin: 1.5rem 0 0.3rem;
  color: var(--ink);
}

.muted { color: var(--ink-soft); font-size: 0.88rem; max-width: 62ch; }

label {
  display: block;
  margin: 0.9rem 0 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}

input, select, textarea {
  width: 100%;
  max-width: 32rem;
  min-height: 2.5rem;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.5rem 0.7rem;
  color: var(--ink);
  font: inherit;
}

textarea { resize: vertical; min-height: 5rem; }

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--green);
  outline-offset: 1px;
  border-color: transparent;
}

input::placeholder, textarea::placeholder { color: var(--ink-faint); }

/* --- buttons -------------------------------------------------------------- */

button.primary, .row button, #board-send, #save-payout {
  appearance: none;
  border-radius: 7px;
  font: inherit;
  font-weight: 600;
  min-height: 2.5rem;
  padding: 0.5rem 1rem;
  cursor: pointer;
}

button.primary {
  /* Block, so it sits under the field it submits rather than beside it. */
  display: block;
  background: var(--green);
  border: 1px solid var(--green);
  color: var(--ground);
  margin-top: 1.1rem;
}

button.primary:hover { background: var(--green-deep); border-color: var(--green-deep); }

.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }

.row button, .row-item button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  border-radius: 7px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 2.25rem;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
}

.row button:hover, .row-item button:hover { border-color: var(--green); color: var(--ink); }
.row button.primary { color: var(--ground); }

/* --- messages ------------------------------------------------------------- */

.msg { margin-top: 0.9rem; min-height: 1.2rem; font-size: 0.88rem; max-width: 62ch; }
.msg.error { color: var(--red); }
.msg.ok { color: var(--green); }

/* --- tiles ---------------------------------------------------------------- */

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.6rem;
  margin: 1rem 0;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.tile .k {
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.tile .v { font-size: 1.05rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* --- cell grid ------------------------------------------------------------ */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.6rem;
  margin: 1rem 0;
}

.slot {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem 0.85rem;
  min-height: 4.25rem;
}

.slot .name { font-weight: 620; font-size: 0.92rem; }
.slot .tag { font-size: 0.75rem; color: var(--ink-faint); }
.slot.anonymous .name { color: var(--ink-soft); font-style: italic; }
.slot.pending .tag { color: var(--gold); }
.slot.ghost { opacity: 0.5; }
.slot.ghost .tag { color: var(--ink-faint); }
.slot.lead { border-color: var(--green); }

/* --- lists ---------------------------------------------------------------- */

.list { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.45rem; }

.row-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.9rem;
}

.row-item span { min-width: 0; overflow-wrap: anywhere; }
.row-item.withheld { opacity: 0.6; border-style: dashed; }

/* --- sign in -------------------------------------------------------------- */

.signin-wrap { display: grid; place-items: center; min-height: 100vh; padding: 2rem; }

/*
 * An explicit display rule beats the browser's default `[hidden] {display:none}`,
 * so anything given a display value needs its own hidden case. Without these the
 * sign-in card stayed on the page behind the console after signing in.
 */
.signin-wrap[hidden], .shell[hidden] { display: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 26rem;
}

.card h2 { margin-bottom: 0.5rem; }

/* --- narrow screens ------------------------------------------------------- */

@media (max-width: 55rem) {
  .shell { flex-direction: column; }

  .rail {
    width: auto;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    overflow-x: auto;
    padding: 0.6rem 0.75rem;
  }

  .brand { padding: 0; }
  .brand h1 { font-size: 1.1rem; }
  .tabs { flex-direction: row; gap: 0.25rem; }
  .tabs button::before { display: none; }
  .rail-foot { margin-top: 0; margin-left: auto; }
  .session { flex-direction: row; align-items: center; padding: 0; }

  main { padding: 1.25rem 1rem 3rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
