/* FAMORE · WhatsApp — тёплый нейтральный фон, графит, один оранжевый акцент */
:root {
  --bg: #f4f2ee; --surface: #fffefc; --sunk: #ebe8e2; --line: #dedad2; --line-2: #cbc6bc;
  --ink: #12110f; --ink-2: #4a4741; --ink-3: #7c776e;
  --accent: #ff5b1f; --accent-ink: #c2410c; --accent-soft: #fff0e8;
  --ok: #15803d; --ok-soft: #e8f5ec; --warn: #a16207; --warn-soft: #fbf4dd; --err: #b42318; --err-soft: #fdecea;
  --radius: 10px; --radius-s: 7px;
  --shadow: 0 1px 2px rgba(18,17,15,.05), 0 8px 24px -12px rgba(18,17,15,.18);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --t-fast: 120ms; --t: 200ms; --ease: cubic-bezier(.2,.7,.2,1);
  --side: 232px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 26px; line-height: 1.2; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.boot { display: grid; place-items: center; height: 100vh; color: var(--ink-3); letter-spacing: .2em; font-size: 12px; text-transform: uppercase; }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #e9e6e0; padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 22px; }
.brand { display: flex; align-items: baseline; gap: 8px; padding: 0 10px; }
.brand b { font-weight: 700; letter-spacing: .22em; font-size: 14px; }
.brand b i { font-style: normal; color: var(--accent); }
.brand span { font-size: 12px; color: #9a958c; letter-spacing: .06em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-s); text-decoration: none; color: #bcb7ad; transition: background var(--t-fast), color var(--t-fast); }
.nav a:hover { background: #1f1d1a; color: #fff; }
.nav a[aria-current="page"] { background: #24211d; color: #fff; }
.nav a[aria-current="page"] svg { color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .badge { margin-left: auto; }
.side-foot { margin-top: auto; padding: 0 10px; font-size: 12px; color: #8f8a80; display: grid; gap: 6px; }
.side-foot .stat { display: flex; justify-content: space-between; }
.side-foot .stat b { color: #e9e6e0; font-weight: 600; }

.main { min-width: 0; padding: 28px clamp(16px, 3vw, 40px) 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.tabbar { display: none; }

/* ---------- элементы ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; padding: 0 14px; border-radius: var(--radius-s);
  border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; text-decoration: none; font-weight: 550; font-size: 14px; white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast); }
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #2a2723; }
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.accent:hover { background: #f04d12; }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); background: var(--err-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--sunk); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn[disabled], .btn[aria-busy="true"] { opacity: .5; pointer-events: none; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { width: 36px; padding: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-pad { padding: 18px 20px; }
.stack { display: grid; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.sep { height: 1px; background: var(--line); margin: 4px 0; }

.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; }
.pill { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--sunk); color: var(--ink-2); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.err { background: var(--err-soft); color: var(--err); }
.pill.acc { background: var(--accent-soft); color: var(--accent-ink); }
.pill.plain::before { display: none; }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.metric { padding: 14px 16px; box-shadow: 1px 0 0 var(--line), 0 1px 0 var(--line); }
.metric b { display: block; font-size: 24px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.metric span { font-size: 12px; color: var(--ink-3); }

.bar { height: 6px; background: var(--sunk); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ink); border-radius: 3px; transition: width var(--t) var(--ease); }
.bar.accent > i { background: var(--accent); }

/* ---------- формы ---------- */
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.hint { font-size: 12px; color: var(--ink-3); }
.input, .select, .textarea { width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--line-2); border-radius: var(--radius-s); background: var(--surface);
  transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(255,91,31,.18); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--err); }
.textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.err-text { color: var(--err); font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; padding: 6px 0; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--ink); flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border: 1px solid var(--line-2); border-radius: 99px; cursor: pointer; font-size: 14px; background: var(--surface); }
.chip:has(input:checked) { border-color: var(--ink); background: var(--ink); color: #fff; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line-2); }
.chip .dot.on { background: #22c55e; }
.drop { border: 1.5px dashed var(--line-2); border-radius: var(--radius); padding: 22px; text-align: center; background: var(--bg); cursor: pointer; transition: border-color var(--t-fast), background var(--t-fast); }
.drop svg { width: 26px; height: 26px; color: var(--ink-3); }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }

.samples { display: grid; gap: 8px; }
.bubble-sample { background: #e7f7dc; border-radius: 10px 10px 10px 2px; padding: 8px 12px; font-size: 14px; white-space: pre-wrap; max-width: 520px; }
.note { padding: 12px 14px; border-radius: var(--radius-s); background: var(--sunk); font-size: 13px; color: var(--ink-2); }
.note.warn { background: var(--warn-soft); color: #6b4a06; }
.note.err { background: var(--err-soft); color: var(--err); }
.note ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- номера ---------- */
.acc-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.acc { display: grid; gap: 14px; padding: 18px; }
.acc-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.acc-top > div:first-child { min-width: 0; }
.acc-phone { font-size: 20px; font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.acc .err-text { font-size: 12px; }
.acc-foot { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
.t th { text-align: left; font-weight: 600; font-size: 12px; color: var(--ink-3); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.t tr:last-child td { border-bottom: 0; }
.t tr.click { cursor: pointer; }
.t tr.click:hover td { background: #faf8f4; }
.t .msg-cell { max-width: 420px; color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; }

.seg { display: inline-flex; background: var(--sunk); border-radius: var(--radius-s); padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 5px; cursor: pointer; font-size: 13px; font-weight: 550; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- диалоги ---------- */
.inbox { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 140px); min-height: 480px; overflow: hidden; }
.inbox-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.inbox-tools { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.chat-list { overflow-y: auto; flex: 1; }
.chat-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); text-decoration: none; }
.chat-item:hover { background: #faf8f4; }
.chat-item[aria-current="true"] { background: var(--accent-soft); }
.chat-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .time { font-size: 12px; color: var(--ink-3); }
.chat-item .last { font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item.unread .last { color: var(--ink); font-weight: 550; }
.thread { display: flex; flex-direction: column; min-height: 0; background: #efeae2; }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.thread-head .back { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 18px clamp(12px, 3vw, 40px); display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(560px, 82%); padding: 7px 10px 5px; border-radius: 10px; background: #fff; box-shadow: 0 1px .5px rgba(0,0,0,.1); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; }
.msg.me { align-self: flex-end; background: #d9fdd3; border-top-right-radius: 3px; }
.msg.them { align-self: flex-start; border-top-left-radius: 3px; }
.msg .meta { display: block; text-align: right; font-size: 11px; color: var(--ink-3); margin-top: 2px; }
.msg .meta .tick.read { color: #2563eb; }
.day-sep { align-self: center; font-size: 12px; background: rgba(255,255,255,.85); padding: 3px 10px; border-radius: 7px; color: var(--ink-2); margin: 8px 0; }
.composer { display: flex; gap: 8px; padding: 10px 12px; background: var(--surface); border-top: 1px solid var(--line); align-items: flex-end; }
.composer .textarea { min-height: 42px; max-height: 160px; resize: none; }
.empty { display: grid; place-items: center; text-align: center; padding: 48px 20px; color: var(--ink-3); gap: 12px; }
.empty h3 { color: var(--ink); }

/* ---------- окна ---------- */
dialog.modal { border: 0; padding: 0; border-radius: 14px; width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px -20px rgba(0,0,0,.45); }
dialog.modal::backdrop { background: rgba(18,17,15,.5); }
dialog.modal[open] { animation: pop var(--t) var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 0; }
.modal-body { padding: 16px 20px 20px; display: grid; gap: 14px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 20px; }
.qr-box { display: grid; place-items: center; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-height: 280px; }
.qr-box img { width: 260px; height: 260px; image-rendering: pixelated; }
.pair-code { font-family: var(--mono); font-size: 34px; letter-spacing: .18em; font-weight: 700; text-align: center; padding: 18px; background: var(--sunk); border-radius: var(--radius); }
ol.steps { margin: 0; padding-left: 20px; display: grid; gap: 4px; font-size: 14px; color: var(--ink-2); }

/* ---------- вход ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--ink); }
.auth-card { width: min(400px, 100%); background: var(--surface); border-radius: 16px; padding: 30px; display: grid; gap: 18px; }
.auth-card .brand b { color: var(--ink); }
.auth-card .brand { padding: 0; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity var(--t), transform var(--t) var(--ease); z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--err); }

.skeleton { background: linear-gradient(90deg, var(--sunk), #f3f0eb, var(--sunk)); background-size: 200% 100%; animation: sk 1.2s infinite linear; border-radius: 6px; height: 14px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- мобильная версия ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 18px 14px calc(84px + env(safe-area-inset-bottom)); }
  h1 { font-size: 22px; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--ink); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { display: grid; justify-items: center; gap: 2px; padding: 6px 0; color: #a7a298; text-decoration: none; font-size: 11px; position: relative; }
  .tabbar a[aria-current="page"] { color: #fff; }
  .tabbar a[aria-current="page"] svg { color: var(--accent); }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar .badge { position: absolute; top: 0; left: 50%; margin-left: 6px; height: 17px; min-width: 17px; font-size: 10px; }
  .mobile-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
  .inbox { grid-template-columns: 1fr; height: calc(100vh - 150px - env(safe-area-inset-bottom)); }
  .inbox.has-chat .inbox-list { display: none; }
  .inbox:not(.has-chat) .thread { display: none; }
  .thread-head .back { display: inline-flex; }
  .acc-list { grid-template-columns: 1fr; }
  .t .hide-m { display: none; }
  .btn { min-height: 42px; }
  .metrics { grid-template-columns: repeat(4, 1fr); }
  .metric { padding: 10px; }
  .metric b { font-size: 18px; }
  .metric span { font-size: 11px; }
  dialog.modal { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 16px 16px 0 0; }
}
@media (min-width: 861px) { .mobile-top { display: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
