/* =====================================================================
   GoPOS — interface (HTML/CSS/JS puro)
   Tema claro/escuro por variáveis; densidade pensada para uso diário.
   ===================================================================== */

:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f4;
  --border: #dde1e7;
  --border-strong: #c4cad3;
  --text: #1c2330;
  --text-2: #4b5565;
  --text-3: #7a8494;
  --accent: #1f4fbf;
  --accent-hover: #1a43a3;
  --accent-soft: #e6edfc;
  --accent-text: #ffffff;
  --titlebar: #1f4fbf;
  --titlebar-text: #ffffff;
  --ok: #157f3c;
  --ok-soft: #e3f4e9;
  --warn: #9a5b00;
  --warn-soft: #fff3dc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .08);
  --radius: 8px;
  --radius-sm: 5px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #13161c;
  --surface: #1b1f27;
  --surface-2: #20252e;
  --surface-3: #282e39;
  --border: #2f3542;
  --border-strong: #3d4453;
  --text: #e7eaf0;
  --text-2: #b3bac6;
  --text-3: #8790a0;
  --accent: #5b8cff;
  --accent-hover: #7aa2ff;
  --accent-soft: #22304f;
  --accent-text: #0d1320;
  --titlebar: #171b22;
  --titlebar-text: #e7eaf0;
  --ok: #4cc27a;
  --ok-soft: #173424;
  --warn: #f0b44c;
  --warn-soft: #3a2c12;
  --danger: #ff7a70;
  --danger-soft: #3d1b19;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--text-3); }
