/* ═══════════════════════════════════════════════════════════
   VARIÁVEIS — Paleta da marca
════════════════════════════════════════════════════════════ */
:root {
  /* Paleta base */
  --color-preto: #010101;
  --color-branco: #ffffff;
  --color-terracota: #d15e14;
  --color-terra: #5f4b3c;
  --color-nude: #f5f2e9;
  --color-argila: #b4a268;
  --color-amarelo: #f5a800;

  /* Mapeamento semântico */
  --bg: var(--color-nude);
  --surface: var(--color-branco);
  --surface-2: #ede9de;
  --border: #ddd8cc;
  --border-strong: #c8c0ad;

  --text-primary: var(--color-preto);
  --text-secondary: var(--color-terra);
  --text-muted: var(--color-argila);

  --accent: var(--color-terracota);
  --accent-bg: #fdf0e8;
  --accent-border: #f0c4a0;
  --accent-hover: #b84e0e;

  --success: #2d7a4f;
  --success-bg: #edf7f1;
  --success-border: #a8d9bc;

  --warning: var(--color-amarelo);
  --warning-bg: #fffbec;
  --warning-border: #fde89a;
  --warning-text: #7a5500;

  --danger: #c0392b;
  --danger-bg: #fdf2f1;
  --danger-border: #f0b8b3;

  --sage: var(--color-terra);
  --sage-bg: #f0ebe6;
  --sage-border: #c8b8ae;

  --r: 8px;
  --rl: 12px;
  --rx: 16px;
}

