:root {
  --bg: #f4f6f5; --card: #ffffff; --text: #18211f; --muted: #66706d; --line: #e2e7e5;
  --brand: #0f5c4d; --brand-soft: #e3f1ed; --on-brand: #ffffff;
  --mine: #dff3ec; --mine-text: #10372f; --note: #fff6dd; --note-line: #f0d48a;
  --error: #b42318; --error-bg: #fef3f2; --ok: #12805c; --ok-bg: #ecfdf3; --warn: #93530b; --warn-bg: #fff4e0;
  --badge: #d4351c;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1413; --card: #18201e; --text: #e6ece9; --muted: #96a29e; --line: #26302d;
    --brand: #3fb497; --brand-soft: #1b2e29; --on-brand: #06231c;
    --mine: #183a31; --mine-text: #d9f3ea; --note: #332a12; --note-line: #6b5a24;
    --error: #f87171; --error-bg: #2a1616; --ok: #4ade80; --ok-bg: #12261b; --warn: #fbbf24; --warn-bg: #2b2310; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif; }
a { color: var(--brand); }
[hidden] { display: none !important; }

.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--brand); color: var(--on-brand); }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 700; }
.brand small { font-weight: 400; opacity: .85; margin-inline-start: 4px; }
.logo { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: var(--on-brand); color: var(--brand); font-size: 13px; letter-spacing: .5px; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 6px 10px; border-radius: 8px;
  background: rgba(255,255,255,.14); max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu summary::-webkit-details-marker { display: none; }
.menu-box { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); min-width: 180px; padding: 10px;
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  display: grid; gap: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.menu-box form { margin: 0; }
.menu-box select { width: 100%; }

.page { max-width: 760px; margin: 0 auto; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.h1 { font-size: 22px; margin: 4px 0 4px; }
.h2 { font-size: 15px; color: var(--muted); font-weight: 600; margin: 22px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.section-head .h2 { margin: 22px 0 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.card.narrow { max-width: 420px; margin: 32px auto; }
.card h1 { margin-top: 0; font-size: 22px; }
.form label { display: block; margin-bottom: 14px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=search], textarea, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.form input { display: block; width: 100%; margin-top: 6px; padding: 11px 12px; }
select { padding: 8px 10px; }
.btn { display: inline-block; border: 1px solid var(--line); background: var(--card); color: var(--brand);
  border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.btn.wide { width: 100%; padding: 12px; }
.small-btn { padding: 6px 12px; font-size: 14px; }
.link { background: none; border: 0; color: var(--brand); font: inherit; cursor: pointer; padding: 4px 0; }
.notice { border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; }
.notice-error { background: var(--error-bg); color: var(--error); }
.notice-success { background: var(--ok-bg); color: var(--ok); }
.notice-warning { background: var(--warn-bg); color: var(--warn); }

.list { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: var(--text); text-decoration: none;
  border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--brand-soft); }
.avatar { flex: none; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 18px; }
.row-main { flex: 1; min-width: 0; display: grid; gap: 1px; }
.row-top { display: flex; justify-content: space-between; gap: 8px; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-when { flex: none; font-size: 12px; color: var(--muted); }
.row-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-preview { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .row-title, .row.unread .row-preview { color: var(--text); font-weight: 700; }
.badge { flex: none; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--badge);
  color: #fff; font-size: 13px; font-weight: 700; display: inline-grid; place-items: center; }
.count { color: var(--muted); font-size: 13px; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--warn); }

.tabs { display: flex; gap: 6px; margin: 12px 0; }
.tabs a { flex: 1; text-align: center; padding: 8px; border-radius: 10px; text-decoration: none; color: var(--muted);
  background: var(--card); border: 1px solid var(--line); font-weight: 600; }
.tabs a.on { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.tabs a.on .badge { background: var(--on-brand); color: var(--brand); }

.thread-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.back { font-size: 30px; line-height: 1; text-decoration: none; padding: 0 6px; color: var(--brand); }
[dir=rtl] .back { transform: scaleX(-1); }
.thread-who { min-width: 0; }
.thread-title { font-weight: 700; font-size: 18px; }
.thread-sub { font-size: 13px; color: var(--muted); }
.tools { margin-bottom: 10px; }
.tools summary { cursor: pointer; color: var(--brand); font-weight: 600; font-size: 14px; }
.tools-box { display: grid; gap: 8px; padding: 10px 0; }
.tools-box form { margin: 0; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form select { flex: 1; min-width: 160px; }

.chat { display: flex; flex-direction: column; gap: 8px; padding: 6px 0 12px; }
.msg { align-self: flex-start; max-width: 86%; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; border-start-start-radius: 4px; padding: 8px 12px; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-color: transparent;
  border-start-start-radius: 16px; border-start-end-radius: 4px; }
.msg.note { background: var(--note); color: var(--text); border: 1px dashed var(--note-line); }
.msg-from { font-size: 12px; font-weight: 700; color: var(--brand); margin-bottom: 2px; }
.msg.note .msg-from { color: var(--warn); }
.msg-body a { color: inherit; text-decoration: underline; }
.msg-meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.msg.mine .msg-meta { color: inherit; opacity: .75; }
.seen { color: var(--ok); font-weight: 600; }
.msg.mine .seen { color: inherit; }
.secret-box { display: flex; align-items: center; gap: 10px; margin: 6px 0 2px; padding: 8px 10px;
  border-radius: 10px; background: var(--bg); color: var(--text); }
.secret-box code { font-size: 17px; letter-spacing: .5px; }
.secret-box.gone { color: var(--muted); }
.event { align-self: center; font-size: 12.5px; color: var(--muted); background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 3px 10px; text-align: center; }
.event.internal { border-style: dashed; }

.composer { position: sticky; bottom: 0; background: var(--bg); padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); }
.kinds { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; margin-bottom: 6px; }
.kinds label { display: inline-flex; align-items: center; gap: 4px; }
.secret-field input { width: 100%; padding: 10px 12px; margin-bottom: 4px; }
.secret-field p { margin: 0 0 6px; }
.compose-row { display: flex; gap: 8px; align-items: flex-end; }
.compose-row textarea { flex: 1; padding: 10px 12px; resize: vertical; min-height: 46px; max-height: 40vh; }
.composer.noting textarea { background: var(--note); border-color: var(--note-line); }

.filter { margin-bottom: 10px; }
.filter select { width: 100%; }
.checks { display: grid; gap: 2px; margin: 4px 0 12px; max-height: 45vh; overflow: auto;
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
.check { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.check.all { padding-bottom: 8px; }
.card textarea { width: 100%; padding: 10px 12px; margin-bottom: 10px; }
.find { width: 100%; padding: 11px 12px; margin: 4px 0 6px; }

.ready { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 6px; }
.ready select { max-width: 100%; }
.wide-select { width: 100%; margin-bottom: 10px; }
.ready-preview { background: var(--brand-soft); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.ready-preview p { margin: 0 0 4px; }

.app-card { background: var(--card); border: 1px solid var(--brand); border-radius: 14px; padding: 14px; margin-bottom: 16px;
  display: grid; gap: 10px; }
.app-card-head { display: flex; gap: 12px; align-items: center; }
.app-card-head img { border-radius: 10px; flex: none; }
.app-card p { margin: 0; }
.ok-text { color: var(--ok); font-weight: 600; margin-inline-end: 10px; }
.warn-text { color: var(--warn); }

.row-form { margin: 0; border-bottom: 1px solid var(--line); }
.row-form:last-child { border-bottom: 0; }
.row-form .row { width: 100%; border: 0; background: none; font: inherit; text-align: start; cursor: pointer; }
.field-label { display: block; font-weight: 600; margin-bottom: 6px; }
.wide-input { width: 100%; padding: 10px 12px; margin-bottom: 4px; }
.page > .btn.wide { display: block; text-align: center; margin-bottom: 12px; }
