:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --bg-3: #334155;
  --fg: #e2e8f0;
  --fg-dim: #94a3b8;
  --accent: #60a5fa;
  --accent-2: #3b82f6;
  --ok: #4ade80;
  --bad: #f87171;
  --border: #334155;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

#app, #app > .shell { height: 100%; display: flex; flex-direction: column; }
.shell { flex-direction: row; }

.loading {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--fg-dim);
}

/* --- login --- */
.login-wrap {
  max-width: 360px; margin: 15vh auto; padding: 32px; text-align: center;
  background: var(--bg-2); border-radius: 12px;
}
.login-wrap h1 { margin-top: 0; font-size: 22px; }
.btn {
  display: inline-block; padding: 10px 16px; border-radius: 8px;
  background: var(--bg-3); color: var(--fg); text-decoration: none;
  border: 1px solid var(--border); cursor: pointer; font: inherit;
}
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: white; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 2px 8px; font-size: 13px; border-radius: 6px;
          background: var(--bg-3); color: var(--fg); border: 1px solid var(--border); cursor: pointer; }
.btn-icon { background: transparent; color: var(--fg-dim); border: none; cursor: pointer; font-size: 18px; padding: 4px 8px; }
.btn-icon:hover { color: var(--fg); }

/* --- shell --- */
.sidebar {
  width: 240px; background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar header {
  padding: 10px 12px; display: flex; flex-direction: column;
  align-items: stretch; gap: 8px; border-bottom: 1px solid var(--border);
}
.sidebar .me { font-size: 13px; color: var(--fg-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-list {
  list-style: none; padding: 8px; margin: 0;
  flex: 1; overflow-y: auto; min-height: 0;
}
.channel-list li {
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.channel-list li:hover { background: var(--bg-3); }
.channel-list li.active { background: var(--accent-2); color: white; }
.channel-list .tag { font-size: 10px; padding: 1px 5px; border-radius: 3px; background: var(--bg-3); color: var(--fg-dim); }
.channel-list li.active .tag { background: rgba(255,255,255,.2); color: white; }

/* Nav tabs live in the sidebar header now, right under the account email. */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.tabs a, .tabs .btn-tab {
  color: var(--fg-dim); text-decoration: none; padding: 4px 10px;
  border-radius: 6px; font-size: 13px; line-height: 1.5;
  background: transparent; border: 1px solid transparent;
  cursor: pointer; font: inherit;
}
.tabs a:hover, .tabs a.active,
.tabs .btn-tab:hover { background: var(--bg-3); color: var(--fg); }
.tabs .btn-tab { font-weight: 600; padding: 4px 12px; }
.admin-only.hidden { display: none; }

/* Big danger button used for "退出登录" inside settings. */
.btn.danger-big {
  display: block; width: 100%; padding: 16px; margin: 12px 0 0;
  background: var(--bad); color: white; border: 1px solid var(--bad);
  font-size: 16px; font-weight: 600; border-radius: 10px;
}
.btn.danger-big:hover { filter: brightness(1.1); }

/* --- main --- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.main .pane { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.pane h2 { margin: 16px 24px; }

/* --- chat --- */
.chat-head {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.chat-head .members { font-size: 12px; color: var(--fg-dim); }
.messages { flex: 1; overflow-y: auto; padding: 16px; }
.msg { margin-bottom: 14px; display: flex; gap: 8px; }
.msg.assistant { justify-content: flex-start; }
.msg.user { justify-content: flex-end; }
/* The inner wrapper owns the max-width; if we put it on .bubble instead,
   flex shrink-to-fit would compute 70% of min-content and break one
   character per line. */
.msg > .wrap { max-width: 70%; min-width: 0; display: flex; flex-direction: column; }
.msg.user > .wrap { align-items: flex-end; }
.msg .bubble {
  padding: 8px 12px; border-radius: 10px;
  background: var(--bg-2); white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--accent-2); color: white; }
.msg .who { font-size: 11px; color: var(--fg-dim); margin-bottom: 2px; }

/* Center timestamp divider between messages. */
.ts-divider {
  text-align: center; color: var(--fg-dim); font-size: 11px;
  margin: 10px 0;
}

.composer {
  border-top: 1px solid var(--border); padding: 10px;
  display: flex; gap: 6px; align-items: flex-end;
}
.composer textarea {
  flex: 1; resize: none; background: var(--bg-2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px;
  font: inherit; min-height: 40px; max-height: 200px;
}
.composer .attach-row {
  display: flex; flex-direction: row; flex-wrap: nowrap;
  gap: 4px; flex-shrink: 0;
}
.composer .chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px;
                  background: var(--bg-3); border-radius: 6px; font-size: 12px; }
.composer .chip button { background: none; border: none; color: var(--fg-dim); cursor: pointer; }
.composer .rec { color: var(--bad); }

.pane-body { padding: 16px 24px; overflow-y: auto; }
.pane-body table { width: 100%; border-collapse: collapse; }
.pane-body th, .pane-body td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.pane-body input, .pane-body select { background: var(--bg-2); color: var(--fg);
  border: 1px solid var(--border); padding: 6px; border-radius: 6px; font: inherit; }
.pill { padding: 1px 6px; border-radius: 10px; background: var(--bg-3); font-size: 11px; }
.pill.admin { background: var(--accent-2); color: white; }

/* --- modal --- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex;
  align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--bg-2); padding: 20px; border-radius: 12px;
  min-width: 300px; max-width: 90vw; max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin-top: 0; }
.modal .row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.modal .row > label { font-size: 12px; color: var(--fg-dim); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.modal .members-check label { display: block; padding: 4px 0; }

/* Camera preview */
.camera-preview video { max-width: 100%; border-radius: 8px; background: #000; }

.err { color: var(--bad); font-size: 13px; }
.ok  { color: var(--ok); font-size: 13px; }
.muted { color: var(--fg-dim); }

/* Mobile */
@media (max-width: 720px) {
  .sidebar {
    width: 100%; height: auto; max-height: 40vh;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .shell { flex-direction: column; }
  .main { flex: 1; min-height: 0; }
}
