:root {
  --bg: #f4f1ec;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6b7075;
  --line: #e4ded5;
  --accent: #7a4df0;
  --accent-ink: #ffffff;
  --in: #ffffff;
  --out: #ece6ff;
  --owner: #dff3e8;
  --warn: #b35c00;
  --ok: #16794a;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316; --panel: #1b1d21; --ink: #e8e6e3; --muted: #9a9ea4; --line: #2c2f35;
    --accent: #9b7bff; --in: #23262b; --out: #2f2750; --owner: #1f3a2d;
    --warn: #f0a24a; --ok: #4cc38a; --danger: #ff6b5e; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, "Segoe UI", "Noto Sans Arabic", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.icon { width: 36px; height: 36px; padding: 0; border-radius: 50%; font-size: 18px; }
input, select, textarea { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.avatar { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #d36bd1); color: #fff; font-weight: 700; flex: none; }
.avatar.big { width: 56px; height: 56px; font-size: 24px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 22px; }
.brand p, .brand small { margin: 0; color: var(--muted); display: block; font-size: 12px; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); padding: 24px; border-radius: 16px; box-shadow: var(--shadow); width: min(380px, 100%); display: grid; gap: 12px; }
.error { color: var(--danger); margin: 0; }

.app { display: grid; grid-template-columns: 340px 1fr; height: 100%; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 14px; }
.tabs { display: flex; gap: 4px; padding: 0 14px 8px; }
.tabs button { flex: 1; border: none; background: transparent; color: var(--muted); padding: 6px; border-bottom: 2px solid transparent; border-radius: 0; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
#search { margin: 0 14px 8px; width: auto; }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; overflow-x: hidden; flex: 1; }
.list li { padding: 10px 14px; border-top: 1px solid var(--line); cursor: pointer; display: grid; gap: 2px; }
.list li:hover, .list li.active { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; min-width: 0; }
.row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.time { color: var(--muted); font-size: 12px; flex: none; }
.badge { background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }
.tag { font-size: 11px; border-radius: 6px; padding: 1px 6px; border: 1px solid var(--line); color: var(--muted); }
.tag.human { color: var(--warn); border-color: currentColor; }
.tag.signed { color: var(--ok); border-color: currentColor; }
.tag.sent { color: var(--warn); border-color: currentColor; }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 16px; }
.empty h2 { color: var(--ink); }
#conversation { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.who { flex: 1; min-width: 0; }
.who small { display: block; color: var(--muted); }
.pill { font-size: 12px; border-radius: 999px; padding: 2px 10px; border: 1px solid currentColor; }
.pill.open { color: var(--ok); } .pill.closed { color: var(--warn); }
.switch { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.switch input { width: auto; accent-color: var(--accent); }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(560px, 85%); padding: 8px 12px; border-radius: 14px; box-shadow: 0 1px 1px rgba(0,0,0,.05); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.in { background: var(--in); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { background: var(--out); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.owner { background: var(--owner); }
.meta { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; text-align: end; }
.meta .failed { color: var(--danger); }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0; }

.panel { background: var(--panel); border-top: 1px solid var(--line); }
.panel summary { padding: 10px 16px; cursor: pointer; font-weight: 600; }
.panel form { display: grid; gap: 8px; padding: 0 16px 14px; }
.composer { display: flex; gap: 8px; padding: 10px 16px; background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { min-height: 42px; max-height: 160px; resize: none; }

dialog { border: none; border-radius: 16px; padding: 20px; background: var(--panel); color: var(--ink); width: min(380px, 92vw); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog form { display: grid; gap: 10px; }
dialog h3 { margin: 0 0 4px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 6px 0 0; padding: 0; flex-wrap: wrap; }
.muted { color: var(--muted); margin: 0; font-size: 14px; }
a.button { display: inline-flex; align-items: center; border-radius: 10px; padding: 8px 14px; text-decoration: none; border: 1px solid var(--line); color: inherit; }
a.button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.small { padding: 4px 10px; font-size: 13px; }
.tag.queued { color: var(--accent); border-color: currentColor; }

.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; max-width: calc(100vw - 32px); box-shadow: var(--shadow); z-index: 10; }
.toast.bad { background: var(--danger); color: #fff; }
.mobile-only { display: none; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app.show-chat .sidebar { display: none; }
  .app:not(.show-chat) .chat { display: none; }
  .mobile-only { display: inline-block; }
  .chat-head { padding: 8px 12px; }
  .messages { padding: 12px; }
}

/* privacy page */
.legal { max-width: 720px; margin: 0 auto; padding: 32px 16px 64px; }
.legal h1 { margin-top: 0; }
.legal h2 { font-size: 18px; margin-top: 28px; }
.legal li { margin: 4px 0; }

/* logs screen */
.logs-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px 0; }
.chip { font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; background: var(--panel); color: var(--muted); }
.chip b { color: var(--ink); font-weight: 600; }
.chip.bad b { color: var(--danger); }
.logs-filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.logs-filters select, .logs-filters input { width: auto; flex: 1 1 150px; min-width: 0; padding: 6px 10px; }
.logs { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; font-size: 13px; }
.log { display: grid; grid-template-columns: 64px 118px 1fr; gap: 8px; padding: 7px 16px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: baseline; }
.log:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.log .t { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.log .ty { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log .body { min-width: 0; overflow-wrap: anywhere; }
.log .ph { color: var(--accent); margin-inline-end: 6px; cursor: pointer; }
.log.lvl-warn { background: color-mix(in srgb, var(--warn) 9%, transparent); }
.log.lvl-error { background: color-mix(in srgb, var(--danger) 11%, transparent); }
.log.lvl-error .ty, .log.lvl-error .body { color: var(--danger); }
.log.lvl-debug { color: var(--muted); }
.log pre { grid-column: 1 / -1; margin: 6px 0 0; padding: 8px; background: var(--bg); border-radius: 8px; overflow-x: auto; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.logs-foot { padding: 8px 16px; border-top: 1px solid var(--line); text-align: center; }
.logs-empty { padding: 24px 16px; color: var(--muted); text-align: center; }
@media (max-width: 760px) {
  .log { grid-template-columns: 64px 1fr; }
  .log .ty { grid-column: 2; }
  .log .body { grid-column: 1 / -1; }
}

/* settings screen */
.head-actions { display: flex; gap: 6px; }
.settings-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.settings-body { flex: 1; overflow-y: auto; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; padding: 16px; align-items: start; }
#settings-form { display: grid; gap: 14px; min-width: 0; }
fieldset { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); padding: 12px 14px 14px; margin: 0; display: grid; gap: 10px; min-width: 0; }
legend { font-weight: 600; padding: 0 6px; }
fieldset label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
fieldset label input, fieldset label select, fieldset label textarea { color: var(--ink); font-size: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
label.check input { width: auto; accent-color: var(--accent); }
.checks { display: grid; gap: 6px; }
fieldset.locked { background: transparent; }
fieldset.locked ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; display: grid; gap: 3px; }
.settings-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.history { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.history li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 13px; }
.history li:first-child { border-top: none; }
.test-box { position: sticky; top: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 8px; }
.test-box h3 { margin: 0; }
.test-out { background: var(--out); border-radius: 12px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.test-out .tools { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); }
@media (max-width: 1000px) { .settings-body { grid-template-columns: 1fr; } .test-box { position: static; } }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } .settings-body { padding: 12px; } }

/* follow-ups */
.tabs button { font-size: 13px; padding: 6px 2px; }
.fu-filter { padding: 0 14px 8px; }
.fu-filter select { padding: 6px 10px; }
.fu-label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.tag.pending { color: var(--accent); border-color: currentColor; }
.tag.needs_invite { color: var(--warn); border-color: currentColor; }
.tag.done { color: var(--ok); border-color: currentColor; }
.tag.failed { color: var(--danger); border-color: currentColor; }
.fu-actions { display: flex; gap: 6px; margin-top: 4px; }
