/* ====================================================================================================================
 * s7-ui.css — camada ÚNICA de layout e controles do S7 (portal + todos os módulos).
 * Fonte oficial: shared/s7-ui.css. Cada módulo recebe uma CÓPIA IDÊNTICA em public/assets/s7-ui.css (rode `python3 shared/sync-ui.py`;
 * o teste tests/test_s7_ui.py confere). Não edite as cópias. Carregada logo depois do CSS base de cada módulo.
 *
 * Regras de ouro (valem para qualquer tela nova):
 *  1. Campo = .input | .select | .textarea dentro de .field (rótulo + controle + .help/.error). Mesma altura, raio, borda, foco e estados.
 *  2. Linhas de campos = .form-grid (colunas que se ajustam; 1 coluna no celular). Ações do formulário = .form-actions.
 *  3. Botões = .btn (44 px) ou .btn.sm (34 px). Nunca altura própria em tela.
 *  4. Filtros = .toolbar (no celular cada controle ocupa a linha inteira). Abas = .tabs (rolam na horizontal, não quebram).
 *  5. Nada passa da largura da tela: tabelas dentro de .table-wrap, textos longos quebram (.wrap-any), seletores nunca cortam o texto.
 * ==================================================================================================================== */
:root {
  --ui-h: 44px;          /* altura de campo e botão */
  --ui-h-sm: 34px;       /* botão pequeno */
  --ui-pad-x: .75rem;
  --ui-gap: 1rem;
  --ui-r: var(--s7-radius, 8px);
  --ui-line: var(--s7-border-strong, #c9ced6);
  --ui-surface: var(--s7-surface, #fff);
  --ui-text: var(--s7-text, #10131A);
  --ui-muted: var(--s7-text-muted, #5b6270);
  --ui-focus: var(--s7-focus, #2F6BFF);
  --ui-danger: var(--s7-danger, #B3261E);
}
*, *::before, *::after { box-sizing: border-box; }
img, svg, video, canvas { max-width: 100%; }
img { height: auto; }

/* ---------- 1. campos ---------- */
.input, .select, .textarea,
:where(.page, .content, .card, .auth-form, .guest-card, form) :where(input, select, textarea):not([type=checkbox], [type=radio], [type=file], [type=range], [type=color], [type=hidden], [type=submit], [type=button], [type=reset], [type=image]) {
  display: block; width: 100%; min-width: 0; max-width: 100%; min-height: var(--ui-h); padding: .5rem var(--ui-pad-x);
  border: 1px solid var(--ui-line); border-radius: var(--ui-r); background-color: var(--ui-surface); color: var(--ui-text);
  font: inherit; font-size: 1rem; line-height: 1.35; box-shadow: none;
}
.textarea, :where(.page, .content, .card, .form) textarea { min-height: 5.5rem; resize: vertical; line-height: 1.45; }
.select, :where(.page, .content, .card, .auth-form, .guest-card, form) select:not([multiple]) {
  padding-right: 2.25rem; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; cursor: pointer;
}
select[multiple] { min-height: 8rem; padding: .35rem; }
.input::placeholder, .textarea::placeholder { color: var(--ui-muted); opacity: .8; text-overflow: ellipsis; }
.input:focus, .select:focus, .textarea:focus, :where(.page, .content, .card, form) :where(input, select, textarea):focus { outline: 2px solid var(--ui-focus); outline-offset: 1px; }
.input[readonly], .textarea[readonly] { text-overflow: ellipsis; }
.input:disabled, .select:disabled, .textarea:disabled { opacity: .6; cursor: not-allowed; }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--ui-danger); }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; flex: none; margin: 0; }
input[type=file] { width: 100%; max-width: 100%; min-height: var(--ui-h); padding: .45rem var(--ui-pad-x); border: 1px solid var(--ui-line); border-radius: var(--ui-r); background: var(--ui-surface); color: var(--ui-text); font: inherit; font-size: .95rem; }
input[type=file]::file-selector-button { margin-right: .75rem; min-height: 30px; padding: 0 .8rem; border: 1px solid var(--ui-line); border-radius: calc(var(--ui-r) - 2px); background: var(--s7-surface-2, #f3f4f7); color: var(--ui-text); font: inherit; font-weight: 700; cursor: pointer; }
input[type=range] { width: 100%; max-width: 100%; min-height: 28px; }
input[type=color] { flex: none; }
.input.mono, .mono.input, input.mono { font-family: var(--s7-mono, ui-monospace, monospace); font-size: .95rem; }
.field-sel-eco { display: block; margin-top: .25rem; color: var(--ui-muted); font-size: .85rem; line-height: 1.35; overflow-wrap: anywhere; }

/* ---------- 2. rótulo + campo + ajuda ---------- */
.field { display: flex; flex-direction: column; gap: .35rem; margin: 0 0 var(--ui-gap); min-width: 0; }
.field > label, .field > .label-text, label.label { font-size: .9rem; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.field .help, .help { color: var(--ui-muted); font-size: .82rem; line-height: 1.4; overflow-wrap: anywhere; }
.field .error, .error { color: var(--ui-danger); font-size: .85rem; line-height: 1.4; overflow-wrap: anywhere; }
.check, .proj-chk { display: flex; align-items: flex-start; gap: .55rem; min-width: 0; line-height: 1.4; }
.check input, .proj-chk input { margin-top: .2rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 0 var(--ui-gap); align-items: start; }
.form-grid > .field { margin-bottom: var(--ui-gap); }
.form-grid > .field[style*="grid-column"] { grid-column: 1 / -1; }
.form-actions, .live-form-actions, .s7-form-actions, .proj-foot { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem .75rem; }
.form-actions > .btn, .live-form-actions > .btn, .s7-form-actions > .btn { flex: 0 0 auto; }
.field-row, .row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; min-width: 0; }
.input-group, .live-linkrow, .proj-cor { display: flex; align-items: stretch; gap: .5rem; min-width: 0; }
.input-group > .input, .live-linkrow > .input, .proj-cor > .input { flex: 1 1 auto; min-width: 0; }
.input-group > .btn, .live-linkrow > .btn { flex: none; }

/* ---------- 3. botões ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: var(--ui-h); padding: .25rem 1rem; line-height: 1.25; text-align: center; max-width: 100%; }
.btn.sm { height: var(--ui-h-sm); min-height: var(--ui-h-sm); padding: 0 .7rem; font-size: .875rem; line-height: 1.2; white-space: nowrap; }
.btn.block { display: flex; width: 100%; }
.btn.icon-only { padding: 0; width: var(--ui-h); }
.btn.sm.icon-only { width: var(--ui-h-sm); }
.btn > svg, .btn > .icon { flex: none; }

/* ---------- 4. cabeçalho da página, ações, filtros, abas ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem 1rem; min-width: 0; }
.page-head > div { min-width: 0; }
.page-head h1 { overflow-wrap: anywhere; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; min-width: 0; }
.card, .card-body, .card-head { min-width: 0; }
.card-head { flex-wrap: wrap; row-gap: .5rem; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; min-width: 0; }
.toolbar > * { min-width: 0; }
.sr-only { position: absolute !important; left: 0; top: 0; width: 1px !important; height: 1px !important; max-width: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
.toolbar .select { width: auto; max-width: 100%; min-width: 9rem; }
.toolbar .search, .toolbar .s7-search { flex: 1 1 240px; }
.tabs, .live-tabs, .segmented, .insc-abas-h, .pill-checks { max-width: 100%; }
.tabs, .live-tabs { display: flex; gap: .25rem; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.tabs > *, .live-tabs > a { flex: none; white-space: nowrap; }
.segmented { overflow-x: auto; scrollbar-width: none; }
.segmented::-webkit-scrollbar { display: none; }

/* ---------- 5. nada passa da tela ---------- */
.table-wrap { position: relative; overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
.table-wrap > .table { min-width: max-content; }
.table.responsive { min-width: 0; }
code, pre, .wrap-any, .help, .muted, td, th, dd { overflow-wrap: anywhere; }
pre { white-space: pre-wrap; max-width: 100%; }
td .btn, td form { max-width: 100%; }

/* ---------- 6. celular e tablet estreito ---------- */
@media (max-width: 900px) {
  .page-actions { width: 100%; }
  .page-actions > .btn, .page-actions > form, .page-actions > a { flex: 1 1 auto; }
  .page-actions > form > .btn { width: 100%; }
}
@media (max-width: 700px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar > :not(.sr-only), .toolbar .select, .toolbar .input, .toolbar .search, .toolbar .s7-search { width: 100%; max-width: none; flex: 1 1 auto; }
  .form-actions > .btn, .live-form-actions > .btn, .s7-form-actions > .btn { flex: 1 1 auto; }
  .input-group, .live-linkrow { flex-wrap: wrap; }
  .input-group > .btn, .live-linkrow > .btn { flex: 1 1 100%; }
  .card-head > .btn, .card-head > .page-actions { max-width: 100%; }
  /* cabeçalho do módulo (Eventos): o seletor de evento ganha a largura que sobra, sem encolher até sumir o texto */
  .topbar { flex-wrap: nowrap; }
  .topbar .inst-atual { display: none; }
  .topbar:has(.event-switch) .grow { display: none; }   /* com seletor de evento, ele ocupa o espaço; sem ele, o espaçador empurra tema e perfil para a direita */
  .topbar .event-switch { flex: 1 1 0; min-width: 0; }
  .topbar .event-switch .select { width: 100%; max-width: none; min-width: 0; }
  .topbar .event-switch label { display: none; }
}
@media (max-width: 900px) {
  .sidebar:not(.open) { box-shadow: none; }
  .app:not(.nav-open) .sidebar { box-shadow: none; }
}

/* ---------- 7. casos que já apareceram nas telas (a regra vale para todos) ---------- */
[style*="inline-flex"], [style*="display:flex"], [style*="display: flex"] { flex-wrap: wrap; }
:where([style*="flex"]) > :where(.input, .select) { flex: 1 1 9rem; min-width: 0; }
td .input, td .select, .table .input, .table .select { min-width: 8rem; }
.proj-pos { width: 5rem; min-width: 4.5rem; }
.proj-ctl { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 0 .75rem; }
.insc-admin { grid-template-columns: minmax(0, 1fr) 15rem; }
.insc-admin > * { min-width: 0; }
.search .input { padding-left: 2.5rem; }
@media (max-width: 860px) { .insc-admin { grid-template-columns: minmax(0, 1fr); } .insc-abas ul { max-width: 100%; } }
@media (max-width: 700px) {
  .card-body { padding-left: 1rem; padding-right: 1rem; }
  .proj-set { padding: .9rem .8rem .35rem; }
  .presenca-codigo { font-size: clamp(1.1rem, 5.4vw, 1.6rem); }
  .page-head h1 { font-size: clamp(1.5rem, 7.5vw, 2.1rem); }
}

form[style*="display:inline"] > .input, form[style*="display: inline"] > .input { width: 12rem; max-width: 100%; }
.input.presenca-codigo { font-size: clamp(1.1rem, 5.4vw, 1.6rem); }
.input::placeholder, .textarea::placeholder { font-size: .9rem; }
summary.btn { display: inline-flex; list-style: none; cursor: pointer; }
summary.btn::-webkit-details-marker { display: none; }
.empty .btn svg, .empty .btn .icon { width: 20px; height: 20px; margin: 0; opacity: 1; }
.toolbar > .field { margin: 0; flex: 1 1 12rem; min-width: 0; }
.toolbar > .field .select, .toolbar > .field .input { width: 100%; max-width: none; }
.toolbar > .btn { align-self: flex-end; }
@media (max-width: 700px) { .toolbar > .btn { align-self: stretch; } .toolbar > .field { flex: 1 1 auto; } }
.mod-menu > summary.btn, details > summary.btn { height: var(--ui-h); min-height: var(--ui-h); }
.toolbar .search, .toolbar .s7-search { flex: 1 1 280px; min-width: min(100%, 16rem); }
.toolbar > .field:has(input:not([type=date], [type=month], [type=checkbox])) { flex-basis: 16rem; }
.proj-set .form-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
form[style*="display:inline"] > .input, form[style*="display: inline"] > .input { width: 14rem; }

.event-switch label { white-space: nowrap; }
