/* ==========================================================================
   Base compartilhada (site, agendamento e painel): tokens, reset e componentes
   ========================================================================== */
:root {
  --bg: #f7f5f3;
  --surface: #ffffff;
  --surface-2: #faf8f6;
  --ink: #1f1a1d;
  --ink-2: #4a4146;
  --muted: #7b7176;
  --line: #e9e3df;
  --line-2: #f1ece8;
  --brand: #8e3b5f;
  --brand-600: #7a3151;
  --brand-50: #f8edf2;
  --brand-100: #f1dbe5;
  --gold: #b88a52;
  --ok: #23774c; --ok-50: #e6f4ec;
  --warn: #9a6200; --warn-50: #fdf3dd;
  --bad: #b3261e; --bad-50: #fbe9e8;
  --info: #2f5ea8; --info-50: #e7eef9;
  --violet: #6b4bb5; --violet-50: #efeafa;
  --gray-50: #f1efee;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(31, 26, 29, .06);
  --shadow: 0 1px 2px rgba(31, 26, 29, .05), 0 4px 16px rgba(31, 26, 29, .06);
  --shadow-lg: 0 12px 40px rgba(31, 26, 29, .18);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --display: Georgia, 'Times New Roman', serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
img { max-width: 100%; display: block; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; } h4 { font-size: .95rem; }
p { margin: 0 0 .75rem; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .tiny { font-size: .75rem; }
.nowrap { white-space: nowrap; } .right { text-align: right; } .center { text-align: center; }
.strong { font-weight: 650; } .num { font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; } .row.end { justify-content: flex-end; } .row.nowrap { flex-wrap: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 12px; }
.grid-2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.grid-3 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.icon.sm { width: 15px; height: 15px; } .icon.lg { width: 22px; height: 22px; }

/* Botões */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--brand); color: #fff; font-weight: 600; font-size: .92rem; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, box-shadow .15s, transform .05s; }
.btn:hover { background: var(--brand-600); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-busy="true"] { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { background: var(--surface-2); border-color: #dcd3cd; }
.btn.ghost { background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--gray-50); }
.btn.danger { background: var(--bad); } .btn.danger:hover { background: #962019; }
.btn.success { background: var(--ok); } .btn.success:hover { background: #1b603d; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: .84rem; border-radius: 8px; }
.btn.lg { min-height: 48px; padding: 0 22px; font-size: 1rem; }
.btn.block { width: 100%; }
.btn.icon-only { padding: 0; width: 40px; } .btn.sm.icon-only { width: 32px; }
.btn .spinner { width: 16px; height: 16px; border-width: 2px; margin: 0; border-color: rgba(255,255,255,.4); border-top-color: #fff; }

/* Formulários */
label, .label { display: block; font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field { margin-bottom: 14px; min-width: 0; }
.field .hint { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.field .error-text { font-size: .8rem; color: var(--bad); margin-top: 4px; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=time], input[type=search], input:not([type]), select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); outline: none;
  transition: border-color .15s, box-shadow .15s; font-size: 16px; /* 16px evita zoom no iOS */ }
textarea { min-height: 90px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-100); }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--bad); }
input:disabled, select:disabled, textarea:disabled { background: var(--gray-50); color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; font-size: .92rem; color: var(--ink); cursor: pointer; margin: 0 14px 8px 0; min-height: 32px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
.input-group { display: flex; align-items: stretch; }
.input-group > span { display: flex; align-items: center; padding: 0 10px; background: var(--gray-50); border: 1px solid var(--line); border-right: 0; border-radius: 10px 0 0 10px; color: var(--muted); font-size: .9rem; }
.input-group > input { border-radius: 0 10px 10px 0; }
.form-row { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); }
fieldset { border: 0; padding: 0; margin: 0 0 8px; }
legend { font-weight: 650; margin-bottom: 8px; padding: 0; }

/* Cartões */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 18px; min-width: 0; }
.card.pad-0 { padding: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 650; white-space: nowrap; background: var(--gray-50); color: var(--ink-2); }
.badge.pending { background: var(--warn-50); color: var(--warn); }
.badge.confirmed { background: var(--info-50); color: var(--info); }
.badge.in_service { background: var(--violet-50); color: var(--violet); }
.badge.completed, .badge.ok, .badge.paid, .badge.sent { background: var(--ok-50); color: var(--ok); }
.badge.cancelled, .badge.bad, .badge.failed, .badge.refunded { background: var(--bad-50); color: var(--bad); }
.badge.no_show { background: #f3e6e6; color: #7a2e2e; }
.badge.reschedule_requested, .badge.warn { background: #fff0e0; color: #a14d00; }
.badge.info { background: var(--info-50); color: var(--info); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }

/* Tabelas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table tr.muted-row td { color: var(--muted); }
.table .actions { white-space: nowrap; text-align: right; }

/* Alertas e estados */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: 10px; font-size: .9rem; margin-bottom: 12px; background: var(--info-50); color: var(--info); }
.alert.warn { background: var(--warn-50); color: var(--warn); }
.alert.bad { background: var(--bad-50); color: var(--bad); }
.alert.ok { background: var(--ok-50); color: var(--ok); }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty .icon { width: 36px; height: 36px; margin: 0 auto 10px; display: block; stroke-width: 1.5; opacity: .6; }
.spinner { width: 24px; height: 24px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--line-2) 25%, #f7f3f0 37%, var(--line-2) 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; border-radius: 8px; min-height: 14px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* Modal */
dialog.modal { border: 0; padding: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink); overflow: hidden; }
dialog.modal.lg { width: min(820px, calc(100vw - 24px)); }
dialog.modal.sm { width: min(420px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(31, 26, 29, .45); }
dialog.modal[open] { display: flex; flex-direction: column; animation: pop .14s ease-out; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 18px; overflow-y: auto; overscroll-behavior: contain; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--surface-2); flex-wrap: wrap; }
@media (max-width: 600px) {
  dialog.modal, dialog.modal.lg, dialog.modal.sm { width: 100vw; max-width: 100vw; max-height: 94dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .modal-foot .btn { flex: 1 1 auto; }
}

/* Toast */
.toasts { position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 1000; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); font-size: .9rem; display: flex; gap: 8px; align-items: center; animation: pop .15s ease-out; pointer-events: auto; }
.toast.bad { background: var(--bad); } .toast.ok { background: #1d5e3c; }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; font-size: .92rem; min-height: 44px; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.seg { display: inline-flex; background: var(--gray-50); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: .85rem; color: var(--ink-2); cursor: pointer; min-height: 34px; }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* Avatar */
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--brand-50); color: var(--brand); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex: none; font-size: .95rem; overflow: hidden; }
.avatar.lg { width: 64px; height: 64px; font-size: 1.3rem; }
.avatar.sm { width: 30px; height: 30px; font-size: .78rem; }
