/* =====================================================================
   Temas — cada tema só redefine as variáveis abaixo.
   O tema é escolhido no painel (padrão) e o visitante pode trocar.
   ===================================================================== */

/* Floresta (padrão de segurança quando o tema é desconhecido) */
:root,
[data-theme="floresta"] {
  --bg: #f6f4ee;
  --card: #ffffff;
  --ink: #1d2320;
  --muted: #5f6a63;
  --primary: #14532d;
  --primary-ink: #ffffff;
  --accent: #f2a516;
  --accent-ink: #2a1c00;
  --danger: #b42318;
  --danger-line: #f0c9c5;
  --line: #e2ded2;
  --soft: #ece8dc;
  --field: #ffffff;
  --field-line: #cfc9b9;

  --header-bg: #14532d;
  --header-ink: #ffffff;
  --header-line: #f2a516;
  --bar-bg: #1d2320;
  --bar-ink: #ffffff;

  --hero-bg: var(--card);
  --hero-ink: var(--ink);
  --hero-muted: var(--muted);
  --hero-value: var(--primary);
  --hero-line: var(--line);
  --hero-btn-bg: var(--primary);
  --hero-btn-ink: var(--primary-ink);

  --ok-bg: #dcf3e3;   --ok-ink: #0b3d1e;
  --warn-bg: #fdf0cf; --warn-ink: #5a3d00;
  --err-bg: #fde4e1;  --err-ink: #7a1a12;

  --shadow: 0 1px 2px rgba(20, 30, 24, .06), 0 8px 24px -12px rgba(20, 30, 24, .18);
  --backdrop: rgba(16, 24, 20, .6);
  color-scheme: light;
}

/* Brasil — verde, amarelo e azul da bandeira */
[data-theme="brasil"] {
  --bg: #f3f9ee;
  --card: #ffffff;
  --ink: #0d2a1a;
  --muted: #4d6355;
  --primary: #007a33;
  --primary-ink: #ffffff;
  --accent: #ffdf00;
  --accent-ink: #002776;
  --danger: #b42318;
  --danger-line: #f0c9c5;
  --line: #d6e6cc;
  --soft: #e4f1da;
  --field: #ffffff;
  --field-line: #b7cdaa;

  --header-bg: #007a33;
  --header-ink: #ffffff;
  --header-line: #ffdf00;
  --bar-bg: #002776;
  --bar-ink: #ffffff;

  --hero-bg: #002776;
  --hero-ink: #ffffff;
  --hero-muted: #b9c8ee;
  --hero-value: #ffdf00;
  --hero-line: #002776;
  --hero-btn-bg: #ffdf00;
  --hero-btn-ink: #002776;

  --ok-bg: #dcf3e3;   --ok-ink: #0b3d1e;
  --warn-bg: #fff5bf; --warn-ink: #4d3f00;
  --err-bg: #fde4e1;  --err-ink: #7a1a12;
  --backdrop: rgba(0, 24, 70, .6);
}

/* Oceano */
[data-theme="oceano"] {
  --bg: #eef5f9;
  --card: #ffffff;
  --ink: #12222d;
  --muted: #566a78;
  --primary: #0b4f7a;
  --primary-ink: #ffffff;
  --accent: #ff9f1c;
  --accent-ink: #2b1700;
  --line: #d5e3ec;
  --soft: #e2edf4;
  --field-line: #b3c8d6;

  --header-bg: #0b4f7a;
  --header-line: #ff9f1c;
  --bar-bg: #0c2b3f;

  --ok-bg: #d9f2ea;   --ok-ink: #07402f;
  --warn-bg: #ffecc9; --warn-ink: #5a3500;
  --backdrop: rgba(8, 28, 42, .6);
}

/* Pôr do sol */
[data-theme="por-do-sol"] {
  --bg: #fff6ee;
  --card: #ffffff;
  --ink: #2b1810;
  --muted: #7a5f52;
  --primary: #be3a1d;
  --primary-ink: #ffffff;
  --accent: #f5b942;
  --accent-ink: #3a2200;
  --line: #f1dccb;
  --soft: #fbe9d9;
  --field-line: #e2c4ad;

  --header-bg: #7a2412;
  --header-line: #f5b942;
  --bar-bg: #3a1a10;

  --ok-bg: #dff1df;   --ok-ink: #14401a;
  --backdrop: rgba(43, 20, 12, .6);
}

