:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #16191f;
  --muted: #5f6b7a;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-soft: #e3f4f2;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --warn: #a15c00;
  --warn-soft: #fff3df;
  --info: #1d5fbf;
  --info-soft: #e8f0fd;
  --ok: #1b7f3b;
  --ok-soft: #e5f5ea;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1e232b;
    --border: #2a313b;
    --text: #e8ebef;
    --muted: #9aa5b1;
    --accent: #2bb3a3;
    --accent-hover: #3fc6b6;
    --accent-soft: #12302d;
    --danger: #ff6b6b;
    --danger-soft: #3a1c1c;
    --warn: #f0b350;
    --warn-soft: #3a2c14;
    --info: #79a8ff;
    --info-soft: #1a2740;
    --ok: #5fd28a;
    --ok-soft: #16301f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.app { max-width: 960px; margin: 0 auto; padding: 0 16px 48px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 0; margin-bottom: 8px; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; text-decoration: none; color: var(--text); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 20px; height: 20px; }

h1 { font-size: 22px; margin: 18px 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0 0 8px; }
.sub { color: var(--muted); margin: 0 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 550; white-space: nowrap;
  text-decoration: none; color: var(--text); min-height: 38px;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 4px 10px; min-height: 32px; font-size: 13px; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.trainer-card { display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: inherit; }
.trainer-card:hover { border-color: var(--accent); }
.trainer-card .name { font-weight: 650; font-size: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.add-card {
  display: grid; place-items: center; min-height: 150px; border: 1.5px dashed var(--border);
  border-radius: var(--radius); color: var(--muted); background: transparent; cursor: pointer; font-weight: 550;
}
.add-card:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }

/* ---------- trainer page ---------- */
.back { display: inline-flex; align-items: center; gap: 4px; margin-top: 14px; color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--text); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin-bottom: 6px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab {
  padding: 10px 14px; border: none; background: none; cursor: pointer; color: var(--muted);
  font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- clients ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .search { flex: 1 1 200px; }
.stats { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.stats b { color: var(--text); }
.list { display: flex; flex-direction: column; gap: 8px; }
.client {
  display: grid; gap: 6px 16px; align-items: center;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1.3fr) auto;
  padding: 12px 14px;
}
.client.paused { opacity: 0.6; }
.client .who { min-width: 0; }
.client .who .n { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client .who .p { color: var(--muted); font-size: 13px; }
.client .meta-label { color: var(--muted); font-size: 12px; display: none; }
.client .actions { display: flex; gap: 4px; justify-content: flex-end; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.list-head {
  display: grid; gap: 16px; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1.3fr) auto;
  padding: 0 14px; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
}
.list-head span:last-child { width: 170px; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-weight: 600; font-size: 14px; }
.field .hint { color: var(--muted); font-size: 12.5px; }
.input, textarea.input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
}
textarea.input { min-height: 250px; resize: vertical; line-height: 1.45; }
.two { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.preview {
  white-space: pre-wrap; background: var(--accent-soft); border-radius: 10px 10px 10px 2px;
  padding: 10px 12px; font-size: 14px; max-width: 420px;
}
.preview b { font-weight: 700; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.danger-zone { border-color: var(--danger-soft); margin-top: 18px; }
.error-text { color: var(--danger); font-size: 14px; }

/* ---------- WhatsApp ---------- */
.wa { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr) auto; align-items: start; }
.qr { background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--border); }
.qr img { display: block; width: 260px; height: 260px; }
.steps { margin: 8px 0 0; padding-left: 20px; }
.steps li { margin-bottom: 4px; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; display: inline-block; vertical-align: -4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- history ---------- */
.hist { display: flex; gap: 12px; padding: 10px 14px; align-items: flex-start; }
.hist .icon { width: 24px; flex: none; text-align: center; }
.hist .body { flex: 1; min-width: 0; }
.hist .time { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.preview-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
details summary { cursor: pointer; font-weight: 600; }

/* ---------- empty / login ---------- */
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 6px; }
.login { max-width: 360px; margin: 12vh auto 0; }
.login .brand { justify-content: center; margin-bottom: 18px; font-size: 20px; }
.banner { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- modal & toast ---------- */
.modal {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal::backdrop { background: rgba(15, 18, 22, 0.45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 550;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------- phones ---------- */
@media (max-width: 680px) {
  .list-head { display: none; }
  .client { grid-template-columns: 1fr auto; }
  .client .when { grid-column: 1 / -1; grid-row: 2; }
  .client .adm { display: none; }
  .client .actions { grid-column: 2; grid-row: 1; }
  .wa { grid-template-columns: 1fr; }
  .qr img { width: 100%; height: auto; max-width: 280px; margin: 0 auto; }
  .two { grid-template-columns: 1fr; }
  h1 { font-size: 20px; }
  .tab { padding: 10px 9px; font-size: 14px; }
}
.section-title { margin: 22px 0 10px; }
