/* trmn — terminal-flavoured interface. Monospace everywhere, no imagery. */

:root {
  --bg:        #0a0b0c;
  --bg-panel:  #0e1011;
  --bg-inset:  #121516;
  --line:      #1e2325;
  --line-soft: #171b1d;
  --fg:        #c9cfca;
  --fg-strong: #eef2ee;
  --dim:       #6d7873;
  --dimmer:    #4a534f;
  --accent:    #d97757;
  --green:     #7bd88f;
  --amber:     #e0b072;
  --red:       #e8737f;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas,
          "DejaVu Sans Mono", "Liberation Mono", monospace;
  --row: 1.55;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--fg);
  font: 13px/var(--row) var(--mono);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  /* faint corner glow so pure black doesn't look flat */
  background-image:
    radial-gradient(1200px 600px at 50% -10%, #12171a 0%, transparent 70%),
    radial-gradient(900px 500px at 110% 110%, #131013 0%, transparent 70%);
}

/* Very light scanlines + vignette. Enough to read as a terminal, not enough to hurt. */
#crt {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  background:
    repeating-linear-gradient(to bottom,
      rgba(255,255,255,.014) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.38) 100%);
}

@media (prefers-reduced-motion: no-preference) {
  #crt::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, transparent, rgba(217,119,87,.035), transparent);
    height: 30%;
    animation: sweep 9s linear infinite;
  }
  @keyframes sweep {
    0%   { transform: translateY(-40%); opacity: 0; }
    12%  { opacity: 1; }
    88%  { opacity: 1; }
    100% { transform: translateY(320%); opacity: 0; }
  }
}

.view { height: 100%; }
[hidden] { display: none !important; }

::selection { background: rgba(217,119,87,.28); }

button, input, textarea {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
}

:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  border: 1px solid var(--line);
  background: var(--bg-inset);
  color: var(--fg);
  padding: 3px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--fg-strong); }
.btn:disabled { opacity: .45; cursor: progress; }
.btn.ghost { background: none; color: var(--dim); }
.btn.ghost:hover { color: var(--accent); }

.prompt { color: var(--accent); user-select: none; }
.badge { letter-spacing: -.02em; }

.mascot {
  margin: 0;
  font: inherit;
  line-height: 1.02;
  white-space: pre;
  letter-spacing: 0;
}

/* ─────────────────────────────── auth ─────────────────────────────── */

#auth {
  display: grid;
  place-items: center;
  padding: 20px;
  overflow: auto;
}

.auth-box {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  background: linear-gradient(#0e1112, #0b0d0e);
  padding: 26px 26px 20px;
  box-shadow: 0 0 0 1px #000, 0 24px 60px -20px rgba(0,0,0,.9);
}

.logo {
  margin: 0;
  color: var(--accent);
  font: inherit;
  line-height: 1.05;
  white-space: pre;
  text-shadow: 0 0 18px rgba(217,119,87,.35);
}

.tagline {
  color: var(--dim);
  margin: 8px 0 16px;
  letter-spacing: .04em;
}

.boot {
  margin: 0 0 16px;
  font: inherit;
  color: var(--dimmer);
  white-space: pre-wrap;
  min-height: calc(4 * 1.55em);
}
.boot .ok { color: var(--green); }

.field {
  display: grid;
  grid-template-columns: 7ch 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.field label { color: var(--dim); }
.field label::after { content: ":"; color: var(--dimmer); }
.field input {
  border: 1px solid var(--line);
  background: var(--bg-inset);
  padding: 6px 8px;
  min-width: 0;
  caret-color: var(--accent);
}
.field input:focus { border-color: var(--accent); outline: none; }
.field input::placeholder { color: var(--dimmer); }

.preview {
  margin: 12px 0 4px;
  font: inherit;
  line-height: 1.02;
  white-space: pre;
  min-height: calc(4 * 1.02em);
  color: var(--dimmer);
}

.auth-msg {
  min-height: 1.55em;
  margin: 6px 0 12px;
  color: var(--amber);
  overflow-wrap: anywhere;
}
.auth-msg.err { color: var(--red); }
.auth-msg.ok  { color: var(--green); }

.auth-actions {
  display: flex;
  gap: 8px;
}
.auth-actions .btn { flex: 1; }

.auth-note {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  color: var(--dimmer);
}
.auth-note p { margin: 0 0 6px; }

/* ─────────────────────────────── shell ─────────────────────────────── */

/* minmax(0,1fr) keeps the single column from being widened to its content's
   min-content size, which would otherwise push the whole shell past the viewport. */
#app {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: minmax(0, 1fr);
}

#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel);
  min-width: 0;
}
.brand {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.brand-sub { color: var(--dimmer); }
.spacer { flex: 1; }
.self-name {
  color: var(--fg-strong);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.net { color: var(--dimmer); white-space: nowrap; }
.net .dot { color: var(--dimmer); font-style: normal; margin-right: 5px; }
.net.online { color: var(--dim); }
.net.online .dot { color: var(--green); }
.net.sync .dot { color: var(--amber); }

#body {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 0;
  min-width: 0;
}

/* ────────────────────────────── sidebar ────────────────────────────── */

#sidebar {
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  grid-template-columns: minmax(0, 1fr);
  border-right: 1px solid var(--line);
  background: var(--bg-panel);
  min-height: 0;
}

