:root {
  --accent: #c8102e;
  --bg: #f4f4f2;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --line: #e2e2de;
  --ok: #1f7a46;
  --ok-bg: #e5f4ea;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --err: #a8162b;
  --err-bg: #fde8eb;
  --info-bg: #e9f0fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--accent); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .6rem; }
.card > h2:first-child, form.card > input + h2 { margin-top: 0; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: .35rem; }

/* ---- Barra superior ---- */
.topbar {
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
  padding: .7rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-mark { width: 14px; height: 22px; border-radius: 3px; background: repeating-linear-gradient(90deg, var(--accent) 0 4px, #fff 4px 5px); box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
.topbar-info { color: var(--muted); font-size: .88rem; margin-left: auto; }
.adminnav { display: flex; gap: .2rem; flex-wrap: wrap; }
.adminnav a { padding: .35rem .7rem; border-radius: 6px; color: var(--muted); text-decoration: none; font-size: .92rem; }
.adminnav a:hover { background: var(--bg); color: var(--text); }
.adminnav a.on { background: var(--bg); color: var(--text); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
.logout { margin: 0 0 0 auto; }
.topbar-info + .logout { margin-left: 0; }

/* ---- Estrutura ---- */
.container { max-width: 1000px; margin: 0 auto; padding: 1.75rem 1.25rem 3rem; }
.container.wide { max-width: 1320px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem 1.5rem; margin-bottom: 1.25rem; box-shadow: var(--shadow); }
.card.narrow { max-width: 540px; margin: 2.5rem auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 1.25rem; align-items: start; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card { margin-top: 1.25rem; }
.pagehead { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; margin-bottom: .75rem; }
.pagehead h1 { margin: 0; }

/* ---- Formulários ---- */
.form { display: flex; flex-direction: column; gap: .9rem; }
.form.row { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
.form.row > label { flex: 1 1 200px; }
.form.row > label.narrowfield { flex: 0 0 90px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .9rem 1.25rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
label small { font-weight: 400; color: var(--muted); }
label.check { flex-direction: row; align-items: flex-start; gap: .55rem; font-weight: 400; }
label.check input { margin-top: .25rem; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: #fff;
  border: 1px solid #cfcfca; border-radius: 7px; padding: .55rem .7rem; width: 100%;
}
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
input[type=color] { padding: .2rem; height: 2.5rem; }
input[type=file] { padding: .4rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
textarea { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; line-height: 1.45; resize: vertical; }
.num { width: 5.5rem; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input { flex: 1 1 260px; width: auto; }
.filters select { width: auto; }

/* ---- Botões ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  font: inherit; font-weight: 600; font-size: .92rem; line-height: 1.2;
  padding: .6rem 1.05rem; border-radius: 7px; border: 1px solid #cfcfca;
  background: #fff; color: var(--text); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f6f6f4; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { background: #fff; border-color: var(--err); color: var(--err); }
.btn.danger:hover { background: var(--err-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0, 0, 0, .05); }
.btn.small { padding: .35rem .65rem; font-size: .85rem; }
.danger-text { color: var(--err) !important; }
.btn-link { font: inherit; background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; font-size: .9rem; }
.btn-link:hover { color: var(--text); text-decoration: underline; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.25rem; }
form.inline { display: inline; margin: 0; }
.chip { font: inherit; font-family: ui-monospace, Consolas, monospace; font-size: .78rem; border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: .1rem .55rem; margin: .15rem .1rem; cursor: pointer; }
.chip:hover { border-color: var(--accent); }

/* ---- Alertas e etiquetas ---- */
.alert { border-radius: 8px; padding: .75rem 1rem; margin-bottom: 1rem; border: 1px solid transparent; }
.alert ul { margin: 0; padding-left: 1.1rem; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.error { background: var(--err-bg); color: var(--err); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.info { background: var(--info-bg); }
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; text-decoration: none; white-space: nowrap; background: #ececea; color: #555; }
.badge.pending { background: var(--warn-bg); color: var(--warn); }
.badge.approved { background: var(--ok-bg); color: var(--ok); }
.badge.rejected, .badge.revoked { background: var(--err-bg); color: var(--err); }
.badge.expired { background: #ececea; color: #666; }

/* ---- Tabelas ---- */
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .6rem .75rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafaf8; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafaf8; }
.table td.right { text-align: right; }
.table.compact th, .table.compact td { padding: .4rem .5rem; font-size: .9rem; }
.table tr.warn td { background: var(--warn-bg); }
.details-cell { max-width: 420px; overflow-wrap: anywhere; font-size: .85rem; color: var(--muted); }
.pager { display: flex; gap: .3rem; flex-wrap: wrap; margin: 1rem 0; }
.pager a { padding: .3rem .65rem; border-radius: 6px; border: 1px solid var(--line); background: #fff; text-decoration: none; color: var(--text); }
.pager a.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.details { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; margin: 0 0 .5rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }

/* ---- Modelos ---- */
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.tabs a { padding: .55rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--text); border-color: var(--accent); font-weight: 600; }
.preview { width: 100%; height: 560px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.qr { display: block; border: 1px solid var(--line); border-radius: 8px; margin: .75rem 0; image-rendering: pixelated; }

/* ---- Lista de documentos (sócio) ---- */
.doclist { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.doccard { display: flex; gap: 1rem; padding: 1.15rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--text); box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s; }
.doccard:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(0, 0, 0, .08); }
.doccard h2 { margin: 0 0 .25rem; font-size: 1.05rem; }
.doccard p { margin: .3rem 0; }
.doccard-body { flex: 1; min-width: 0; }
.doccard-icon { flex: 0 0 42px; height: 54px; border-radius: 3px 10px 3px 3px; background: linear-gradient(135deg, #fff 0 70%, #e5e5e0 70%); border: 1px solid var(--line); box-shadow: inset 4px 0 0 var(--accent); }
progress { width: 100%; height: 6px; appearance: none; border: 0; border-radius: 99px; background: #ececea; overflow: hidden; margin: .5rem 0 .2rem; }
progress::-webkit-progress-bar { background: #ececea; border-radius: 99px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 99px; }

@media (max-width: 640px) {
  .container { padding: 1.1rem .9rem 2rem; }
  .card { padding: 1.1rem; }
  .card.narrow { margin: 1rem auto; }
  .grid2 { grid-template-columns: 1fr; }
  .details { grid-template-columns: 1fr; gap: .1rem; }
  .details dd { margin-bottom: .5rem; }
  .topbar-info { margin-left: 0; width: 100%; order: 3; }
}

/* Os documentos não podem ser impressos. */
.noprint { display: none; }
@media print {
  body.viewer-body > * { display: none !important; }
  body.viewer-body > .noprint { display: block !important; padding: 3rem; font-size: 18pt; }
}

/* ---- Logótipo ---- */
.brand-logo { width: 36px; height: 36px; object-fit: contain; }
.hero-logo { display: flex; justify-content: center; margin: 2rem 0 -1rem; }
.hero-logo img { width: 96px; height: 96px; object-fit: contain; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .18)); }
.logo-row { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.logo-row .form.row { flex: 1 1 360px; }
.logo-preview { width: 88px; height: 88px; display: flex; align-items: center; justify-content: center; border: 1px dashed var(--line); border-radius: 8px; background: #fff; }
.logo-preview img { width: 72px; height: 72px; object-fit: contain; }

/* =====================================================================
   Tema "Varzim" — inspirado em varzim.pt e store.varzim.pt:
   cabeçalho preto, Poppins em maiúsculas, cantos retos, vermelho e dourado do emblema.
   ===================================================================== */
@font-face { font-family: "Poppins"; font-weight: 400; font-display: swap; src: url(/static/fonts/poppins-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Poppins"; font-weight: 400; font-display: swap; src: url(/static/fonts/poppins-latin-ext-400-normal.woff2) format("woff2"); unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Poppins"; font-weight: 600; font-display: swap; src: url(/static/fonts/poppins-latin-600-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Poppins"; font-weight: 600; font-display: swap; src: url(/static/fonts/poppins-latin-ext-600-normal.woff2) format("woff2"); unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Poppins"; font-weight: 700; font-display: swap; src: url(/static/fonts/poppins-latin-700-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Poppins"; font-weight: 700; font-display: swap; src: url(/static/fonts/poppins-latin-ext-700-normal.woff2) format("woff2"); unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }

body.theme-varzim {
  --bg: #f8f8f8;
  --text: #303030;
  --muted: #69727d;
  --line: #e4e4e4;
  --gold: #f2c230;
  --radius: 0px;
  --shadow: none;
  --font: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
.theme-varzim h1, .theme-varzim h2 { font-weight: 700; text-transform: uppercase; letter-spacing: .01em; }
.theme-varzim h1 { font-size: 1.5rem; }
.theme-varzim h2 { font-size: 1rem; }
/* Traço vermelho sobre os títulos principais, como na loja. */
.theme-varzim main h1::before { content: ""; display: block; width: 40px; height: 3px; background: var(--accent); margin-bottom: .7rem; }
.theme-varzim .pagehead h1::before, .theme-varzim .viewer h1::before { display: none; }

.theme-varzim .topbar { background: #000; border-bottom: 0; padding: .8rem 1.5rem; }
.theme-varzim .brand { color: #fff; text-transform: uppercase; font-weight: 700; letter-spacing: .02em; }
.theme-varzim .brand-logo { width: 44px; height: 44px; }
.theme-varzim .topbar-info, .theme-varzim .btn-link { color: #bdbdbd; }
.theme-varzim .btn-link:hover { color: #fff; }
.theme-varzim .adminnav a { color: #d6d6d6; text-transform: uppercase; font-size: .82rem; letter-spacing: .03em; border-radius: 0; }
.theme-varzim .adminnav a:hover { background: transparent; color: #fff; }
.theme-varzim .adminnav a.on { background: transparent; color: #fff; box-shadow: inset 0 -2px 0 var(--accent); }

.theme-varzim .card, .theme-varzim .tablewrap, .theme-varzim .doccard { border-radius: 0; border-color: #e6e6e6; }
.theme-varzim .btn { border-radius: 0; text-transform: uppercase; letter-spacing: .04em; font-size: .82rem; padding: .7rem 1.2rem; border-color: #000; color: #000; }
.theme-varzim .btn.small { padding: .4rem .7rem; font-size: .74rem; }
.theme-varzim .btn.primary { background: #000; border-color: #000; color: #fff; }
.theme-varzim .btn.primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); filter: none; }
.theme-varzim .btn.ghost { border-color: transparent; }
.theme-varzim .btn.danger { border-color: var(--err); color: var(--err); }
.theme-varzim input, .theme-varzim select, .theme-varzim textarea { border-radius: 0; border-color: #cfcfcf; }
.theme-varzim textarea { font-family: ui-monospace, Consolas, monospace; }
.theme-varzim .badge { border-radius: 0; text-transform: uppercase; letter-spacing: .03em; font-size: .7rem; }
.theme-varzim .alert { border-radius: 0; border-left: 3px solid currentColor; }
.theme-varzim .table th { background: #fff; color: #000; font-weight: 700; }
.theme-varzim .tabs a.on, .theme-varzim .pager a.on { border-radius: 0; }
.theme-varzim .pager a { border-radius: 0; }
.theme-varzim .chip { border-radius: 0; }
.theme-varzim .doccard-icon { border-radius: 0; box-shadow: inset 4px 0 0 var(--accent), inset 0 -3px 0 var(--gold); }
.theme-varzim progress::-webkit-progress-bar, .theme-varzim progress { border-radius: 0; }
.theme-varzim progress::-webkit-progress-value { border-radius: 0; }
.theme-varzim .hero-logo { margin-top: 2.5rem; }
.theme-varzim .card.narrow { border-top: 3px solid #000; }
