:root {
  --bg: #F6F5F3; --card: #FFFFFF; --ink: #1B1D22; --muted: #6B7280; --line: #E5E2DC;
  --accent: #E2231A; --accent-ink: #FFFFFF; --accent-soft: #FDECEB;
  --ok: #167A3E; --ok-soft: #E3F4EA; --warn: #9A5B00; --warn-soft: #FFF1D6; --bad: #B42318; --bad-soft: #FDE7E5; --info: #1D5FA8; --info-soft: #E4EEFA; --off: #6B7280; --off-soft: #ECEBE8;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  --nav-h: 64px;
}
:root:not([data-theme="light"]) { color-scheme: light dark; }
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151A; --card: #1D1F26; --ink: #F1F1F0; --muted: #9AA0AA; --line: #2C2F38;
    --accent-soft: #3A1816; --ok: #4CC17E; --ok-soft: #14301F; --warn: #F2B84B; --warn-soft: #3A2C0E; --bad: #FF7A6E; --bad-soft: #3A1816; --info: #7FB2F0; --info-soft: #14283F; --off: #9AA0AA; --off-soft: #272A32;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); min-height: 100vh; }
h1 { font-size: 1.5rem; line-height: 1.2; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; margin: 16px 0 8px; }
a { color: inherit; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
.link { color: var(--accent); text-decoration: none; font-weight: 600; }

/* Estrutura */
.shell { display: grid; min-height: 100vh; grid-template-rows: auto 1fr auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand strong { display: block; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand small { color: var(--muted); }
.logo { width: 34px; height: 34px; border-radius: 10px; background: #1B1D22; color: var(--accent); display: grid; place-items: center; font-weight: 800; font-size: 1.15rem; flex: none; }
.who { display: flex; align-items: center; gap: 10px; font-size: .85rem; }
.who .muted { display: none; }
.view { padding: 16px 16px calc(var(--nav-h) + 28px); max-width: 980px; width: 100%; margin: 0 auto; }
.foot { text-align: center; font-size: .8rem; color: var(--muted); padding: 8px 16px; }
.shell > .foot { padding-bottom: calc(var(--nav-h) + 16px); }
.foot a { color: var(--accent); text-decoration: none; }

.nav { position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h); background: var(--card); border-top: 1px solid var(--line); display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; z-index: 30; padding-bottom: env(safe-area-inset-bottom); }
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .68rem; text-decoration: none; color: var(--muted); padding: 6px 2px; }
.nav a .ico { font-size: 1.25rem; line-height: 1; }
.nav a[aria-current="page"] { color: var(--accent); font-weight: 700; }
.nav a:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; border-radius: 8px; }

@media (min-width: 860px) {
  .shell { grid-template-columns: 220px 1fr; grid-template-rows: auto 1fr auto; }
  .topbar { grid-column: 1 / -1; }
  .nav { position: static; grid-column: 1; grid-row: 2 / 4; display: flex; flex-direction: column; gap: 4px; height: auto; border-top: 0; border-right: 1px solid var(--line); padding: 14px 10px; background: transparent; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 10px; font-size: .95rem; padding: 10px 12px; border-radius: 10px; }
  .nav a[aria-current="page"] { background: var(--accent-soft); }
  .view { grid-column: 2; padding-bottom: 40px; }
  .shell > .foot { grid-column: 2; padding-bottom: 20px; }
  .who .muted { display: inline; }
}

/* Páginas */
.page { display: grid; gap: 16px; }
.page.narrow { max-width: 560px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat strong { display: block; font-size: 1.8rem; line-height: 1.1; }
.stat span { font-size: .8rem; color: var(--muted); }
.stat.warn { background: var(--warn-soft); border-color: transparent; }
.banner { padding: 12px 14px; border-radius: var(--radius); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.group-title { font-size: 1rem; margin: 4px 0 8px; }
.list { display: grid; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.empty { text-align: center; padding: 36px 16px; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.loading { padding: 24px; text-align: center; color: var(--muted); }

/* Reservas */
.res { display: grid; grid-template-columns: 64px 1fr; gap: 4px 12px; background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--ok); border-radius: var(--radius); padding: 12px; }
.res-pending { border-left-color: var(--warn); }
.res-cancelled, .res-no_show { border-left-color: var(--off); opacity: .7; }
.res-time strong { font-size: 1.25rem; display: block; }
.res-time small { color: var(--muted); }
.res-name { font-weight: 700; }
.res-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: .92rem; }
.res-meta .party { color: var(--ink); font-weight: 600; }
.res-notes { margin-top: 4px; font-size: .9rem; background: var(--off-soft); padding: 6px 10px; border-radius: 8px; }
.res-notes.internal { background: var(--info-soft); }
.res-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; vertical-align: middle; }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-bad { background: var(--bad-soft); color: var(--bad); }
.chip-info { background: var(--info-soft); color: var(--info); }
.chip-off { background: var(--off-soft); color: var(--off); }

/* Calendário */
.tabs { display: inline-flex; background: var(--off-soft); border-radius: 12px; padding: 4px; gap: 4px; justify-self: start; }
.tab { border: 0; background: transparent; padding: 8px 16px; border-radius: 9px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.datenav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.datenav input[type="date"] { width: auto; flex: 1 1 150px; max-width: 220px; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.weekday { display: grid; gap: 2px; justify-items: center; text-align: center; padding: 10px 2px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; font: inherit; color: inherit; cursor: pointer; }
.weekday.today { border-color: var(--accent); }
.weekday.empty-day { opacity: .7; }
.weekday small { text-transform: uppercase; color: var(--muted); font-size: .7rem; }
.weekday strong { font-size: 1.1rem; }
.weekday .count { font-weight: 800; font-size: 1.2rem; }
.weekday .muted { font-size: .65rem; }
@media (max-width: 480px) { .weekday .chip { font-size: .6rem; padding: 1px 5px; } }

/* Formulários */
.form { gap: 16px; }
.field { display: grid; gap: 6px; }
.field label, .check { font-weight: 600; font-size: .95rem; }
input, select, textarea { font: inherit; color: inherit; background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 12px; width: 100%; min-height: 46px; }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); vertical-align: middle; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, .person:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
input:disabled { opacity: .7; }
.with-unit { display: flex; align-items: center; gap: 10px; }
.with-unit input { max-width: 130px; }
.form-inline { display: grid; gap: 8px; }
.form-error { color: var(--bad); min-height: 1.2em; font-size: .92rem; }
.stepper { display: inline-flex; align-items: center; gap: 14px; }
.stepper output { font-size: 1.6rem; font-weight: 800; min-width: 40px; text-align: center; }
.times { display: grid; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.time-chip { border: 1.5px solid var(--line); background: var(--card); color: var(--ink); padding: 10px 14px; border-radius: 12px; font: inherit; font-weight: 700; cursor: pointer; min-height: 44px; }
.time-chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.searchbar input { max-width: 420px; }
.person { display: grid; text-align: left; gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font: inherit; color: inherit; cursor: pointer; }
.hours { display: grid; gap: 12px; }
.hours-day { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.hours-day > strong { width: 120px; }
.period { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.period input[type="time"] { width: 112px; }
.period .seats { width: 96px; }

/* Botões */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1.5px solid transparent; border-radius: 12px; padding: 10px 16px; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost.danger { color: var(--bad); }
.btn-sm { padding: 6px 12px; min-height: 38px; font-size: .9rem; }
.btn-lg { padding: 14px 20px; font-size: 1.05rem; min-height: 52px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); font-size: 1.4rem; line-height: 1; cursor: pointer; display: inline-grid; place-items: center; flex: none; }

/* Janelas e avisos */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: end center; z-index: 100; padding: 0; }
.modal { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 18px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.modal-body { display: grid; gap: 12px; }
@media (min-width: 640px) { .backdrop { place-items: center; padding: 20px; } .modal { border-radius: 20px; } }
#toasts { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 12px); display: grid; gap: 8px; z-index: 200; justify-items: center; pointer-events: none; }
.toast { background: #1B1D22; color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); max-width: 460px; }
.toast-bad { background: var(--bad); }
.toast-warn { background: var(--warn); color: #fff; }
@media (min-width: 860px) { #toasts { bottom: 20px; } }

/* Entrar */
.login-wrap { min-height: 100vh; display: grid; align-content: center; justify-items: center; gap: 16px; padding: 20px; }
.login { width: 100%; max-width: 400px; }
.login .brand { margin-bottom: 4px; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

.noscript { padding: 24px; }

/* Simulador de conversa (só em demonstração) */
.wa-tools { display: flex; gap: 8px; align-items: center; }
.wa-tools select { width: auto; }
.wa-phone { display: grid; grid-template-rows: auto 1fr auto; max-width: 440px; height: min(72vh, 680px); margin: 0 auto; background: #ECE5DD; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.wa-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; background: #075E54; color: #fff; }
.wa-top .chip { font-size: .66rem; }
.wa-log { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.wa-hint { text-align: center; padding: 24px 12px; color: #54656f; }
.wa-msg { max-width: 86%; padding: 8px 10px; border-radius: 10px; font-size: .95rem; box-shadow: 0 1px 1px rgba(0,0,0,.12); color: #111B21; }
.wa-me { align-self: flex-end; background: #D9FDD3; border-top-right-radius: 2px; white-space: pre-wrap; }
.wa-bot { align-self: flex-start; background: #fff; border-top-left-radius: 2px; }
.wa-text { white-space: pre-wrap; }
.wa-actions { display: grid; gap: 6px; margin: 8px -4px -2px; }
.wa-btn { font: inherit; font-weight: 600; font-size: .9rem; color: #027EB5; background: #fff; border: 0; border-top: 1px solid #E9EDEF; padding: 9px 6px; cursor: pointer; border-radius: 0 0 8px 8px; }
.wa-btn:hover:not(:disabled) { background: #F0F7FA; }
.wa-btn:disabled { color: #8696A0; cursor: default; }
.wa-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.wa-rows { display: grid; gap: 6px; }
.wa-row { display: grid; gap: 2px; text-align: left; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; min-height: 44px; }
.wa-row:hover { background: var(--accent-soft); }
.wa-input { display: flex; gap: 8px; padding: 8px; background: #F0F2F5; }
.wa-input input { flex: 1; min-width: 0; }
@media (max-width: 640px) { .wa-phone { height: max(300px, calc(100dvh - 350px)); } }

/* Indicador no menu */
.nav a { position: relative; }
.nav a .badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: .7rem; font-weight: 700; display: grid; place-items: center; }
@media (min-width: 900px) { .nav a .badge { position: static; margin-left: auto; } }

/* Conversas */
.conv { text-decoration: none; gap: 6px; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-human_handoff { border-left: 4px solid var(--warn); }
.conv-page { gap: 12px; }
.conv-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.conv-head h1 { margin-bottom: 2px; }
.back { justify-self: start; text-decoration: none; }
.chat { display: flex; flex-direction: column; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; max-height: 58vh; min-height: 220px; overflow-y: auto; }
.chat-msg { max-width: 86%; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); }
.chat-in { align-self: flex-start; background: var(--bg); }
.chat-out { align-self: flex-end; background: var(--accent-soft); }
.chat-human { background: var(--info-soft); }
.chat-system { background: var(--off-soft); }
.chat-who { font-size: .72rem; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.chat-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { display: grid; gap: 8px; }
.composer textarea { width: 100%; resize: vertical; }
.composer-bar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.composer-bar small { flex: 1 1 240px; }

/* Conteúdo largo (conversas) nunca estica a página: as colunas da grelha podem encolher */
.view, .page, .page > * { min-width: 0; }
.chat { overflow-x: hidden; }
