:root {
  --bg: #f6f7f9; --card: #ffffff; --text: #1d2330; --muted: #6b7385; --line: #e3e6ec;
  --accent: #2f6fed; --accent-text: #ffffff; --ok: #1f9d55; --bad: #d64545; --warn: #c98a00;
  --input: #ffffff; --bubble-user: #e8f0fe; --bubble-bot: #f1f2f5; --code: #f4f5f8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --card: #1a1e26; --text: #e6e9ef; --muted: #98a0b3; --line: #2a303b;
    --accent: #5b8ff9; --accent-text: #0b0e13; --input: #141820; --bubble-user: #1f2c47;
    --bubble-bot: #232833; --code: #141820;
    color-scheme: dark;   /* dark native scrollbars, checkboxes and time pickers */
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* classes with their own display must not un-hide elements */
body { margin: 0; background: var(--bg); color: var(--text); accent-color: var(--accent);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 24px 0 6px; padding-top: 16px; border-top: 1px solid var(--line); }
.card > h3:first-child, #profile-form > h3:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.empty { font-size: 13px; color: var(--muted); padding: 10px 2px; }
button { font: inherit; border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.small { padding: 4px 9px; font-size: 13px; }
button.danger { background: transparent; color: var(--bad); border: 1px solid var(--line); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--input);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; }
textarea { resize: vertical; min-height: 38px; }
textarea.autosize { overflow-y: hidden; resize: none; }
.inline { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.inline input { width: 84px; margin: 0; }
.prepay { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: var(--code); }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; }
.error-box { border: 1px solid var(--bad); color: var(--bad); border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
.error-box ul { margin: 4px 0 0; padding-left: 18px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
main { max-width: 1180px; margin: 0 auto; padding: 18px 16px 60px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 12px; }

.topbar { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; gap: 12px; align-items: center; padding: 10px 16px; flex-wrap: wrap; }
.brand { display: flex; gap: 8px; align-items: center; margin-right: auto; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; order: 3; width: 100%; }
@media (min-width: 900px) { .tabs { order: 0; width: auto; } }
.tabs button { background: transparent; color: var(--muted); padding: 6px 10px; }
.tabs button.active { color: var(--text); background: var(--bg); }

.chatbot-select { margin-left: 10px; padding: 4px 8px; font-size: 14px; max-width: 220px; }
.level { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 0 0 12px; }
.meter { height: 10px; border-radius: 6px; background: var(--line); overflow: hidden; margin: 8px 0; }
.meter .bar { height: 100%; background: var(--ok); }
.meter .bar.yellow { background: var(--warn); }
.meter .bar.red { background: var(--bad); }
.channel { border-top: 1px solid var(--line); padding: 14px 0 4px; }
.channel .who { font-weight: 600; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--bg); color: var(--muted);
  border: 1px solid var(--line); font-weight: 400; }

.grid { display: grid; gap: 12px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.stat .n { font-size: 26px; font-weight: 600; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.field .help { font-size: 12px; color: var(--muted); margin-top: 3px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
.check input { width: auto; margin: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; white-space: nowrap; }
td input, td select, td textarea { padding: 5px 7px; font-size: 13px; min-width: 70px; }
.hours td { vertical-align: middle; }

.split { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .split { grid-template-columns: 340px 1fr; } }
.conv-list { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow: auto; }
.conv-list li { padding: 10px; border-radius: 8px; cursor: pointer; border-bottom: 1px solid var(--line); }
.conv-list li:hover, .conv-list li.active { background: var(--bg); }
.conv-list .who { font-weight: 500; }
.conv-list .last { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-log { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow: auto; padding: 4px 0 12px; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--bubble-user); }
.msg.assistant { align-self: flex-start; background: var(--bubble-bot); }
.msg.tool, .msg.note { align-self: center; font-size: 12px; color: var(--muted); background: transparent; padding: 2px; }
.chat-card #chat-form input { flex: 1; min-width: 200px; }
.sticky-actions { position: sticky; bottom: 0; z-index: 2; background: var(--bg); padding: 12px 0; }
/* inside a card the bar becomes the card's footer: same colour, full width, divider on top */
.card .sticky-actions { background: var(--card); margin: 20px -18px -18px; padding: 12px 18px;
  border-top: 1px solid var(--line); border-radius: 0 0 12px 12px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 8px; font-size: 14px; max-width: calc(100% - 32px); }