.pane-head {
  padding: 8px 12px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .14em;
  border-bottom: 1px solid var(--line-soft);
}

#newconv {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line-soft);
}
#newconv input {
  flex: 1;
  min-width: 0;
  caret-color: var(--accent);
}
#newconv input::placeholder { color: var(--dimmer); }

.convs { overflow-y: auto; min-height: 0; }

.conv {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 12px;
  cursor: pointer;
  text-align: left;
  border-left: 2px solid transparent;
}
.conv:hover { background: var(--bg-inset); }
.conv.active {
  background: var(--bg-inset);
  border-left-color: var(--accent);
}
.conv .name {
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv.active .name { color: var(--fg-strong); }
.conv .dot { color: var(--dimmer); font-size: 9px; }
.conv .dot.on { color: var(--green); }
.conv .unread {
  color: var(--bg);
  background: var(--accent);
  padding: 0 5px;
  font-size: 11px;
}
.convs .empty { padding: 10px 12px; color: var(--dimmer); }

.newgroup {
  margin: 0;
  border: none;
  border-top: 1px solid var(--line-soft);
  border-radius: 0;
  text-align: left;
  padding: 7px 12px;
  background: none;
}

.conv-sep {
  padding: 8px 12px 3px;
  color: var(--dimmer);
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 11px;
}

.conv .gmark {
  color: var(--accent);
  letter-spacing: -.02em;
}
.conv .members { color: var(--dimmer); font-size: 11px; }
/* A group with a call running gets a live marker in the list. */
.conv .incall { color: var(--green); }

.pane-foot {
  padding: 8px 12px;
  border-top: 1px solid var(--line-soft);
  color: var(--dimmer);
}
.fp-line { overflow-wrap: anywhere; }
.fp-line b { display: block; color: var(--dim); font-weight: 400; }
.fp-line .fp-val { color: var(--dimmer); }
.suite { margin-top: 4px; }

/* ──────────────────────────────── chat ──────────────────────────────── */

#chat {
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  /* minmax(0,…) as on #app: an implicit `auto` column is sized to its content's
     min-content, which lets children grow wider than the pane and overflow. */
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
  min-width: 0;
}

/* ─────────────────────────────── call bar ─────────────────────────────── */

.callbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
  background: #12100f;
  box-shadow: inset 0 0 0 1px rgba(217,119,87,.16);
}
.callbar .state { color: var(--accent); white-space: nowrap; }
.callbar .who { color: var(--fg-strong); white-space: nowrap; }
.callbar .meta { color: var(--dimmer); white-space: nowrap; }
.callbar .clock { color: var(--fg); font-variant-numeric: tabular-nums; }
.callbar .vu { color: var(--green); white-space: pre; letter-spacing: -.5px; }
.callbar .vu.out { color: var(--amber); }
.callbar .vu.off { color: var(--dimmer); }
.callbar .spacer { flex: 1; min-width: 8px; }
.callbar .btn { padding: 2px 9px; }
.callbar.ringing { background: #14110d; }

@media (prefers-reduced-motion: no-preference) {
  .callbar.ringing .state { animation: blink 1.05s steps(2, start) infinite; }
  @keyframes blink { to { opacity: .35; } }
}

.chat-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel);
  min-height: 0;
}
.chat-head .who { min-width: 0; }
.chat-head .peer {
  color: var(--fg-strong);
  font-size: 14px;
}
.chat-head .meta { color: var(--dimmer); overflow-wrap: anywhere; }
.chat-head .meta .lock { color: var(--green); }
.chat-head .meta .off { color: var(--dimmer); }
.chat-head .meta .on { color: var(--green); }