.mono { font-family: var(--mono); font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-lg { width: 22px; height: 22px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------------------------------------ splash */
.splash {
  height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: var(--titlebar); color: var(--titlebar-text);
}
.splash-logo { width: 72px; height: 72px; border-radius: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.splash-name { font-size: 28px; font-weight: 650; letter-spacing: .5px; }
.splash-status { opacity: .85; min-height: 20px; }
.splash-bar { width: 180px; height: 3px; background: rgba(255,255,255,.2); border-radius: 3px; overflow: hidden; }
.splash-bar::after { content: ""; display: block; width: 40%; height: 100%; background: #fff; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }

/* ------------------------------------------------------------ ecrãs de entrada */
.gate {
  height: 100vh; display: grid; place-items: center; padding: 24px; overflow: auto;
  background: linear-gradient(160deg, var(--titlebar) 0 38%, var(--bg) 38%);
}
.gate-card {
  width: min(440px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 28px;
}
.gate-card.wide { width: min(560px, 100%); }
.gate-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.gate-brand img { width: 40px; height: 40px; border-radius: 10px; }
.gate-brand .name { font-size: 20px; font-weight: 650; }
.gate-brand .sub { color: var(--text-3); font-size: 13px; }
.gate h1 { font-size: 18px; margin: 0 0 4px; }
.gate p.lead { color: var(--text-2); margin: 0 0 18px; }
.gate-footer { margin-top: 16px; display: flex; justify-content: space-between; align-items: center; color: var(--text-3); font-size: 12px; }

/* ------------------------------------------------------------ formulários */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field label .req { color: var(--danger); margin-left: 2px; }
.field .help { font-size: 12px; color: var(--text-3); }
.field .err { font-size: 12px; color: var(--danger); min-height: 0; }
.input, select.input, textarea.input {
  width: 100%; height: 34px; padding: 6px 10px; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); outline: none; transition: border-color .12s, box-shadow .12s;
}
textarea.input { height: auto; min-height: 76px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input[readonly] { background: var(--surface-2); color: var(--text-2); }
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 14px; max-height: 260px; overflow: auto;
  padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.form-error { grid-column: 1 / -1; padding: 9px 12px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); font-size: 13px; }
.form-section { grid-column: 1 / -1; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3);
  padding-top: 6px; border-top: 1px solid var(--border); margin-top: 4px; }
.form-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }

/* ------------------------------------------------------------ botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 34px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap; font-weight: 550; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.block { width: 100%; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn .kbd { font-size: 11px; opacity: .7; font-weight: 400; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }

/* ------------------------------------------------------------ janela principal */
.shell { height: 100vh; display: grid; grid-template-rows: auto auto auto 1fr auto; }
.titlebar {
  display: flex; align-items: center; gap: 14px; height: 44px; padding: 0 12px; background: var(--titlebar); color: var(--titlebar-text);
}
.titlebar .brand { display: flex; align-items: center; gap: 9px; font-weight: 650; }
.titlebar .brand img { width: 24px; height: 24px; border-radius: 6px; }
.titlebar .company { opacity: .9; font-size: 13px; padding-left: 12px; border-left: 1px solid rgba(255,255,255,.3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 28vw; }
.titlebar .scope-badge { font-size: 11px; font-weight: 700; letter-spacing: .06em; background: rgba(255,255,255,.18); padding: 3px 8px; border-radius: 99px; }
.titlebar .tb-btn { background: transparent; border: 0; color: inherit; height: 32px; min-width: 32px; padding: 0 8px; border-radius: 6px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; }
.titlebar .tb-btn:hover { background: rgba(255,255,255,.14); }

.gsearch { position: relative; flex: 1; max-width: 520px; margin: 0 auto; }
.gsearch input {
  width: 100%; height: 30px; padding: 0 12px 0 34px; border-radius: 6px; border: 1px solid transparent; outline: none;
  background: rgba(255,255,255,.16); color: var(--titlebar-text);
}
.gsearch input::placeholder { color: rgba(255,255,255,.75); }
.gsearch input:focus { background: var(--surface); color: var(--text); border-color: var(--border); }
.gsearch input:focus::placeholder { color: var(--text-3); }
.gsearch .icon { position: absolute; left: 10px; top: 6px; opacity: .8; pointer-events: none; }
.gsearch-results {
  position: absolute; left: 0; right: 0; top: 36px; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); max-height: 60vh; overflow: auto; z-index: 60; padding: 6px 0;
}
.gsearch-results .grp { padding: 6px 12px 2px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.gsearch-results .item { display: flex; gap: 10px; align-items: baseline; padding: 7px 12px; cursor: pointer; }
.gsearch-results .item.active, .gsearch-results .item:hover { background: var(--accent-soft); }
.gsearch-results .item .sub { color: var(--text-3); font-size: 12px; margin-left: auto; }
.gsearch-results .empty { padding: 12px; color: var(--text-3); }

/* menu superior */
.menubar { display: flex; align-items: center; gap: 2px; height: 30px; padding: 0 6px; background: var(--surface); border-bottom: 1px solid var(--border); position: relative; z-index: 50; }
.menubar > .m { position: relative; }
.menubar > .m > button { height: 26px; padding: 0 10px; border: 0; background: transparent; border-radius: 4px; cursor: pointer; font-size: 13px; }
.menubar > .m > button:hover, .menubar > .m.open > button { background: var(--surface-3); }
.dropdown {
  position: absolute; top: 28px; left: 0; min-width: 240px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 5px; z-index: 70;
}
.dropdown .mi, .ctxmenu .mi { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; background: transparent; border-radius: 5px; cursor: pointer; text-align: left; font-size: 13.5px; }
.dropdown .mi:hover:not(:disabled), .dropdown .mi:focus-visible, .ctxmenu .mi:hover:not(:disabled), .ctxmenu .mi:focus-visible { background: var(--accent-soft); outline: none; }
.dropdown .mi:disabled, .ctxmenu .mi:disabled { opacity: .45; cursor: default; }
.dropdown .mi .sc, .ctxmenu .mi .sc { margin-left: auto; color: var(--text-3); font-size: 12px; }
.dropdown .sep, .ctxmenu .sep { height: 1px; background: var(--border); margin: 5px 4px; }

/* barra de ferramentas (ribbon) */
.ribbon { display: flex; align-items: stretch; gap: 4px; padding: 6px 10px; background: var(--surface-2); border-bottom: 1px solid var(--border); min-height: 62px; overflow-x: auto; }
.ribbon .group { display: flex; align-items: stretch; gap: 2px; padding-right: 8px; margin-right: 4px; border-right: 1px solid var(--border); }
.ribbon .group:last-child { border-right: 0; }
.rb {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-width: 64px; padding: 4px 8px;
  border: 1px solid transparent; background: transparent; border-radius: 6px; cursor: pointer; font-size: 12px; color: var(--text);
}
.rb:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border); }
.rb:disabled { opacity: .4; cursor: default; }
.rb .icon { width: 22px; height: 22px; color: var(--accent); }
.rb.danger .icon { color: var(--danger); }

/* corpo */
.body { display: grid; grid-template-columns: 232px 1fr; min-height: 0; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); overflow: auto; padding: 10px 8px 16px; }
.sidebar .sec { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); padding: 12px 10px 6px; }
.sidebar .nav { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; text-align: left; color: var(--text-2); }
.sidebar .nav:hover { background: var(--surface-3); color: var(--text); }
.sidebar .nav.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.workspace { display: grid; grid-template-rows: auto 1fr; min-width: 0; min-height: 0; }

