/* Cosmos ERP — estilos base */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e4e7ec;
  --text: #101828;
  --text-2: #475467;
  --muted: #667085;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --on-primary: #ffffff;
  --success: #067647;
  --success-soft: #ecfdf3;
  --danger: #d92d20;
  --danger-hover: #b42318;
  --danger-soft: #fef3f2;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --sidebar: #111827;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #64748b;
  --sidebar-active: #1f2937;
  --focus: 0 0 0 3px rgba(79, 70, 229, .25);
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --sidebar-w: 248px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17;
    --surface: #121826;
    --surface-2: #161d2d;
    --border: #253047;
    --text: #e6e9f0;
    --text-2: #b4bccb;
    --muted: #8a94a8;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --primary-soft: #1e1b4b;
    --success: #47cd89;
    --success-soft: #0b2a1c;
    --danger: #f97066;
    --danger-hover: #fda29b;
    --danger-soft: #2d1513;
    --warning: #fdb022;
    --warning-soft: #2b1d05;
    --sidebar: #080b12;
    --sidebar-active: #161d2d;
    --focus: 0 0 0 3px rgba(129, 140, 248, .35);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.3; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sprite { display: none; }
.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Shell ---------- */
.app { display: flex; min-height: 100vh; }
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  width: var(--sidebar-w); flex: none;
  display: flex; flex-direction: column;
  background: var(--sidebar); color: var(--sidebar-text);
  padding: 18px 12px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: #334155 transparent;
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; }
.brand:hover { text-decoration: none; }
.brand .icon { width: 24px; height: 24px; color: #818cf8; }
.brand small { font-size: 11px; font-weight: 600; color: #818cf8; border: 1px solid #3730a3; border-radius: 4px; padding: 0 5px; letter-spacing: .04em; }
.nav-section { margin-bottom: 18px; }
.nav-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--sidebar-muted); padding: 0 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; color: var(--sidebar-text); font-weight: 500;
}
.nav-item:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.nav-item.is-active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #818cf8; }
.nav-item.is-disabled { color: var(--sidebar-muted); cursor: default; }
.nav-item.is-disabled:hover { background: none; color: var(--sidebar-muted); }
/* Submenus (details/summary) */
.nav-group > summary { list-style: none; cursor: pointer; user-select: none; }
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-caret { margin-left: auto; display: inline-flex; color: var(--sidebar-muted); transition: transform .15s; }
.nav-caret .icon { width: 14px; height: 14px; }
.nav-group[open] > summary .nav-caret { transform: rotate(180deg); }
.nav-group > summary .nav-badge + .nav-caret { margin-left: 6px; }
.nav-group[open] > summary .nav-badge { display: none; }
.nav-sub { margin: 2px 0 4px 21px; padding-left: 8px; border-left: 1px solid #1e293b; display: grid; gap: 1px; }
.nav-sub .nav-item { padding-top: 6px; padding-bottom: 6px; font-size: 14px; }
.nav-sub .nav-item .icon { width: 16px; height: 16px; }
.soon { margin-left: auto; font-style: normal; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border: 1px solid currentColor; border-radius: 99px; padding: 0 6px; opacity: .8; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; font-size: 12px; color: var(--sidebar-muted); }
.sidebar-foot small { padding: 0 10px 4px; }
.nav-collapse { width: 100%; border: 0; background: none; font: inherit; cursor: pointer; color: var(--sidebar-muted); }
.nav-collapse .icon { transition: transform .2s; }
/* Busca no menu (Ctrl+K): filtra os módulos; ↑ ↓ escolhem e Enter abre. */
.nav-search { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; padding: 0 10px; height: 36px; border: 1px solid #334155; border-radius: 8px; background: #0b1220; color: var(--sidebar-muted); }
.nav-search:focus-within { border-color: #818cf8; }
.nav-search input[type=search] { flex: 1; width: auto; min-width: 0; height: 100%; border: 0; border-radius: 0; background: none; box-shadow: none; color: #fff; font: inherit; font-size: 13.5px; outline: none; padding: 0; }
.nav-search input::placeholder { color: var(--sidebar-muted); }
.nav-search input::-webkit-search-cancel-button { filter: invert(1); opacity: .5; }
.nav-kbd { font-family: inherit; font-size: 10px; color: var(--sidebar-muted); border: 1px solid #334155; border-radius: 4px; padding: 0 5px; white-space: nowrap; }
.nav-search:focus-within .nav-kbd { display: none; }
.nav-item.is-focused { background: var(--sidebar-active); color: #fff; outline: 1px solid #818cf8; outline-offset: -1px; }
.sidebar [hidden] { display: none !important; }
.list-results [hidden], .toolbar [hidden] { display: none !important; }
.js .no-js-only { display: none; }
.js .show-absent { display: none; } /* Field.ShowWhen: campo que não se aplica à opção escolhida */
.list-results.is-loading { opacity: .6; transition: opacity .15s; }
.nav-empty { margin: 0 10px 12px; font-size: 13px; color: var(--sidebar-muted); }
.sidebar, .sidebar .brand span, .sidebar .brand small { transition: width .2s; }

/* Menu recolhido (só desktop) */
@media (min-width: 901px) {
  .nav-collapsed .sidebar { width: 68px; padding-left: 10px; padding-right: 10px; overflow-x: hidden; }
  .nav-collapsed .sidebar .brand { justify-content: center; padding-left: 0; padding-right: 0; }
  .nav-collapsed .sidebar .brand span, .nav-collapsed .sidebar .brand small,
  .nav-collapsed .nav-item > span, .nav-collapsed .nav-item .soon, .nav-collapsed .nav-search,
  .nav-collapsed .sidebar-foot small { display: none; }
  .nav-collapsed .nav-title { font-size: 0; height: 1px; background: #1e293b; margin: 6px 8px 10px; padding: 0; }
  .nav-collapsed .nav-item { justify-content: center; padding: 10px 0; }
  .nav-collapsed .nav-collapse .icon { transform: rotate(180deg); }
  .nav-collapsed .nav-caret, .nav-collapsed .nav-group > summary .nav-badge { display: none; }
  .nav-collapsed .nav-sub { margin-left: 0; padding-left: 0; border-left: 0; }
}

/* Atalhos */
kbd { display: inline-block; min-width: 22px; padding: 1px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; background: var(--surface-2); font: 600 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center; color: var(--text-2); }
.shortcuts-btn { margin-left: 8px; }
.shortcuts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px 28px; padding-bottom: 20px; }
.shortcuts-grid h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 12px 0 8px; }
.shortcuts-grid dl { margin: 0; display: grid; gap: 6px; }
.shortcuts-grid dl > div { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.shortcuts-grid dt { min-width: 104px; display: flex; gap: 4px; align-items: center; color: var(--muted); }
.shortcuts-grid dd { margin: 0; }
.table tr.is-selected td { background: var(--primary-soft); }
.table tr.is-selected td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
@media (pointer: coarse) { .shortcuts-btn, .nav-kbd { display: none; } }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  height: 60px; padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 600; color: var(--text-2); }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar-user form { margin: 0; }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta small { color: var(--muted); font-size: 12px; }
.topbar .menu-btn, .scrim { display: none; }
.content { padding: 28px 32px 48px; width: 100%; }

.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  font-weight: 650; font-size: 13px;
}
.avatar-sm { width: 32px; height: 32px; font-size: 12px; }

/* ---------- Componentes ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .muted { margin-top: 4px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.crumbs a { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.crumbs .icon { width: 14px; height: 14px; }
.section-title { margin: 28px 0 12px; font-size: 14px; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; box-shadow: var(--focus); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-block { width: 100%; }
.btn:disabled, .btn:disabled:hover { opacity: .5; cursor: not-allowed; background: var(--surface); }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 8px;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.icon-btn.is-disabled { opacity: .35; cursor: default; }

.alert { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 8px; margin-bottom: 18px; border: 1px solid; }
.alert .icon { margin-top: 1px; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.alert-info { background: var(--primary-soft); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 30%, transparent); }
.alert-warn { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 550; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge .icon { width: 13px; height: 13px; }
.badge-accent { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-muted { color: var(--muted); }
.badge-warn { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ---------- Formulários ---------- */
.stack { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; align-content: start; }
.field > span { font-weight: 550; color: var(--text-2); font-size: 13px; }
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { height: auto; min-height: 80px; resize: vertical; line-height: 1.5; padding-top: 8px; padding-bottom: 8px; font: inherit; }
.hint { color: var(--muted); font-size: 12px; }
input.is-suggested { background: var(--primary-soft); } /* preenchido por sugestão (Resource.Suggest) */
/* Seleção com pesquisa (Field.Searchable, app.js) */
.ss { position: relative; }
.ss::after { content: ""; position: absolute; right: 14px; top: 50%; width: 7px; height: 7px; margin-top: -6px; border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); pointer-events: none; }
.ss .ss-input { padding-right: 36px; text-overflow: ellipsis; }
.ss-list { position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px); max-height: min(300px, 50dvh); overflow: auto; overscroll-behavior: contain;
  padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 12px 32px rgba(16, 24, 40, .18); }
.ss-list.ss-float { position: fixed; right: auto; top: auto; } /* dentro de rolagem (sub-grade): left/top/width pelo app.js */
.subgrid .ss .ss-input { padding-right: 28px; }
.subgrid .ss::after { right: 11px; }
.ss-opt { padding: 8px 10px; border-radius: 6px; font-size: 14px; cursor: pointer; overflow-wrap: anywhere; }
.ss-opt.is-active { background: var(--surface-2); }
.ss-opt.is-selected { color: var(--primary); font-weight: 600; }
.ss-opt.ss-none { color: var(--muted); }
.ss-empty { padding: 8px 10px; color: var(--muted); font-size: 13px; }
@media (pointer: coarse) { .ss-opt { padding: 12px 10px; } }
.error { color: var(--danger); font-size: 12px; font-weight: 500; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }

.form { padding: 4px 24px; }
.form fieldset { border: 0; margin: 0; padding: 20px 0; border-bottom: 1px solid var(--border); }
.form legend { float: left; width: 100%; font-weight: 650; font-size: 15px; padding: 0; margin-bottom: 14px; }
.form legend + * { clear: both; }
.form legend + p { margin: -8px 0 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }
.grid-2 > .wide { grid-column: 1 / -1; }
.matrix { border: 1px solid var(--border); border-radius: 8px; }
/* Grade de permissões em modal (FieldMatrix.Modal) */
.matrix-summary { display: grid; gap: 12px; justify-items: start; }
.matrix-full { display: inline-flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); font-weight: 550; font-size: 14px; }
.matrix-full[hidden], .chips[hidden] { display: none; }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 4px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; color: var(--text-2); }
.matrix-group th { background: var(--surface); color: var(--primary); font-size: 11px; padding-top: 14px; text-transform: uppercase; letter-spacing: .05em; }
.matrix-group td { background: var(--surface); padding-top: 14px; }
.matrix-group.depth-1 th { text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text-2); padding-left: 26px; padding-top: 10px; }
.matrix-group.depth-1 td { padding-top: 10px; }
.matrix-group input[type=checkbox] { opacity: .85; }
tr.depth-1 .matrix-name { padding-left: 26px; }
tr.depth-2 .matrix-name { padding-left: 44px; }
.matrix-level-col { white-space: nowrap; text-align: left !important; width: 1%; }
.matrix .level { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.matrix .level[data-level="Completo"] { background: var(--success-soft, #ecfdf3); color: var(--success); }
.matrix .level[data-level="Consulta"] { background: var(--primary-soft); color: var(--primary); }
.matrix .level[data-level="Personalizado"] { background: var(--warning-soft, #fffaeb); color: var(--warning); }
.matrix-group[hidden], [data-matrix-row][hidden] { display: none; }
.matrix-empty { padding: 16px; text-align: center; }
.matrix-empty[hidden] { display: none; }
.modal { width: min(760px, calc(100vw - 32px)); max-height: min(86vh, 900px); padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: 0 24px 64px rgba(16,24,40,.25); }
.modal.modal-wide { width: min(1180px, calc(100vw - 32px)); }
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgba(15, 23, 42, .5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; }
.modal-tools { padding: 12px 20px; border-bottom: 1px solid var(--border); }
.modal-tools .search { display: block; max-width: none; }
.modal-body { overflow: auto; padding: 12px 20px; flex: 1; min-height: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.field.is-off .matrix { opacity: .5; }
/* Modal de confirmação (data-confirm) */
.confirm-modal { width: min(440px, calc(100vw - 32px)); }
.confirm-body { display: flex; gap: 16px; padding: 22px 22px 8px; }
.confirm-icon { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); }
.confirm-icon.is-danger { background: var(--danger-soft); color: var(--danger); }
.confirm-title { font-size: 16px; margin-bottom: 6px; }
.confirm-msg { color: var(--text-2); font-size: 14px; line-height: 1.5; }
.confirm-modal .modal-foot { border-top: 0; padding-top: 12px; }

/* Filtros e ordenação tipo Excel (cabeçalho das listas) */
.th-btn { display: inline-flex; align-items: center; gap: 4px; margin: -4px -6px; padding: 4px 6px; border: 0; border-radius: 6px; background: none; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; }
.th-btn:hover, .th-btn[aria-expanded="true"] { background: var(--border); color: var(--text); }
.th-btn .icon { width: 14px; height: 14px; }
.th-caret { display: inline-flex; opacity: 0; transition: opacity .15s; }
.th-btn:hover .th-caret, .th-btn:focus-visible .th-caret, .th-btn[aria-expanded="true"] .th-caret { opacity: 1; }
.th-btn.is-filtered, .th-btn.is-sorted { color: var(--primary); }
.table th.num .th-btn { flex-direction: row-reverse; }
.col-menu { position: absolute; inset: auto; margin: 0; z-index: 30; width: 290px; padding: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); box-shadow: 0 16px 40px rgba(16,24,40,.18); }
.col-menu[open] { display: flex; flex-direction: column; }
.col-menu-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--border); }
.col-menu-head strong { font-size: 14px; }
.col-menu-section { padding: 6px; border-bottom: 1px solid var(--border); display: grid; gap: 2px; }
.col-menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 6px; background: none; font: inherit; font-size: 14px; color: var(--text); cursor: pointer; text-align: left; }
.col-menu-item:hover { background: var(--surface-2); }
.col-menu-item.is-active { color: var(--primary); font-weight: 550; }
.col-menu-item .icon { width: 16px; height: 16px; color: var(--muted); }
.col-menu-search { display: block; max-width: none; margin: 4px; min-width: 0; }
.col-menu-list { max-height: 260px; overflow: auto; margin: 2px 4px 4px; border: 1px solid var(--border); border-radius: 6px; padding: 4px 0; }
.col-menu-list > p { padding: 8px 10px; }
.col-menu-opt { display: flex; align-items: center; gap: 8px; padding: 5px 10px; font-size: 14px; cursor: pointer; }
.col-menu-opt[hidden] { display: none; }
.col-menu-opt:hover { background: var(--surface-2); }
.col-menu-opt input { width: 16px; height: 16px; accent-color: var(--primary); flex: none; }
.col-menu-opt span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-menu-all { font-weight: 550; border-bottom: 1px solid var(--border); padding-bottom: 7px; margin-bottom: 3px; }
.col-menu-note { padding: 0 8px 4px; }
.col-menu-note[hidden] { display: none; }
.col-menu-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.filter-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.filter-chips-title { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-right: 4px; }
.filter-chips-title .icon { width: 14px; height: 14px; }
.chip-filter { display: inline-flex; align-items: center; gap: 6px; background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.chip-filter:hover { text-decoration: none; filter: brightness(.97); }
.chip-filter .icon { width: 13px; height: 13px; }

/* Soft delete */
.toolbar-end { margin-left: auto; }
.table tr.is-deleted td { color: var(--muted); }
.table tr.is-deleted .thumb, .table tr.is-deleted .avatar { filter: grayscale(1); opacity: .7; }
.tag-deleted { font-style: normal; font-size: 11px; font-weight: 600; color: var(--danger); background: var(--danger-soft); border-radius: 4px; padding: 0 5px; margin-left: 4px; }
.deleted-banner { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 14px 18px; margin-bottom: 18px; border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); background: var(--danger-soft); }
.deleted-banner > div { display: flex; align-items: center; gap: 10px; color: var(--danger); }
.deleted-banner form { margin: 0; }
.timeline-restore::before { border-color: var(--success); }

/* Lightbox */
[data-lightbox] { cursor: zoom-in; }
.lightbox { padding: 0; border: 0; background: rgba(10, 12, 20, .94); max-width: 100vw; max-height: 100vh; width: 100vw; height: 100dvh; margin: 0; }
.lightbox[open] { display: grid; grid-template-rows: auto 1fr auto; }
.lightbox::backdrop { background: rgba(10, 12, 20, .88); }
.lightbox-bar { display: flex; justify-content: flex-end; gap: 8px; padding: 12px; }
.lightbox-bar .icon-btn { color: #fff; background: rgba(255,255,255,.12); width: 40px; height: 40px; }
.lightbox-bar .icon-btn:hover { background: rgba(255,255,255,.22); color: #fff; }
.lightbox-stage { display: grid; place-items: center; min-height: 0; overflow: auto; padding: 0 16px; }
.lightbox-stage img { max-width: calc(100vw - 32px); max-height: calc(100dvh - 130px); object-fit: contain; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.5); cursor: zoom-in; background: #fff; }
.lightbox.is-zoomed .lightbox-stage { place-items: start center; }
.lightbox.is-zoomed .lightbox-stage img { max-width: none; max-height: none; cursor: zoom-out; }
.lightbox-caption { color: #e5e7eb; text-align: center; padding: 12px 16px 18px; font-size: 14px; }

/* Escolha da qualidade da foto */
.quality-modal { width: min(520px, calc(100vw - 32px)); }
.quality-options { display: grid; gap: 10px; padding: 16px 20px 20px; }
.quality-option { display: grid; gap: 4px; width: 100%; -webkit-appearance: none; appearance: none; text-align: left; padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.quality-option:hover, .quality-option:focus-visible { border-color: var(--primary); box-shadow: var(--focus); outline: none; }
.quality-option strong { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.quality-option strong .badge { font-style: normal; }
.quality-option span { font-variant-numeric: tabular-nums; color: var(--primary); font-weight: 550; font-size: 14px; }
.quality-option small { color: var(--muted); font-size: 13px; line-height: 1.4; }
.photo-preview { position: relative; }
.photo-hd { position: absolute; top: 0; left: 0; margin: 8px; padding: 1px 6px; border-radius: 4px; background: rgba(15,23,42,.75); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .04em; pointer-events: none; }

/* Galeria de fotos (FieldGallery) */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.gallery-item { position: relative; margin: 0; aspect-ratio: 1; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-2); display: flex; flex-direction: column; }
.gallery-img { flex: 1; min-height: 0; display: block; }
.gallery-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-item.is-cover { border: 2px solid var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.gallery-item.is-cover::before { content: "★ Capa"; position: absolute; top: 6px; left: 6px; z-index: 1; padding: 1px 7px; border-radius: 4px; background: var(--primary); color: #fff; font-size: 11px; font-weight: 700; }
.gallery-item.is-pending { border-style: dashed; border-color: var(--primary); }
.gallery-new, .gallery-hd { position: absolute; top: 6px; right: 6px; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 700; color: #fff; background: rgba(15,23,42,.75); pointer-events: none; }
.gallery-new { background: var(--success); }
.gallery-item.is-deleting .gallery-img { opacity: .3; filter: grayscale(1); }
.gallery-item.is-deleting::after { content: "Será excluída"; position: absolute; inset: 0 0 38px; display: grid; place-items: center; color: var(--danger); font-weight: 700; font-size: 13px; pointer-events: none; }
.gallery-actions { display: flex; border-top: 1px solid var(--border); background: var(--surface); }
.gallery-btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 4px; height: 36px; border: 0; background: none; font: inherit; font-size: 12px; color: var(--text-2); cursor: pointer; position: relative; }
.gallery-btn + .gallery-btn { border-left: 1px solid var(--border); }
.gallery-btn:hover { background: var(--surface-2); }
.gallery-btn .icon { width: 15px; height: 15px; }
.gallery-btn input { position: absolute; opacity: 0; pointer-events: none; }
.gallery-btn:has(input[type=radio]:checked) { color: var(--primary); font-weight: 600; }
.gallery-btn:has(input[type=radio]:checked) .icon { fill: currentColor; }
.gallery-btn:has(input[type=radio]:disabled) { opacity: .4; cursor: default; }
.gallery-del:hover, .gallery-btn.gallery-del:has(input:checked) { color: var(--danger); }
.gallery-btn:has(input:focus-visible) { box-shadow: inset var(--focus); }
.gallery-btn.gallery-grip { flex: 0 0 34px; cursor: grab; touch-action: none; color: var(--text-3, var(--text-2)); }
.gallery-btn.gallery-grip:focus-visible { box-shadow: inset var(--focus); outline: none; }
.gallery-item.is-dragging { opacity: .35; border-style: dashed; }
.gallery-ghost { position: fixed; left: 0; top: 0; z-index: 1000; margin: 0; pointer-events: none; box-shadow: 0 12px 32px rgba(15,23,42,.3); transform-origin: 0 0; opacity: .95; }
body.is-sorting, body.is-sorting * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }
@media (pointer: fine) { .gallery-img img { cursor: grab; } }
.gallery-target { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 2px 0 10px; font-size: 13px; font-weight: 400; color: var(--text-2); }
.gallery-target .icon { width: 16px; height: 16px; }
.gallery-target select { height: 32px; max-width: 100%; font-size: 13px; }
.gallery-item:has(.gallery-owner) { aspect-ratio: 4 / 5; }
.gallery-owner { display: block; border-top: 1px solid var(--border); background: var(--surface); }
.gallery-owner select { width: 100%; height: 30px; padding: 0 8px; border: 0; border-radius: 0; background: transparent; color: var(--text-2); font-size: 12px; }
.gallery-owner.is-sku select { color: var(--primary); font-weight: 600; }
.gallery-item:has(.gallery-owner) .gallery-crop { bottom: 76px; }
.gallery-crop { position: absolute; right: 6px; bottom: 44px; z-index: 1; display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 50%; background: rgba(15,23,42,.7); color: #fff; cursor: pointer; }
.gallery-crop:hover { background: var(--primary); }
.gallery-crop:focus-visible { outline: none; box-shadow: var(--focus); }
.gallery-crop .icon { width: 16px; height: 16px; }
.gallery-item.is-deleting .gallery-crop { display: none; }
.gallery-item[hidden] { display: none; }
.gallery-btn[aria-pressed="true"] { color: var(--primary); font-weight: 600; }
.gallery-btn[aria-pressed="true"] .icon { fill: currentColor; }
.gallery-btn[data-gallery-cover]:focus-visible, .gallery-btn[data-gallery-delete]:focus-visible { box-shadow: inset var(--focus); outline: none; }
.gallery-item.is-busy { opacity: .55; pointer-events: none; }
.gallery-item.is-busy::after { content: ""; position: absolute; top: calc(50% - 30px); left: calc(50% - 12px); width: 24px; height: 24px; border: 3px solid rgba(255,255,255,.8); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
.gallery-uploading { position: relative; aspect-ratio: 1; border: 2px dashed var(--primary); border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.gallery-uploading img { width: 100%; height: 100%; object-fit: cover; opacity: .45; display: block; }
.gallery-uploading > div { position: absolute; inset: auto 0 0; display: grid; gap: 6px; padding: 10px; background: var(--surface); }
.gallery-uploading small { font-size: 12px; color: var(--text-2); }
.gallery-progress { display: block; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.gallery-progress > span { display: block; height: 100%; width: 0; background: var(--primary); transition: width .2s; }
@keyframes spin { to { transform: rotate(360deg); } }
.gallery-add { aspect-ratio: 1; display: grid; gap: 8px; align-content: center; padding: 10px; border: 2px dashed var(--border); border-radius: 10px; }
.gallery-add[hidden] { display: none; }
.gallery-add-btn { position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text-2); font-size: 13px; font-weight: 550; cursor: pointer; }
.gallery-add-btn:hover { border-color: var(--primary); color: var(--primary); }
.gallery-add-btn.btn-camera { display: none; }
@media (pointer: coarse) { .gallery-add-btn.btn-camera { display: inline-flex; } }
.lightbox-stage { position: relative; }
.lightbox-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 1; width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; display: grid; place-items: center; cursor: pointer; }
.lightbox-nav:hover { background: rgba(255,255,255,.26); }
.lightbox-nav[hidden] { display: none; }
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }

/* Histórico (auditoria) */
.history { margin-top: 20px; padding: 18px 24px; }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.history-head h2 { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; }
.history-head a { font-size: 13px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item { position: relative; padding: 0 0 18px 22px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline-item:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline-item::before { content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--primary); }
.timeline-create::before { border-color: var(--success); }
.timeline-delete::before { border-color: var(--danger); }
.timeline-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; }
.changes { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.changes li { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 6px 10px; background: var(--surface-2); border-radius: 6px; }
.change-label { color: var(--text-2); font-weight: 550; min-width: 140px; }
.change-values { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 6px; overflow-wrap: anywhere; min-width: 0; }
.changes del { color: var(--danger); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.changes ins { color: var(--success); text-decoration: none; font-weight: 550; }
.changes .arrow { color: var(--muted); }
.changes-details { margin-top: 6px; font-size: 13px; }
.changes-details summary { cursor: pointer; color: var(--primary); }
.history .pager { padding: 14px 0 0; }

/* Foto (FieldImage) */
.photo-field { display: flex; gap: 20px; align-items: flex-start; }
.photo-preview { flex: none; width: 160px; height: 160px; border: 1px dashed var(--border); border-radius: 12px; background: var(--surface-2); overflow: hidden; display: grid; place-items: center; }
.photo-preview a { display: block; width: 100%; height: 100%; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-preview img[hidden] { display: none; }
.photo-empty { display: grid; justify-items: center; gap: 4px; color: var(--muted); }
.photo-empty[hidden] { display: none; }
.photo-empty .icon { width: 32px; height: 32px; opacity: .6; }
.photo-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; align-content: flex-start; }
.photo-actions .hint, .photo-actions .error { flex-basis: 100%; }
.photo-actions .btn { position: relative; overflow: hidden; }
.file-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.btn-camera, .label-touch { display: none; }
@media (pointer: coarse) {
  .btn-camera { display: inline-flex; }
  .label-touch { display: inline; }
  .label-desktop { display: none; }
}
.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; flex: none; background: var(--surface-2); border: 1px solid var(--border); }
.thumb-empty { display: grid; place-items: center; color: var(--muted); }
.matrix .table td { padding-top: 10px; padding-bottom: 10px; }
.matrix .table tbody tr:last-child td { border-bottom: 0; }
.matrix-col { width: 1%; text-align: center !important; white-space: nowrap; padding-left: 12px !important; padding-right: 12px !important; }
.matrix th.matrix-col { font-size: 10.5px; }
.matrix input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; vertical-align: middle; }
.matrix input[type=checkbox]:disabled { cursor: default; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 18px 0 20px; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; height: 40px; }
.switch input { position: absolute; opacity: 0; }
.switch-track { position: relative; width: 38px; height: 22px; border-radius: 99px; background: var(--border); transition: background .15s; flex: none; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus); }
.switch input:disabled + .switch-track { opacity: .55; }

.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 20px; padding: 18px 24px; border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.danger-zone p { margin-top: 2px; }

/* ---------- Tabela / listagem ---------- */
.toolbar { display: flex; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 420px; }
.search .icon { position: absolute; left: 11px; top: 11px; color: var(--muted); }
.search input { padding-left: 36px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:hover { background: var(--surface-2); }
.col-actions { width: 1%; text-align: right; }
.entity-cell { display: flex; align-items: center; gap: 12px; color: var(--text); }
.entity-cell:hover { text-decoration: none; }
/* Árvore matriz/filiais (#905): recuo por nível, igual no celular. */
.entity-cell.tree-d1 { padding-left: 20px; }
.entity-cell.tree-d2 { padding-left: 40px; }
.entity-cell.tree-d3 { padding-left: 60px; }
.entity-cell.tree-d4, .entity-cell.tree-d5, .entity-cell.tree-d6 { padding-left: 80px; }
.entity-cell[class*="tree-d"] { border-left: 2px solid var(--border, #d0d5dd); margin-left: 6px; }
.entity-cell:hover strong { color: var(--primary); }
.entity-cell > span:last-child { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.entity-cell small { color: var(--muted); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; width: 1%; white-space: nowrap; }
.you { font-style: normal; font-size: 11px; font-weight: 600; color: var(--primary); background: var(--primary-soft); border-radius: 4px; padding: 0 5px; margin-left: 4px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; flex-wrap: wrap; }
.pager-links { display: flex; align-items: center; gap: 6px; }
.empty { display: grid; justify-items: center; gap: 10px; padding: 48px 24px; text-align: center; color: var(--muted); }
.empty > .icon { width: 36px; height: 36px; opacity: .6; }
.card.empty h1 { color: var(--text); }

/* ---------- Home ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; display: grid; gap: 6px; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-value.is-alert { color: var(--danger); }
.section-title a { color: inherit; text-decoration: none; }
.section-title a:hover { color: var(--primary); }
.modules { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.module { display: flex; align-items: center; gap: 14px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); box-shadow: var(--shadow); }
a.module:hover { border-color: var(--primary); text-decoration: none; }
.module > .icon:last-child { margin-left: auto; color: var(--muted); }
.module-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); flex: none; }
.module-body { display: flex; flex-direction: column; line-height: 1.35; }
.module-body small { color: var(--muted); }
.module.is-disabled { opacity: .7; box-shadow: none; }
.module.is-disabled .module-icon { background: var(--surface-2); color: var(--muted); }

/* ---------- Login ---------- */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--primary-soft), transparent 60%), var(--bg);
}
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 12px 32px rgba(16,24,40,.08); padding: 32px; }
.auth-card .brand { color: var(--text); padding: 0 0 22px; }
.auth-card h1 { font-size: 20px; }
.auth-card > .muted { margin: 4px 0 22px; }
.auth-links { margin-top: 18px; text-align: center; font-size: 13px; color: var(--muted); }
.auth-links a { color: var(--text-2); }
/* Termo de uso e aviso de privacidade: texto longo, cartão mais largo. */
.auth-card.legal { max-width: 760px; }
.legal-text h2 { font-size: 16px; margin: 22px 0 6px; }
.legal-text p, .legal-text li { line-height: 1.6; color: var(--text-2); }
.legal-text ul { padding-left: 20px; margin: 6px 0; }
.legal-text .version { font-size: 12px; color: var(--muted); }
.check-accept { display: flex; align-items: flex-start; gap: 10px; line-height: 1.5; color: var(--text-2); cursor: pointer; }
/* Verificação em duas etapas: QR code, chave e códigos de recuperação. */
.qr-box { display: grid; place-items: center; margin: 4px 0 18px; }
.qr-box .qr { width: 200px; max-width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--border); }
.steps { padding-left: 20px; margin: 0 0 16px; line-height: 1.6; color: var(--text-2); }
.totp-key { overflow-wrap: anywhere; font-weight: 600; }
.recovery-codes { columns: 2; gap: 16px; padding-left: 24px; margin: 0 0 18px; font-size: 15px; line-height: 1.9; }
/* Assinatura pela landing page (#918): o plano escolhido. */
.plan-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; margin: 0 0 18px; border: 1px solid var(--border); border-radius: 10px; background: var(--primary-soft); }
.plan-summary div { display: grid; gap: 2px; }
.plan-summary .muted { font-size: 13px; }
.plan-price { font-weight: 700; color: var(--primary); }
.check-accept input { width: 20px; height: 20px; margin-top: 1px; flex: none; accent-color: var(--primary); }

/* ---------- Responsivo ---------- */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform .2s ease; }
  .nav-toggle:checked ~ .sidebar { transform: none; }
  .nav-toggle:checked ~ .scrim { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.4); }
  .topbar .menu-btn { display: inline-grid; }
  .topbar { padding: 0 16px; }
  .content { padding: 20px 16px 40px; }
  .user-meta { display: none; }
}
@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
  .form { padding: 0 16px; }
  .danger-zone { flex-direction: column; align-items: stretch; padding: 16px; }
  .table th, .table td { padding-left: 12px; padding-right: 12px; }
  .toolbar { padding: 12px; }
  .table .hide-sm { display: none; }
  /* No celular a coluna principal já abre o registro: sem coluna de ações. */
  .table .col-actions { display: none; }
  .entity-cell strong { overflow-wrap: anywhere; }
  .auth-card { padding: 24px; }
  .matrix-col { padding-left: 4px !important; padding-right: 4px !important; }
  .photo-field { flex-direction: column; align-items: stretch; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .modal { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
  .modal-body, .modal-head, .modal-tools, .modal-foot { padding-left: 16px; padding-right: 16px; }
  .modal-foot .btn { flex: 1; justify-content: center; min-height: 44px; }
  .col-menu:modal { position: fixed; inset: auto 0 0 0; width: 100vw; max-width: 100vw; max-height: 85dvh; border-radius: 14px 14px 0 0; }
  .col-menu::backdrop { background: rgba(15, 23, 42, .45); }
  .col-menu-list { max-height: 40dvh; }
  .col-menu-opt { padding: 9px 12px; }
  .col-menu-foot .btn { flex: 1; justify-content: center; min-height: 44px; }
  /* Modais compactos: altura pelo conteúdo. No iOS Safari, height: fit-content
     com o corpo em flex: 1 (base 0%) colapsa o corpo a 0 e o modal vira só o
     cabeçalho; por isso height: auto e o corpo com base no próprio conteúdo. */
  .quality-modal, .confirm-modal { width: calc(100vw - 32px); height: auto; max-height: calc(100dvh - 32px); margin: auto; border-radius: 14px; }
  .quality-modal .modal-body, .confirm-modal .modal-body { flex: 0 1 auto; }
  .quality-options { padding: 14px 16px 16px; }
  .quality-option { padding: 14px; min-height: 44px; }
  .history { padding: 16px; }
  .change-label { min-width: 0; flex-basis: 100%; }
  .photo-preview { width: 100%; height: auto; aspect-ratio: 4 / 3; }
  .photo-actions .btn { flex: 1; justify-content: center; min-height: 44px; }
  .matrix th, .matrix td { font-size: 12px; }
}

/* Recorte de foto */
.crop-modal { width: min(980px, calc(100vw - 32px)); }
.crop-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 20px; border-bottom: 1px solid var(--border); }
.crop-aspects, .crop-rotate { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chip-btn { height: 30px; padding: 0 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text-2); font: inherit; font-size: 13px; cursor: pointer; }
.chip-btn:hover { border-color: var(--primary); color: var(--primary); }
.chip-btn[aria-pressed="true"] { border-color: var(--primary); background: var(--primary); color: #fff; }
.crop-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 16px; background: #111827; overflow: hidden; }
.crop-frame { position: relative; line-height: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
.crop-frame canvas { display: block; max-width: 100%; max-height: calc(min(86vh, 900px) - 230px); width: auto; height: auto; }
.crop-box { position: absolute; box-sizing: border-box; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.55); cursor: move; touch-action: none; outline: none;
  background-image: linear-gradient(rgba(255,255,255,.35), rgba(255,255,255,.35)), linear-gradient(rgba(255,255,255,.35), rgba(255,255,255,.35)), linear-gradient(90deg, rgba(255,255,255,.35), rgba(255,255,255,.35)), linear-gradient(90deg, rgba(255,255,255,.35), rgba(255,255,255,.35));
  background-size: 100% 1px, 100% 1px, 1px 100%, 1px 100%; background-position: 0 33.33%, 0 66.67%, 33.33% 0, 66.67% 0; background-repeat: no-repeat; }
.crop-box:focus-visible { border-color: var(--primary); }
.crop-h { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; touch-action: none; }
.crop-h::after { content: ""; position: absolute; inset: 6px; border-radius: 2px; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.4); }
.crop-nw { left: 0; top: 0; cursor: nwse-resize; } .crop-n { left: 50%; top: 0; cursor: ns-resize; }
.crop-ne { left: 100%; top: 0; cursor: nesw-resize; } .crop-e { left: 100%; top: 50%; cursor: ew-resize; }
.crop-se { left: 100%; top: 100%; cursor: nwse-resize; } .crop-s { left: 50%; top: 100%; cursor: ns-resize; }
.crop-sw { left: 0; top: 100%; cursor: nesw-resize; } .crop-w { left: 0; top: 50%; cursor: ew-resize; }
.crop-modal .modal-foot { align-items: center; }
.crop-size { margin-right: auto; font-variant-numeric: tabular-nums; }
@media (pointer: coarse) { .crop-h { width: 34px; height: 34px; margin: -17px 0 0 -17px; } .crop-h::after { inset: 11px; } }
@media (max-width: 640px) {
  .crop-modal { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .crop-tools { padding: 8px 12px; }
  .crop-stage { padding: 12px; }
  .crop-frame canvas { max-height: calc(100dvh - 210px); }
  .crop-modal .modal-foot { padding: 10px 12px; }
}

/* Fotos excluídas da galeria (soft delete) */
.gallery-trash { margin-top: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.gallery-trash[hidden] { display: none; }
.gallery-trash summary { display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-2); list-style: none; }
.gallery-trash summary::-webkit-details-marker { display: none; }
.gallery-trash summary::after { content: "▸"; margin-left: auto; transition: transform .15s; }
.gallery-trash[open] summary::after { transform: rotate(90deg); }
.gallery-trash summary .icon { width: 16px; height: 16px; }
.gallery-trash > p { margin: 0 14px 10px; }
.gallery-trash-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 0 14px 14px; }
.trash-item { margin: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.trash-item a { display: block; aspect-ratio: 4 / 3; }
.trash-item img { width: 100%; height: 100%; object-fit: cover; display: block; filter: grayscale(.6); opacity: .8; }
.trash-item figcaption { display: grid; gap: 6px; padding: 8px; background: var(--surface); }
.trash-item small { font-size: 11px; color: var(--text-2); }
.trash-item .btn { justify-content: center; }
@media (max-width: 640px) { .gallery-trash-list { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Selo de situação ao lado do título */
.head-badge { vertical-align: middle; margin-left: 8px; font-size: 13px; }

/* Campos somente leitura com link e arquivo */
.field-static { margin: 0; min-height: 40px; display: flex; align-items: center; padding: 0 2px; }
.field-static a { color: var(--primary); font-weight: 550; }
.file-field { padding: 8px; border: 1px dashed var(--border); border-radius: 8px; background: var(--surface-2); }

/* Abas do formulário (FieldSet.Tab) */
.tabs { margin-top: 4px; }
.tab-list { display: flex; gap: 2px; overflow-x: auto; overflow-y: hidden; box-shadow: inset 0 -1px 0 var(--border); margin-bottom: 18px; scrollbar-width: none; }
.tab-list::-webkit-scrollbar { display: none; }
.tab { position: relative; flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; border: 0; border-bottom: 2px solid transparent; background: none; font: inherit; font-weight: 550; color: var(--text-2); cursor: pointer; border-radius: 6px 6px 0 0; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.tab:focus-visible { outline: none; box-shadow: inset var(--focus); }
.tab.has-error { color: var(--danger); }
.tab-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }
.tab-panel[hidden] { display: none; }
.tab-panel > fieldset:first-child { margin-top: 0; }

/* Sub-grade (FieldGrid) */
.subgrid-wrap { position: relative; border: 1px solid var(--border); border-radius: 10px; } /* relative: os .sr-only absolutos ficam dentro da rolagem */
.subgrid { font-size: 13px; }
.subgrid th { white-space: nowrap; }
.subgrid td { vertical-align: top; }
.subgrid td.num, .subgrid th.num { text-align: right; }
.subgrid td.nowrap { white-space: nowrap; }
.subgrid td.wide { min-width: 220px; }
.subgrid select, .subgrid input[type=text] { width: 100%; min-width: 0; height: 34px; padding: 0 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; }
.subgrid td.num input { text-align: right; width: 80px; }
.subgrid select:focus, .subgrid input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.subgrid td.has-error select, .subgrid td.has-error input { border-color: var(--danger); }
.subgrid .cell-note { display: block; margin-top: 3px; font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.subgrid .error { display: block; margin-top: 3px; font-size: 11.5px; line-height: 1.35; white-space: normal; min-width: 120px; }
.subgrid .cell-note.note-info { color: var(--primary); }
.subgrid .cell-note.note-warn { color: var(--warning); font-weight: 550; }
.subgrid .cell-note.note-ok { color: var(--success); }
.subgrid tr.row-warn > td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
.subgrid tr.row-error > td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.subgrid tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--border); white-space: nowrap; }
.subgrid td a { color: var(--primary); }
.subgrid tr.is-removed td { opacity: .45; }
.subgrid tr.is-removed td .cell-text, .subgrid tr.is-removed td input, .subgrid tr.is-removed td select { text-decoration: line-through; }
.subgrid-add { margin-top: 10px; align-self: flex-start; }
.subgrid .col-drag { width: 40px; padding-left: 6px; padding-right: 0; }
.subgrid-drag { cursor: grab; touch-action: none; color: var(--muted); }
.subgrid-drag:active { cursor: grabbing; }
.subgrid tr.is-dragging td { background: var(--primary-soft); }
.subgrid-remove { position: relative; cursor: pointer; }
.subgrid-remove input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.subgrid-remove:has(input:checked) { color: var(--danger); background: var(--danger-soft, #fee2e2); }
.subgrid-remove:has(input:focus-visible) { box-shadow: var(--focus); }
.action-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; margin-top: 16px; }
.action-bar-input { align-items: flex-end; }
.action-input { flex: 1; margin: 0; }
@media (max-width: 640px) { .action-bar-input { flex-direction: column; align-items: stretch; } }

/* Celular: cada linha da sub-grade vira um cartão (rótulo: valor) */
@media (max-width: 760px) {
  .subgrid-wrap { border: 0; overflow: visible; }
  .subgrid, .subgrid tbody, .subgrid tfoot { display: block; }
  .subgrid thead { display: none; }
  .subgrid tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 12px; padding: 12px; margin-bottom: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
  .subgrid tr.row-warn { border-color: var(--warning); }
  .subgrid tr.row-error { border-color: var(--danger); }
  .subgrid tr > td:first-child { box-shadow: none !important; }
  .subgrid td { display: block; padding: 0; border: 0; text-align: left !important; min-width: 0 !important; }
  .subgrid td::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
  .subgrid td.wide { grid-column: 1 / -1; }
  .subgrid td.nowrap { white-space: normal; }
  .subgrid td.num { width: auto; }
  .subgrid td.num input { width: 100%; text-align: left; }
  .subgrid select, .subgrid input[type=text] { height: 40px; }
  .subgrid tfoot tr { background: var(--surface-2); }
  .subgrid tfoot td:not([data-label]) { display: none; }
  .subgrid tr.subgrid-empty { display: block; }
  .subgrid td.col-drag { grid-column: 1 / -1; width: auto; margin: -4px 0 -2px -6px; }
  .subgrid td.col-drag::before { content: none; }
  .subgrid tr.subgrid-empty td::before { content: none; }
}

.matrix-na { color: var(--border); }

/* Contador no menu (ex.: alertas ativos) */
.nav-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: inline-grid; place-items: center; font-size: 11px; font-style: normal; font-weight: 700; background: var(--sidebar-active); color: var(--sidebar-text); }
.nav-badge-danger { background: var(--danger); color: #fff; }
.nav-badge + .nav-kbd { margin-left: 6px; }
.nav-collapsed .nav-badge { position: absolute; top: 4px; right: 6px; min-width: 16px; height: 16px; font-size: 10px; padding: 0 4px; }
.nav-item { position: relative; }

/* Painel de observabilidade */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented a { padding: 7px 12px; font-size: 13px; color: var(--text-2); text-decoration: none; border-left: 1px solid var(--border); }
.segmented a:first-child { border-left: 0; }
.segmented a.is-active { background: var(--primary); color: var(--on-primary); font-weight: 600; }
.obs-cards { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.obs-card { text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 2px; }
a.obs-card:hover { border-color: var(--primary); }
.obs-card.tone-bad .stat-value { color: var(--danger); }
.obs-card.tone-ok .stat-value { color: var(--success); }
.obs-charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 16px; margin: 18px 0; }
.obs-chart { margin: 0; padding: 14px 16px; }
.obs-chart figcaption { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 12px; margin-bottom: 8px; }
.obs-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--text-2); }
.obs-legend .lg i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; background: currentColor; }
.obs-plot { position: relative; height: 150px; }
.obs-plot svg { width: 100%; height: 100%; display: block; overflow: visible; }
.obs-plot .axis { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.obs-plot .grid { stroke: var(--border); stroke-dasharray: 3 4; stroke-width: 1; vector-effect: non-scaling-stroke; }
.obs-plot .line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.obs-plot .area { fill: var(--primary-soft); stroke: none; opacity: .8; }
.obs-ymax { position: absolute; top: -4px; left: 0; font-size: 11px; color: var(--muted); background: var(--surface); padding-right: 4px; }
.obs-empty { position: absolute; inset: 0; display: grid; place-items: center; }
.obs-x { display: flex; justify-content: space-between; margin-top: 4px; }
.obs-chart > p { margin: 6px 0 0; }
.lg.s1 { color: var(--primary); } .lg.s2 { color: #0ea5e9; } .lg.s-bad { color: var(--danger); } .lg.s-warn { color: var(--warning); }
.line.s1 { stroke: var(--primary); } .line.s2 { stroke: #0ea5e9; } .line.s-bad { stroke: var(--danger); } .line.s-warn { stroke: var(--warning); }
.obs-tables { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
.obs-tables .card { padding: 14px 16px; }
.card-title { font-size: 15px; margin: 0 0 10px; display: flex; justify-content: space-between; align-items: baseline; }
.obs-errors { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.obs-errors li { display: grid; gap: 2px; }
.obs-errors a { color: var(--text); text-decoration: none; }
.obs-errors a:hover strong { color: var(--primary); }
@media (max-width: 900px) { .obs-tables { grid-template-columns: 1fr; } .obs-charts { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .obs-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } .obs-card .stat-value { font-size: 22px; } .segmented a { padding: 7px 9px; } }

/* Cabeçalho com ações (ex.: Executar relatório) */
.page-head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
/* Campo de código (FieldTextarea.Code, ex.: SQL dos relatórios) */
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.5; tab-size: 4; white-space: pre; overflow-x: auto; }

/* Relatórios dinâmicos */
.report-filters { margin-bottom: 16px; }
.report-filters > summary { display: flex; align-items: center; gap: 8px; padding: 14px 16px; cursor: pointer; font-weight: 600; list-style: none; min-height: 44px; }
.report-filters > summary::-webkit-details-marker { display: none; }
.report-filters form { padding: 0 16px; border-top: 1px solid var(--border); }
.report-filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 18px; padding-top: 16px; }
.report-range { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
input[type=date], input[type=number] { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; min-width: 0; }
.report-table td { white-space: nowrap; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.report-table .th-btn { text-decoration: none; }
.field input[type=color] { width: 88px; height: 42px; padding: 3px; cursor: pointer; }

/* Seletor de tema da loja (FieldThemePicker, themepicker.js) */
.tp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tp-card { display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 8px; border: 2px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.tp-card:hover { border-color: var(--muted); }
.tp-card[aria-checked="true"] { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.tp-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.tp-card:disabled { opacity: .6; cursor: not-allowed; }
.tp-name { font-size: 14px; }
.tp-desc { color: var(--muted); font-size: 12px; line-height: 1.35; }
/* Miniatura: um pedaço da loja com as cores, as letras e os cantos do tema. */
.tp-shot { --tp-r: 8px; --tp-rb: 8px; --tp-ff: system-ui, sans-serif; --tp-fw: 700;
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "bar bar" "title btn" "tiles tiles"; align-items: center; gap: 8px;
  padding: 8px; aspect-ratio: 4 / 3; border-radius: 8px; background: var(--tp-bg); color: var(--tp-text); border: 1px solid rgb(0 0 0 / .08); overflow: hidden; }
.tp-bar { grid-area: bar; display: flex; align-items: center; gap: 6px; padding: 4px 6px; background: var(--tp-surface); border-radius: var(--tp-r); }
.tp-logo { width: 16px; height: 8px; border-radius: 2px; background: var(--tp-primary); }
.tp-nav { width: 14px; height: 4px; border-radius: 2px; background: var(--tp-text); opacity: .35; }
.tp-nav:first-of-type { margin-left: auto; }
.tp-title { grid-area: title; font: var(--tp-fw) 26px/1 var(--tp-ff); color: var(--tp-text); }
.tp-btn { grid-area: btn; padding: 4px 8px; font: 600 10px/1.2 system-ui, sans-serif; background: var(--tp-primary); color: var(--tp-primary-ink); border-radius: var(--tp-rb); }
.tp-tiles { grid-area: tiles; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tp-tiles i { height: 28px; background: var(--tp-surface); border-radius: var(--tp-r); border-bottom: 3px solid var(--tp-accent); }
.tp-font-serif { --tp-ff: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; --tp-fw: 500; }
.tp-font-slab { --tp-ff: Rockwell, "Roboto Slab", "Zilla Slab", Georgia, serif; --tp-fw: 700; }
.tp-font-round { --tp-ff: ui-rounded, "Quicksand", "Nunito", "Arial Rounded MT Bold", system-ui, sans-serif; --tp-fw: 700; }
.tp-font-impact { --tp-ff: Impact, "Arial Narrow Bold", "Haettenschweiler", Arial, sans-serif; --tp-fw: 400; }
.tp-radius-sharp { --tp-r: 0; --tp-rb: 0; }
.tp-radius-soft { --tp-r: 8px; --tp-rb: 6px; }
.tp-radius-round { --tp-r: 12px; --tp-rb: 99px; }
.tp-preview { display: grid; gap: 6px; margin-top: 12px; padding: 12px; border: 1px dashed var(--border); border-radius: 10px; background: var(--surface-2); }
.tp-preview-label { font-size: 13px; color: var(--text-2); font-weight: 550; }
.tp-preview-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tp-url { flex: 1 1 240px; min-width: 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: 13px; overflow-wrap: anywhere; color: var(--primary); }
.tp-url:hover { text-decoration: underline; }
