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

html, body {
  height: 100%;
  background: #000;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.loading { visibility: hidden; }
.hidden { display: none !important; }

a { color: inherit; text-decoration: none; }

.btn-primary {
  background: #fff; color: #000; font-weight: 600;
  padding: 10px 20px; border-radius: 8px; border: none; cursor: pointer;
  font-size: 14px; display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; transition: background .2s;
}
.btn-primary:hover { background: #e5e7eb; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.muted { color: #6b7280; }
.small { font-size: 12px; }
.muted-btn { background: none; border: none; color: #6b7280; cursor: pointer; font-size: 14px; }
.muted-btn:hover { color: #fff; }

/* ───────────────── Auth gate ───────────────── */
.auth-gate {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at top, #0a0a0a, #000 70%);
}
.auth-card {
  background: #0a0a0a;
  border: 1px solid #1f2937;
  border-radius: 16px;
  padding: 48px 40px;
  max-width: 420px;
  text-align: center;
}
.auth-card h1 { font-size: 26px; font-weight: 700; letter-spacing: -.01em; margin-bottom: 12px; }
.auth-sub { color: #9ca3af; margin-bottom: 28px; font-size: 14px; line-height: 1.6; }
.auth-error { margin-top: 16px; color: #f87171; font-size: 13px; }

.login-form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.auth-label { font-size: 12px; color: #9ca3af; margin-top: 6px; }
.auth-input {
  background: #050505;
  color: #fff;
  border: 1px solid #1f2937;
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.auth-input:focus { border-color: #4b5563; }
.login-form .btn-primary { margin-top: 16px; width: 100%; padding: 12px; }

/* ───────────────── Topbar ───────────────── */
.app {
  display: flex; flex-direction: column;
  height: 100vh;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid #111;
  background: rgba(0,0,0,0.92);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 24px; }
.logo { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.tabs { display: flex; align-items: center; gap: 4px; }
.tab {
  background: transparent; color: #9ca3af; border: 1px solid transparent;
  padding: 7px 14px; border-radius: 8px; font-size: 13px; cursor: pointer;
  transition: all .15s;
}
.tab:hover { color: #fff; }
.tab.active { color: #fff; background: #0a0a0a; border-color: #1f2937; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 13px; color: #9ca3af; }
.user-email { color: #d1d5db; font-size: 12px; }
.signout { color: #6b7280; font-size: 12px; }
.signout:hover { color: #fff; }

.sync-indicator {
  width: 8px; height: 8px; border-radius: 50%; background: #374151;
}
.sync-indicator.ok { background: #10b981; }
.sync-indicator.warn { background: #f59e0b; }
.sync-indicator.err { background: #ef4444; }

/* ───────────────── Three-pane grid ───────────────── */
.grid {
  display: grid;
  grid-template-columns: 220px 1fr 360px;
  flex: 1;
  min-height: 0;
}
.rail {
  display: flex; flex-direction: column;
  border-right: 1px solid #111;
  min-height: 0;
}
.rail.rail-skai {
  border-right: none;
  border-left: 1px solid #111;
}
.rail-head {
  padding: 14px 18px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .14em; color: #6b7280;
  border-bottom: 1px solid #111;
  display: flex; align-items: center; justify-content: space-between;
}
.channel-list { list-style: none; padding: 8px 0; overflow-y: auto; flex: 1; }
.channel-list li {
  padding: 9px 18px; cursor: pointer; font-size: 13px; color: #d1d5db;
  border-left: 2px solid transparent;
  display: flex; align-items: center; gap: 8px;
  transition: background .12s;
}
.channel-list li:hover { background: #0a0a0a; color: #fff; }
.channel-list li.active { background: #0a0a0a; color: #fff; border-left-color: #fff; }
.channel-name-hash { color: #6b7280; }
.channel-empty { color: #6b7280; padding: 14px 18px; font-size: 12px; }

/* ───────────────── Center ───────────────── */
.center { display: flex; flex-direction: column; min-height: 0; }
.center-head {
  padding: 14px 22px; border-bottom: 1px solid #111;
  display: flex; align-items: baseline; gap: 14px;
}
.center-head h2 { font-size: 16px; font-weight: 600; }
.messages {
  flex: 1; overflow-y: auto;
  padding: 16px 22px;
  display: flex; flex-direction: column; gap: 4px;
}
.messages .empty { color: #6b7280; padding: 32px; text-align: center; }
.msg {
  padding: 4px 0;
  display: grid; grid-template-columns: 32px 1fr; gap: 12px;
}
.msg.continuation { grid-template-columns: 32px 1fr; }
.msg.continuation .msg-avatar,
.msg.continuation .msg-author-line { visibility: hidden; height: 0; padding: 0; margin: 0; }
.msg.continuation { padding: 1px 0; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #1f2937; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: #9ca3af; font-weight: 600;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }

.msg-body { min-width: 0; }
.msg-author-line {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 13px; margin-bottom: 2px;
}
.msg-author { font-weight: 600; color: #fff; }
.msg-bot-tag {
  background: #1e3a8a; color: #93c5fd; font-size: 9px;
  padding: 2px 6px; border-radius: 4px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase;
}
.msg-time { color: #6b7280; font-size: 11px; }
.msg-content { color: #d1d5db; font-size: 14px; line-height: 1.55; word-wrap: break-word; white-space: pre-wrap; }
.msg-attachments { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.msg-attachments a { color: #60a5fa; font-size: 12px; }
.msg-attachments img { max-width: 320px; max-height: 220px; border-radius: 6px; }

/* ───────────────── Skai rail ───────────────── */
.skai-history {
  flex: 1; overflow-y: auto; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.skai-turn { font-size: 13px; line-height: 1.55; }
.skai-turn.user { color: #d1d5db; }
.skai-turn.user .who { color: #9ca3af; font-weight: 600; }
.skai-turn.assistant .who { color: #a78bfa; font-weight: 600; }
.skai-turn.assistant { color: #e5e7eb; }
.skai-turn .body { white-space: pre-wrap; margin-top: 3px; }
.skai-turn .body p { margin: 0 0 6px; }
.skai-turn .body p:last-child { margin-bottom: 0; }
.skai-turn .body code { background: #111; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.skai-turn.error { color: #f87171; }
.skai-turn.pending { color: #6b7280; font-style: italic; }
.skai-turn .engine-badge {
  display: inline-block;
  margin-left: 8px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 4px;
  vertical-align: middle;
}
.skai-turn.assistant .engine-badge.skai { background: #1e1b4b; color: #c4b5fd; }
.skai-turn.assistant .engine-badge.claude { background: #1f2937; color: #fde68a; }
.skai-turn.assistant .engine-badge.codex { background: #064e3b; color: #6ee7b7; }
.skai-turn.assistant.pending-reply { opacity: .55; }
.skai-turn.assistant.pending-reply .body::after { content: ' …'; }

.engine-picker {
  display: flex;
  gap: 4px;
  padding: 8px 14px;
  border-bottom: 1px solid #111;
}
.engine-opt {
  flex: 1;
  background: transparent;
  color: #6b7280;
  border: 1px solid #1f2937;
  border-radius: 6px;
  padding: 5px 0;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  transition: color .12s, background .12s, border-color .12s;
}
.engine-opt:hover { color: #fff; border-color: #374151; }
.engine-opt.active { background: #1f2937; color: #fff; border-color: #374151; }
.rail-title { display: inline-flex; align-items: center; gap: 6px; }

.skai-form {
  border-top: 1px solid #111; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.skai-form textarea {
  background: #0a0a0a; border: 1px solid #1f2937; border-radius: 8px;
  padding: 10px 12px; color: #fff; font-family: inherit; font-size: 13px;
  resize: vertical; min-height: 60px; max-height: 240px;
}
.skai-form textarea:focus { outline: none; border-color: #374151; }
.skai-form-row { display: flex; align-items: center; justify-content: space-between; }
.skai-form button { padding: 7px 16px; font-size: 13px; }

/* ───────────────── Responsive (best-effort, this is desktop tool) ─── */
@media (max-width: 1080px) {
  .grid { grid-template-columns: 180px 1fr 300px; }
}
@media (max-width: 880px) {
  .grid { grid-template-columns: 160px 1fr; }
  .rail.rail-skai { display: none; }
}

/* ── Tab admin ─────────────────────────────────────────────── */
.tabs-admin {
  margin-left: 8px;
  background: transparent;
  border: 1px solid #1f2937;
  color: #9ca3af;
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.tabs-admin:hover { color: #fff; border-color: #374151; }
.tabs-admin.hidden { display: none; }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal.hidden { display: none; }
.modal-card {
  background: #0a0a0a;
  border: 1px solid #1f2937;
  border-radius: 10px;
  padding: 20px 24px;
  width: min(820px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  color: #e5e7eb;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-close {
  background: transparent; border: none; color: #9ca3af;
  font-size: 22px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: #fff; }
.modal-subhead { margin: 16px 0 8px; font-size: 13px; color: #9ca3af; }

.tabs-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabs-table th, .tabs-table td {
  text-align: left; padding: 8px 6px; border-bottom: 1px solid #1f2937;
}
.tabs-table th { color: #9ca3af; font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.tabs-table input[type="text"] {
  background: #050505; border: 1px solid #1f2937; color: #fff;
  border-radius: 6px; padding: 6px 8px; font-size: 12px; width: 100%;
}
.tabs-table input[type="text"]:focus { outline: none; border-color: #374151; }
.tabs-table code { background: #050505; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.row-actions { display: flex; gap: 4px; }
.btn-mini {
  background: #1f2937; border: none; color: #e5e7eb;
  padding: 6px 10px; border-radius: 6px; font-size: 12px; cursor: pointer;
}
.btn-mini:hover { background: #374151; }
.btn-mini.danger { background: #3f1d1d; }
.btn-mini.danger:hover { background: #7f1d1d; }
.pill-live { color: #34d399; font-size: 11px; }
.pill-muted { color: #6b7280; font-size: 11px; }

.tabs-admin-add { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.tabs-admin-add input {
  flex: 1 1 140px;
  background: #050505; border: 1px solid #1f2937; color: #fff;
  border-radius: 6px; padding: 8px 10px; font-size: 13px;
}
.tabs-admin-add input:focus { outline: none; border-color: #374151; }
.tabs-admin-add .btn-primary { flex: 0 0 auto; }

/* Mirror-to-Discord toggle in the Skai composer */
.bridge-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; color: #6b7280; cursor: pointer;
  user-select: none;
}
.bridge-toggle input[type="checkbox"] {
  accent-color: #4ade80;
  margin: 0;
}
.bridge-toggle:hover { color: #9ca3af; }

/* Admin link in dashboard topbar */
.admin-link {
  background: #1f2937;
  color: #e5e7eb;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  text-decoration: none;
  border: 1px solid #374151;
  margin-right: 4px;
}
.admin-link:hover { background: #374151; color: #fff; }