/* ═══════════════════════════════════════════════════════════
   FONTE — Henderson Sans Basic
════════════════════════════════════════════════════════════ */
@font-face {
  font-family: "HendersonSans";
  src: url("fonts/HendersonSansBasicRegular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "HendersonSans";
  src: url("fonts/HendersonSansBasicBold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family:
    "HendersonSans",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 12px;
  line-height: 1.6;
  min-height: 100vh;
  overflow: hidden;
}

/* Garantir fonte em inputs, selects e botões */
input,
select,
textarea,
button {
  font-family:
    "HendersonSans",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

/* ═══════════════════════════════════════════════════════════
   HEADER
════════════════════════════════════════════════════════════ */
.hdr {
  background: var(--color-preto);
  border-bottom: 1px solid #1a1a1a;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 13px;
  color: var(--color-branco);
  letter-spacing: -0.01em;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: transparent;
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
}

.hbadge {
  background: var(--color-terra);
  color: var(--color-nude);
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hright {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.sdot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #444;
  display: inline-block;
  transition: background 0.3s;
}
.sdot.ok {
  background: var(--success);
}

.hright .btn {
  background: transparent;
  border-color: #333;
  color: #aaa;
  font-size: 11px;
}
.hright .btn:hover {
  background: #1a1a1a;
  border-color: #555;
  color: var(--color-branco);
}

/* ═══════════════════════════════════════════════════════════
   API BANNER
════════════════════════════════════════════════════════════ */
.api-banner {
  background: var(--warning-bg);
  border-bottom: 2px solid var(--warning-border);
  padding: 0.5rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 12px;
  color: var(--warning-text);
}
.api-banner a {
  color: var(--color-terracota);
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}
.api-banner.hidden {
  display: none;
}

/* ═══════════════════════════════════════════════════════════
   LAYOUT
════════════════════════════════════════════════════════════ */
.layout {
  display: grid;
  grid-template-columns: 264px 1fr;
  height: calc(100vh - 52px);
}
.layout.has-banner {
  height: calc(100vh - 52px - 36px);
}

/* ═══════════════════════════════════════════════════════════
   SIDEBAR
════════════════════════════════════════════════════════════ */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sb-top {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.sb-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

/* UPLOAD ZONE */
.upzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--rl);
  padding: 1.2rem 0.75rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.upzone:hover,
.upzone.drag {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.upzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.upzone strong {
  font-size: 11px;
  display: block;
  margin-top: 0.4rem;
  color: var(--text-primary);
}
.upzone p {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.up-ico {
  width: 32px;
  height: 32px;
  background: var(--accent-bg);
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.5rem;
  color: var(--accent);
}

/* FILE LIST */
.flist {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.fitem {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.5rem 0.6rem;
  border-radius: var(--r);
  cursor: pointer;
  border: 1px solid transparent;
  border-left: 3px solid transparent;
  transition: all 0.1s;
  margin-bottom: 3px;
}
.fitem:hover {
  background: var(--bg);
}
.fitem.active {
  background: var(--accent-bg);
  border-color: var(--accent-border);
  border-left-color: var(--accent);
}
.fitem.approved {
  border-left-color: var(--success);
}

.fthumb {
  width: 28px;
  height: 34px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
  overflow: hidden;
}
.fthumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.finfo {
  flex: 1;
  overflow: hidden;
}
.fname {
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fmeta {
  font-size: 10px;
  color: var(--text-muted);
}

.fstat {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 10px;
}
.fstat.pending {
  background: var(--surface-2);
  color: var(--text-muted);
}
.fstat.processing {
  background: var(--accent-bg);
  color: var(--accent);
}
.fstat.done {
  background: var(--success-bg);
  color: var(--success);
}
.fstat.approved {
  background: var(--success);
  color: white;
}
.fstat.error {
  background: var(--danger-bg);
  color: var(--danger);
}

/* SIDEBAR BOTTOM */
.sb-bot {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sb-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  margin-bottom: 0.25rem;
}
.stat-box {
  background: var(--bg);
  border-radius: var(--r);
  padding: 0.4rem 0.5rem;
  text-align: center;
  border: 1px solid var(--border);
}
.stat-n {
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
}
.stat-l {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}
.stat-n.c-blue {
  color: var(--accent);
}
.stat-n.c-green {
  color: var(--success);
}
.stat-n.c-warn {
  color: var(--color-amarelo);
}

/* ═══════════════════════════════════════════════════════════
   MAIN
════════════════════════════════════════════════════════════ */
.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* TABS */
.tabs {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 0 1.25rem;
  display: flex;
  gap: 0;
}
.tab {
  padding: 0.7rem 0.9rem 0.65rem;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.1s;
  display: flex;
  align-items: center;
  gap: 5px;
}
.tab:hover {
  color: var(--text-primary);
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tbadge {
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: 10px;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
}
.tab.active .tbadge {
  background: var(--accent-bg);
  color: var(--accent);
}

/* TOOLBAR */
.toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: nowrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

.toolbar-filters {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex: 1;
  flex-wrap: nowrap;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: nowrap;
}

.toolbar-sep {
  width: 1px;
  height: 16px;
  background: var(--border-strong);
  margin: 0 0.15rem;
}

.filter-select {
  padding: 0.22rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 10px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
  transition: border-color 0.1s;
  max-width: 160px;
}
.filter-select:focus {
  border-color: var(--accent);
}

.sel-all-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 10px;
  color: var(--text-secondary);
  padding: 0.22rem 0.5rem;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  white-space: nowrap;
}
.sel-all-wrap input[type="checkbox"] {
  width: 12px;
  height: 12px;
  cursor: pointer;
  accent-color: var(--accent);
}
.sel-count {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* CONTENT */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

/* EMPTY STATE */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
  color: var(--text-secondary);
  gap: 0.75rem;
}
.empty-ico {
  width: 56px;
  height: 56px;
  background: var(--surface-2);
  border-radius: var(--rx);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.25rem;
  color: var(--text-muted);
}
.empty h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.empty p {
  font-size: 11px;
  max-width: 260px;
}

/* ═══════════════════════════════════════════════════════════
   INVOICE CARD
════════════════════════════════════════════════════════════ */
.inv-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--rl);
  margin-bottom: 0.75rem;
  overflow: hidden;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
.inv-row:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.inv-row.selected {
  border-left-color: var(--accent);
  border-color: var(--accent-border);
}
.inv-row.approved {
  border-left-color: var(--success);
}
.inv-row.lancada {
  border-left-color: var(--color-terra);
  opacity: 0.8;
}

/* INV HEADER */
.inv-hdr {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.inv-hdr:hover {
  background: var(--bg);
}

.inv-cb {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.inv-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--r);
  background: var(--sage-bg);
  border: 1px solid var(--sage-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  color: var(--sage);
  flex-shrink: 0;
}

.inv-title {
  font-weight: 600;
  font-size: 12px;
}
.inv-sub {
  font-size: 11px;
  color: var(--text-secondary);
}
.inv-badges {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  margin-left: auto;
}

.inv-toggle {
  margin-left: 0.5rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}
.inv-toggle.open {
  transform: rotate(180deg);
}

/* INV BODY */
.inv-body {
  display: none;
}
.inv-body.open {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

/* LEFT: Preview */
.inv-preview {
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 1rem;
  min-height: 400px;
  gap: 0.5rem;
}
.inv-preview canvas,
.inv-preview img {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}
.preview-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pdf-pages {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}
.pdf-page-btn {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.1s;
}
.pdf-page-btn:hover {
  background: var(--bg);
}
.pdf-page-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* RIGHT: Fields */
.inv-fields {
  padding: 1rem;
  overflow-y: auto;
  max-height: 500px;
}
.fields-section {
  margin-bottom: 1rem;
}
.fields-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}
.fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
.fields-grid.full {
  grid-template-columns: 1fr;
}

.fld {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.fld-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.fld-input {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: 11px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.1s;
}
.fld-input:focus {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.fld-input.changed {
  border-color: var(--warning);
  background: var(--warning-bg);
}

/* Lines mini table */
.lines-mini {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-top: 0.35rem;
}
.lines-mini th {
  padding: 0.3rem 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}
.lines-mini td {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
}
.lines-mini tr:hover td {
  background: var(--bg);
}
.lines-mini td input {
  border: none;
  background: transparent;
  font-size: 11px;
  width: 100%;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
}

/* APPROVE BAR */
.approve-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.approve-status {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
}
.approve-status.ok {
  color: var(--success);
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════
   EXPORT / TABLE PANELS
════════════════════════════════════════════════════════════ */
.export-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rl);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.export-title {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.excel-ico {
  width: 22px;
  height: 22px;
  background: #1d6f42;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.etable-wrap {
  overflow-x: auto;
}
.etable {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  white-space: nowrap;
}
.etable th {
  padding: 0.4rem 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.etable td {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
}
.etable td:first-child {
  color: var(--text-muted);
  font-size: 10px;
}
.col-pend {
  background: var(--warning-bg);
  color: var(--warning-text);
  font-style: italic;
}

/* ═══════════════════════════════════════════════════════════
   CONFIG SECTIONS
════════════════════════════════════════════════════════════ */
.cfg-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rl);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.cfg-section.sage-section {
  border-left: 4px solid var(--color-terra);
}
.cfg-title {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}

.fgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.fg {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.fg.full {
  grid-column: 1 / -1;
}

.flabel {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.finput {
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  font-size: 11px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.1s;
  width: 100%;
}
.finput:focus {
  border-color: var(--accent);
}

/* API / KEY inputs */
.key-wrap {
  position: relative;
  flex: 1;
}
.key-wrap input {
  width: 100%;
  padding-right: 2.2rem;
}
.key-toggle {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px;
  display: flex;
  align-items: center;
  transition: color 0.1s;
}
.key-toggle:hover {
  color: var(--accent);
}
.key-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* SUPPLIER ROW */
.sup-row {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ═══════════════════════════════════════════════════════════
   BOTÃO LANÇAR SAGE X3 (destaque especial)
════════════════════════════════════════════════════════════ */
.btn-sage {
  background: var(--color-terra);
  color: var(--color-nude);
  border-color: var(--color-terra);
  font-weight: 600;
  padding: 0.45rem 1rem;
  gap: 6px;
}
.btn-sage:hover {
  background: #4a3a2e;
  border-color: #4a3a2e;
  color: var(--color-branco);
}
.btn-sage:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-sage-sm {
  background: var(--color-terra);
  color: var(--color-nude);
  border-color: var(--color-terra);
  font-weight: 600;
}
.btn-sage-sm:hover {
  background: #4a3a2e;
}

/* ═══════════════════════════════════════════════════════════
   BOTÕES GERAIS
════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0.4rem 0.8rem;
  border-radius: var(--r);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-primary);
  transition: all 0.1s;
  font-family: inherit;
  white-space: nowrap;
}
.btn:hover {
  background: var(--bg);
}
.btn:active {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--color-preto);
  color: var(--color-branco);
  border-color: var(--color-preto);
}
.btn-primary:hover {
  background: #1a1a1a;
}

.btn-accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-accent:hover {
  background: var(--accent-hover);
}

.btn-success {
  background: var(--success);
  color: white;
  border-color: var(--success);
}
.btn-success:hover {
  background: #236040;
}

.btn-danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
.btn-sm {
  padding: 0.22rem 0.5rem;
  font-size: 10px;
}
.btn-full {
  width: 100%;
  justify-content: center;
}

/* ═══════════════════════════════════════════════════════════
   TAGS / BADGES
════════════════════════════════════════════════════════════ */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 9px;
  font-weight: 600;
}
.tag-blue {
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid var(--accent-border);
}
.tag-green {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-border);
}
.tag-warn {
  background: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
}
.tag-gray {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.tag-terra {
  background: var(--sage-bg);
  color: var(--sage);
  border: 1px solid var(--sage-border);
}
.tag-terracota {
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid var(--accent-border);
}

/* ═══════════════════════════════════════════════════════════
   ALERTS
════════════════════════════════════════════════════════════ */
.alert {
  padding: 0.65rem 0.9rem;
  border-radius: var(--r);
  font-size: 12px;
  display: flex;
  gap: 7px;
  align-items: flex-start;
  margin-bottom: 0.75rem;
  border: 1px solid;
}
.alert-info {
  background: var(--accent-bg);
  border-color: var(--accent-border);
  color: #7a2e00;
}
.alert-warn {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning-text);
}
.alert-success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: #1a4d30;
}
.alert-sage {
  background: var(--sage-bg);
  border-color: var(--sage-border);
  color: var(--color-terra);
}

/* ═══════════════════════════════════════════════════════════
   SPINNER & PROGRESS
════════════════════════════════════════════════════════════ */
.spin {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: rot 0.7s linear infinite;
}
@keyframes rot {
  to {
    transform: rotate(360deg);
  }
}

.prog-wrap {
  background: var(--surface-2);
  border-radius: 4px;
  height: 3px;
  overflow: hidden;
  margin-top: 5px;
}
.prog-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s;
}

/* ═══════════════════════════════════════════════════════════
   LOADING OVERLAY
════════════════════════════════════════════════════════════ */
.loading-ov {
  position: fixed;
  inset: 0;
  background: rgba(1, 1, 1, 0.6);
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.loading-ov.active {
  display: flex;
}

.loading-box {
  background: var(--surface);
  border-radius: var(--rx);
  padding: 2rem;
  text-align: center;
  width: auto;
  min-width: 260px;
  max-width: min(90vw, 500px);
  border-top: 3px solid var(--accent);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}
.loading-box .spin {
  width: 28px;
  height: 28px;
  border-width: 3px;
  margin: 0 auto 0.75rem;
  display: block;
}
.lmsg {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 0.35rem;
  word-break: break-word;
  white-space: normal;
}
.lsub {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════════════════
   SCROLLBAR
════════════════════════════════════════════════════════════ */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* FILE STATUS ROW */
.file-status-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
}

.file-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border-strong);
  flex-shrink: 0;
  transition: background 0.3s;
}
.file-dot.ok {
  background: var(--success);
}
.file-dot.waiting {
  background: var(--warning);
}
.file-dot.error {
  background: var(--danger);
}

/* ETIQUETAS PERSONALIZADAS */
.tag-etiqueta {
  background: #f0e8ff;
  color: #6d28d9;
  border: 1px solid #ddd6fe;
  cursor: pointer;
  transition: all 0.1s;
}
.tag-etiqueta:hover {
  background: #ede0ff;
  border-color: #c4b5fd;
}

.etiqueta-input-wrap {
  display: inline-flex;
  align-items: center;
}

.etiqueta-input {
  border: 1px dashed var(--border-strong);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 10px;
  font-family: inherit;
  background: transparent;
  color: var(--text-secondary);
  outline: none;
  width: 90px;
  transition: all 0.15s;
  cursor: text;
}

.etiqueta-input:focus {
  border-color: #6d28d9;
  background: #f0e8ff;
  color: #6d28d9;
  width: 130px;
}

.etiqueta-input::placeholder {
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════
   ECRÃ DE LOGIN
════════════════════════════════════════════════════════════ */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-nude);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0;
}

.login-overlay.hidden {
  display: none;
}

.login-box {
  background: var(--surface);
  border-radius: var(--rx);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 40px rgba(1, 1, 1, 0.12);
  border-top: 3px solid var(--color-terracota);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2rem;
  justify-content: center;
}

.login-logo-icon {
  width: 38px;
  height: 38px;
  background: var(--color-preto);
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-preto);
}

.login-sub {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 0.85rem;
}

.login-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.login-input {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  font-size: 12px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.login-input:focus {
  border-color: var(--color-terracota);
}

.login-error {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: var(--r);
  padding: 0.5rem 0.75rem;
  font-size: 11px;
  color: var(--danger);
  margin-bottom: 0.75rem;
  display: none;
}

.login-error.visible {
  display: block;
}

.btn-login {
  width: 100%;
  justify-content: center;
  padding: 0.65rem;
  font-size: 12px;
  font-weight: 700;
  background: var(--color-preto);
  color: white;
  border: none;
  border-radius: var(--r);
  cursor: pointer;
  font-family: inherit;
  margin-top: 0.5rem;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-login:hover {
  background: #2d2b27;
}
.btn-login:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.login-sage-badge {
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 1rem;
}

/* Utilizador logado no header */
.user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 10px;
  color: #aaa;
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-terra);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--color-nude);
  flex-shrink: 0;
}

.btn-logout {
  background: transparent;
  border: 1px solid #333;
  color: #aaa;
  padding: 0.2rem 0.5rem;
  border-radius: var(--r);
  font-size: 10px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.1s;
}
.btn-logout:hover {
  background: #1a1a1a;
  color: white;
}

/* ═══════════════════════════════════════════════════════════
   PÁGINA DE ENTRADA
════════════════════════════════════════════════════════════ */
.entrada-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-nude);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
}
.entrada-overlay.hidden {
  display: none;
}

.entrada-box {
  background: var(--surface);
  border-radius: var(--rx);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 8px 40px rgba(1, 1, 1, 0.12);
  border-top: 3px solid var(--color-terracota);
}

.entrada-header {
  text-align: center;
  margin-bottom: 2rem;
}

.entrada-bem-vindo {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 0.75rem;
}

.entrada-botoes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.entrada-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2rem 1rem;
  border-radius: var(--rl);
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  text-align: center;
}

.entrada-btn:hover {
  border-color: var(--color-terracota);
  background: var(--accent-bg);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(209, 94, 20, 0.15);
}

.entrada-btn-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--rl);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-terra);
  transition: all 0.2s;
}

