/* ============================================================
   TOKENS
   ============================================================ */
:root {
  --paper: #EEEDE6;
  --paper-raised: #FAF9F5;
  --ink: #1B2430;
  --ink-soft: #4A5364;
  --ink-faint: #8A93A3;
  --rule: #D8D5C8;
  --rule-strong: #C4C0AF;
  --rail: #1B2430;
  --rail-text: #C7CCD6;
  --rail-text-dim: #7C879A;
  --rail-active: #2A3444;
  --accent: #0F6B5C;
  --accent-ink: #0B5347;
  --accent-tint: #E1EDE9;
  --amber: #A5680F;
  --amber-tint: #F6EBD6;
  --red: #A5382D;
  --red-tint: #F5E3E0;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --radius: 5px;
  --radius-lg: 10px;
  color-scheme: light;
}
:root:not([data-theme="light"]) {
  @media (prefers-color-scheme: dark) {
    --paper: #14181F;
    --paper-raised: #1B212B;
    --ink: #E8E6DD;
    --ink-soft: #ABB3C2;
    --ink-faint: #6C7484;
    --rule: #2B3240;
    --rule-strong: #3A4252;
    --rail: #0E1218;
    --rail-text: #C7CCD6;
    --rail-text-dim: #6C7688;
    --rail-active: #1E2530;
    --accent: #3FAE94;
    --accent-ink: #7FCBB6;
    --accent-tint: #16302A;
    --amber: #D9A24B;
    --amber-tint: #332913;
    --red: #D9756A;
    --red-tint: #331B18;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #14181F;
  --paper-raised: #1B212B;
  --ink: #E8E6DD;
  --ink-soft: #ABB3C2;
  --ink-faint: #6C7484;
  --rule: #2B3240;
  --rule-strong: #3A4252;
  --rail: #0E1218;
  --rail-text: #C7CCD6;
  --rail-text-dim: #6C7688;
  --rail-active: #1E2530;
  --accent: #3FAE94;
  --accent-ink: #7FCBB6;
  --accent-tint: #16302A;
  --amber: #D9A24B;
  --amber-tint: #332913;
  --red: #D9756A;
  --red-tint: #331B18;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  display: flex;
  min-height: 100%;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ============================================================
   RAIL (nav)
   ============================================================ */
#rail {
  width: 15rem;
  flex-shrink: 0;
  background: var(--rail);
  color: var(--rail-text);
  min-height: 100vh;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.rail-brand {
  padding: 1.5rem 1.25rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.rail-brand .mark { font-size: 1.4rem; line-height: 1; }
.rail-brand h1 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: #fff;
  margin: 0.5rem 0 0.15rem;
  letter-spacing: 0.01em;
}
.rail-brand p { margin: 0; font-size: 0.72rem; color: var(--rail-text-dim); letter-spacing: 0.03em; }
.rail-nav { flex: 1; padding: 1rem 0.75rem; }
.rail-link {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.55rem 0.75rem; border-radius: var(--radius);
  font-size: 0.88rem; font-weight: 500; cursor: pointer;
  color: var(--rail-text-dim); margin-bottom: 0.15rem;
  transition: background .12s, color .12s;
}
.rail-link svg { width: 1.05rem; height: 1.05rem; flex-shrink: 0; opacity: 0.85; }
.rail-link:hover { background: rgba(255,255,255,0.05); color: var(--rail-text); }
.rail-link.active { background: var(--rail-active); color: #fff; }
.rail-link .count {
  margin-left: auto; font-family: var(--font-mono); font-size: 0.68rem;
  background: rgba(255,255,255,0.09); padding: 0.1rem 0.4rem; border-radius: 999px;
  color: var(--rail-text-dim);
}
.rail-link.active .count { background: rgba(255,255,255,0.15); color: #fff; }
.rail-foot { padding: 1rem 1.25rem 1.25rem; border-top: 1px solid rgba(255,255,255,0.08); }
.rail-foot .lbl { font-size: 0.7rem; color: var(--rail-text-dim); letter-spacing: 0.04em; margin-bottom: 0.5rem; }
.rail-foot .num { font-family: var(--font-mono); font-size: 0.82rem; color: #fff; margin-bottom: 0.4rem; }
.rail-track { height: 0.3rem; background: rgba(255,255,255,0.1); border-radius: 999px; overflow: hidden; }
.rail-bar { height: 100%; background: var(--accent); width: 0%; transition: width .4s ease; }

/* mobile rail toggle */
#rail-toggle {
  display: none; position: fixed; top: calc(0.75rem + env(safe-area-inset-top,0px)); left: 0.75rem; z-index: 30;
  background: var(--rail); color: #fff; border: none; border-radius: var(--radius);
  width: 2.25rem; height: 2.25rem; align-items: center; justify-content: center; cursor: pointer;
}

/* ============================================================
   MAIN
   ============================================================ */
main { margin-left: 15rem; flex: 1; min-height: 100vh; min-width: 0; }
#page { padding: 2.25rem 2.5rem 4rem; max-width: 76rem; margin: 0 auto; }
@media (max-width: 900px) {
  #rail { transform: translateX(-100%); transition: transform .2s ease; }
  #rail.open { transform: translateX(0); }
  #rail-toggle { display: flex; }
  main { margin-left: 0; }
  #page { padding: 4.5rem 1.1rem 3rem; }
}
.hd { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.6rem; }
.hd h1 { font-family: var(--font-display); font-size: 1.9rem; font-weight: 600; margin: 0; color: var(--ink); letter-spacing: -0.01em; }
.hd p.sub { margin: 0.3rem 0 0; color: var(--ink-soft); font-size: 0.92rem; }

/* ============================================================
   COMPONENTS
   ============================================================ */
.panel { background: var(--paper-raised); border: 1px solid var(--rule); border-radius: var(--radius-lg); }
.hairline-top { border-top: 1px solid var(--rule); }
.hairline-bottom { border-bottom: 1px solid var(--rule); }

.stat { padding: 1rem 1.1rem; }
.stat .l { font-size: 0.76rem; color: var(--ink-faint); margin: 0 0 0.3rem; text-transform: none; }
.stat .v { font-family: var(--font-display); font-size: 1.7rem; font-weight: 600; margin: 0; }

.seg { display: inline-flex; gap: 0.2rem; background: var(--paper); border: 1px solid var(--rule); padding: 0.2rem; border-radius: 999px; }
.seg button {
  border: none; background: transparent; padding: 0.4rem 0.9rem; border-radius: 999px;
  font-size: 0.82rem; font-weight: 500; color: var(--ink-soft); cursor: pointer; font-family: var(--font-body);
}
.seg button.active { background: var(--ink); color: var(--paper-raised); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.42rem 0.85rem; border-radius: var(--radius); font-size: 0.84rem; font-weight: 500;
  cursor: pointer; border: 1px solid transparent; font-family: var(--font-body);
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn-primary { background: var(--ink); color: var(--paper-raised); border-color: var(--ink); }
.btn-primary:hover { opacity: 0.85; }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-accent:hover { background: var(--accent-ink); }
.btn-outline { background: var(--paper-raised); color: var(--ink); border-color: var(--rule-strong); }
.btn-outline:hover { background: var(--paper); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: transparent; }
.btn-ghost:hover { background: var(--paper); color: var(--ink); }
.btn-danger { background: transparent; color: var(--red); border-color: var(--rule-strong); }
.btn-danger:hover { background: var(--red-tint); border-color: var(--red); }
.btn-sm { padding: 0.28rem 0.6rem; font-size: 0.76rem; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.field { width: 100%; padding: 0.5rem 0.7rem; border: 1px solid var(--rule-strong); border-radius: var(--radius);
  font-size: 0.85rem; font-family: var(--font-body); background: var(--paper-raised); color: var(--ink); outline: none; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
label.flabel { font-size: 0.76rem; font-weight: 600; color: var(--ink-soft); display: block; margin-bottom: 0.3rem; }

table { width: 100%; border-collapse: collapse; }
th.th { text-align: left; padding: 0.6rem 0.9rem; font-size: 0.68rem; font-weight: 600; color: var(--ink-faint);
  letter-spacing: 0.04em; border-bottom: 1px solid var(--rule); background: var(--paper); }
td.td { padding: 0.65rem 0.9rem; font-size: 0.85rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
tbody tr:last-child td.td { border-bottom: none; }
tbody tr:hover td.td { background: var(--paper); }
.twrap { overflow-x: auto; }

.pill { display: inline-flex; align-items: center; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.72rem; font-weight: 500; border: 1px solid transparent; }
.pill-daily { background: #E3ECF7; color: #2B4F82; }
.pill-weekly { background: #EDE6F7; color: #5B3E8C; }
.pill-fortnightly { background: #E4E9F8; color: #33438C; }
.pill-monthly { background: var(--amber-tint); color: var(--amber); }
.pill-bi-monthly { background: #F7E9DA; color: #8C4E1F; }
.pill-quarterly { background: var(--red-tint); color: var(--red); }
.pill-annual { background: var(--paper); color: var(--ink-faint); border-color: var(--rule); }

.status { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.12rem 0.55rem; border-radius: 999px; font-size: 0.72rem; font-weight: 500; }
.status-y { background: var(--accent-tint); color: var(--accent-ink); }
.status-w { background: var(--amber-tint); color: var(--amber); }
.status-n { background: var(--red-tint); color: var(--red); }
.status-p { background: var(--paper); color: var(--ink-faint); border: 1px solid var(--rule); }
.status-o { background: var(--red-tint); color: var(--red); }

.banner { border-radius: var(--radius); padding: 0.65rem 1rem; font-size: 0.85rem; display: flex; align-items: center; gap: 0.6rem; justify-content: space-between; flex-wrap: wrap; }
.banner-accent { background: var(--accent-tint); color: var(--accent-ink); border: 1px solid var(--accent); }
.banner-amber { background: var(--amber-tint); color: var(--amber); border: 1px solid #E3C486; }

.modal-overlay { position: fixed; inset: 0; background: rgba(15,18,24,0.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal { background: var(--paper-raised); border-radius: var(--radius-lg); box-shadow: 0 24px 64px rgba(0,0,0,0.35); width: 100%; max-width: 30rem; max-height: 88vh; overflow-y: auto; border: 1px solid var(--rule); }
.modal-wide { max-width: 40rem; }
.modal-hd { padding: 1rem 1.25rem; border-bottom: 1px solid var(--rule); display: flex; align-items: center; justify-content: space-between; }
.modal-hd h3 { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; margin: 0; }
.modal-ft { padding: 0.9rem 1.25rem; border-top: 1px solid var(--rule); display: flex; justify-content: flex-end; gap: 0.5rem; }

.icon-btn { background: none; border: none; cursor: pointer; padding: 0.2rem; display: inline-flex; color: var(--ink-faint); }
.icon-btn:hover { color: var(--ink); }

.page-enter { animation: rise .18s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.empty { text-align: center; padding: 3rem 1rem; color: var(--ink-faint); font-size: 0.88rem; }
.muted { color: var(--ink-faint); }
.mono { font-family: var(--font-mono); }
::selection { background: var(--accent-tint); }

/* ============================================================
   ADDED: name-gate, connection status, avatars
   ============================================================ */
#gate {
  position: fixed; inset: 0; z-index: 100; background: var(--paper);
  display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.gate-card { width: 100%; max-width: 22rem; background: var(--paper-raised); border: 1px solid var(--rule); border-radius: var(--radius-lg); padding: 1.75rem; }
.gate-card .mark { font-size: 1.8rem; margin-bottom: 0.5rem; }
.gate-card h2 { font-family: var(--font-display); font-size: 1.35rem; font-weight: 600; margin: 0 0 0.3rem; }
.gate-card p.sub { margin: 0 0 1.25rem; color: var(--ink-soft); font-size: 0.85rem; }
.gate-row { display: flex; gap: 0.5rem; margin-bottom: 0.9rem; }
.gate-role { flex: 1; padding: 0.55rem; text-align: center; border: 1px solid var(--rule-strong); border-radius: var(--radius); font-size: 0.82rem; cursor: pointer; background: var(--paper-raised); }
.gate-role.active { background: var(--ink); color: var(--paper-raised); border-color: var(--ink); }

.who-chip { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; color: var(--rail-text-dim); cursor: pointer; }
.who-avatar { width: 1.4rem; height: 1.4rem; border-radius: 999px; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 0.68rem; font-weight: 600; flex-shrink: 0; }

.conn-dot { width: 0.45rem; height: 0.45rem; border-radius: 999px; display: inline-block; margin-right: 0.35rem; }
.conn-live .conn-dot { background: #3FAE94; }
.conn-off .conn-dot { background: var(--red); }
.conn-wrap { display: flex; align-items: center; font-size: 0.7rem; color: var(--rail-text-dim); padding: 0 1.25rem 0.6rem; }

.entry-by { font-size: 0.68rem; color: var(--ink-faint); margin-top: 0.1rem; }