/* Noite */
[data-theme="noite"] {
  --bg: #0e1411;
  --card: #17201b;
  --ink: #e8f0ea;
  --muted: #9bab9f;
  --primary: #4ade80;
  --primary-ink: #052a12;
  --accent: #fbbf24;
  --accent-ink: #2a1c00;
  --danger: #ff8a80;
  --danger-line: #6b2b27;
  --line: #28352d;
  --soft: #22302a;
  --field: #101713;
  --field-line: #3a4b40;

  --header-bg: #0a0f0c;
  --header-ink: #e8f0ea;
  --header-line: #4ade80;
  --bar-bg: #0a0f0c;

  --ok-bg: #12351f;   --ok-ink: #a7f0c2;
  --warn-bg: #3a2f0d; --warn-ink: #ffe08a;
  --err-bg: #3d1a17;  --err-ink: #ffc2bb;

  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px -12px rgba(0, 0, 0, .6);
  --backdrop: rgba(0, 0, 0, .7);
  color-scheme: dark;
}

/* =====================================================================
   Base
   ===================================================================== */

:root {
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  font-size: 1rem;
  transition: background-color .25s ease, color .25s ease;
}

img { max-width: 100%; height: auto; display: block; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; text-wrap: balance; }
p { margin: 0 0 1rem; text-wrap: pretty; }
a { color: var(--primary); }
code { background: var(--soft); padding: .1rem .35rem; border-radius: 6px; font-size: .9em; }

.container { width: min(100% - 2rem, 62rem); margin-inline: auto; }
.muted { color: var(--muted); }
.link { font-weight: 600; }
.h2 { font-size: 1.5rem; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 2.75rem; padding: .6rem 1.2rem;
  border: 2px solid transparent; border-radius: 999px;
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.btn--primary { background: var(--primary); color: var(--primary-ink); box-shadow: 0 6px 16px -8px var(--primary); }
.btn--accent { background: var(--accent); color: var(--accent-ink); }
.btn--ghost { background: transparent; color: var(--primary); border-color: var(--line); }
.btn--danger { background: transparent; color: var(--danger); border-color: var(--danger-line); }
.btn--sm { min-height: 2.25rem; padding: .3rem .9rem; font-size: .9rem; }
.btn--block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: .75rem; }

.icon-btn {
  width: 2.5rem; height: 2.5rem; border-radius: 50%;
  border: 0; background: var(--soft); color: var(--ink);
  font-size: 1.5rem; line-height: 1; cursor: pointer;
}

/* ---------- Cabeçalho e rodapé ---------- */
.site-header {
  background: var(--header-bg); color: var(--header-ink);
  border-bottom: 4px solid var(--header-line);
}
.site-header__inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1rem; padding-block: .85rem; }
.site-header__actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.site-header .btn--ghost { color: var(--header-ink); border-color: rgba(255,255,255,.4); }
.brand {
  display: inline-flex; align-items: center; min-width: 0;
  color: var(--header-ink); font-weight: 800; font-size: 1.1rem; text-decoration: none; overflow-wrap: anywhere;
}
.site-footer { padding-block: 2rem; color: var(--muted); text-align: center; }