.entrada-btn:hover .entrada-btn-icon {
  background: var(--accent-bg);
  color: var(--color-terracota);
}

.entrada-btn-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.entrada-btn-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════
   EXPLORADOR DE ARQUIVO
════════════════════════════════════════════════════════════ */
.arquivo-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 9997;
  display: flex;
  flex-direction: column;
}
.arquivo-overlay.hidden {
  display: none;
}

.arquivo-header {
  background: var(--color-preto);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid #222;
}

.arquivo-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 1;
  flex-wrap: wrap;
}

.arquivo-bc-item {
  font-size: 12px;
  color: #888;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color 0.1s;
}

.arquivo-bc-item:hover,
.arquivo-bc-item.active {
  color: var(--color-nude);
}

.arquivo-bc-sep {
  color: #555;
  font-size: 12px;
}

.arquivo-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.arquivo-loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 13px;
  padding: 2rem;
}

/* Grid de pastas/ficheiros */
.arquivo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
}

.arquivo-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 0.75rem;
  border-radius: var(--rl);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.arquivo-item:hover {
  border-color: var(--color-terracota);
  background: var(--accent-bg);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(209, 94, 20, 0.1);
}

.arquivo-item-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
}

.arquivo-item-nome {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-word;
  line-height: 1.3;
}

