/* jk-chat — one stylesheet, no external assets. Light and dark both first-class. */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #eef0f4;
  --sidebar: #1d2230;
  --sidebar-text: #c7cddb;
  --sidebar-muted: #7f8aa3;
  --sidebar-active: #2c3446;
  --text: #171a21;
  --muted: #6b7385;
  --border: #e0e3ea;
  --accent: #4f6bed;
  --accent-ink: #ffffff;
  --bubble: #ffffff;
  --bubble-self: #4f6bed;
  --bubble-self-ink: #ffffff;
  --ok: #22a06b;
  --warn: #c8811a;
  --danger: #d34c4c;
  --shadow: 0 1px 2px rgba(16, 20, 32, .06), 0 8px 24px rgba(16, 20, 32, .06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1219;
    --panel: #161b25;
    --panel-2: #1c222e;
    --sidebar: #0c0f16;
    --sidebar-text: #b9c1d3;
    --sidebar-muted: #6d7688;
    --sidebar-active: #1e2534;
    --text: #e8ebf2;
    --muted: #8d96a9;
    --border: #262d3a;
    --accent: #6b83ff;
    --bubble: #1c222e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu,
        "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

/* ------------------------------------------------------------ app shell */

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100dvh;
}

/* ------------------------------------------------------------ sidebar */

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 0 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 16px 14px;
  font-weight: 650;
  letter-spacing: -.01em;
  color: #fff;
}
.brand-mark { font-size: 19px; }

.rooms-head, .people-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
}

.rooms {
  overflow-y: auto;
  padding: 0 8px;
  flex: 0 1 auto;
  max-height: 40vh;
}

.room {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--sidebar-text);
  text-align: left;
}
.room:hover { background: var(--sidebar-active); }
.room.is-active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.room-hash { color: var(--sidebar-muted); }
.room-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.room-count {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--sidebar-muted);
  background: rgba(255, 255, 255, .07);
  border-radius: 999px;
  padding: 1px 7px;
}
.room-count.full { color: #ffb4b4; background: rgba(211, 76, 76, .22); }

.people {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 16px 8px;
  font-size: 13px;
}
.person {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 0;
  color: var(--sidebar-text);
}
.person .swatch {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
}
.person span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.me {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-top: 1px solid rgba(255, 255, 255, .07);
  background: rgba(0, 0, 0, .18);
}
.me-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 650;
  font-size: 13px;
}
.me-text { min-width: 0; flex: 1; }
.me-nick {
  color: #fff;
  font-weight: 600;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.me-sub { font-size: 11.5px; color: var(--sidebar-muted); }

.icon-btn {
  border: 0;
  background: transparent;
  color: inherit;
  opacity: .75;
  border-radius: 8px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  font-size: 16px;
  line-height: 1;
}
.icon-btn:hover { opacity: 1; background: rgba(255, 255, 255, .1); }

/* ------------------------------------------------------------ main */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  height: 58px;
  flex: none;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar .icon-btn { color: var(--text); }

.room-head { flex: 1; min-width: 0; }

.room-title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-sub {
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Secret mode switch — deliberately loud when armed. */
.secret-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 550;
}
.secret-toggle:hover { border-color: var(--accent); color: var(--text); }
.secret-toggle.is-on {
  border-color: var(--ok);
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 12%, transparent);
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}
.status[data-state="online"] .dot { background: var(--ok); }
.status[data-state="connecting"] .dot { background: var(--warn); animation: pulse 1.2s infinite; }
.status[data-state="offline"] .dot { background: var(--danger); }

@keyframes pulse { 50% { opacity: .3; } }

/* ------------------------------------------------------------ messages */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 18px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.day {
  align-self: center;
  margin: 14px 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--panel-2);
  border-radius: 999px;
  padding: 4px 12px;
}

.sys {
  align-self: center;
  font-size: 12px;
  color: var(--muted);
  padding: 3px 0;
}

.row {
  display: flex;
  gap: 9px;
  max-width: min(720px, 92%);
  margin-top: 10px;
}
.row.grouped { margin-top: 2px; }
.row.self { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 12px;
  font-weight: 650;
}
.row.grouped .avatar { visibility: hidden; height: 0; }

.stack { min-width: 0; }

.meta {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-bottom: 3px;
  font-size: 12px;
}
.row.self .meta { flex-direction: row-reverse; }
.row.grouped .meta { display: none; }

