:root {
  --bg: #f6f6f4; --panel: #ffffff; --ink: #1b1d1f; --muted: #62676d; --line: #e3e3df;
  --accent: #0f6e5a; --accent-ink: #ffffff; --warn: #a15c00; --warn-bg: #fff4e0; --danger: #b3261e; --danger-bg: #fdecea;
  --info-bg: #e8f2ef; --bubble-in: #ffffff; --bubble-out: #dff3ec; --bubble-admin: #e6ecff; --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121416; --panel: #1b1e21; --ink: #e9eaeb; --muted: #9aa0a6; --line: #2c3035; --accent: #4fc3a1; --accent-ink: #08231c;
    --warn: #ffb74d; --warn-bg: #3a2a10; --danger: #ff8a80; --danger-bg: #3b1a18; --info-bg: #17302a; --bubble-in: #23272b; --bubble-out: #1d3a31; --bubble-admin: #222c44; }
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { resize: vertical; min-height: 64px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 17px; } h2 { font-size: 15px; } h3 { font-size: 14px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--info-bg); color: var(--accent); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.error { color: var(--danger); font-size: 13px; min-height: 1em; }

/* admin shell */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 2; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: .2px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border: none; background: transparent; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--info-bg); color: var(--accent); font-weight: 600; }
main { padding: 16px; }
.login { max-width: 360px; margin: 10vh auto; padding: 24px; display: grid; gap: 12px; }

.inbox { display: grid; grid-template-columns: minmax(240px, 330px) 1fr; gap: 12px; height: calc(100vh - 90px); }
.inbox-left { display: grid; grid-template-rows: auto 1fr; gap: 8px; min-height: 0; }
.list { overflow: auto; }
input.check { width: auto; }
.list-item { display: grid; gap: 3px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; background: none; border-radius: 0; border-left: 3px solid transparent; text-align: left; width: 100%; border-top: 0; border-right: 0; }
.list-item[aria-current="true"] { background: var(--info-bg); border-left-color: var(--accent); }
.list-item .preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; overflow: hidden; }
.conv header { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 6px; }
.thread { overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 78%; padding: 8px 11px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; border: 1px solid var(--line); }
.bubble.in { align-self: flex-start; background: var(--bubble-in); }
.bubble.out { align-self: flex-end; background: var(--bubble-out); }
.bubble.admin { background: var(--bubble-admin); }
.bubble .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.composer { padding: 10px 12px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: grid; gap: 6px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
.table-wrap { overflow-x: auto; }
.stack { display: grid; gap: 12px; }
.pad { padding: 12px; }
.form-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

@media (max-width: 760px) {
  .inbox { grid-template-columns: 1fr; height: auto; }
  .list { max-height: 40vh; }
  main { padding: 10px; }
}

/* chat + simulator */
.chat-shell { max-width: 460px; margin: 0 auto; height: 100vh; display: grid; grid-template-rows: auto 1fr auto; background: var(--panel); border-inline: 1px solid var(--line); }
.chat-shell header { padding: 14px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 4px; }
.chat-shell .thread { min-height: 0; }
.chat-shell form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.wa { height: 640px; max-height: calc(100vh - 40px); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.wa header { background: #075e54; color: #fff; }
.wa header .muted { color: #cfe9e4; }
.wa .thread { background: #ece5dd; }
.wa .bubble.in { background: #fff; color: #111; border-color: #ddd; }
.wa .bubble.out { background: #dcf8c6; color: #111; border-color: #cfe9b8; }
@media (prefers-color-scheme: dark) {
  .wa .thread { background: #0b141a; }
  .wa .bubble.in { background: #202c33; color: #e9edef; border-color: #2a3942; }
  .wa .bubble.out { background: #005c4b; color: #e9edef; border-color: #005c4b; }
}
.sim-grid { display: grid; grid-template-columns: 380px 1fr; gap: 16px; max-width: 1100px; margin: 16px auto; padding: 0 16px; }
@media (max-width: 860px) { .sim-grid { grid-template-columns: 1fr; } }

/* The hidden attribute must win over component display rules (e.g. label { display: grid }). */
[hidden] { display: none !important; }
