/* =====================================================================
   Txt Buddy - interface styles
   Mobile-first: base rules are for phones, wider screens are layered on
   with min-width media queries. Nothing should ever scroll sideways.
   ===================================================================== */

/* Self-hosted fonts (no Google/CDN calls - faster and GDPR-friendly) */
@font-face { font-family: "Poppins"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/poppins-400.woff") format("woff"); }
@font-face { font-family: "Poppins"; font-style: normal; font-weight: 500 600; font-display: swap; src: url("../fonts/poppins-500.woff") format("woff"); }
@font-face { font-family: "Poppins"; font-style: normal; font-weight: 700 900; font-display: swap; src: url("../fonts/poppins-700.woff") format("woff"); }

:root {
  --bg: #f2f6fb;
  --surface: #ffffff;
  --surface-2: #f6f9fc;
  --surface-3: #eef3f8;
  --ink: #0e2236;
  --ink-2: #44596e;
  --ink-3: #7a8ea3;
  --line: #e1e9f1;
  --line-strong: #cfdbe7;

  --brand: #1592e6;
  --brand-strong: #0b75bf;
  --brand-ink: #075a95;
  --brand-soft: #e2f1fd;
  --sun: #ffc53d;
  --sun-strong: #e9a800;
  --sun-soft: #fff4d4;

  --ok: #15803d;   --ok-soft: #e3f6e9;
  --bad: #c62828;  --bad-soft: #fde8e8;
  --wait: #a35a00; --wait-soft: #fff1d9;
  --info: #0b6fb5; --info-soft: #e2f1fd;
  --muted-soft: #edf1f5;

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(14, 34, 54, .06);
  --shadow: 0 1px 2px rgba(14, 34, 54, .05), 0 6px 20px rgba(14, 34, 54, .06);
  --shadow-lg: 0 18px 50px rgba(14, 34, 54, .18);
  --focus: 0 0 0 3px rgba(21, 146, 230, .35);

  --header-h: 60px;
  --bottomnav-h: 64px;
  --sidebar-w: 256px;
  --safe-b: env(safe-area-inset-bottom, 0px);

  --font: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1622; --surface: #102131; --surface-2: #0d1c2a; --surface-3: #15293c;
    --ink: #e8f1fa; --ink-2: #a9bccf; --ink-3: #7690a8; --line: #1e3449; --line-strong: #2a4560;
    --brand: #3aa9f2; --brand-strong: #63bcf6; --brand-ink: #9bd3fa; --brand-soft: #12324b;
    --sun-soft: #3a2e0c; --ok: #4ade80; --ok-soft: #10301d; --bad: #f87171; --bad-soft: #3a1515;
    --wait: #fbbf24; --wait-soft: #35270a; --info: #7cc4f7; --info-soft: #12324b; --muted-soft: #1a2c3d;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    --shadow-lg: 0 18px 50px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a1622; --surface: #102131; --surface-2: #0d1c2a; --surface-3: #15293c;
  --ink: #e8f1fa; --ink-2: #a9bccf; --ink-3: #7690a8; --line: #1e3449; --line-strong: #2a4560;
  --brand: #3aa9f2; --brand-strong: #63bcf6; --brand-ink: #9bd3fa; --brand-soft: #12324b;
  --sun-soft: #3a2e0c; --ok: #4ade80; --ok-soft: #10301d; --bad: #f87171; --bad-soft: #3a1515;
  --wait: #fbbf24; --wait-soft: #35270a; --info: #7cc4f7; --info-soft: #12324b; --muted-soft: #1a2c3d;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  --shadow-lg: 0 18px 50px rgba(0,0,0,.5);
  color-scheme: dark;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.55;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
img, svg, video { max-width: 100%; height: auto; display: block; }
a { color: var(--brand-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 800; letter-spacing: -0.01em; }
p { margin: 0 0 .75em; }
code, kbd, pre { font-family: var(--mono); font-size: .9em; }
button { font: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
[hidden] { display: none !important; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; min-height: 100dvh; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 12px 0 16px;
  display: flex; align-items: center; gap: 12px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px); -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand-mini { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.topbar .brand-mini img { width: 34px; height: 34px; flex: none; }
.topbar .page-title { font-size: 1.12rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .actions { display: flex; align-items: center; gap: 6px; flex: none; }

.sidebar { display: none; }

.main {
  padding: 16px 16px calc(var(--bottomnav-h) + var(--safe-b) + 24px);
  max-width: 1240px; margin: 0 auto; width: 100%;
}

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  height: calc(var(--bottomnav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgba(14, 34, 54, .06);
}
.bottomnav a, .bottomnav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 0; padding: 6px 2px; border: 0; background: none; cursor: pointer;
  color: var(--ink-3); font-size: .72rem; font-weight: 700; text-decoration: none;
}
.bottomnav i { font-size: 1.2rem; }
.bottomnav .active { color: var(--brand-strong); }
.bottomnav .active i { transform: translateY(-1px); }
.bottomnav .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; font-size: clamp(.62rem, 2.75vw, .74rem); letter-spacing: -0.01em; }

@media (min-width: 1024px) {
  .sidebar {
    display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
    background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; z-index: 30;
  }
  .sidebar .logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; }
  .sidebar .logo img { width: 40px; height: 40px; }
  .sidebar .logo span { font-weight: 900; font-size: 1.35rem; color: var(--brand-strong); letter-spacing: -0.02em; }
  .sidebar nav { display: flex; flex-direction: column; gap: 4px; }
  .sidebar .nav-section { margin: 18px 10px 6px; font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
  .sidebar nav a {
    display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px;
    color: var(--ink-2); font-weight: 700; text-decoration: none;
  }
  .sidebar nav a i { width: 20px; text-align: center; color: var(--ink-3); }
  .sidebar nav a:hover { background: var(--surface-3); color: var(--ink); }
  .sidebar nav a.active { background: var(--brand-soft); color: var(--brand-ink); }
  .sidebar nav a.active i { color: var(--brand-strong); }
  .sidebar .account { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
  .sidebar .account .who { min-width: 0; flex: 1; }
  .sidebar .account .who strong { display: block; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sidebar .account .who small { color: var(--ink-3); font-size: .78rem; }

  .app { padding-left: var(--sidebar-w); }
  .topbar { padding-left: 28px; padding-right: 20px; height: 68px; }
  .topbar .brand-mini img { display: none; }
  .topbar .page-title { font-size: 1.35rem; }
  .topbar .menu-btn { display: none; }
  .main { padding: 28px 28px 48px; }
  .bottomnav { display: none; }
}

.avatar {
  width: 38px; height: 38px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: .95rem;
  background: var(--sun); color: #3a2a00;
}

/* ---------- Typography helpers ---------- */
.muted { color: var(--ink-2); }
.subtle { color: var(--ink-3); font-size: .875rem; }
.mono { font-family: var(--mono); }
.break { overflow-wrap: break-word; }
@media (max-width: 767.98px) { .break { overflow-wrap: anywhere; } }
.nowrap { white-space: nowrap; }
.text-ok { color: var(--ok); } .text-bad { color: var(--bad); }

/* ---------- Layout helpers ---------- */
.stack > * + * { margin-top: 16px; }
.stack > input[type="hidden"] + :not(input[type="hidden"]) { margin-top: 0; }
.stack-sm > * + * { margin-top: 10px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px)  { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 640px)  { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 900px)  { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .grid-dash { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); align-items: start; } }
.span-all { grid-column: 1 / -1; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); min-width: 0;
}
.card-body { padding: 16px; }
.card-head { padding: 14px 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 1.08rem; display: flex; align-items: center; gap: 10px; }
.card-head h2 .ico { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-strong); font-size: .95rem; }
.card-head .spacer { flex: 1; }
.card-foot { padding: 12px 16px; border-top: 1px solid var(--line); }
@media (min-width: 640px) {
  .card-body { padding: 22px; }
  .card-head { padding: 16px 22px; }
  .card-foot { padding: 14px 22px; }
}

/* Welcome / hero strip */
.hello {
  position: relative; overflow: hidden; border-radius: var(--radius-lg); padding: 18px;
  background: linear-gradient(135deg, var(--brand) 0%, #33b1f5 100%); color: #fff;
}
.hello h1 { font-size: 1.35rem; }
.hello h1, .hello .content p { color: #fff; }
.hello p { margin: 4px 0 0; opacity: .92; }
.hello .sun { position: absolute; right: -18px; top: -18px; width: 96px; height: 96px; border-radius: 50%; background: var(--sun); opacity: .9; }
.hello .sun::after { content: ""; position: absolute; inset: 22px; border-radius: 50%; background: rgba(255,255,255,.35); }
.hello .content { position: relative; padding-right: 70px; }
@media (min-width: 640px) { .hello { padding: 24px 28px; } .hello h1 { font-size: 1.6rem; } .hello .sun { width: 140px; height: 140px; right: -20px; top: -40px; } }

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.stat .k { font-size: .78rem; font-weight: 800; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: 6px; }
.stat .v { font-size: 1.6rem; font-weight: 900; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.ok .v { color: var(--ok); } .stat.bad .v { color: var(--bad); } .stat.wait .v { color: var(--wait); } .stat.brand .v { color: var(--brand-strong); }

/* ---------- Buttons ---------- */
.btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 800; font-size: .95rem; line-height: 1; cursor: pointer; text-decoration: none !important;
  transition: background .15s, border-color .15s, color .15s, transform .05s; white-space: nowrap;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(21,146,230,.28); }
.btn-primary:hover { background: var(--brand-strong); }
.btn-sun { background: var(--sun); color: #3a2a00; }
.btn-sun:hover { background: var(--sun-strong); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-soft { background: var(--brand-soft); color: var(--brand-ink); }
.btn-soft:hover { filter: brightness(.97); }
.btn-danger { background: var(--bad-soft); color: var(--bad); }
.btn-danger:hover { background: var(--bad); color: #fff; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: .85rem; border-radius: 10px; }
.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 36px; }
.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 52px; font-size: 1.02rem; border-radius: 14px; }
.btn-bare { background: none; border: 0; color: var(--ink-2); }
.btn-bare:hover { background: var(--surface-3); }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }
@media (min-width: 640px) { .btn-row > .btn { flex: 0 0 auto; } }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-weight: 800; font-size: .88rem; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.field > label .opt { font-weight: 600; color: var(--ink-3); font-size: .8rem; }
.hint { font-size: .8rem; color: var(--ink-3); }
.err { font-size: .82rem; color: var(--bad); font-weight: 700; }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 12px 14px;
  font: inherit; font-size: 16px; /* 16px stops iOS zooming in */
  color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line-strong); border-radius: 12px;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.input[readonly] { background: var(--surface-2); color: var(--ink-2); }
.input.is-invalid, .textarea.is-invalid { border-color: var(--bad); }
.textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.select {
  -webkit-appearance: none; appearance: none; padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%237a8ea3' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
input[type="datetime-local"].input { min-width: 0; }
.input-group { display: flex; gap: 8px; }
.input-group > .input, .input-group > .select { flex: 1; min-width: 0; }
.checkbox { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-weight: 600; }
.checkbox input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--brand); flex: none; }

/* Switch */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; cursor: pointer; }
.switch .txt { min-width: 0; }
.switch .txt strong { display: block; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { flex: none; width: 50px; height: 30px; border-radius: 30px; background: var(--line-strong); position: relative; transition: background .2s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }

/* Segmented control */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-3); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 10px; border-radius: 9px; font-weight: 800; font-size: .9rem; color: var(--ink-2); cursor: pointer; text-align: center; }
.segmented input:checked + label { background: var(--surface); color: var(--brand-ink); box-shadow: var(--shadow-sm); }
.segmented input:focus-visible + label { box-shadow: var(--focus); }

/* Recipient chips input */
.chips-input {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  min-height: 52px; padding: 7px 8px; border: 1.5px solid var(--line-strong); border-radius: 12px; background: var(--surface); cursor: text;
}
.chips-input:focus-within { border-color: var(--brand); box-shadow: var(--focus); }
.chips-input input { flex: 1 1 140px; min-width: 120px; border: 0; outline: 0; background: transparent; font: inherit; font-size: 16px; color: var(--ink); padding: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  min-height: 34px; padding: 0 6px 0 12px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; font-size: .88rem;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { width: 26px; height: 26px; border-radius: 50%; border: 0; background: transparent; color: inherit; cursor: pointer; display: grid; place-items: center; flex: none; }
.chip button:hover { background: rgba(0,0,0,.08); }
.chip.invalid { background: var(--bad-soft); color: var(--bad); }

/* Composer tools */
.tools { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tools::-webkit-scrollbar { display: none; }
.tools .btn { flex: none; }
.meter { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--surface-3); color: var(--ink-2); font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.pill.warn { background: var(--wait-soft); color: var(--wait); }

/* ---------- Alerts / toasts ---------- */
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 12px; font-weight: 600; font-size: .93rem; border: 1px solid transparent; }
.alert i { margin-top: 3px; }
.alert > div { min-width: 0; overflow-wrap: anywhere; }
.alert-success, .alert-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-error, .alert-bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.alert-warning { background: var(--wait-soft); color: var(--wait); border-color: color-mix(in srgb, var(--wait) 25%, transparent); }
.alert-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.alerts { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.toasts { position: fixed; z-index: 200; left: 12px; right: 12px; bottom: calc(var(--bottomnav-h) + var(--safe-b) + 12px); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
@media (min-width: 1024px) { .toasts { left: auto; right: 24px; bottom: 24px; width: 380px; } }
.toast { pointer-events: auto; box-shadow: var(--shadow-lg); animation: toast-in .25s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: .78rem; font-weight: 800; white-space: nowrap; }
.badge i { font-size: .75rem; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-wait { background: var(--wait-soft); color: var(--wait); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: var(--muted-soft); color: var(--ink-2); }
.badge-sun { background: var(--sun-soft); color: #7a5800; }
:root[data-theme="dark"] .badge-sun { color: var(--sun); }

.gw { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 700; color: var(--ink-2); }
.gw i { color: var(--brand-strong); }

/* ---------- Responsive tables -> cards on phones ---------- */
.table-wrap { width: 100%; }
.rtable { width: 100%; border-collapse: collapse; font-size: .93rem; }
.rtable th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 800; padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.rtable td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: top; min-width: 0; }
.rtable tr:last-child td { border-bottom: 0; }
.rtable .msg-text { max-width: 46ch; overflow-wrap: anywhere; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.rtable .actions-cell { text-align: right; white-space: nowrap; }
.rtable .actions-cell .btn + .btn { margin-left: 6px; }

@media (max-width: 767.98px) {
  .rtable, .rtable tbody, .rtable tr, .rtable td { display: block; width: 100%; }
  .rtable thead { display: none; }
  .rtable tr { padding: 14px 16px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 12px; }
  .rtable tr:last-child { border-bottom: 0; }
  .rtable td { padding: 0; border: 0; }
  .rtable td[data-label]::before { content: attr(data-label); display: block; font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-bottom: 2px; }
  .rtable td.cell-main { grid-column: 1 / 2; }
  .rtable td.cell-side { grid-column: 2 / 3; grid-row: 1; text-align: right; justify-self: end; }
  .rtable td.cell-full { grid-column: 1 / -1; }
  .rtable td.cell-full[data-label]::before { display: none; }
  .rtable td.cell-half { grid-column: span 1; }
  .rtable .msg-text { max-width: none; -webkit-line-clamp: 4; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 4px 0; }
  .rtable .actions-cell { grid-column: 1 / -1; text-align: left; display: flex; gap: 8px; padding-top: 6px; }
  .rtable .actions-cell .btn { flex: 1; }
  .rtable .actions-cell .btn + .btn { margin-left: 0; }
}

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.pager .pages { display: flex; gap: 6px; flex-wrap: wrap; }
.pager .page { min-width: 40px; height: 40px; padding: 0 8px; display: inline-grid; place-items: center; border-radius: 10px; font-weight: 800; color: var(--ink-2); border: 1px solid var(--line); background: var(--surface); text-decoration: none; }
.pager .page:hover { background: var(--surface-3); text-decoration: none; }
.pager .page.current { background: var(--brand); color: #fff; border-color: var(--brand); }
.pager .page.disabled { opacity: .45; pointer-events: none; }
@media (max-width: 639.98px) { .pager .pages .num:not(.current) { display: none; } .pager { justify-content: center; } .pager .summary { width: 100%; text-align: center; } }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 36px 16px; color: var(--ink-2); }
.empty .ico { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 20px; display: grid; place-items: center; font-size: 1.6rem; background: var(--brand-soft); color: var(--brand-strong); }
.empty h3 { font-size: 1.05rem; color: var(--ink); margin-bottom: 4px; }

/* ---------- Lists (templates / contacts / sheets) ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); min-width: 0; }
.list > li:last-child { border-bottom: 0; }
.list .body { min-width: 0; flex: 1; }
.list .title { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { color: var(--ink-2); font-size: .88rem; overflow-wrap: anywhere; }
.list .sub.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.list .tail { flex: none; display: flex; gap: 6px; }
.list-pick > li { cursor: pointer; }
.list-pick > li:hover { background: var(--surface-2); }
@media (min-width: 640px) { .list > li { padding: 14px 22px; } }

.search { position: relative; }
.search i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search .input { padding-left: 40px; }

/* ---------- Modal: bottom sheet on phones, dialog on desktop ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal .scrim { position: absolute; inset: 0; background: rgba(8, 20, 33, .55); animation: fade .2s; }
.modal .sheet {
  position: relative; width: 100%; max-height: 92vh; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 22px 22px 0 0; box-shadow: var(--shadow-lg);
  padding-bottom: var(--safe-b); animation: sheet-up .25s ease-out;
}
.modal .sheet::before { content: ""; width: 40px; height: 5px; border-radius: 5px; background: var(--line-strong); margin: 8px auto 0; flex: none; }
.modal .sheet-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px 12px; border-bottom: 1px solid var(--line); }
.modal .sheet-head h3 { font-size: 1.1rem; flex: 1; min-width: 0; }
.modal .sheet-body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal .sheet-body.flush { padding: 0; }
.modal .sheet-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.modal .sheet-foot .btn { flex: 1; }
@media (min-width: 640px) {
  .modal { align-items: center; padding: 24px; }
  .modal .sheet { max-width: 560px; border-radius: 20px; max-height: 86vh; animation: pop .2s ease-out; }
  .modal .sheet::before { display: none; }
  .modal .sheet-head { padding: 16px 20px; }
  .modal .sheet-body { padding: 20px; }
  .modal .sheet-foot { padding: 14px 20px; justify-content: flex-end; }
  .modal .sheet-foot .btn { flex: 0 0 auto; }
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
body.modal-open { overflow: hidden; }

/* More menu sheet items */
.menu-list a, .menu-list button {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 16px; border: 0; background: none;
  color: var(--ink); font-weight: 700; text-align: left; text-decoration: none; cursor: pointer; border-radius: 12px; min-height: 52px;
}
.menu-list a:hover, .menu-list button:hover { background: var(--surface-3); }
.menu-list i { width: 22px; text-align: center; color: var(--brand-strong); }
.menu-list .danger, .menu-list .danger i { color: var(--bad); }

/* ---------- Balances ---------- */
.balances { display: flex; flex-direction: column; gap: 8px; }
.balance { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); min-width: 0; }
.balance .name { flex: 1 1 auto; min-width: 7em; font-weight: 700; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.balance .val { font-weight: 900; font-variant-numeric: tabular-nums; margin-left: auto; text-align: right; overflow-wrap: anywhere; }
.balance .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.balance.bad .dot { background: var(--bad); }
.balance.bad .val { color: var(--ink-3); font-weight: 700; font-size: .85rem; }

/* ---------- Auth pages ---------- */
.auth {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(1200px 500px at 110% -10%, rgba(255,197,61,.35), transparent 60%),
    radial-gradient(900px 500px at -20% 110%, rgba(21,146,230,.25), transparent 60%),
    var(--bg);
}
.auth-card { width: 100%; max-width: 440px; }
.auth-card.wide { max-width: 760px; }
.auth-logo { display: block; width: 150px; margin: 0 auto 18px; }
.auth-card .card-body { padding: 22px; }
@media (min-width: 640px) { .auth-card .card-body { padding: 32px; } }
.auth-card h1 { font-size: 1.45rem; text-align: center; }
.auth-card .lead { text-align: center; color: var(--ink-2); margin: 6px 0 22px; }
.auth-foot { text-align: center; margin-top: 18px; color: var(--ink-2); font-size: .92rem; }
.code-input { text-align: center; letter-spacing: .5em; font-size: 1.5rem !important; font-weight: 800; font-family: var(--mono); }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 52px; }
.pw-wrap .toggle-pw { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }

/* ---------- Docs ---------- */
.doc h2 { font-size: 1.25rem; margin: 6px 0 10px; }
.doc h3 { font-size: 1.02rem; margin: 18px 0 8px; }
.doc p, .doc li { color: var(--ink-2); }
.doc pre { background: #0d1b2a; color: #d7e7f7; padding: 14px 16px; border-radius: 12px; overflow-x: auto; font-size: .84rem; line-height: 1.55; max-width: 100%; -webkit-overflow-scrolling: touch; }
.doc code:not(pre code) { background: var(--surface-3); padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere; }
.method { display: inline-block; padding: 3px 9px; border-radius: 8px; font-weight: 900; font-size: .75rem; letter-spacing: .04em; color: #fff; }
.method.post { background: var(--ok); } .method.get { background: var(--brand); }
.endpoint { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); font-family: var(--mono); font-size: .88rem; overflow-wrap: anywhere; }
.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin-bottom: 8px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; min-height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 800; color: var(--ink-2); cursor: pointer; }
.tabs button.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.toc { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; }
.toc::-webkit-scrollbar { display: none; }
.toc a { flex: none; }

/* Video recorder */
.recorder video { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #0b1724; border-radius: 14px; }
.rec-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--bad); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* Loader */
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--brand-soft); border-top-color: var(--brand); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 10px; height: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Footer */
.footer { text-align: center; color: var(--ink-3); font-size: .8rem; padding: 24px 0 0; }

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

/* Small-screen utilities */
@media (max-width: 639.98px) {
  .hide-sm { display: none !important; }
  .segmented label { padding: 0 6px; font-size: .84rem; gap: 6px; }
}
@media (min-width: 640px) { .show-sm { display: none !important; } }
.switch .txt .subtle { display: block; font-weight: 500; }
.switch .txt strong { font-weight: 800; }

/* Collapsible cards (settings) */
details.card.fold > summary { list-style: none; cursor: pointer; border-bottom: 1px solid transparent; }
details.card.fold > summary::-webkit-details-marker { display: none; }
details.card.fold[open] > summary { border-bottom-color: var(--line); }
details.card.fold .fold-chev { color: var(--ink-3); transition: transform .2s; }
details.card.fold[open] .fold-chev { transform: rotate(180deg); }
.section-title { font-size: 1.15rem; margin-top: 12px !important; }
.hook-box { border: 1px dashed var(--line-strong); border-radius: 12px; padding: 4px 12px; background: var(--surface-2); }

/* Unread badges */
.nav-badge { margin-left: auto; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--bad); color: #fff; font-size: .72rem; font-weight: 800; display: inline-grid; place-items: center; }
.bottomnav .ico-wrap { position: relative; display: inline-block; }
.dot-badge { position: absolute; top: -6px; right: -12px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: .64rem; font-weight: 800; display: grid; place-items: center; border: 2px solid var(--surface); }

/* Inbox + conversation */
.convo-list > li { cursor: pointer; }
.convo-list > li.unread .title { color: var(--ink); }
.convo-list > li.unread .sub { color: var(--ink); font-weight: 700; }
.convo-list .when { font-size: .75rem; color: var(--ink-3); white-space: nowrap; }
.convo-list .count { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--brand); color: #fff; font-size: .72rem; font-weight: 800; display: inline-grid; place-items: center; }
.thread { display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.bubble-row { display: flex; flex-direction: column; max-width: 82%; }
.bubble-row.out { align-self: flex-end; align-items: flex-end; }
.bubble-row.in { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 10px 14px; border-radius: 18px; overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.45; }
.bubble-row.out .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 6px; }
.bubble-row.in .bubble { background: var(--surface-3); color: var(--ink); border-bottom-left-radius: 6px; }
.bubble-row.out.failed .bubble { background: var(--bad-soft); color: var(--bad); }
.bubble-meta { font-size: .72rem; color: var(--ink-3); margin-top: 3px; padding: 0 6px; display: flex; gap: 6px; align-items: center; }
.day-sep { align-self: center; font-size: .72rem; font-weight: 800; color: var(--ink-3); background: var(--surface-2); border: 1px solid var(--line); padding: 3px 10px; border-radius: 999px; margin: 6px 0; }
.reply-bar { position: sticky; bottom: calc(var(--bottomnav-h) + var(--safe-b)); z-index: 20; background: var(--surface); border-top: 1px solid var(--line); padding: 10px 12px; display: flex; gap: 8px; align-items: flex-end; border-radius: 0 0 var(--radius) var(--radius); }
.reply-bar .textarea { min-height: 48px; max-height: 160px; resize: none; }
@media (min-width: 1024px) { .reply-bar { bottom: 0; } }
.keyword { display: inline-flex; align-items: center; gap: 4px; font-size: .7rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: var(--wait-soft); color: var(--wait); }
.chips-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips-row::-webkit-scrollbar { display: none; }
.chip-btn { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); font-weight: 700; font-size: .86rem; text-decoration: none !important; cursor: pointer; white-space: nowrap; }
.chip-btn .n { font-size: .74rem; color: var(--ink-3); }
.chip-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip-btn.active .n { color: rgba(255,255,255,.8); }
.chip-btn.danger.active { background: var(--bad); border-color: var(--bad); }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-ink); margin: 2px 4px 0 0; }
.tag.bad { background: var(--bad-soft); color: var(--bad); }

/* Improve with AI */
.chip-btn.on, .chip-btn[aria-pressed="true"] { background: var(--brand-soft, var(--surface-3)); border-color: var(--brand, var(--line-strong)); color: var(--brand-ink, var(--ink)); }
.chip-btn:disabled { opacity: .6; cursor: default; }
#ai-result[aria-busy="true"] { opacity: .6; }

.ai-orig { margin-top: 4px; font-size: .8rem; color: var(--ink-3); }
.ai-orig summary { cursor: pointer; font-weight: 700; }
.ai-orig > div { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink-2); }
