/* ChatPilot back office. Plain CSS, no libraries. Mobile first; logical properties for right-to-left. */
:root {
  --bg: #f4f6f8; --card: #fff; --ink: #17212b; --muted: #5b6875; --line: #dde3e9;
  --brand: #0f6e5c; --brand-ink: #fff; --brand-soft: #e3f2ee; --accent: #1f5fbf;
  --ok: #17663a; --ok-bg: #e6f4ea; --err: #a1261d; --err-bg: #fbe9e7; --warn: #8a5a00; --warn-bg: #fff4d6;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 2px 8px rgba(16, 24, 32, .05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.5; }
a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #f2b705; outline-offset: 2px;
}
h1 { font-size: 1.5rem; margin: .2em 0 .6em; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .6em; }
h3 { font-size: 1rem; margin: 1.2em 0 .5em; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .88em; background: #eef1f4; padding: .05em .35em; border-radius: 4px; }
.skip { position: absolute; inset-inline-start: -9999px; }
.skip:focus { inset-inline-start: 8px; top: 8px; background: #fff; padding: 8px 12px; z-index: 10; }

.topbar { background: var(--brand); color: var(--brand-ink); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 16px; }
.brand { color: inherit; text-decoration: none; font-weight: 700; display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.logo { background: #fff; color: var(--brand); border-radius: 8px; width: 30px; height: 30px; display: inline-grid; place-items: center; font-size: .8rem; }
.tag { font-weight: 500; font-size: .78rem; background: rgba(255, 255, 255, .18); padding: 2px 8px; border-radius: 999px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45vw; }
.nav-toggle { background: transparent; color: inherit; border: 1px solid rgba(255, 255, 255, .5); border-radius: 8px; padding: 6px 12px; font: inherit; cursor: pointer; min-height: 40px; }
.mainnav { display: none; width: 100%; flex-direction: column; gap: 2px; padding-top: 6px; }
.mainnav.open { display: flex; }
.mainnav a, .mainnav .linkish { color: #fff; text-decoration: none; padding: 10px 8px; border-radius: 8px; text-align: start; font-size: 1rem; }
.mainnav a[aria-current="page"] { background: rgba(255, 255, 255, .18); font-weight: 600; }
.mainnav a:hover, .mainnav .linkish:hover { background: rgba(255, 255, 255, .12); }
@media (min-width: 900px) {
  .nav-toggle { display: none; }
  .mainnav { display: flex; flex-direction: row; width: auto; padding: 0; align-items: center; }
  .mainnav a, .mainnav .linkish { padding: 6px 10px; font-size: .95rem; }
}

.wrap { max-width: 1120px; margin: 0 auto; padding: 18px 14px 40px; }
@media (min-width: 700px) { .wrap { padding: 26px 22px 48px; } }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 0 24px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card.narrow { max-width: 460px; margin-inline: auto; }
.card.center { text-align: center; }
.card.highlight { border-color: var(--brand); background: var(--brand-soft); }
.grid2 { display: grid; gap: 18px; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 1fr; align-items: start; } .grid2 > .card { margin-bottom: 0; } }

.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .92rem; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid #b9c3cd; border-radius: 8px; padding: 9px 11px; min-height: 44px; width: 100%; }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; }
textarea { min-height: 80px; }
.hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
.field-error { color: var(--err); font-weight: 600; font-size: .85rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; border-radius: 8px; padding: 9px 16px; min-height: 44px; border: 1px solid #b9c3cd; background: #fff; color: var(--ink); text-decoration: none; cursor: pointer; }
.btn:hover { background: #f0f3f6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #0b5a4b; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 36px; padding: 5px 12px; font-size: .88rem; }
.linkish { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 6px 0; text-decoration: underline; }
form.inline { display: inline; }

.flash { border-radius: 8px; padding: 10px 14px; margin: 0 0 16px; font-weight: 500; }
.flash-ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #b7dfc4; }
.flash-error { background: var(--err-bg); color: var(--err); border: 1px solid #f2c1bb; }
.note { background: var(--warn-bg); color: #5c3d00; border: 1px solid #f1dc9d; border-radius: 8px; padding: 10px 14px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.block { display: block; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 18px; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1000px) { .tiles { grid-template-columns: repeat(6, 1fr); } .tiles.small { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.tile .num { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.tile .lbl { color: var(--muted); font-size: .85rem; }
.tile.good .num { color: var(--ok); }
.tile.bad { border-color: var(--err); } .tile.bad .num { color: var(--err); }
a.tile:hover { border-color: var(--brand); }

.head-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; }
.filters { display: grid; gap: 10px; align-items: end; margin: 6px 0 10px; }
@media (min-width: 700px) { .filters { grid-template-columns: 2fr 1fr 1fr auto auto; } }
.list-filter { max-width: 360px; margin-bottom: 12px; }
.crumbs { margin: 0; font-size: .9rem; }

.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); margin-bottom: 18px; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: start; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f7f9fb; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
@media (max-width: 699px) {
  table.list thead { display: none; }
  table.list tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table.list td { display: grid; grid-template-columns: 96px minmax(0, 1fr); column-gap: 10px; border: 0; padding: 4px 10px; }
  table.list td::before { content: attr(data-label); grid-column: 1; grid-row: 1 / span 4; color: var(--muted); font-size: .8rem; font-weight: 600; }
  table.list td > * { grid-column: 2; justify-self: start; max-width: 100%; }
}
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #eef1f4; color: #33404d; vertical-align: middle; }
.s-active { background: var(--ok-bg); color: var(--ok); }
.s-trial { background: var(--warn-bg); color: var(--warn); }
.s-suspended { background: var(--err-bg); color: var(--err); }
.s-closed { background: #e4e7ea; color: #4b5560; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 14px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.people { list-style: none; padding: 0; margin: 0; }
.people li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.people li:last-child { border-bottom: 0; }
.secret { font-family: ui-monospace, Consolas, monospace; background: #fff; border: 1px dashed var(--brand); border-radius: 8px; padding: 10px 12px; margin: 8px 0; overflow-wrap: anywhere; font-size: 1rem; letter-spacing: .04em; }
.steps { padding-inline-start: 20px; }
.steps li { margin-bottom: 10px; }
.checklist { list-style: none; padding: 0; }
.checklist li { padding: 6px 0 6px 28px; position: relative; color: var(--muted); }
.checklist li::before { content: "○"; position: absolute; inset-inline-start: 4px; }
.checklist li.done { color: var(--ink); }
.checklist li.done::before { content: "✓"; color: var(--ok); font-weight: 700; }

.plan-grid { display: grid; gap: 16px; }
@media (min-width: 700px) { .plan-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .plan-grid { grid-template-columns: repeat(3, 1fr); } }
.plan { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.plan > .btn { margin-top: auto; }
.plan-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.price { font-size: 1.5rem; font-weight: 700; margin: 0; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.inline-form select { width: auto; min-height: 36px; padding: 4px 8px; }
.pager { display: flex; gap: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.actions form { margin: 0; }
.qr { width: 200px; max-width: 70vw; margin: 10px 0; }
.qr svg { width: 100%; height: auto; display: block; border: 1px solid var(--line); border-radius: 6px; }
.viewing { background: #3b2a00; color: #ffe9a8; padding: 10px 16px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; text-align: center; }
.meter { height: 10px; background: #e9ecef; border-radius: 999px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--brand); width: 0; }
.meter-10 { width: 10% !important; } .meter-20 { width: 20% !important; } .meter-30 { width: 30% !important; } .meter-40 { width: 40% !important; }
.meter-50 { width: 50% !important; } .meter-60 { width: 60% !important; } .meter-70 { width: 70% !important; } .meter-80 { width: 80% !important; background: #b7791f !important; }
.meter-90 { width: 90% !important; background: #b7791f !important; } .meter-100 { width: 100% !important; background: var(--err) !important; }
.viewing .btn { background: #ffe9a8; color: #3b2a00; border-color: #ffe9a8; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
/* Inbox */
.inbox { display: grid; gap: 14px; }
.inbox-list, .inbox-conv { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.inbox-conv { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.inbox.has-conv .inbox-list { display: none; }
.inbox:not(.has-conv) .inbox-conv { display: none; }
@media (min-width: 900px) {
  .inbox { grid-template-columns: 340px minmax(0, 1fr); align-items: start; }
  .inbox.has-conv .inbox-list, .inbox:not(.has-conv) .inbox-conv { display: flex; }
  .inbox-list { display: flex; flex-direction: column; max-height: calc(100vh - 130px); position: sticky; top: 12px; }
  .back { display: none; }
}
.tabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.wrap:has(.inbox) { max-width: 1440px; }
.tabs a { padding: 9px 9px; text-decoration: none; color: var(--muted); white-space: nowrap; border-bottom: 3px solid transparent; font-size: .92rem; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
.count { background: #eef1f4; border-radius: 999px; padding: 0 7px; font-size: .78rem; }
.inbox-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); }
.inbox-filters input[type=search] { flex: 1 1 140px; min-height: 38px; }
.inbox-filters select { width: auto; min-height: 38px; padding: 4px 8px; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.conv-list .empty { padding: 16px; }
.conv-item { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--line); }
.conv-item:hover, .conv-item.active { background: var(--brand-soft); }
.ci-top { display: flex; justify-content: space-between; gap: 8px; }
.ci-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.conv-head { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.conv-head h1 { font-size: 1.2rem; margin: 0; }
.conv-head > div { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.back { text-decoration: none; font-weight: 600; padding: 6px 0; }
.window { border-radius: 8px; padding: 8px 12px; font-size: .9rem; }
.window.open { background: var(--ok-bg); color: var(--ok); }
.window.shut { background: var(--warn-bg); color: #5c3d00; }
.conv-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.conv-controls label { flex-direction: row; align-items: center; gap: 6px; font-weight: 500; }
.conv-controls select { width: auto; min-height: 36px; padding: 4px 8px; }
.transcript { list-style: none; margin: 0; padding: 8px; display: flex; flex-direction: column; gap: 8px; background: #eef3f1; border-radius: 8px; max-height: 60vh; overflow-y: auto; min-height: 160px; }
.msg { max-width: 82%; padding: 8px 10px; border-radius: 10px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.06); display: flex; flex-direction: column; gap: 3px; }
.msg-in { align-self: flex-start; border-top-left-radius: 2px; }
.msg-out { align-self: flex-end; background: #d9f7e8; border-top-right-radius: 2px; }
.msg-failed { background: var(--err-bg); }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-meta { color: var(--muted); align-self: flex-end; }
.msg-error { color: var(--err); }
.msg-img { max-width: 240px; max-height: 240px; border-radius: 6px; }
.tick-read { color: #1f5fbf; font-weight: 600; }
.tick-failed { color: var(--err); font-weight: 600; }
.composer { display: flex; flex-direction: column; gap: 8px; }
.composer .quick { width: auto; align-self: flex-start; min-height: 36px; }
.tpl-form { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
details.card summary { cursor: pointer; font-weight: 600; }
.empty-conv { padding: 30px 10px; text-align: center; }