.arquivo-item-meta {
  font-size: 10px;
  color: var(--text-muted);
}

.arquivo-item.pasta .arquivo-item-icon {
  color: var(--color-amarelo);
}
.arquivo-item.pdf .arquivo-item-icon {
  color: var(--danger);
}

/* Visualizador de PDF */
.arquivo-pdf-viewer {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.arquivo-pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.arquivo-pdf-frame {
  flex: 1;
  border: none;
  background: #525659;
}

/* Vazio */
.arquivo-vazio {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem;
  color: var(--text-muted);
  gap: 0.75rem;
  text-align: center;
}

/* ═══════════════════════════════════════════════════════════
   MODAL
════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(1, 1, 1, 0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-overlay.hidden {
  display: none;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--rx);
  padding: 1.75rem;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 8px 40px rgba(1, 1, 1, 0.2);
  border-top: 3px solid var(--color-terracota);
}

.modal-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVIDADE
════════════════════════════════════════════════════════════ */

/* ── Tablet (até 1024px) ─────────────────────────────────── */
@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 220px 1fr;
  }

  .inv-body {
    flex-direction: column;
  }

  .inv-preview {
    width: 100%;
    max-height: 300px;
  }

  .inv-fields {
    max-height: none;
  }

  .toolbar-row {
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .toolbar-group {
    flex-wrap: wrap;
  }
}

