/* =====================================================================
   Design system — tokens, base e componentes compartilhados
   ===================================================================== */
:root {
  --accent: #c9a24d;
  --radius: 14px;
  --radius-sm: 10px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Playfair Display', Georgia, serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --danger: #ef5b5b; --success: #3ecf8e; --warning: #f0b429; --info: #5aa9ff;
  color-scheme: dark;
}
:root[data-theme='dark'] {
  --bg: #0d0e11; --surface: #15171c; --surface-2: #1c1f26; --surface-3: #242832;
  --border: #2d313c; --text: #eceef2; --muted: #a8aebb;
  --accent-text: var(--accent); --accent-ink: #14110a;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --overlay: rgba(5,6,8,.72);
}
:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f5f3ee; --surface: #ffffff; --surface-2: #f1eee8; --surface-3: #e8e4dc;
  --border: #e2ded5; --text: #1a1c21; --muted: #5d636f;
  --accent-text: color-mix(in srgb, var(--accent) 62%, #000); --accent-ink: #14110a;
  --shadow: 0 10px 30px rgba(40,30,10,.10);
  --overlay: rgba(20,18,12,.45);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.55; font-size: 15px; -webkit-font-smoothing: antialiased; min-height: 100vh; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.2; letter-spacing: -.01em; }
p { margin: 0 0 1em; }
a { color: inherit; text-decoration: none; }
img, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.ico { width: 1.15em; height: 1.15em; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: inline-block; vertical-align: -.2em; }
.container { width: min(1140px, 100% - 2rem); margin-inline: auto; }
.narrow { width: min(640px, 100% - 2rem); margin-inline: auto; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
.mt-1{margin-top:.5rem}.mt-2{margin-top:1rem}.mt-3{margin-top:1.5rem}.mb-1{margin-bottom:.5rem}.mb-2{margin-bottom:1rem}
.row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.show-light { display: none; } [data-theme='light'] .show-light { display: inline-block; } [data-theme='light'] .show-dark { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Botões ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; padding: .65rem 1.1rem; border-radius: var(--radius-sm); border: 1px solid transparent; font-weight: 600; font-size: .92rem; transition: transform .15s var(--ease), background .15s, border-color .15s, opacity .15s; white-space: nowrap; line-height: 1.2; user-select: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-busy='true'] { opacity: .55; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-soft { background: var(--surface-2); color: var(--text); }
.btn-soft:hover { background: var(--surface-3); }
.btn-danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 24%, transparent); }
.btn-success { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.btn-sm { padding: .42rem .75rem; font-size: .84rem; }
.btn-lg { padding: .95rem 1.6rem; font-size: 1rem; border-radius: 12px; }
.btn-block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--text); transition: background .15s; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.sm { width: 32px; height: 32px; }
.link { color: var(--accent-text); font-weight: 600; display: inline-flex; align-items: center; gap: .35rem; }
.link:hover { text-decoration: underline; }
.spinner { width: 20px; height: 20px; border: 2.5px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Formulários ---------- */
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; min-width: 0; }
.field > label, .label { font-size: .82rem; font-weight: 600; color: var(--muted); }
.input, .select, .textarea { width: 100%; padding: .7rem .85rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); transition: border-color .15s, box-shadow .15s; min-height: 44px; }
.textarea { min-height: 84px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239097a5' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2.2rem; }
.input[aria-invalid='true'] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .8rem; }
.hint { font-size: .78rem; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }
@media (max-width: 560px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.check { display: inline-flex; align-items: center; gap: .55rem; cursor: pointer; font-size: .92rem; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; z-index: 1; margin: 0; }
.switch i { position: absolute; inset: 0; background: var(--surface-3); border-radius: 99px; transition: background .2s; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s var(--ease); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }
.money { position: relative; } .money::before { content: 'R$'; position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .85rem; pointer-events: none; }
.money .input { padding-left: 2.3rem; }

/* ---------- Cards, chips, badges ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.card-flat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 1rem; }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .65rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: .78rem; font-weight: 600; }
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .6rem; border-radius: 99px; font-size: .74rem; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.badge.ok { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.badge.warn { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.badge.bad { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.badge.info { background: color-mix(in srgb, var(--info) 16%, transparent); color: var(--info); }
.badge.neutral { background: var(--surface-2); color: var(--muted); }
.avatar { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 20%, var(--surface-2)); color: var(--accent-text); font-weight: 700; font-size: .85rem; flex: none; }
.avatar-lg { width: 84px; height: 84px; font-size: 1.6rem; font-family: var(--font-display); }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty .ico { width: 2.2rem; height: 2.2rem; margin: 0 auto .75rem; opacity: .6; }
.skeleton-block { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--radius); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: .75rem 1rem; background: var(--surface-2); white-space: nowrap; }
.table td { padding: .8rem 1rem; border-top: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.table .r { text-align: right; } .table .c { text-align: center; }

/* ---------- Abas / segmentado ---------- */
.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: 11px; gap: 2px; max-width: 100%; overflow-x: auto; }
.seg button { border: 0; background: transparent; padding: .45rem .9rem; border-radius: 8px; font-weight: 600; font-size: .86rem; color: var(--muted); white-space: nowrap; }
.seg button[aria-pressed='true'], .seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.2); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; padding: 1rem; z-index: 90; animation: fade .15s; backdrop-filter: blur(3px); }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; width: min(520px, 100%); max-height: min(90vh, 880px); display: flex; flex-direction: column; box-shadow: var(--shadow); animation: pop .2s var(--ease); }
.modal.wide { width: min(720px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 1.4rem; overflow-y: auto; }
.modal-foot { display: flex; gap: .6rem; justify-content: flex-end; padding: 1rem 1.4rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } } @keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@media (max-width: 560px) { .modal-backdrop { place-items: end center; padding: 0; } .modal { border-radius: 18px 18px 0 0; max-height: 92vh; } }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 120; max-width: min(380px, calc(100vw - 2rem)); }
.toast { display: flex; gap: .65rem; align-items: flex-start; background: var(--surface-3); border: 1px solid var(--border); border-left: 4px solid var(--info); padding: .8rem 1rem; border-radius: 12px; box-shadow: var(--shadow); animation: pop .2s var(--ease); font-size: .9rem; }
.toast.ok { border-left-color: var(--success); } .toast.err { border-left-color: var(--danger); } .toast.warn { border-left-color: var(--warning); }
@media (max-width: 640px) { #toasts { left: 1rem; bottom: 5.2rem; } }

.boot { min-height: 100vh; display: grid; place-items: center; }
.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); font-size: .9rem; border: 1px solid; display: flex; gap: .6rem; align-items: flex-start; }
.alert.warn { background: color-mix(in srgb, var(--warning) 12%, transparent); border-color: color-mix(in srgb, var(--warning) 35%, transparent); color: var(--warning); }
.alert.bad { background: color-mix(in srgb, var(--danger) 12%, transparent); border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }
.alert.info { background: color-mix(in srgb, var(--info) 12%, transparent); border-color: color-mix(in srgb, var(--info) 35%, transparent); color: var(--info); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }

/* ---------- Ajustes de acessibilidade e toque ---------- */
.input, .select, .textarea { background: var(--surface-2); border-color: color-mix(in srgb, var(--border) 70%, var(--muted)); }
@media (pointer: coarse) { .icon-btn { width: 42px; height: 42px; } .icon-btn.sm { width: 40px; height: 40px; } .btn-sm { min-height: 40px; } .check input { width: 22px; height: 22px; } }
.check { align-items: center; line-height: 1.3; }
.check input { margin: 0; flex: none; }