/* Losango da bandeira ao lado do nome (somente no tema Brasil) */
[data-theme="brasil"] .brand::before {
  content: "";
  flex: none;
  width: 1.9rem; height: 1.3rem; margin-right: .65rem;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  background: radial-gradient(circle at center, #002776 0 .32rem, transparent .33rem), #ffdf00;
}

/* Seletor de tema */
.theme-select {
  width: auto; min-height: 2.5rem; padding: .35rem 2rem .35rem .9rem;
  border-radius: 999px; font-size: .9rem; font-weight: 600; cursor: pointer;
  color: var(--header-ink); background-color: rgba(255,255,255,.12);
  border: 1.5px solid rgba(255,255,255,.4);
}
.theme-select option { color: var(--ink); background: var(--card); }

/* ---------- Banner e hero ---------- */
.banner { margin-top: 1.25rem; border-radius: var(--radius); overflow: hidden; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.banner img { width: 100%; max-height: 26rem; object-fit: cover; }

.hero { display: grid; gap: 1.5rem; margin-block: 1.5rem; }
.hero h1 { font-size: clamp(1.75rem, 5vw, 2.75rem); }
.hero__text p { color: var(--muted); font-size: 1.1rem; max-width: 36rem; }
.hero__total {
  display: flex; flex-direction: column; gap: .35rem;
  background: var(--hero-bg); color: var(--hero-ink);
  border: 1px solid var(--hero-line); border-radius: var(--radius);
  padding: 1.5rem; box-shadow: var(--shadow);
}
.hero__label { color: var(--hero-muted); font-size: .95rem; }
.hero__value { font-size: clamp(2rem, 7vw, 2.75rem); color: var(--hero-value); line-height: 1.1; font-variant-numeric: tabular-nums; }
.hero__meta { color: var(--hero-muted); margin-bottom: .75rem; }
.hero__total .btn--primary { background: var(--hero-btn-bg); color: var(--hero-btn-ink); box-shadow: none; }

@media (min-width: 52rem) {
  .hero { grid-template-columns: 1.3fr 1fr; align-items: center; margin-block: 2.5rem; }
}

/* ---------- Painel e ranking ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.5rem; box-shadow: var(--shadow); }
.panel__head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.panel__head h2, .panel__head h1 { margin: 0; }
.empty { color: var(--muted); padding: 1rem 0; margin: 0; }

.rank { list-style: none; margin: 0; padding: 0; }
.rank__item { display: flex; align-items: center; gap: .85rem; padding: .8rem .5rem; border-top: 1px solid var(--line); border-radius: 10px; transition: background-color .15s ease; }
.rank__item:first-child { border-top: 0; }
.rank__item:hover { background: var(--soft); }
.rank__pos {
  flex: none; width: 2.2rem; height: 2.2rem; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--soft); font-weight: 800; font-variant-numeric: tabular-nums;
}
.rank__item--top .rank__pos { background: var(--accent); color: var(--accent-ink); }
.rank__item--top .rank__name { font-weight: 700; }
.rank__name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.rank__amount { font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; white-space: nowrap; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-top: 1.25rem; flex-wrap: wrap; }

/* ---------- Formulários ---------- */
.form { display: flex; flex-direction: column; gap: 1rem; }
label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; font-size: .95rem; }
input, textarea, select {
  width: 100%; min-height: 2.9rem; padding: .6rem .8rem;
  font: inherit; font-weight: 400; color: var(--ink);
  background: var(--field); border: 1.5px solid var(--field-line); border-radius: 10px;
}
textarea { resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 1.25rem; min-height: 1.25rem; height: 1.25rem; accent-color: var(--primary); flex: none; }
.check { flex-direction: row; align-items: center; gap: .6rem; }
input[type="file"] { padding: .5rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .88rem; }
.form__error { color: var(--danger); font-weight: 600; margin: 0; }

.money-input { display: flex; align-items: center; border: 1.5px solid var(--field-line); border-radius: 10px; background: var(--field); }
.money-input span { padding-left: .85rem; font-weight: 700; color: var(--muted); }
.money-input input { border: 0; background: transparent; font-size: 1.25rem; font-weight: 700; }
.money-input:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.money-input input:focus-visible { outline: 0; }

.alert { padding: .75rem 1rem; border-radius: 10px; font-weight: 600; margin: 0 0 1rem; }
.alert--ok { background: var(--ok-bg); color: var(--ok-ink); }
.alert--warn { background: var(--warn-bg); color: var(--warn-ink); }
.alert--error { background: var(--err-bg); color: var(--err-ink); }

/* ---------- Modais ---------- */
.modal {
  width: min(92vw, 28rem); max-height: 92vh; overflow-y: auto;
  padding: 1.25rem; border: 0; border-radius: 18px;
  background: var(--card); color: var(--ink);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
}
.modal::backdrop { background: var(--backdrop); }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.modal__head h2 { margin: 0; font-size: 1.35rem; }

.modal--popup { padding: 0; width: min(92vw, 26rem); position: relative; border-top: 5px solid var(--accent); }
.popup__img { width: 100%; max-height: 18rem; object-fit: cover; }
.popup__body { padding: 1.25rem; }
.icon-btn--float { position: absolute; top: .6rem; right: .6rem; z-index: 2; background: var(--card); box-shadow: 0 2px 8px rgba(0,0,0,.25); }

.pay__amount { text-align: center; margin-bottom: .5rem; }
.pay__qr { display: grid; place-items: center; padding: .75rem; background: #fff; border: 1px solid var(--line); border-radius: 12px; margin-bottom: .75rem; }
.pay__qr img { width: min(100%, 14rem); height: auto; }
.pay__timer { text-align: center; color: var(--muted); }
.pay__timer strong { color: var(--danger); font-variant-numeric: tabular-nums; }
.pay__hint { text-align: center; margin: .75rem 0 0; font-size: .9rem; }
#pay-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; margin-bottom: .75rem; }
.result { text-align: center; }
.result__title { font-size: 1.5rem; font-weight: 800; color: var(--primary); }

/* ---------- Login / instalação ---------- */
.auth { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth__card { width: min(100%, 26rem); background: var(--card); border: 1px solid var(--line); border-top: 5px solid var(--accent); border-radius: var(--radius); padding: 1.75rem; box-shadow: var(--shadow); }
.auth__card h1 { font-size: 1.6rem; }

/* ---------- Painel administrativo ---------- */
.admin-bar { background: var(--bar-bg); color: var(--bar-ink); border-bottom: 4px solid var(--header-line); }
.admin-bar__inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; padding-block: .75rem; }
.admin-nav { display: flex; flex-wrap: wrap; gap: .25rem; }
.admin-nav a { color: var(--bar-ink); text-decoration: none; padding: .45rem .9rem; border-radius: 999px; font-weight: 600; }
.admin-nav a:hover { background: rgba(255,255,255,.12); }
.admin-nav a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.admin-bar .btn--ghost { color: var(--bar-ink); border-color: rgba(255,255,255,.4); }
.admin-main { padding-block: 1.5rem 3rem; }

.stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); margin-bottom: 1.5rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; box-shadow: var(--shadow); }
.stat span { display: block; color: var(--muted); font-size: .9rem; }
.stat strong { font-size: 1.6rem; color: var(--primary); font-variant-numeric: tabular-nums; }