.who { font-weight: 650; font-size: 13px; }
.when { color: var(--muted); font-variant-numeric: tabular-nums; }

.badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .03em;
  color: var(--ok);
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0 5px;
  opacity: .85;
}

.bubble {
  background: var(--bubble);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-top-left-radius: 5px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.row.self .bubble {
  background: var(--bubble-self);
  border-color: transparent;
  color: var(--bubble-self-ink);
  border-top-left-radius: var(--radius);
  border-top-right-radius: 5px;
}
.bubble a { color: inherit; text-underline-offset: 2px; }

/* Encrypted traffic: locked until the right passphrase is set. */
.bubble.locked {
  background: repeating-linear-gradient(
    -45deg, var(--panel-2), var(--panel-2) 8px, transparent 8px, transparent 16px
  );
  border-style: dashed;
  box-shadow: none;
}
.row.self .bubble.locked { color: var(--muted); }
.lock-note { font-size: 12.5px; color: var(--muted); font-style: italic; }
.bubble.decrypted { border-color: var(--ok); }
.lock-tag { margin-right: 6px; opacity: .85; }

.typing {
  height: 18px;
  padding: 0 20px 2px;
  font-size: 12px;
  color: var(--muted);
  flex: none;
}

/* ------------------------------------------------------------ composer */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 18px 16px;
  flex: none;
  background: var(--panel);
  border-top: 1px solid var(--border);
  position: relative;
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 160px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  outline: 0;
}
.composer textarea:focus { border-color: var(--accent); }
.composer.secret textarea { border-color: var(--ok); }
.composer.secret button { background: var(--ok); }

.counter {
  position: absolute;
  right: 74px;
  bottom: 22px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.counter.over { color: var(--danger); font-weight: 600; }

.composer button {
  flex: none;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
}
.composer button:disabled { opacity: .4; cursor: default; }

/* ------------------------------------------------------------ gate & modals */

.gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(8px);
  overflow-y: auto;
}

.gate-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 26px 24px 22px;
  text-align: center;
}
.gate-mark { font-size: 30px; }
.gate-card h2 { margin: 8px 0 4px; font-size: 20px; letter-spacing: -.015em; }
.gate-lead { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  margin-bottom: 18px;
  background: var(--panel-2);
  border-radius: 11px;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 7px 4px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 550;
}
.tab.is-active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

.pane { display: none; text-align: left; }
.pane.is-active { display: block; }

.pane label {
  display: block;
  margin: 12px 0 5px;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
}
.pane label .opt { font-weight: 400; text-transform: none; opacity: .8; }

.pane input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  outline: 0;
}
.pane input:focus { border-color: var(--accent); }

/* Public / private choice in the room dialog. */
.segmented {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--panel-2);
  border-radius: 11px;
}
.segmented label { flex: 1; margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  padding: 8px 4px;
  text-align: center;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
}
.segmented input:checked + span {
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

.hint { margin: 12px 0 0; font-size: 12px; line-height: 1.55; color: var(--muted); }
.field-note { min-height: 15px; font-size: 11.5px; margin-top: 4px; }
.field-note.ok { color: var(--ok); }
.field-note.bad { color: var(--danger); }

.gate-error {
  margin-top: 12px;
  padding: 8px 11px;
  border-radius: 9px;
  font-size: 12.5px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.primary, .ghost, .danger {
  width: 100%;
  margin-top: 14px;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-weight: 600;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.primary:disabled { opacity: .55; cursor: default; }

.code {
  margin: 6px 0 2px;
  padding: 14px;
  border-radius: 11px;
  background: var(--panel-2);
  border: 1px dashed var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 19px;
  letter-spacing: .06em;
  word-break: break-all;
}

/* ------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(440px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: 11px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  box-shadow: var(--shadow);
}

/* ------------------------------------------------------------ narrow */

.only-narrow { display: none; }
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .45); }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .only-narrow { display: grid; }
  .sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    width: 268px;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .app.nav-open .sidebar { transform: none; }
  .rooms { max-height: 46vh; }
  .row { max-width: 96%; }
  .counter { right: 70px; }
  .secret-label { display: none; }
  .secret-toggle { padding: 6px 9px; }
  .topbar { gap: 8px; padding: 0 12px; }
}

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