.log {
  overflow-y: auto;
  padding: 12px 14px 16px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.log::-webkit-scrollbar { width: 9px; }
.log::-webkit-scrollbar-thumb { background: var(--line); }

/* Fixed columns so every row's icon and name line up like real terminal output. */
.line {
  display: grid;
  grid-template-columns: 9ch 18ch 1fr;
  gap: 8px;
  padding: 1px 0;
  overflow-wrap: anywhere;
}
.line .ts { color: var(--dimmer); user-select: none; }
.line .who { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line .who .nm { color: var(--dim); }
.line .text { white-space: pre-wrap; color: var(--fg); }
.line.mine .text { color: var(--fg-strong); }
.line.bad .text { color: var(--red); }
.line:hover { background: rgba(255,255,255,.018); }

.sys {
  color: var(--dimmer);
  padding: 3px 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.sys.warn { color: var(--amber); }
.sys.err { color: var(--red); }
.sys.hi { color: var(--fg); }
.sys .k { color: var(--accent); }
.sys .rule { color: var(--line); }

.more {
  display: block;
  margin: 0 auto 10px;
  color: var(--dim);
}

/* ───────────────────────────── attachments ───────────────────────────── */

.attach {
  display: inline-block;
  max-width: min(420px, 100%);
  border: 1px solid var(--line);
  background: var(--bg-inset);
  padding: 5px 8px;
  margin: 2px 0;
}
.attach .kind { color: var(--accent); }
.attach .name { color: var(--fg-strong); overflow-wrap: anywhere; }
.attach .meta { color: var(--dimmer); }
.attach .row { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.attach .btn { padding: 1px 8px; }
.attach.bad { border-color: var(--red); }
.attach.bad .name { color: var(--red); }

.attach .shot {
  display: block;
  margin-top: 6px;
  max-width: 100%;
  max-height: 320px;
  border: 1px solid var(--line-soft);
  background: #000;
  cursor: zoom-in;
  image-rendering: auto;
}
.attach .placeholder {
  margin-top: 6px;
  padding: 14px 10px;
  border: 1px dashed var(--line);
  color: var(--dimmer);
  text-align: center;
}

/* Full-size viewer */
#viewer {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  gap: 10px;
  background: rgba(4,5,6,.94);
  padding: 24px;
}
#viewer img {
  max-width: 100%;
  max-height: calc(100% - 3em);
  border: 1px solid var(--line);
}
#viewer .bar { color: var(--dim); display: flex; gap: 12px; align-items: center; }

/* Drag-and-drop target */
#chat.dropping::after {
  content: "release to attach";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(217,119,87,.10);
  border: 1px dashed var(--accent);
  color: var(--accent);
  pointer-events: none;
  z-index: 30;
}
#chat { position: relative; }

.empty-chat {
  display: grid;
  place-content: center;
  gap: 10px;
  height: 100%;
  color: var(--dimmer);
  text-align: center;
}
.empty-chat pre { margin: 0; font: inherit; line-height: 1.02; color: var(--accent); opacity: .8; }

.typing {
  padding: 0 14px;
  height: 1.7em;
  color: var(--dimmer);
}

#composer {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-panel);
}
#composer .prompt { padding-top: 2px; }
#input {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 9em;
  padding: 2px 0;
  caret-color: var(--accent);
  overflow-y: auto;
}
#input::placeholder { color: var(--dimmer); }
#input:focus { outline: none; }
.btn.send { align-self: flex-end; }

/* ───────────────────────────── responsive ───────────────────────────── */

.only-narrow { display: none; }

@media (max-width: 720px) {
  #body { grid-template-columns: 1fr; }
  #sidebar {
    position: absolute;
    z-index: 20;
    top: 37px;
    bottom: 0;
    left: 0;
    width: min(280px, 84vw);
    border-right: 1px solid var(--line);
    box-shadow: 24px 0 60px -20px #000;
    transform: translateX(-101%);
    transition: transform .16s ease-out;
  }
  #sidebar.open { transform: none; }
  .only-narrow { display: inline-block; }
  .brand-sub { display: none; }
  /* Keep the connection dot, drop the word, so the bar always fits. */
  .net .net-label { display: none; }
  .net .dot { margin-right: 0; }
  #topbar { gap: 8px; }
  .line { grid-template-columns: 14ch 1fr; }
  .line .ts { display: none; }
  .btn.send { display: none; }
}