.tabs { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.tab { padding: .4rem 1rem; border-radius: 999px; border: 1.5px solid var(--line); text-decoration: none; font-weight: 600; background: var(--card); color: var(--ink); }
.tab[aria-current="page"] { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .7rem .6rem; border-top: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .85rem; color: var(--muted); border-top: 0; }
.table .num { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 700; }
.rename { display: flex; gap: .4rem; min-width: 14rem; }
.rename input { min-height: 2.25rem; padding: .3rem .6rem; }
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

.badge { display: inline-block; padding: .15rem .65rem; border-radius: 999px; font-size: .8rem; font-weight: 700; }
.badge--paid { background: var(--ok-bg); color: var(--ok-ink); }
.badge--pending { background: var(--warn-bg); color: var(--warn-ink); }
.badge--expired, .badge--cancelled { background: var(--soft); color: var(--muted); }

.settings-grid { display: grid; gap: 1.5rem; }
@media (min-width: 52rem) { .settings-grid { grid-template-columns: 1fr 1fr; align-items: start; } }
.settings-grid .panel { margin: 0; }
.preview-img { max-height: 9rem; border-radius: 10px; border: 1px solid var(--line); object-fit: cover; }
.field-group { display: flex; flex-direction: column; gap: .5rem; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* Tutorial de instalação */
.tutorial { margin-block: 1rem; border: 1px solid var(--line); border-radius: 12px; background: color-mix(in srgb, var(--primary) 6%, var(--card)); }
.tutorial summary { cursor: pointer; padding: .8rem 1rem; font-weight: 700; color: var(--primary); }
.steps { counter-reset: step; list-style: none; margin: 0; padding: 0 1rem 1rem; display: flex; flex-direction: column; gap: .75rem; }
.steps li { counter-increment: step; position: relative; padding-left: 2.4rem; line-height: 1.5; font-size: .95rem; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: .05rem;
  display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 999px;
  background: var(--primary); color: var(--primary-ink, #fff); font-weight: 700; font-size: .85rem;
}
.steps code { background: var(--line); padding: .05rem .35rem; border-radius: 6px; font-size: .88em; }

/* Escolha de tema no painel */
.theme-opts { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); border: 0; margin: 0; padding: 0; }
.theme-opt {
  flex-direction: row; align-items: center; gap: .6rem;
  padding: .65rem .75rem; border: 2px solid var(--line); border-radius: 12px;
  background: var(--card); cursor: pointer;
}
.theme-opt:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
.theme-opt__swatch { display: flex; flex: none; border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.theme-opt__swatch i { display: block; width: 1rem; height: 1.6rem; }

@media (max-width: 45rem) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--line); border-radius: 12px; padding: .5rem .75rem; margin-bottom: .85rem; }
  .table td { border: 0; padding: .35rem 0; display: flex; gap: .75rem; justify-content: space-between; align-items: center; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; font-weight: 600; flex: none; }
  .table td.cell-rename { flex-direction: column; align-items: stretch; }
  .rename { min-width: 0; }
}

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