:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --bg2: var(--tg-theme-secondary-bg-color, #0f1620);
  --text: var(--tg-theme-text-color, #eef2f6);
  --hint: var(--tg-theme-hint-color, #8b9aa8);
  --link: var(--tg-theme-link-color, #5fb6ff);
  --btn: var(--tg-theme-button-color, #2ea6ff);
  --btn-text: var(--tg-theme-button-text-color, #06121d);
  --line: rgba(255, 255, 255, 0.09);
  --card: rgba(255, 255, 255, 0.05);
  --ok: #35d07f;
  --warn: #f5a623;
  --danger: #ff5c5c;
  --r: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, "SF Pro Text", Roboto, "Segoe UI", sans-serif;
  min-height: 100%;
  overscroll-behavior-y: none;
}

#app { padding-bottom: calc(78px + env(safe-area-inset-bottom)); min-height: 100vh; }
.hidden { display: none !important; }

/* ---------- header ---------- */
.head {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.head h1 { margin: 0; font-size: 19px; letter-spacing: -0.2px; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--hint); }
.head-left { display: flex; align-items: center; gap: 8px; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #2ea6ff, #8b5cf6);
  background-size: cover; background-position: center;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff;
  flex: 0 0 auto;
}
.avatar.big { width: 56px; height: 56px; font-size: 19px; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--card); border: 0; color: var(--text);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */
main { padding: 14px 16px 0; }
.view > * + * { margin-top: 14px; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.gap { gap: 8px; margin-top: 14px; }
.center { text-align: center; }

.field { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.field label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 8px; }
.field-head label { margin-bottom: 8px; }
.hint { font-size: 11.5px; color: var(--hint); font-weight: 400; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--hint); }

.input {
  width: 100%; margin-top: 8px;
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; font-size: 15px; outline: none;
}
.input:focus { border-color: var(--btn); }
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 11px 14px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: transform 0.08s ease, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--btn); color: var(--btn-text); border-color: transparent; }
.btn.full { width: 100%; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn:disabled { opacity: 0.45; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chipbox { display: flex; flex-wrap: wrap; gap: 6px; }
.chipbox:empty { display: none; }
.chips button, .chip {
  border: 1px solid var(--line); background: var(--bg2); color: var(--text);
  border-radius: 999px; padding: 7px 12px; font-size: 13px; cursor: pointer;
}
.chips button.on { background: var(--btn); color: var(--btn-text); border-color: transparent; }
.chip.removable::after { content: " ×"; opacity: 0.6; }
.swatches button { padding-left: 26px; position: relative; }
.swatches button::before {
  content: ""; position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  width: 11px; height: 11px; border-radius: 50%; background: var(--dot, #888);
  border: 1px solid rgba(255, 255, 255, 0.35);
}

/* ---------- suggestions ---------- */
.suggest {
  margin-top: 6px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg2); overflow: hidden;
}
.suggest button {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  color: var(--text); padding: 10px 12px; font-size: 14px; cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.suggest button:last-child { border-bottom: 0; }
.suggest small { color: var(--hint); float: right; }

/* ---------- segmented ---------- */
.seg { display: flex; gap: 4px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg button {
  flex: 1; border: 0; background: none; color: var(--hint);
  padding: 7px 4px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.seg button.on { background: var(--btn); color: var(--btn-text); }

/* ---------- presets ---------- */
.presets { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.presets button { border: 1px dashed var(--line); background: none; color: var(--hint); border-radius: 999px; padding: 6px 11px; font-size: 12.5px; cursor: pointer; }

/* ---------- switch ---------- */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px; font-size: 14px; cursor: pointer;
}
.switch-row input { display: none; }
.switch { width: 44px; height: 26px; border-radius: 999px; background: #3a4652; position: relative; flex: 0 0 auto; transition: background 0.18s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.18s; }
.switch-row input:checked + .switch { background: var(--ok); }
.switch-row input:checked + .switch::after { transform: translateX(18px); }

/* ---------- cards d'annonce ---------- */
.item {
  display: flex; gap: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px; text-decoration: none; color: inherit;
}
.item img { width: 68px; height: 86px; object-fit: cover; border-radius: 9px; background: var(--bg2); flex: 0 0 auto; }
.item .t { font-size: 13.5px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .meta { font-size: 12px; color: var(--hint); margin-top: 4px; }
.item .price { font-size: 14px; font-weight: 700; margin-top: 6px; color: var(--ok); }

/* ---------- alerte ---------- */
.alert { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.alert-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.alert h3 { margin: 0; font-size: 15px; }
.alert .filters { font-size: 12px; color: var(--hint); margin-top: 4px; line-height: 1.5; }
.alert .actions { display: flex; gap: 8px; margin-top: 10px; }
.alert .actions .btn { padding: 8px 11px; font-size: 12.5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-top: 6px; flex: 0 0 auto; }
.dot.off { background: var(--warn); }
.alert-meta { font-size: 11.5px; color: var(--hint); margin-top: 8px; }

/* ---------- carte bancaire ---------- */
.bankcard {
  border-radius: 18px; padding: 18px; color: #fff;
  background: linear-gradient(135deg, #1f6feb, #7b3fe4 60%, #d946ef);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  min-height: 148px; display: flex; flex-direction: column; justify-content: space-between;
}
.bankcard-top { display: flex; justify-content: space-between; font-size: 12px; letter-spacing: 2px; opacity: 0.9; }
.bankcard-num { font-size: 19px; letter-spacing: 2.5px; font-family: ui-monospace, Menlo, monospace; }
.bankcard-bottom { display: flex; gap: 26px; font-size: 12px; }
.bankcard-bottom small { display: block; opacity: 0.7; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; }
.card-form { display: flex; flex-direction: column; gap: 8px; }

/* ---------- profil / stats ---------- */
.profile { display: flex; align-items: center; gap: 14px; }
.profile h2 { margin: 0; font-size: 18px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.stats b { display: block; font-size: 20px; }
.stats small { color: var(--hint); font-size: 11px; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; gap: 2px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg2) 92%, transparent);
  backdrop-filter: blur(16px); border-top: 1px solid var(--line);
}
.tab {
  flex: 1; border: 0; background: none; color: var(--hint);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10.5px; padding: 6px 0; border-radius: 12px; cursor: pointer;
}
.tab svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab.on { color: var(--link); }

/* ---------- divers ---------- */
.empty { text-align: center; padding: 46px 10px; }
.empty-emoji { font-size: 40px; }
.empty h2 { margin: 8px 0 4px; font-size: 17px; }
.empty p { color: var(--hint); font-size: 13px; margin: 0 0 16px; }

.preview-field .badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.area { resize: vertical; min-height: 74px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.help summary { font-size: 12px; color: var(--link); cursor: pointer; margin-top: 8px; }
.help p { margin: 6px 0 0; }
.help code { background: var(--bg2); padding: 1px 4px; border-radius: 4px; }
.item .score { font-size: 11.5px; color: var(--warn); margin-top: 4px; }
.idbox { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-top: 8px; font-size: 12.5px; }
.idbox code { color: var(--link); font-family: ui-monospace, Menlo, monospace; }
.btn.mini { padding: 5px 9px; font-size: 11.5px; border-radius: 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #000d; color: #fff; padding: 11px 16px; border-radius: 999px;
  font-size: 13px; z-index: 60; max-width: 84vw; text-align: center;
  animation: in 0.18s ease;
}
@keyframes in { from { opacity: 0; transform: translate(-50%, 8px); } }
