:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #111827; --accent-ink: #fff; --ok: #047857; --ok-bg: #ecfdf5; --warn: #b45309; --warn-bg: #fffbeb;
  --bad: #b91c1c; --bad-bg: #fef2f2; --info: #1d4ed8; --info-bg: #eff6ff; --radius: 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink); background: var(--bg); font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: inherit; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { display: grid; place-items: center; min-height: 100vh; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.right { margin-left: auto; }
.stack > * + * { margin-top: 10px; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: #111827; color: #e5e7eb; padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 15px; padding: 4px 10px 16px; color: #fff; }
.brand span { display: block; font-weight: 400; font-size: 12px; color: #9ca3af; }
.nav { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: #d1d5db; }
.nav:hover { background: #1f2937; }
.nav.active { background: #374151; color: #fff; }
.nav .badge { margin-left: auto; }
.side .me { margin-top: auto; padding: 10px; font-size: 12px; color: #9ca3af; border-top: 1px solid #374151; }
.main { padding: 22px 26px; min-width: 0; }
.menu-btn { display: none; }

/* components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 12px; }
.g4 { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat .v { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat .l { color: var(--muted); font-size: 12px; }
.badge { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; text-align: center; background: #e5e7eb; color: #374151; }
.badge.red { background: #dc2626; color: #fff; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #f3f4f6; color: #374151; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover { background: #f9fafb; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { background: #1f2937; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
button.link { border: 0; background: none; padding: 0; color: var(--info); }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; color: var(--ink); width: 100%; }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; }
label.inline input { width: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.err { color: var(--bad); background: var(--bad-bg); padding: 8px 10px; border-radius: 8px; }
.note { background: var(--info-bg); color: #1e3a8a; padding: 10px 12px; border-radius: 8px; }
.warnbox { background: var(--warn-bg); color: #78350f; padding: 10px 12px; border-radius: 8px; }

/* inbox */
.inbox { display: grid; grid-template-columns: 340px 1fr; gap: 12px; height: calc(100vh - 110px); }
.list { overflow-y: auto; padding: 0; }
.conv { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover { background: #f9fafb; }
.conv.sel { background: #eef2ff; }
.conv .name { font-weight: 600; }
.thread { display: flex; flex-direction: column; min-height: 0; padding: 0; }
.thread-head { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; background: #fafafa; }
.bubble { max-width: 72%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.4; }
.bubble.in { align-self: flex-start; background: #fff; border: 1px solid var(--line); }
.bubble.out { align-self: flex-end; background: #111827; color: #fff; }
.bubble.out.ai { background: #4338ca; }
.bubble.failed { outline: 2px solid #dc2626; }
.bubble .meta { font-size: 10px; opacity: .7; margin-top: 3px; }
.composer { border-top: 1px solid var(--line); padding: 12px 16px; }
.draft { border: 2px solid #6366f1; background: #eef2ff; border-radius: 10px; padding: 10px; margin-bottom: 10px; }

/* login */
.auth { width: 360px; max-width: 92vw; }

/* bars */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 90px; }
.bars div { flex: 1; background: #6366f1; border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars div:hover::after { content: attr(data-t); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: #111; color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 4px; white-space: nowrap; }

/* modal + toast */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; z-index: 20; }
.modal { background: #fff; border-radius: 12px; padding: 18px; width: 560px; max-width: 94vw; max-height: 90vh; overflow-y: auto; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 30; max-width: 90vw; }
.toast.bad { background: #b91c1c; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 15; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; margin-bottom: 12px; }
  .main { padding: 14px; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .inbox.has-sel .list { display: none; }
  .inbox:not(.has-sel) .thread { display: none; }
  .msgs { max-height: 55vh; }
  .bubble { max-width: 88%; }
}