/* ── Mobile grande (até 768px) ───────────────────────────── */
@media (max-width: 768px) {
  /* Header */
  .hdr {
    padding: 0 0.75rem;
  }

  .logo img {
    height: 22px;
  }

  .logo span {
    display: none; /* esconder título no mobile */
  }

  .hbadge {
    display: none;
  }

  /* Layout — sidebar em cima, main em baixo */
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: calc(100vh - 44px);
  }

  /* Sidebar horizontal no topo */
  .sidebar {
    flex-direction: row;
    height: auto;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sb-top {
    flex: 1;
    padding: 0.5rem;
  }

  .upzone {
    padding: 0.75rem;
    min-height: 80px;
  }

  .upzone p {
    display: none;
  }

  .flist {
    width: 180px;
    flex-shrink: 0;
    border-left: 1px solid var(--border);
    max-height: 200px;
  }

  .sb-bot {
    width: 140px;
    flex-shrink: 0;
    padding: 0.5rem;
    border-left: 1px solid var(--border);
    gap: 0.4rem;
  }

  .sb-stats {
    gap: 0.25rem;
  }
  .stat-n {
    font-size: 13px;
  }

  /* Toolbar */
  .toolbar {
    padding: 0.35rem 0.5rem;
  }

  .toolbar-row {
    flex-wrap: wrap;
    gap: 0.3rem;
  }

  .toolbar-sep {
    display: none;
  }

  .filter-select {
    max-width: 130px;
    font-size: 9px;
  }

  /* Faturas */
  .inv-hdr {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .inv-badges {
    width: 100%;
    flex-wrap: wrap;
    margin-left: 0 !important;
    gap: 0.25rem;
  }

  .inv-body {
    flex-direction: column;
  }

  .inv-preview {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 250px;
  }

  .inv-fields {
    max-height: none;
    padding: 0.75rem;
  }

  .fields-grid {
    grid-template-columns: 1fr;
  }

  /* Tabs */
  .tabs {
    padding: 0 0.5rem;
  }

  .tab {
    padding: 0.5rem 0.6rem;
    font-size: 10px;
  }

  /* Modal */
  .modal-box {
    margin: 1rem;
    max-width: calc(100vw - 2rem);
  }

  /* Loading */
  .loading-box {
    margin: 1rem;
    max-width: calc(100vw - 2rem);
  }
}

/* ── Mobile pequeno (até 480px) ──────────────────────────── */
@media (max-width: 480px) {
  body {
    font-size: 11px;
  }

  .hdr {
    height: 44px;
  }

  /* Sidebar ainda mais compacta */
  .flist {
    width: 130px;
  }
  .sb-bot {
    width: 110px;
  }
  .sb-stats {
    display: none;
  }

  /* Botões da toolbar */
  .btn-sm {
    padding: 0.2rem 0.4rem;
    font-size: 9px;
  }

  .btn-sm svg {
    display: none;
  }

  /* Fatura */
  .inv-avatar {
    display: none;
  }

  .inv-title {
    font-size: 11px;
  }
  .inv-sub {
    font-size: 10px;
  }

  /* Tabela de linhas */
  .lines-mini {
    font-size: 9px;
  }

  .lines-mini input {
    font-size: 9px;
  }

  /* Etiquetas */
  .etiqueta-input {
    width: 70px;
    font-size: 9px;
  }

  .tag {
    font-size: 8px;
    padding: 1px 5px;
  }
}

/* ── Landscape mobile ────────────────────────────────────── */
@media (max-width: 768px) and (orientation: landscape) {
  .layout {
    grid-template-columns: 200px 1fr;
    grid-template-rows: 1fr;
    height: calc(100vh - 44px);
  }

  .sidebar {
    flex-direction: column;
    height: 100%;
    max-height: none;
    border-right: 1px solid var(--border);
    border-bottom: none;
  }

  .flist {
    width: auto;
    border-left: none;
    max-height: none;
  }

  .sb-bot {
    width: auto;
    border-left: none;
  }
}

/* ═══════════════════════════════════════════════════════════
   VIA VERDE
════════════════════════════════════════════════════════════ */
.vv-panel {
  padding: 1.5rem;
  max-width: 800px;
  margin: 0 auto;
}

.vv-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--color-verde);
}

.vv-uploads {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.vv-upload-box {
  border: 2px dashed var(--border);
  border-radius: var(--rl);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  background: var(--surface);
}

.vv-upload-box:hover {
  border-color: var(--color-verde);
  background: rgba(34, 139, 34, 0.04);
}

.vv-upload-box.loaded {
  border-color: var(--color-verde);
  border-style: solid;
  background: rgba(34, 139, 34, 0.06);
}

.vv-upload-ico {
  width: 44px;
  height: 44px;
  border-radius: var(--rl);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.vv-upload-box.loaded .vv-upload-ico {
  color: var(--color-verde);
}

.vv-upload-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
}

.vv-upload-sub {
  font-size: 10px;
  color: var(--text-muted);
}

.vv-upload-box.loaded .vv-upload-sub {
  color: var(--color-verde);
}

.vv-dados {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rl);
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.vv-dados-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

.vv-campo {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.vv-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.vv-resultado {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--rl);
  padding: 1rem;
  font-size: 12px;
}

@media (max-width: 768px) {
  .vv-uploads {
    grid-template-columns: 1fr;
  }
  .vv-dados-row {
    grid-template-columns: 1fr 1fr;
  }
}
