:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --fg: #1b1b1f;
  --muted: #6b6b75;
  --line: #e2e2e8;
  --accent: #2563eb;
  --warn: #b45309;
  --ok: #15803d;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111114;
    --panel: #1b1b21;
    --fg: #ececf1;
    --muted: #9b9ba6;
    --line: #2d2d35;
    --accent: #60a5fa;
    --warn: #fbbf24;
    --ok: #4ade80;
  }
}
:root[data-theme="dark"] {
  --bg: #111114;
  --panel: #1b1b21;
  --fg: #ececf1;
  --muted: #9b9ba6;
  --line: #2d2d35;
  --accent: #60a5fa;
  --warn: #fbbf24;
  --ok: #4ade80;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
button, textarea, input {
  font: inherit;
  color: inherit;
}
button {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.icon { border: none; background: none; padding: 0 0.4rem; color: var(--muted); }

.app {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
}
.brand { font-weight: 700; font-size: 1.2rem; }
.sessions { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.75rem; }
.group-title { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.25rem; }
.session { display: flex; align-items: center; border-radius: 8px; }
.session.active { background: var(--bg); }
.session-open {
  flex: 1;
  text-align: left;
  border: none;
  background: none;
  padding: 0.35rem 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.side-nav { display: flex; gap: 0.4rem; }
.side-nav button { flex: 1; }
.side-nav button.active { border-color: var(--accent); color: var(--accent); }

main {
  flex: 1;
  min-width: 0;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
}
.view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.view[hidden] { display: none; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.75rem;
}
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.75rem; min-height: 200px; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.6rem 0.8rem; max-width: 780px; }
.msg.user { align-self: flex-end; }
.msg .who { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.15rem; }
.msg .text { white-space: pre-wrap; word-break: break-word; }
.composer { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.composer textarea {
  flex: 1;
  resize: vertical;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 0.6rem;
}

.cards { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); margin-top: 0.75rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem; display: flex; flex-direction: column; gap: 0.5rem; }
.card header { display: flex; justify-content: space-between; gap: 0.5rem; }
.size { color: var(--muted); white-space: nowrap; }
.badges { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.badge { border: 1px solid var(--line); border-radius: 999px; padding: 0 0.5rem; font-size: 0.8rem; color: var(--muted); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.actions { display: flex; gap: 0.4rem; align-items: center; }
.note { color: var(--muted); font-size: 0.9rem; margin: 0; }
.muted { color: var(--muted); }
.status { min-height: 1.4rem; font-size: 0.9rem; color: var(--muted); margin-bottom: 0.5rem; }
.status.error { color: var(--warn); }
.narrow { width: 8rem; padding: 0.4rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }

.bar { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; }
.bar .status { flex: 1; }
.grow { flex: 1; min-width: 12rem; padding: 0.45rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.code {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.6rem;
  overflow-x: auto;
  white-space: pre;
  font-size: 0.85rem;
}
code { font-family: ui-monospace, Menlo, Consolas, monospace; }
.keytext { word-break: break-all; font-family: ui-monospace, Menlo, Consolas, monospace; }
.key-new { border: 1px solid var(--accent); border-radius: 8px; padding: 0.6rem; margin: 0.5rem 0; background: var(--panel); display: flex; flex-direction: column; gap: 0.4rem; }
.key-row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; padding: 0.45rem 0; border-bottom: 1px solid var(--line); }
table.log { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.log th, table.log td { border-bottom: 1px solid var(--line); padding: 0.25rem 0.4rem; text-align: start; }

@media (max-width: 700px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--line); }
  main { padding: 0.75rem; }
}
