/* Riso Facial — Design System tokens & base components.
   Canonical source: DESIGN_SYSTEM.md / design-system.html.
   Rule: only the palette below. No blue, no green, no teal. Positive = wine,
   negative = #b00020. Off-palette color is a design bug. */

:root {
  --wine: #781828;
  --wine-deep: #580015;
  --gold: #C8A848;
  --bg: #F8F0F0;
  --surface: #fff;
  --ink: #231919;
  --muted: #897172;
  --faint: #bfaaaa;
  --wine-tint: #F8E3E3;
  --gold-tint: #FBF1D9;
  --row-alt: #FBF7F7;
  --hairline: #f0e6e6;
  --cool-line: rgba(128, 136, 152, .18);
  --positive: #781828;
  --negative: #b00020;
  --gold-text: #7a5b00;
  --radius: 24px;
  --shadow: 0 4px 32px -10px rgba(120, 24, 40, .08);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: 'Manrope', system-ui, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--wine); text-decoration: none; }
a:hover { text-decoration: underline; }

.serif { font-family: 'Newsreader', Georgia, serif; }

/* Signature label: uppercase, letter-spaced, muted. */
.label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

.muted { color: var(--muted); }
.tabular { font-variant-numeric: tabular-nums; }

/* --- Card --- */
.card {
  background: var(--surface);
  border: 1px solid var(--cool-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card.p-6 { padding: 24px; }
.card.p-7 { padding: 28px; }
.card--gold { border-top: 4px solid var(--gold); }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: 9999px;
  border: 1px solid transparent;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-primary { background: var(--wine); color: #fff; }
.btn-primary:hover { background: var(--wine-deep); text-decoration: none; }
.btn-secondary { background: transparent; color: var(--wine); border-color: var(--cool-line); }
.btn-secondary:hover { background: rgba(120, 24, 40, .06); text-decoration: none; }
.btn-danger { background: var(--negative); color: #fff; }
.btn-danger:hover { filter: brightness(.92); text-decoration: none; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- Form fields --- */
.form-group { margin-bottom: 18px; }
.form-group > label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.field {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--cool-line);
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
}
.field:focus {
  outline: none;
  border-color: var(--wine);
  box-shadow: 0 0 0 3px var(--wine-tint);
}

/* --- Messages / alerts (semantic, palette-safe) --- */
.alert { padding: 12px 16px; border-radius: 12px; font-size: 13px; margin-bottom: 14px; }
.alert-success { background: var(--wine-tint); color: var(--wine); }
.alert-error { background: #f7dcdf; color: var(--negative); }
.alert-warning { background: var(--gold-tint); color: var(--gold-text); }

.form-errors { color: var(--negative); font-size: 13px; margin-bottom: 14px; }

/* --- Auth screens (login / select clinic): centered card, no shell --- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 400px; padding: 40px 36px; }
.auth-brand { text-align: center; margin-bottom: 28px; }
.auth-brand .logo { font-size: 30px; font-weight: 600; color: var(--wine); }
.auth-brand .sub { margin-top: 4px; }

/* --- App shell: fixed header + sidebar + content --- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  padding: 0 32px;
  background: var(--bg);
  border-bottom: 1px solid var(--cool-line);
}
.app-header .brand { font-family: 'Newsreader', serif; font-size: 22px; font-weight: 600; color: var(--wine); }
.header-right { display: flex; align-items: center; gap: 16px; }

.clinic-select {
  padding: 8px 14px;
  border: 1px solid var(--cool-line);
  border-radius: 9999px;
  background: var(--surface);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--wine);
  cursor: pointer;
}
.user-name { font-size: 13px; color: var(--muted); }

.app-shell { display: flex; align-items: flex-start; max-width: 1480px; margin: 0 auto; }
.sidebar { width: 232px; flex: 0 0 232px; padding: 24px 16px; }
.content { flex: 1; min-width: 0; padding: 28px 32px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  padding: 10px 18px;
  border-radius: 9999px;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}
.nav-link:hover { background: rgba(120, 24, 40, .06); color: var(--wine); text-decoration: none; }
.nav-link.active { background: var(--wine); color: #fff; }
.nav-link .material-symbols-outlined { font-size: 20px; }

.page-title { font-family: 'Newsreader', serif; font-size: 28px; font-weight: 500; margin: 0 0 4px; }
.page-eyebrow { margin-bottom: 20px; }

/* Pills / badges */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 9999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.pill-wine { background: var(--wine-tint); color: var(--wine); }
.pill-gold { background: var(--gold-tint); color: var(--gold-text); }

.app-footer {
  max-width: 1480px;
  margin: 0 auto;
  padding: 16px 32px 32px;
  color: var(--faint);
  font-size: 11px;
}

/* --- Header left group + sidebar toggle --- */
.header-left { display: flex; align-items: center; gap: 12px; }
.nav-toggle {
  background: none; border: 1px solid var(--cool-line); border-radius: 10px;
  width: 38px; height: 38px; display: inline-flex; align-items: center;
  justify-content: center; cursor: pointer; color: var(--wine);
}
.nav-toggle:hover { background: rgba(120, 24, 40, .06); }

/* --- Collapsed sidebar (icon rail); collapsed by default --- */
html.nav-collapsed .sidebar { width: 64px; flex-basis: 64px; padding: 24px 8px; }
html.nav-collapsed .nav-label { display: none; }
html.nav-collapsed .nav-link { justify-content: center; padding: 10px; gap: 0; }
html.nav-collapsed .nav-link .pill { display: none; }

/* --- Page head: title + primary actions --- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 10px; flex-wrap: nowrap; overflow-x: auto; }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(35, 25, 25, .5);
  display: none; align-items: flex-start; justify-content: center;
  z-index: 60; padding: 40px 20px; overflow: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 0 20px 60px -20px rgba(120, 24, 40, .35);
  width: 100%; max-width: 520px; padding: 28px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-head .page-title { font-size: 22px; margin: 0; }
.modal-close { background: none; border: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-close:hover { color: var(--wine); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.detail-value { font-size: 14px; margin-top: 3px; }

/* --- Toolbar / search --- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 18px; }
.toolbar .field { width: auto; min-width: 260px; }
/* Keep every filter on a single line (scrolls horizontally if narrow). */
.toolbar--inline { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; }
.toolbar--inline .field { min-width: 0; flex-shrink: 0; }
.toolbar--inline > label, .toolbar--inline > button, .toolbar--inline > .field { flex-shrink: 0; white-space: nowrap; }

/* --- Dense table (.xls) --- */
.xls-wrap { border-radius: 16px; border: 1px solid var(--hairline); overflow: auto; background: var(--surface); }
table.xls { width: 100%; border-collapse: collapse; font-size: 13px; }
.xls th {
  background: var(--wine); color: #fff; font-size: 11px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase; text-align: left;
  padding: 11px 14px; position: sticky; top: 0; white-space: nowrap;
}
.xls td { padding: 10px 14px; border-bottom: 1px solid var(--hairline); }
.xls tr:nth-child(even) td { background: var(--row-alt); }
.xls tr:last-child td { border-bottom: none; }
.xls .num { text-align: right; font-variant-numeric: tabular-nums; }
.xls .row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.xls .row-actions a { font-size: 12px; font-weight: 600; }
.xls .row-actions form { display: inline; }
.link-danger { color: var(--negative); background: none; border: none; padding: 0; font: inherit; font-weight: 600; cursor: pointer; }
.link-action { color: var(--wine); background: none; border: none; padding: 0; font: inherit; font-weight: 600; cursor: pointer; }

/* --- Badges (palette-safe: no green/blue) --- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 9999px; font-size: 11px; font-weight: 700; }
.badge-neutral { background: var(--wine-tint); color: var(--wine); }
.badge-gold { background: var(--gold-tint); color: var(--gold-text); }
.badge-muted { background: #efe7e7; color: var(--muted); }
.badge-danger { background: #f7dcdf; color: var(--negative); }

/* --- Empty state --- */
.empty-state { padding: 40px; text-align: center; color: var(--muted); }

/* --- Pagination --- */
.pagination { display: flex; gap: 8px; align-items: center; margin-top: 18px; font-size: 13px; }
.pagination a { padding: 6px 12px; border: 1px solid var(--cool-line); border-radius: 9999px; }

/* --- Forms --- */
.form-card { max-width: 720px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.field-check { width: auto; margin-right: 8px; }
.check-row { display: flex; align-items: center; margin-bottom: 18px; font-weight: 600; color: var(--muted); }
.help-text { font-size: 11px; color: var(--faint); margin-top: 4px; }
.errorlist { list-style: none; padding: 0; margin: 4px 0 0; color: var(--negative); font-size: 12px; }
.section-title { font-family: 'Newsreader', serif; font-size: 18px; margin: 24px 0 12px; }
/* Agrupamento por proximidade (Gestalt): cada .form-section é um bloco semântico —
   espaçamento generoso entre blocos, compacto entre label/input dentro de cada um. */
.form-section { padding-bottom: 24px; margin-bottom: 24px; border-bottom: 1px solid var(--hairline); }
.form-section:last-of-type { padding-bottom: 0; margin-bottom: 20px; border-bottom: none; }
.form-section-context { display: flex; align-items: center; gap: 10px; }

/* --- Attachment field (widgets.js: data-attachment-field) --- */
.attachment-field { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.attachment-list { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.attachment-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px; border: 1px solid var(--cool-line); border-radius: 12px;
  background: var(--row-alt); font-size: 13px;
}
.attachment-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip-remove {
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border: 0; border-radius: 50%; background: transparent;
  color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer;
}
.attachment-chip-remove:hover { background: #f7dcdf; color: var(--negative); }

/* --- Tabs (content sections within a page, e.g. detalhe do chamado) --- */
.tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--hairline); margin-bottom: 20px; flex-wrap: wrap; }
.tab-link {
  appearance: none; background: none; border: none; cursor: pointer; font-family: inherit;
  padding: 10px 2px; font-size: 14px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s, border-color .15s;
}
.tab-link:hover { color: var(--wine); }
.tab-link.active { color: var(--wine); border-bottom-color: var(--wine); }
.tab-panel[hidden] { display: none; }
.formset-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 12px; align-items: end; padding: 12px 0; border-bottom: 1px dashed var(--hairline); }
.formset-row .form-group { margin-bottom: 0; }
.btn-remove-item {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: #f7dcdf; color: var(--negative); cursor: pointer;
}
.btn-remove-item:hover { background: #f0c7cc; }
.btn-remove-item .material-symbols-outlined { font-size: 20px; }
[data-supplier-row] input[name$="-DELETE"] { display: none; }


/* --- Form widgets: quantity stepper --- */
.stepper {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--cool-line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  max-width: 180px;
}
.stepper:focus-within {
  border-color: var(--wine);
  box-shadow: 0 0 0 3px var(--wine-tint);
}
.stepper-btn {
  border: 0;
  background: var(--wine-tint);
  color: var(--wine);
  width: 40px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}
.stepper-btn:hover { background: var(--wine); color: #fff; }
.stepper-input.field {
  width: 80px;
  border: 0;
  border-radius: 0;
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-shadow: none;
}
.stepper-input.field:focus { box-shadow: none; }
/* Hide the native number spinners so only our buttons remain. */
.stepper-input::-webkit-outer-spin-button,
.stepper-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-input { -moz-appearance: textfield; }

/* --- Form widgets: product combobox --- */
.combobox { position: relative; }
.combobox-native { display: none; }
.combobox-list {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  margin-top: 4px;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--cool-line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 4px;
}
.combobox-option {
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--ink);
}
.combobox-option:hover,
.combobox-option.active { background: var(--wine-tint); color: var(--wine); }
.combobox-empty { padding: 10px 12px; color: var(--muted); font-size: 13px; }

/* --- Form widgets: date picker --- */
.datepicker { position: relative; }
.datepicker-display.field { padding-right: 44px; }
.datepicker-icon {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 40px;
  border: 0;
  background: transparent;
  color: var(--wine);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.datepicker-icon .material-symbols-outlined { font-size: 20px; }
.datepicker-pop {
  position: absolute;
  z-index: 40;
  margin-top: 6px;
  width: 288px;
  background: var(--surface);
  border: 1px solid var(--cool-line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px;
}
.dp-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.dp-nav {
  border: 0; background: var(--wine-tint); color: var(--wine);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 16px; line-height: 1;
}
.dp-nav:hover { background: var(--wine); color: #fff; }
.dp-select {
  flex: 1; padding: 6px 8px; border: 1px solid var(--cool-line);
  border-radius: 8px; background: var(--surface); color: var(--ink); font-family: inherit; font-size: 13px;
}
.dp-dow, .dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-dow span {
  text-align: center; font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; padding-bottom: 4px;
}
.dp-cell {
  border: 0; background: transparent; color: var(--ink);
  height: 34px; border-radius: 8px; cursor: pointer;
  font-variant-numeric: tabular-nums; font-size: 13px;
}
.dp-cell:hover { background: var(--wine-tint); color: var(--wine); }
.dp-blank { background: transparent; cursor: default; }
.dp-today { box-shadow: inset 0 0 0 1px var(--wine); color: var(--wine); }
.dp-selected { background: var(--wine); color: #fff; }
.dp-selected:hover { background: var(--wine-deep); color: #fff; }

/* --- Form widgets: BRL money mask --- */
.money-field { position: relative; }
.money-prefix {
  position: absolute; left: 14px; top: 0; height: 100%;
  display: flex; align-items: center; color: var(--muted); font-size: 14px; pointer-events: none;
}
.money-display.field { padding-left: 36px; text-align: right; font-variant-numeric: tabular-nums; }

/* --- Página pública de aprovação (RF-032) — lida no celular, sem app shell ---
   Coluna única já no desktop de propósito: é um documento pra ler, não um painel. */
.public-wrap { max-width: 620px; margin: 0 auto; padding: 20px 16px calc(40px + env(safe-area-inset-bottom)); }
.public-brand { font-size: 15px; font-weight: 600; color: var(--wine); text-align: center; margin-bottom: 18px; }
.public-head { margin-bottom: 16px; }
.public-head .page-title { font-size: 26px; }
/* 132px: o menor mínimo que ainda cabe 2 colunas num celular de 390px (2x132+18 = 282,
   contra 310 disponíveis dentro do card) — em 1 coluna estes 4 fatos curtos empurravam a
   descrição pra fora da primeira tela. */
.public-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 14px 18px; }
.public-title { font-family: 'Newsreader', Georgia, serif; font-size: 19px; line-height: 1.35; margin: 0 0 14px; }
/* 16px é o piso de leitura confortável no celular; pre-wrap devolve as quebras de linha que a
   mensagem do WhatsApp teve de achatar, e anywhere impede que um link colado estoure a tela. */
.public-doc {
  font-size: 16px; line-height: 1.7; color: var(--ink);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.public-figure { margin: 0 0 14px; }
.public-figure img { display: block; width: 100%; height: auto; border-radius: 14px; border: 1px solid var(--hairline); }
.public-figure figcaption { margin-top: 6px; }
/* min-height 52px: alvo de toque confortável no celular. */
.public-file {
  display: flex; align-items: center; gap: 12px; min-height: 52px;
  padding: 12px 14px; margin-bottom: 8px;
  border: 1px solid var(--cool-line); border-radius: 14px;
  background: var(--row-alt); color: var(--ink); font-size: 14px; font-weight: 600;
}
.public-file:hover { background: var(--wine-tint); text-decoration: none; }
.public-file-icon { flex-shrink: 0; font-size: 18px; }
.public-file-name { min-width: 0; overflow-wrap: anywhere; }
.public-file-name .help-text { margin-top: 2px; }
/* O CPF mascarado é uma segunda linha do campo Paciente, não um sufixo do nome. */
.public-facts .help-text { display: block; }
.public-foot { margin-top: 22px; text-align: center; font-size: 11px; color: var(--faint); line-height: 1.6; }


/* --- Responsivo / PWA ---------------------------------------------------------------
   Desktop e tablet largo mantêm o shell acima intacto. Tudo que é só-celular fica
   escondido aqui e é ligado no @media (max-width: 820px) mais abaixo — o mesmo
   breakpoint que static/js/app.js usa (MOBILE_QUERY) pra decidir gaveta x trilho. */

.brand-block { display: flex; flex-direction: column; min-width: 0; }
.header-account { display: flex; align-items: center; gap: 16px; }
.header-context,
.header-bell,
.drawer-head,
.drawer-backdrop,
.bottom-nav,
.composer-jump,
.bulk-select-all-mobile { display: none; }

.header-bell {
  position: relative; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 12px; color: var(--wine);
}
.header-bell:hover { background: rgba(120, 24, 40, .06); text-decoration: none; }
.header-bell-count {
  position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9999px; background: var(--wine); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 18px; text-align: center;
}

/* Linha de chips de sub-filtro (status). */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* type=search sem o visual nativo do WebKit, que destoa do .field. */
.field[type="search"] { -webkit-appearance: none; appearance: none; }

/* Detalhe do chamado: a descrição ocupa 2 trilhas só quando o grid tem ao menos 2
   (minmax 280px). Abaixo disso o span criava uma coluna implícita e estourava a tela. */
@media (min-width: 900px) {
  .detail-main { grid-column: span 2; }
}
.chat-body { margin: 6px 0 0; overflow-wrap: anywhere; }

/* Rolagem horizontal com indicação: a borda que ainda tem conteúdo esmaece (app.js). */
.xls-wrap.scroll-more-right {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
}
.xls-wrap.scroll-more-left {
  -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 36px), transparent);
  mask-image: linear-gradient(to left, #000 calc(100% - 36px), transparent);
}
.xls-wrap.scroll-more-left.scroll-more-right {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent);
  mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent);
}

@media (max-width: 820px) {
  /* Header compacto: marca + contexto à esquerda, sino à direita. Conta (nome, Trocar
     Tenant, Sair) vai para o topo da gaveta — nada trunca nem empurra a largura. */
  .app-header {
    height: auto; min-height: 56px; gap: 8px;
    padding: 6px 12px; padding-top: max(6px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .header-left { gap: 8px; min-width: 0; }
  .app-header .brand { font-size: 19px; line-height: 1.2; }
  .brand-suffix, .header-account { display: none; }
  .header-context {
    display: block; font-size: 11px; font-weight: 600; color: var(--muted);
    line-height: 1.3; overflow-wrap: anywhere;
  }
  .header-right { gap: 4px; flex-shrink: 0; }
  .header-bell { display: inline-flex; }
  .nav-toggle { width: 44px; height: 44px; flex-shrink: 0; }

  .app-shell { display: block; }
  .content {
    padding: 18px 14px 24px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .app-footer { padding: 8px 14px 20px; }

  /* Gaveta modal. visibility:hidden quando fechada tira os links do tab e do leitor
     de tela; o atraso na transição deixa o slide de saída terminar antes de esconder. */
  .sidebar,
  html.nav-collapsed .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 70;
    width: min(86vw, 320px); flex-basis: auto;
    padding: 12px 12px calc(16px + env(safe-area-inset-bottom));
    padding-top: max(12px, env(safe-area-inset-top));
    background: var(--bg); overflow-y: auto; overscroll-behavior: contain;
    box-shadow: 0 20px 60px -20px rgba(120, 24, 40, .45);
    transform: translateX(-105%); visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
  }
  html.nav-open .sidebar { transform: none; visibility: visible; transition: transform .22s ease; }
  html.nav-collapsed .nav-label { display: inline; }
  html.nav-collapsed .nav-link,
  .nav-link { justify-content: flex-start; gap: 12px; padding: 12px 18px; min-height: 44px; }
  .drawer-backdrop {
    display: block; position: fixed; inset: 0; z-index: 65;
    background: rgba(35, 25, 25, .5); opacity: 0; pointer-events: none; transition: opacity .22s;
  }
  html.nav-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
  html.nav-open, html.nav-open body { overflow: hidden; }

  .drawer-head { display: block; padding: 0 6px 16px; margin-bottom: 12px; border-bottom: 1px solid var(--cool-line); }
  .drawer-head-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
  .drawer-head .brand { font-family: 'Newsreader', serif; font-size: 20px; font-weight: 600; color: var(--wine); }
  .drawer-close {
    width: 44px; height: 44px; border: 1px solid var(--cool-line); border-radius: 12px;
    background: none; color: var(--wine); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
  }
  .drawer-user { margin: 0 0 6px; font-weight: 600; overflow-wrap: anywhere; }
  .drawer-tenant { white-space: normal; overflow-wrap: anywhere; text-align: left; }
  .drawer-account-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
  .drawer-account-actions .btn { width: 100%; }

  /* Navegação inferior fixa. */
  body.has-bottom-nav { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    padding: 0 max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left));
    background: var(--surface); border-top: 1px solid var(--cool-line);
    box-shadow: 0 -4px 24px -12px rgba(120, 24, 40, .18);
  }
  .bottom-nav-item {
    flex: 1 1 0; min-width: 0; min-height: 60px; padding: 6px 2px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    background: none; border: 0; font-family: inherit; font-size: 11px; font-weight: 600;
    color: var(--muted); cursor: pointer;
  }
  .bottom-nav-item:hover { text-decoration: none; color: var(--wine); }
  .bottom-nav-item .material-symbols-outlined { font-size: 24px; }
  .bottom-nav-item.active { color: var(--wine); }
  .bottom-nav-item.active .material-symbols-outlined { background: var(--wine-tint); border-radius: 9999px; padding: 2px 14px; }
  .bottom-nav-new .material-symbols-outlined { color: var(--wine); }

  /* Alvos de toque e coluna única. */
  .btn { min-height: 44px; }
  .field { font-size: 16px; min-height: 44px; } /* 16px evita o zoom automático do iOS no foco. */
  .page-title { font-size: 24px; }
  .page-head { align-items: stretch; }
  .page-head .actions { flex-direction: column; align-items: stretch; width: 100%; overflow: visible; }
  .page-head .actions .badge { align-self: flex-start; }
  .form-row, .formset-row, .detail-grid { grid-template-columns: 1fr; }
  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .btn { width: 100%; }
  .card.p-6 { padding: 18px; }
  .card.p-7 { padding: 22px; }
  .pagination { flex-wrap: wrap; }
  .pagination a { min-height: 44px; display: inline-flex; align-items: center; padding: 8px 16px; }

  /* Toolbars: sem rolagem lateral aqui (cortaria o popup do datepicker/combobox);
     busca em largura total, demais filtros dividem a linha e quebram quando preciso. */
  .toolbar, .toolbar--inline { flex-wrap: wrap; overflow: visible; padding-bottom: 0; }
  .toolbar > .field, .toolbar > .datepicker, .toolbar > .combobox { flex: 1 1 150px; min-width: 0 !important; }
  .toolbar > .toolbar-search, .toolbar > input[type="search"], .toolbar > input[type="text"] { flex: 1 1 100%; }
  .toolbar > .btn { flex: 1 1 auto; }

  /* Abas e chips: uma linha que rola na horizontal. */
  .tabs--scroll, .chip-row {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; scroll-snap-type: x proximity;
  }
  .tabs--scroll::-webkit-scrollbar, .chip-row::-webkit-scrollbar { display: none; }
  .tabs--scroll { gap: 18px; }
  .tabs--scroll .tab-link { flex-shrink: 0; white-space: nowrap; min-height: 44px; scroll-snap-align: start; }
  .chip-row .badge {
    flex-shrink: 0; white-space: nowrap; display: inline-flex; align-items: center;
    min-height: 44px; padding: 0 16px; font-size: 12px; scroll-snap-align: start;
  }

  /* Tabelas comuns: mantêm todas as colunas, com rolagem horizontal indicada. */
  .xls-wrap { -webkit-overflow-scrolling: touch; }

  /* Listas de chamados (_table.html): cada linha vira um card, rótulo à esquerda e
     valor à direita — mesmas colunas, nenhuma escondida. O thead some; o "todos" do
     lote tem uma cópia na barra de ações (.bulk-select-all-mobile). */
  .xls-wrap--cards { border: 0; background: transparent; overflow: visible; border-radius: 0; }
  .xls--cards, .xls--cards tbody { display: block; }
  .xls--cards thead { display: none; }
  .xls--cards tr.row-link {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px;
    padding: 14px 16px; margin-bottom: 10px;
    background: var(--surface); border: 1px solid var(--cool-line); border-radius: 16px;
    box-shadow: var(--shadow);
  }
  .xls--cards td, .xls--cards tr:nth-child(even) td { display: block; padding: 0; border: 0; background: transparent; }
  .xls--cards tbody tr.row-link:hover td { background: transparent; }
  .xls--cards tr.row-link:active { background: var(--row-alt); }
  .xls--cards .cell-title {
    grid-column: 1; grid-row: 1; font-weight: 700; font-size: 15px; line-height: 1.35;
    margin-bottom: 8px; overflow-wrap: anywhere;
  }
  .xls--cards .row-select-cell { grid-column: 2; grid-row: 1; margin: -10px -10px 0 0; }
  .xls--cards td[data-label] {
    grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center;
    gap: 12px; padding: 5px 0; border-top: 1px solid var(--hairline); text-align: right;
    overflow-wrap: anywhere;
  }
  .xls--cards td[data-label]::before {
    content: attr(data-label); flex-shrink: 0; text-align: left;
    font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  }
  .xls--cards tr.row-empty, .xls--cards tr.row-empty td { display: block; }
  .row-select-hit { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; cursor: pointer; }
  .row-select-hit input, .bulk-select-all-mobile input { width: 20px; height: 20px; margin: 0; }
  .bulk-select-all-mobile { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 600; color: var(--muted); cursor: pointer; }
  #bulk-queue-form select.field { flex: 1 1 100%; }
  #bulk-queue-form .btn { flex: 1 1 auto; }

  /* Detalhe do chamado. */
  .action-stack .btn { width: 100%; }
  .action-stack .badge { align-self: flex-start; }
  .chat-meta, .history-row { flex-wrap: wrap; gap: 2px 10px; }
  .chat-thread .card { padding: 14px; }
  .composer { scroll-margin-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .composer .btn { width: 100%; }
  /* Atalho em fluxo, logo antes do formulário: gruda acima da nav inferior só enquanto o
     formulário está fora da tela e some quando ele aparece (app.js) — não cobre o form. */
  .composer-jump {
    display: flex; width: max-content; margin: 12px 0 0 auto;
    position: sticky; z-index: 5; bottom: calc(76px + env(safe-area-inset-bottom));
    box-shadow: 0 8px 24px -8px rgba(120, 24, 40, .45);
  }
  .composer-jump.is-hidden { visibility: hidden; }

  /* Modais viram folha inferior que cabe na tela e rola por dentro. */
  .modal-overlay { align-items: flex-end; padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .modal { padding: 20px; border-radius: 20px; max-height: calc(100dvh - 24px); overflow-y: auto; }
  .modal-close { width: 44px; height: 44px; }
  .datepicker-pop { width: min(288px, calc(100vw - 32px)); }
  .attachment-chip-remove { width: 36px; height: 36px; }

  .auth-card { padding: 32px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .drawer-backdrop { transition: none !important; }
}
