:root {
  --bg: #0a0f1a;
  --panel: #111a2b;
  --panel-2: #16223a;
  --line: #1f2d47;
  --text: #e6edf7;
  --muted: #7d8ba5;
  --accent: #38bdf8;
  --accent-2: #22d3ee;
  --ok: #4ade80;
  --err: #f87171;
}

* { box-sizing: border-box; margin: 0; }

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

button {
  font: inherit;
  border: 0;
  border-radius: 10px;
  padding: 0.6rem 1rem;
  cursor: pointer;
  background: var(--panel-2);
  color: var(--text);
  transition: background 0.15s, transform 0.08s, opacity 0.15s;
}
button:hover:not(:disabled) { background: #1e2d4a; }
button:active:not(:disabled) { transform: scale(0.98); }
button:disabled { opacity: 0.5; cursor: default; }

button.primary {
  background: linear-gradient(135deg, var(--accent), #0ea5e9);
  color: #04121f;
  font-weight: 650;
}
button.primary:hover:not(:disabled) { background: linear-gradient(135deg, var(--accent-2), var(--accent)); }
button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover { background: var(--panel-2); color: var(--text); }

input, textarea {
  font: inherit;
  width: 100%;
  background: #0d1626;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
input:focus, textarea:focus { border-color: var(--accent); }

.err { color: var(--err); font-size: 0.85rem; min-height: 1.1em; }
.fineprint { color: var(--muted); font-size: 0.8rem; }

/* ---------------- gate ---------------- */

.gate {
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at 15% 0%, rgba(56, 189, 248, 0.13), transparent 55%),
    radial-gradient(ellipse at 85% 100%, rgba(34, 211, 238, 0.09), transparent 55%);
}

.gate-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.mark {
  font-size: 2.4rem;
  color: var(--accent);
  text-align: center;
  animation: pulse 3s ease-in-out infinite;
}
.mark.small { font-size: 1.1rem; animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* Terminal wordmark, after the OpenClyde PPC client's startup banner:
   bold accent name, muted build line, block cursor. */
.logo {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--accent);
  font-weight: 700;
  display: inline-flex;
  align-items: baseline;
}
.logo::before { content: "$ "; color: var(--muted); font-weight: 400; }
.logo.big { font-size: 2rem; justify-content: center; display: flex; }
.logo-cursor { animation: blink 1s steps(2) infinite; font-weight: 400; }
.logo-sub {
  text-align: center; color: var(--muted); font-size: 0.78rem;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.gate-card h1 { text-align: center; font-size: 1.45rem; }
.sub { text-align: center; color: var(--muted); font-size: 0.9rem; }

.tabs { display: flex; gap: 0.4rem; background: #0d1626; padding: 0.25rem; border-radius: 12px; }
.tabs button { flex: 1; background: transparent; color: var(--muted); padding: 0.5rem; }
.tabs button.active { background: var(--panel-2); color: var(--text); }

#gate-form { display: flex; flex-direction: column; gap: 0.7rem; }
#gate-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.82rem; color: var(--muted); }

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

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

aside {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 0.85rem;
  gap: 0.7rem;
  min-height: 0;
}

.side-head { display: flex; align-items: center; gap: 0.5rem; padding: 0.2rem 0.3rem; }
.new-chat { width: 100%; }

.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.25rem; min-height: 0; }

.conv {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.88rem;
}
.conv:hover { background: var(--panel-2); color: var(--text); }
/* Live OpenClyde sessions (read-only view inside the chat page). */
.live-row { display: flex; align-items: center; gap: 0.45rem; padding: 0.4rem 0.6rem; border-radius: 8px;
  cursor: pointer; color: var(--muted); font-size: 0.85rem; min-width: 0; }
.live-row:hover, .live-row.active { background: var(--panel-2); color: var(--text); }
.live-row .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.live-row .dot.live { background: #22c55e; } .live-row .dot.stale { background: #eab308; }
.live-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-row .lbl small { display: block; color: var(--muted); font-size: 0.72rem; }
.live-link { font-size: 0.8rem; color: var(--accent); text-decoration: none; padding: 0.2rem 0.5rem;
  border: 1px solid var(--line); border-radius: 6px; }
.evline { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78rem; color: var(--muted);
  padding: 0.15rem 0.75rem; white-space: pre-wrap; word-break: break-word; }
.evline.tool { color: var(--accent); }
.evline.ask { color: #eab308; border: 1px solid #eab30855; border-radius: 8px; padding: 0.5rem 0.75rem; margin: 0.4rem 0; }
.evline.err { color: #f87171; }
.readonly-note { color: var(--muted); font-size: 0.8rem; padding: 0.3rem 0.75rem; }
.conv.active { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.conv .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .del { opacity: 0; padding: 0.1rem 0.35rem; border-radius: 6px; font-size: 0.9rem; }
.conv:hover .del { opacity: 0.6; }
.conv .del:hover { opacity: 1; background: #7f1d1d; }

.side-foot { border-top: 1px solid var(--line); padding-top: 0.7rem; display: flex; flex-direction: column; gap: 0.5rem; }
.who { display: flex; align-items: center; gap: 0.6rem; font-size: 0.88rem; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #0369a1);
  color: #04121f; font-weight: 700; font-size: 0.8rem;
  display: grid; place-items: center;
}
.role { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; }
.side-actions { display: flex; gap: 0.4rem; }
.side-actions button { flex: 1; font-size: 0.85rem; padding: 0.45rem; }

main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

header {
  display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap;
  padding: 0.9rem 1.2rem; border-bottom: 1px solid var(--line);
}
header h2 { font-size: 1rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-badge {
  margin-left: auto; font-size: 0.72rem; color: var(--accent);
  border: 1px solid var(--line); border-radius: 999px; padding: 0.2rem 0.7rem;
}

.meter { display: inline-flex; align-items: center; gap: 0.45rem; }
.meter-bar {
  width: 90px; height: 6px; border-radius: 999px;
  background: #0d1626; border: 1px solid var(--line); overflow: hidden; display: block;
}
.meter-fill {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.4s ease;
}
.meter-fill.hot { background: linear-gradient(90deg, #f59e0b, var(--err)); }
.meter-text {
  font-size: 0.7rem; color: var(--muted); white-space: nowrap;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.messages { flex: 1; overflow-y: auto; padding: 1.4rem; display: flex; flex-direction: column; gap: 1rem; }

.empty { margin: auto; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 0.4rem; }
.empty-mark { font-size: 2.6rem; color: var(--accent); opacity: 0.5; }

.turn { display: flex; gap: 0.75rem; max-width: 900px; width: 100%; align-self: center; animation: rise 0.2s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.turn .bubble {
  padding: 0.75rem 1rem; border-radius: 14px; line-height: 1.55;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.turn.user { justify-content: flex-end; }
.turn.user .bubble { background: linear-gradient(135deg, #0e7490, #155e75); border-bottom-right-radius: 4px; max-width: 75%; }
.turn.assistant .bubble { background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; flex: 1; }
.turn.system .bubble {
  background: transparent; border: 1px dashed var(--line);
  color: var(--muted); font-size: 0.85rem; flex: 1;
}
.turn .tag { font-size: 0.7rem; color: var(--muted); margin-bottom: 0.25rem; display: block; }

.cursor::after {
  content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; margin-left: 1px;
}
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

.composer { display: flex; gap: 0.6rem; padding: 0.9rem 1.2rem 0.3rem; align-items: flex-end; }
.composer textarea { resize: none; max-height: 40vh; overflow-y: auto; }
.composer-err { padding: 0 1.2rem 0.6rem; }

/* ---------------- projects ---------------- */

.proj-sec { display: flex; flex-direction: column; gap: 0.25rem; }
.proj-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.2rem 0.3rem; color: var(--muted);
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em;
}
button.mini { padding: 0.1rem 0.45rem; font-size: 0.9rem; border-radius: 6px; }
.proj-list { display: flex; flex-direction: column; gap: 0.2rem; max-height: 30vh; overflow-y: auto; }
.proj {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.65rem; border-radius: 10px; cursor: pointer;
  color: var(--muted); font-size: 0.85rem;
}
.proj:hover { background: var(--panel-2); color: var(--text); }
.proj .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj .pcount { font-size: 0.72rem; }

.proj-select {
  background: var(--panel-2); color: var(--text); font: inherit; font-size: 0.8rem;
  border: 1px solid var(--line); border-radius: 999px; padding: 0.25rem 0.6rem;
  max-width: 200px; outline: none;
}

.file-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.6rem; background: #0d1626; border-radius: 10px; font-size: 0.88rem; }
.file-row .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .fsize { color: var(--muted); font-size: 0.75rem; }
.file-row .del { padding: 0.1rem 0.4rem; border-radius: 6px; }
.file-row .del:hover { background: #7f1d1d; }
.pm-actions { display: flex; justify-content: space-between; gap: 0.6rem; }
button.danger:hover { background: #7f1d1d; color: var(--text); }

/* ---------------- admin ---------------- */

.modal-back { position: fixed; inset: 0; background: rgba(3, 7, 18, 0.75); display: grid; place-items: center; z-index: 50; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 1.5rem; width: min(560px, 92vw); display: flex; flex-direction: column; gap: 0.8rem;
  max-height: 85vh; overflow-y: auto;
}
.user-rows { display: flex; flex-direction: column; gap: 0.4rem; }
.user-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.6rem; background: #0d1626; border-radius: 10px; font-size: 0.88rem; }
.user-row .uname { flex: 1; }
.user-row select { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 0.35rem 0.5rem; font: inherit; }
.invite-row { display: flex; align-items: center; gap: 0.6rem; }
code { background: #0d1626; border-radius: 6px; padding: 0.25rem 0.5rem; font-size: 0.85rem; color: var(--accent); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  aside { display: none; }
}