/* abas (janelas internas) */
.tabs { display: flex; align-items: flex-end; gap: 2px; padding: 6px 8px 0; background: var(--surface-3); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px 0 12px; border: 1px solid transparent; border-bottom: 0;
  border-radius: 7px 7px 0 0; background: transparent; cursor: pointer; font-size: 13px; color: var(--text-2); max-width: 220px; white-space: nowrap;
}
.tab .t { overflow: hidden; text-overflow: ellipsis; }
.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--surface); border-color: var(--border); color: var(--text); font-weight: 600; margin-bottom: -1px; height: 33px; }
.tab .x { width: 20px; height: 20px; border-radius: 4px; display: grid; place-items: center; opacity: .6; border: 0; background: transparent; cursor: pointer; }
.tab .x:hover { opacity: 1; background: var(--surface-3); }
.tab .x .icon { width: 14px; height: 14px; }
.panes { position: relative; overflow: hidden; background: var(--surface); }
.pane { position: absolute; inset: 0; overflow: auto; padding: 20px 22px 28px; }

/* barra de estado */
.statusbar { display: flex; align-items: center; gap: 16px; height: 26px; padding: 0 12px; background: var(--surface-2); border-top: 1px solid var(--border); font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; }
.statusbar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; margin-right: 6px; }
.statusbar .dot.off { background: var(--danger); }
.statusbar .dot.sync { background: var(--warn); }

/* ------------------------------------------------------------ conteúdo */
.page-head { display: flex; align-items: flex-start; gap: 12px 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { font-size: 20px; margin: 0; font-weight: 650; }
.page-head .desc { color: var(--text-3); margin-top: 2px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.banner { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 13.5px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner.info { background: var(--accent-soft); color: var(--accent); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--text-3); font-size: 12.5px; font-weight: 600; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .foot { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.panel > .ph { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); font-weight: 650; }
.panel > .ph .actions { margin-left: auto; display: flex; gap: 6px; }
.panel > .pb { padding: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* tabela */
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar .search { position: relative; width: min(340px, 100%); }
.toolbar .search .icon { position: absolute; left: 9px; top: 8px; color: var(--text-3); }
.toolbar .search input { padding-left: 32px; }
.toolbar select.input, .toolbar input[type=date].input { width: auto; max-width: 240px; }
.toolbar .row { flex-wrap: wrap; }
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; background: var(--surface); }
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-weight: 650; color: var(--text-2); font-size: 12.5px;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; z-index: 1; }
table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tbody tr { cursor: default; }
table.grid tbody tr:hover { background: var(--surface-2); }
table.grid tbody tr.sel { background: var(--accent-soft); }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid .empty td { text-align: center; color: var(--text-3); padding: 28px; cursor: default; }
.pager { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--text-2); font-size: 13px; }
.pager .grow { flex: 1; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.key { font-family: var(--mono); font-size: 13px; letter-spacing: .5px; background: var(--surface-3); padding: 2px 7px; border-radius: 4px; }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.activity li:last-child { border-bottom: 0; }
.activity .when { margin-left: auto; color: var(--text-3); white-space: nowrap; font-size: 12px; }

/* ------------------------------------------------------------ modal */
.modal-back { position: fixed; inset: 0; background: rgba(12, 16, 24, .45); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { width: min(640px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.modal.lg { width: min(860px, 100%); }
.modal.sm { width: min(440px, 100%); }
.modal .mh { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal .mh h3 { margin: 0; font-size: 16px; }
.modal .mh .x { margin-left: auto; }
.modal .mb { padding: 18px; overflow: auto; }
.modal .mf { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; }
.modal .mf .left { margin-right: auto; color: var(--text-3); font-size: 12px; align-self: center; }

/* menu de contexto */
.ctxmenu { position: fixed; z-index: 120; min-width: 180px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 5px; }

/* notificações */
#toasts { position: fixed; right: 16px; bottom: 36px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { display: flex; gap: 10px; align-items: flex-start; min-width: 280px; max-width: 420px; padding: 11px 14px; background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); font-size: 13.5px; animation: pop .16s ease-out; }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; gap: 10px; color: var(--text-3); padding: 20px 0; }
.copy-box { display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); }
.copy-box .val { font-family: var(--mono); font-size: 15px; flex: 1; overflow-wrap: anywhere; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.perm-grid fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px 10px; margin: 0; }
.perm-grid legend { font-weight: 650; font-size: 13px; padding: 0 4px; text-transform: capitalize; }

@media (max-width: 900px) {
  .body { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .form, .grid-2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------ impressão */
.print-only { display: none; }
@media print {
  body { overflow: visible; background: #fff; color: #000; }
  .titlebar, .menubar, .ribbon, .sidebar, .tabs, .statusbar, .toolbar, .pager, #toasts, .page-head .actions, .no-print { display: none !important; }
  .shell, .body, .workspace, .panes { display: block; height: auto; }
  .pane { position: static; padding: 0; }
  .pane:not(.active-pane) { display: none; }
  .print-only { display: block; margin-bottom: 12px; }
  .table-wrap { border: 0; overflow: visible; }
  table.grid th { position: static; background: #eee; }
}

/* =====================================================================
   Módulos operacionais: PDV, vendas, stock, etiquetas, tesouraria, RH
   ===================================================================== */
.row.wrap { flex-wrap: wrap; }
.small { font-size: 12px; }
.strong { font-weight: 650; }
.neg { color: var(--danger); }
.pos { color: var(--ok); }
.zero { color: var(--text-3); }
.stat .value.sm { font-size: 20px; }
.card.stat.alert { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); background: var(--danger-soft); }
.card.clickable, .card.stat.acc { cursor: pointer; }
.card.clickable:hover, .card.stat.acc:hover { border-color: var(--accent); }
.card.stat.acc .label { display: flex; align-items: center; gap: 6px; }
.card.stat.acc .label .icon { width: 15px; height: 15px; }
.card.stat.inactive { opacity: .6; }
.card.stat.total { background: var(--accent-soft); border-color: transparent; }
.sum-box { padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.input.cell { height: 28px; padding: 3px 6px; width: 96px; }
.lines { max-height: 42vh; }
.split { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: start; }
.receipt-preview { background: #fff; color: #000; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-sm); max-height: 70vh; overflow: auto; }

/* seletor de produto */
.picker { position: relative; flex: 1; }
.picker > .icon { position: absolute; left: 10px; top: 8px; color: var(--text-3); pointer-events: none; }
.picker > input { padding-left: 34px; }
.picker-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: 50vh; overflow: auto; z-index: 90; padding: 4px 0; }
.picker-list .item { display: flex; align-items: center; gap: 12px; padding: 7px 12px; cursor: pointer; }
.picker-list .item.active { background: var(--accent-soft); }
.picker-list .sub { color: var(--text-3); font-size: 12px; }
.picker-list .empty { padding: 10px 12px; color: var(--text-3); }
.pick-list { display: flex; flex-direction: column; gap: 4px; max-height: 40vh; overflow: auto; }
.pick { display: flex; align-items: center; gap: 10px; text-align: left; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
.pick:hover, .pick:focus-visible { border-color: var(--accent); background: var(--accent-soft); outline: none; }

/* PDV */
.pdv { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; height: 100%; min-height: 480px; }
.pos-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; gap: 10px; }
.pos-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pos-bar select.input { width: auto; min-width: 200px; }
.pos-main .banner { margin: 0; align-items: center; }
.pos-scan { display: flex; gap: 8px; }
.pos-scan .picker input { height: 44px; font-size: 16px; }
.pos-scan .picker > .icon { top: 13px; }
.pos-qty { width: 80px !important; height: 44px !important; font-size: 16px; }
.pos-cart-wrap { flex: 1; min-height: 0; }
.pos-cart td { vertical-align: middle; }
.pos-cart .badge { margin-top: 3px; }
.pos-side { display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow: auto; }
.pos-customer { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; background: var(--surface-2); }
.pos-customer .label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-bottom: 2px; }
.pos-totals { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; display: flex; flex-direction: column; gap: 4px; }
.pos-totals .r { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; color: var(--text-2); }
.pos-totals .r.total { color: var(--text); font-size: 28px; font-weight: 700; border-top: 1px solid var(--border); padding-top: 8px; margin-top: 4px; }
.pos-totals .r.total span:first-child { font-size: 15px; align-self: center; }
.pos-pay { height: 58px; font-size: 20px; }
.pos-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pos-actions .btn { justify-content: flex-start; }
.pos-keys { font-size: 11.5px; color: var(--text-3); line-height: 1.6; }
.pos-last .banner { margin: 0; }
.pos-change { font-size: 20px; font-weight: 700; }
.pay-total { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 16px; border-radius: var(--radius); background: var(--accent-soft); color: var(--accent); }
.pay-total strong { font-size: 30px; }
.pay-rows { display: flex; flex-direction: column; gap: 8px; }
.pay-row { display: grid; grid-template-columns: 120px 160px auto 1fr; gap: 8px; align-items: center; }
.pay-row label { font-weight: 600; }
.pay-row .full { grid-column: 2 / -1; }
.pay-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pay-summary > div { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); }
.pay-summary strong { font-size: 22px; }

/* gráficos */
svg.chart { width: 100%; height: 190px; display: block; }
svg.chart .chart-label { font-size: 10px; fill: var(--text-3); }
.chart-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar .track { height: 8px; border-radius: 4px; background: var(--surface-3); margin-top: 4px; overflow: hidden; }
.hbar .bar { height: 100%; background: var(--accent); border-radius: 4px; }

/* RH */
table.payroll .input.cell { width: 72px; }
table.payroll td, table.payroll th { padding-left: 6px; padding-right: 6px; }
table.grid tfoot th { background: var(--surface-2); border-top: 1px solid var(--border-strong); padding: 8px 10px; text-align: left; }
table.grid tfoot th.num { text-align: right; }

/* etiquetas */
.labels-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.label-preview { overflow: auto; background: var(--surface-3); padding: 12px; border-radius: var(--radius-sm); max-height: 70vh; }
.label-preview .labels-roll { display: flex; flex-wrap: wrap; gap: 8px; }
.label-preview .sheet { zoom: .72; background: #fff; box-shadow: var(--shadow-sm); margin: 0 auto 12px; }
.tag-label { background: #fff; color: #000; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 1.2mm 1.5mm; gap: .3mm; text-align: center; font-family: Arial, Helvetica, sans-serif; line-height: 1.12; box-sizing: border-box; }
.label-preview .labels-roll .tag-label { outline: 1px dashed #bbb; }
.label-preview .sheet .tag-label { outline: 1px dashed #ddd; }
.tag-label.empty { background: transparent; }
.l-company { font-size: .8em; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.l-name { font-weight: 700; max-width: 100%; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.l-price { font-weight: 800; font-size: 1.55em; white-space: nowrap; }
.l-barcode { flex: 1; min-height: 0; width: 100%; display: flex; }
.l-barcode svg { width: 100%; height: 100%; }
.l-nocode, .l-code { font-size: .82em; font-family: Consolas, 'Courier New', monospace; letter-spacing: .08em; line-height: 1; }
.sheet { width: 210mm; height: 297mm; box-sizing: border-box; display: grid; align-content: start; }
svg.barcode { display: block; }

/* talões (58/80/99 mm) */
.receipt { font: 9pt/1.28 "Consolas", "Courier New", monospace; color: #000; background: #fff; box-sizing: border-box; }
.receipt.w58 { width: 48mm; font-size: 7.5pt; }
.receipt.w80 { width: 72mm; }
.receipt.w99 { width: 90mm; font-size: 10pt; }
.r-center { text-align: center; }
.r-strong { font-weight: 700; }
.r-big { font-size: 1.25em; }
.r-small { font-size: .85em; }
.r-muted { color: #444; }
.r-pre { white-space: pre-line; }
.r-line { display: flex; justify-content: space-between; gap: 6px; }
.r-line > span:first-child { flex: none; }
.r-line > span:last-child { text-align: right; min-width: 0; overflow-wrap: anywhere; }
.r-total { font-weight: 800; font-size: 1.2em; margin: 2px 0; }
.r-rule { border-top: 1px dashed #000; margin: 4px 0; }
.r-rule.solid { border-top-style: solid; }
.r-item { margin-bottom: 2px; }
.r-name { overflow-wrap: anywhere; }
.r-sign { margin-top: 18px; }

/* documentos A4 */
.doc-a4 { color: #000; background: #fff; font: 10.5pt/1.4 Arial, Helvetica, sans-serif; }
.doc-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 12px; }
.doc-title { font-size: 14pt; font-weight: 700; }
.doc-right { text-align: right; }
.doc-kv { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.doc-kv th, .doc-kv td { border: 1px solid #999; padding: 4px 6px; text-align: left; }
.doc-kv th { background: #f0f0f0; width: 18%; }
.doc-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.doc-table th, .doc-table td { border: 1px solid #999; padding: 4px 6px; text-align: left; }
.doc-table.small { font-size: 8.5pt; }
.doc-table th { background: #f0f0f0; }
.doc-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.doc-table .doc-net th, .doc-table .doc-net td { font-weight: 700; background: #e6e6e6; }
.doc-signs { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 50px; }
.doc-signs > div { border-top: 1px solid #000; padding-top: 4px; text-align: center; }
.payslips .payslip + .payslip { break-before: page; }

#print-root { display: none; }

@media (max-width: 1100px) {
  .pdv { grid-template-columns: 1fr; height: auto; }
  .labels-layout, .split, .chart-pair { grid-template-columns: 1fr; }
  .pay-row { grid-template-columns: 100px 1fr; }
}

/* ------------------------------------------------------------ impressão de documentos */
@page receipt { margin: 0; }
@page a4 { size: A4; margin: 12mm; }
@page a4l { size: A4 landscape; margin: 10mm; }
@page sheet { size: A4; margin: 0; }
@page label-50x30 { size: 50mm 30mm; margin: 0; }
@page label-40x25 { size: 40mm 25mm; margin: 0; }
@page label-60x40 { size: 60mm 40mm; margin: 0; }

@media print {
  body.printing-doc > *:not(#print-root) { display: none !important; }
  body.printing-doc #print-root { display: block; }
  #print-root.pr-receipt { page: receipt; }
  #print-root.pr-receipt .receipt { padding: 2mm 0; margin: 0 auto; }
  #print-root.pr-a4 { page: a4; }
  #print-root.pr-a4-landscape { page: a4l; }
  #print-root.pr-sheet { page: sheet; }
  #print-root.pr-sheet .sheet { break-after: page; }
  #print-root.pr-sheet .sheet:last-child { break-after: auto; }
  #print-root.pr-label-50x30 { page: label-50x30; }
  #print-root.pr-label-40x25 { page: label-40x25; }
  #print-root.pr-label-60x40 { page: label-60x40; }
  #print-root .labels-roll .tag-label { break-after: page; }
  #print-root .labels-roll .tag-label:last-child { break-after: auto; }
  #print-root .tag-label { outline: 0; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* =====================================================================
   Documentos, compras, relatórios, backups, RH (fase 3)
   ===================================================================== */
.modal.xl { width: min(1180px, 100%); }
.doc-customer { min-height: 40px; }
.doc-totals { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; display: flex; flex-direction: column; gap: 4px; min-width: 280px; }
.doc-totals .r { display: flex; justify-content: space-between; gap: 16px; font-variant-numeric: tabular-nums; color: var(--text-2); }
.doc-totals .r.total { color: var(--text); font-size: 22px; font-weight: 700; border-top: 1px solid var(--border); padding-top: 6px; margin-top: 2px; }
.doc-totals.right-box { margin-left: auto; width: 320px; }
.doc-bottom { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.doc-bottom .field .input.num { max-width: 140px; }
.reports-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; align-items: start; }
.report-nav { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px; position: sticky; top: 0; }
.report-nav .sec { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); padding: 10px 8px 4px; }
.report-nav .nav { display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; color: var(--text-2); }
.report-nav .nav:hover { background: var(--surface-3); color: var(--text); }
.report-nav .nav.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.report-out .page-head h2 { font-size: 17px; }
table.grid tr.strong-row td { font-weight: 700; background: var(--surface-2); }
pre.code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-3); padding: 10px 12px; border-radius: var(--radius-sm); overflow-x: auto; white-space: pre-wrap; }
.pos-printmode { width: auto !important; height: 30px; font-size: 12.5px; }
button.badge { border: 0; cursor: pointer; }
.link.small { font-size: 11.5px; margin-left: 4px; }
@media (max-width: 1100px) {
  .reports-layout, .doc-bottom { grid-template-columns: 1fr; }
}
.pos-bar > .row { flex-wrap: wrap; min-width: 0; }
.pos-bar .badge { white-space: nowrap; }
.plan { border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 10px 12px; background: var(--surface-2); }
.plan-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
.plan-fields .plan-preview { grid-column: 1 / -1; color: var(--accent); font-weight: 600; font-size: 13px; }
@media (max-width: 700px) { .plan-fields { grid-template-columns: 1fr; } }
