/* ============================================================
   Sistema de Facturacao - Folha de estilos principal
   Design responsivo (desktop / tablet / telemovel)
   ============================================================ */

:root {
  --brand:        #1f6feb;
  --brand-dark:   #1858c4;
  --brand-soft:   #e8f0fe;
  --success:      #16a34a;
  --success-soft: #dcfce7;
  --danger:       #dc2626;
  --danger-soft:  #fee2e2;
  --warning:      #d97706;
  --warning-soft: #fef3c7;
  --info:         #0891b2;
  --info-soft:    #cffafe;

  --bg:        #f4f6fb;
  --surface:   #ffffff;
  --surface-2: #f8fafc;
  --line:      #e4e8ef;
  --text:      #0f172a;
  --text-soft: #475569;
  --muted:     #94a3b8;

  --sidebar-bg:   #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1f6feb;

  --radius:   14px;
  --radius-sm: 9px;
  --shadow:   0 1px 2px rgba(15,23,42,.06), 0 8px 24px -12px rgba(15,23,42,.18);
  --shadow-lg: 0 24px 60px -24px rgba(15,23,42,.35);
  --sidebar-w: 258px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0b1220; --surface: #111a2e; --surface-2: #0f1729; --line: #1f2b45;
  --text: #e6edf7; --text-soft: #a9b7cd; --muted: #7c8aa3;
  --brand-soft: #16294a; --success-soft: #10331f; --danger-soft: #3a1420; --warning-soft: #3a2a0d;
  --sidebar-bg: #070d18;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 14.5px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
code { background: var(--surface-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; font-size: .86em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.muted { color: var(--muted); }
.soft  { color: var(--text-soft); }
.small { font-size: .86rem; }
.tiny  { font-size: .78rem; }
.text-right { text-align: right; } .text-center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt0{margin-top:0}.mt1{margin-top:.5rem}.mt2{margin-top:1rem}.mt3{margin-top:1.5rem}
.mb0{margin-bottom:0}.mb1{margin-bottom:.5rem}.mb2{margin-bottom:1rem}.mb3{margin-bottom:1.5rem}
.flex { display:flex; gap:.5rem; align-items:center; }
.flex-between { display:flex; gap:.75rem; align-items:center; justify-content:space-between; flex-wrap:wrap; }
.flex-wrap { flex-wrap: wrap; }
.grow { flex:1 1 auto; }
.hide { display:none !important; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ----------------------------- Layout ----------------------------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: var(--sidebar-bg);
  color: var(--sidebar-text); display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0; z-index: 60; overflow-y: auto;
  transition: transform .25s ease;
}
.sidebar-head { padding: 18px 18px 12px; display:flex; align-items:center; gap:10px; }
.sidebar-logo {
  width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg,#2f81f7,#1e40af);
  display:grid; place-items:center; color:#fff; font-weight:800; flex:0 0 36px;
}
/* Logotipo da empresa carregado nas configurações (personaliza o menu lateral) */
.sidebar-logo.has-image { background:#fff; overflow:hidden; }
.sidebar-logo.has-image img { width:100%; height:100%; object-fit:contain; display:block; }
.sidebar-brand { font-weight: 700; color: #fff; font-size: 1rem; line-height:1.15; }
.sidebar-brand small { display:block; font-weight:400; color:#8fa3bf; font-size:.72rem; }
.sidebar nav { padding: 6px 10px 24px; }
.nav-group { margin-top: 6px; }
/* Cada grupo do menu lateral e um acordeao: o titulo e um botao e a respectiva
   lista fica escondida ate ser clicada. O grupo que contem a pagina actual abre
   sozinho, para nao esconder o local onde o utilizador esta. */
.nav-group-title {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; background: none; border: 0; cursor: pointer; font-family: inherit;
  text-align: left; border-radius: 10px;
  font-size: .68rem; text-transform: uppercase; letter-spacing: .09em;
  color: #7b8ba3; padding: 8px 11px; font-weight: 700;
  transition: background .15s ease, color .15s ease;
}
.nav-group-title:hover { background: rgba(255,255,255,.06); color: #cbd5e1; }
.nav-group.open .nav-group-title { color: #cbd5e1; }
/* Seta desenhada em CSS (sem caracteres que dependem da fonte do sistema):
   aponta a direita e roda para baixo quando o grupo abre. */
.nav-caret {
  flex: 0 0 auto; width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  opacity: .6; transition: transform .2s ease;
}
.nav-group.open .nav-caret { transform: rotate(90deg); }
/* A lista anima de altura 0 ate a altura real do conteudo: sem valores fixos,
   a abertura e o fecho ficam suaves nos dois sentidos. */
.nav-group-body {
  display: grid; grid-template-rows: 0fr;
  transition: grid-template-rows .22s ease;
}
.nav-group.open .nav-group-body { grid-template-rows: 1fr; }
.nav-group-inner { overflow: hidden; min-height: 0; }
@media (prefers-reduced-motion: reduce) {
  .nav-group-body, .nav-caret, .nav-group-title { transition: none; }
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 10px;
  color: var(--sidebar-text); font-size: .89rem; font-weight: 500; margin-bottom: 2px;
}
.nav-item:hover { background: rgba(255,255,255,.07); text-decoration: none; color:#fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item .ic { width: 18px; text-align: center; opacity: .95; font-size: .95rem; }
.nav-item .pill {
  margin-left:auto; background: rgba(255,255,255,.14); border-radius: 20px; padding: 1px 8px; font-size: .7rem;
}
.sidebar-foot { margin-top: auto; padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: .78rem; color:#8fa3bf; }

.main { flex: 1 1 auto; min-width: 0; margin-left: var(--sidebar-w); display:flex; flex-direction:column; }
.topbar {
  position: sticky; top: 0; z-index: 40; background: rgba(255,255,255,.86);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
  padding: 12px 20px; display: flex; align-items: center; gap: 14px;
}
[data-theme="dark"] .topbar { background: rgba(17,26,46,.86); }
.topbar h1 { font-size: 1.08rem; margin: 0; }
.topbar .sub { font-size: .78rem; color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color:#fff;
  display:grid; place-items:center; font-weight: 700; font-size: .82rem; overflow:hidden;
}
.avatar img { width:100%; height:100%; object-fit: cover; }
.user-chip { display:flex; align-items:center; gap:9px; padding: 4px 10px 4px 4px; border:1px solid var(--line); border-radius: 30px; background: var(--surface); }
.user-chip .nm { font-size:.83rem; font-weight:600; line-height:1.1; }
.user-chip .rl { font-size:.72rem; color:var(--muted); }
.content { padding: 20px; flex: 1 1 auto; }
.content-inner { max-width: 1500px; margin: 0 auto; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; font-size: 1rem;
}
.icon-btn:hover { background: var(--surface-2); }
#sidebarToggle { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: translateX(0); }
  .main { margin-left: 0; }
  #sidebarToggle { display: grid; }
  .sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(2,6,23,.5); z-index: 55;
  }
  body.nav-open .sidebar-backdrop { display: block; }
  .content { padding: 14px; }
  .topbar { padding: 10px 14px; }
}

/* ----------------------------- Cards ----------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display:flex; align-items:center; gap:12px; flex-wrap:wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .actions { margin-left: auto; display:flex; gap:8px; flex-wrap: wrap; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* ----------------------------- KPI ----------------------------- */
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi .label { font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.kpi .value { font-size: 1.5rem; font-weight: 700; margin: 6px 0 2px; letter-spacing: -.02em; }
.kpi .delta { font-size: .8rem; font-weight: 600; }
.kpi .delta.up { color: var(--success); } .kpi .delta.down { color: var(--danger); }
.kpi .ic-badge { position:absolute; right: 14px; top: 14px; width: 38px; height: 38px; border-radius: 11px; display:grid; place-items:center; font-size: 1.05rem; background: var(--brand-soft); color: var(--brand); }
.kpi.g-green .ic-badge { background: var(--success-soft); color: var(--success); }
.kpi.g-red .ic-badge { background: var(--danger-soft); color: var(--danger); }
.kpi.g-amber .ic-badge { background: var(--warning-soft); color: var(--warning); }
.kpi.g-cyan .ic-badge { background: var(--info-soft); color: var(--info); }

/* ----------------------------- Botoes ----------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: .875rem; font-weight: 600;
  cursor: pointer; line-height: 1.2; white-space: nowrap; transition: .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger  { background: var(--danger);  border-color: var(--danger);  color: #fff; }
.btn-ghost   { background: transparent; }
.btn-sm { padding: 6px 10px; font-size: .8rem; border-radius: 8px; }
.btn-lg { padding: 13px 22px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn[disabled], .btn.disabled { opacity: .55; pointer-events: none; }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* ----------------------------- Formularios ----------------------------- */
.field { margin-bottom: 14px; }
.field > label, .label { display: block; font-size: .8rem; font-weight: 650; color: var(--text-soft); margin-bottom: 5px; }
.field .hint { font-size: .76rem; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=tel], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: .9rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31,111,235,.15); }
input[readonly], input[disabled], select[disabled] { background: var(--surface-2); color: var(--text-soft); }
textarea { min-height: 84px; resize: vertical; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 18px, calc(100% - 11px) 18px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid .span-2 { grid-column: span 1; } }
.check { display: flex; align-items: center; gap: 8px; font-size: .88rem; font-weight: 500; }
.check input { width: auto; }
.search-bar { display:flex; gap:10px; flex-wrap: wrap; align-items: end; }
.search-bar .field { margin-bottom: 0; min-width: 150px; }
.input-group { display: flex; }
.input-group input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* ----------------------------- Tabelas ----------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.table th, table.table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.table thead th {
  background: var(--surface-2); font-size: .73rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-soft); font-weight: 700; position: sticky; top: 0; z-index: 1;
}
table.table tbody tr:hover { background: var(--surface-2); }
table.table td.num, table.table th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--line); }
table.table.compact th, table.table.compact td { padding: 7px 10px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); }
.empty .big { font-size: 1.8rem; display:block; margin-bottom: 6px; opacity: .5; }

/* ----------------------------- Badges ----------------------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px; font-size: .74rem; font-weight: 700; line-height: 1.5; white-space: nowrap; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger  { background: var(--danger-soft);  color: var(--danger); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.info    { background: var(--info-soft);    color: var(--info); }
.badge.primary { background: var(--brand-soft);   color: var(--brand); }
.badge.muted   { background: var(--surface-2);    color: var(--text-soft); border: 1px solid var(--line); }

/* ----------------------------- Alertas ----------------------------- */
.alert { padding: 12px 15px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: .88rem; border: 1px solid transparent; display:flex; gap:10px; align-items:flex-start; }
.alert-success { background: var(--success-soft); color: #14532d; border-color: #bbf7d0; }
.alert-danger  { background: var(--danger-soft);  color: #7f1d1d; border-color: #fecaca; }
.alert-warning { background: var(--warning-soft); color: #78350f; border-color: #fde68a; }
.alert-info    { background: var(--info-soft);    color: #164e63; border-color: #a5f3fc; }
[data-theme="dark"] .alert { color: var(--text); }
.toast-box { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #0f172a; color: #fff; padding: 11px 15px; border-radius: 10px; font-size: .86rem; box-shadow: var(--shadow-lg); animation: slideIn .25s ease; }
.toast.ok { background: #14532d; } .toast.err { background: #7f1d1d; }
@keyframes slideIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ----------------------------- Tabs ----------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs .tab { padding: 10px 15px; font-size: .88rem; font-weight: 600; color: var(--text-soft); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs .tab:hover { color: var(--text); text-decoration: none; }
.tabs .tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ----------------------------- Modal ----------------------------- */
.modal { position: fixed; inset: 0; background: rgba(2,6,23,.55); z-index: 120; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal.open { display: flex; }
.modal-card { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-card.wide { max-width: 860px; }
.modal-head { padding: 15px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.modal-head h3 { margin: 0; }
.modal-head .close { margin-left: auto; background: none; border: 0; font-size: 1.3rem; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; background: var(--surface-2); }

/* ----------------------------- Graficos ----------------------------- */
.chart-box { position: relative; width: 100%; }
.chart-box canvas { width: 100%; display: block; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: .8rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--text-soft); }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ----------------------------- POS ----------------------------- */
.pos-shell { display: grid; grid-template-columns: 1fr 420px; gap: 16px; align-items: start; }
.pos-products { min-width: 0; }
.pos-cart { position: sticky; top: 76px; }
.pos-search input { font-size: 1.05rem; padding: 14px 16px; }
.pos-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.pos-tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; cursor: pointer; text-align: left; transition: .12s; }
.pos-tile:hover { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31,111,235,.12); }
.pos-tile .nm { font-weight: 600; font-size: .87rem; line-height: 1.25; margin-bottom: 4px; min-height: 2.4em; }
.pos-tile .pr { font-weight: 700; color: var(--brand); }
.pos-tile .st { font-size: .72rem; color: var(--muted); }
.pos-tile.out { opacity: .5; }
.cart-lines { max-height: 40vh; overflow-y: auto; }
.cart-line { display: grid; grid-template-columns: 1fr auto; gap: 6px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.cart-line .nm { font-size: .85rem; font-weight: 600; }
.cart-line .meta { font-size: .76rem; color: var(--muted); }
.cart-line .qty { display: flex; align-items: center; gap: 6px; }
.cart-line .qty button { width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-weight: 700; }
.total-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: .88rem; }
.total-row.grand { font-size: 1.2rem; font-weight: 800; border-top: 2px solid var(--line); margin-top: 8px; padding-top: 10px; }
/* Balcao: o seletor de cliente ocupa a largura toda e o botao de novo cliente
   fica ao lado, com area de toque quadrada (o POS e usado com o dedo). */
.pos-client-row { display: flex; gap: 8px; align-items: center; }
.pos-client-row select { flex: 1; min-width: 0; }
.pos-client-row .btn-plus {
  flex: 0 0 auto; width: 42px; height: 42px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.35rem; font-weight: 700; line-height: 1;
}
@media (max-width: 1100px) {
  .pos-shell { grid-template-columns: 1fr; }
  .pos-cart { position: static; }
}

/* ----------------------------- Diversos ----------------------------- */
.pager { display: flex; gap: 6px; align-items: center; justify-content: center; padding: 14px; flex-wrap: wrap; }
.pager a, .pager span { padding: 6px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: .84rem; background: var(--surface); }
.pager .active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.pager .disabled { opacity: .5; }
.list-clean { list-style: none; margin: 0; padding: 0; }
.list-clean li { padding: 10px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 12px; align-items: center; }
.list-clean li:last-child { border-bottom: 0; }
.progress { height: 8px; background: var(--surface-2); border-radius: 20px; overflow: hidden; border: 1px solid var(--line); }
.progress > i { display: block; height: 100%; background: var(--brand); }
.stat-line { display:flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size:.88rem; }
.stat-line:last-child { border-bottom: 0; }
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; }

/* ----------------------------- Impressao ----------------------------- */
.print-shell { background: #eef1f6; min-height: 100vh; padding: 22px 12px 60px; }
.print-toolbar { max-width: 210mm; margin: 0 auto 14px; display: flex; gap: 10px; justify-content: flex-end; }
.doc-sheet {
  width: 210mm; min-height: 290mm; margin: 0 auto; background: #fff; color: #000;
  padding: 14mm 14mm; box-shadow: 0 10px 40px -18px rgba(0,0,0,.4); font-size: 11.5px; line-height: 1.45;
}
.doc-sheet.receipt { width: 80mm; min-height: auto; padding: 6mm 5mm; font-size: 11px; }
.doc-head { display: flex; gap: 16px; border-bottom: 2px solid #111; padding-bottom: 10px; margin-bottom: 12px; }
.doc-head .brand { flex: 1 1 auto; }
.doc-head .brand h1 { font-size: 17px; margin: 0 0 2px; }
.doc-head .logo { width: 74px; height: 74px; object-fit: contain; }
.doc-title { text-align: right; }
.doc-title .t { font-size: 15px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.doc-title .n { font-size: 13px; font-weight: 700; }
.doc-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; margin-bottom: 12px; }
.doc-meta .box { border: 1px solid #999; border-radius: 6px; padding: 8px 10px; }
.doc-meta .box .h { font-size: 9.5px; text-transform: uppercase; letter-spacing: .07em; color: #444; font-weight: 700; margin-bottom: 3px; }
table.doc-table { width: 100%; border-collapse: collapse; font-size: 10.8px; }
table.doc-table th, table.doc-table td { border: 1px solid #777; padding: 5px 6px; }
table.doc-table thead th { background: #eceff3; font-size: 9.5px; text-transform: uppercase; letter-spacing: .04em; }
table.doc-table td.num { text-align: right; }
.doc-totals { margin-left: auto; width: 62mm; margin-top: 10px; }
.doc-totals div { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dotted #bbb; }
.doc-totals .grand { font-size: 13px; font-weight: 800; border-top: 2px solid #111; border-bottom: 0; margin-top: 4px; padding-top: 6px; }
.doc-foot { margin-top: 22px; display: flex; gap: 24px; }
.doc-foot .sig { flex: 1 1 0; border-top: 1px solid #444; padding-top: 4px; font-size: 9.5px; text-align: center; }
.doc-terms { margin-top: 14px; font-size: 9.5px; color: #333; border-top: 1px dashed #999; padding-top: 8px; }

/* Rodape legal dos documentos (certificacao do software) */
.doc-legal { margin-top: 22px; border-top: 1px solid #999; padding-top: 8px; text-align: center; }
.doc-legal .cert { font-size: 10px; font-weight: 700; color: #111; letter-spacing: .01em; }
.doc-legal .note { font-size: 9.5px; color: #333; margin-top: 3px; }
.doc-legal .meta { font-size: 8.5px; color: #555; margin-top: 4px; }
.doc-stamp { position: relative; }
.doc-stamp .cancelled { position: absolute; top: 40%; left: 12%; font-size: 40px; color: rgba(200,0,0,.28); transform: rotate(-18deg); font-weight: 900; letter-spacing: .1em; }

@media print {
  body { background: #fff; }
  .print-toolbar, .no-print { display: none !important; }
  .print-shell { background: #fff; padding: 0; }
  .doc-sheet { box-shadow: none; margin: 0; width: auto; min-height: auto; padding: 8mm; }
  @page { size: A4; margin: 8mm; }
  .doc-sheet.receipt { width: 72mm; }
  @page :first { }
}
@media print and (max-width: 100mm) { @page { size: 80mm auto; margin: 3mm; } }

/* ----------------------------- Autenticação ----------------------------- */
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand .auth-logo {
  display: block; margin: 0 auto 14px; max-width: 170px; max-height: 96px;
  width: auto; height: auto; object-fit: contain;
}
.auth-brand .auth-logo-fallback {
  width: 68px; height: 68px; flex-basis: 68px; border-radius: 20px;
  margin: 0 auto 14px; font-size: 1.7rem; font-weight: 800;
}
.auth-brand h1 { font-size: 1.32rem; margin: 0 0 4px; }
.auth-brand .sub { color: var(--muted); font-size: .84rem; }

.auth-page {
  background: radial-gradient(1200px 600px at 10% -10%, #1e3a8a 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 120%, #0ea5e9 0%, transparent 55%), #0b1220;
}
/* Tela de entrada centrada no meio do ecrã, dividida em 4 blocos:
   1) logotipo centrado (pequeno)  2) credenciais (esquerda)
   3) criar nova conta (direita)   4) observações de iniciação de sessão (em baixo) */
.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 28px 16px; overflow-y: auto;
}
.auth-frame { width: 100%; max-width: 940px; margin: auto; display: flex; flex-direction: column; gap: 14px; }

/* 1. Bloco do logotipo: centrado e em tamanho pequeno */
.auth-banner {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; text-align: center;
  background: var(--surface); border-radius: 14px; padding: 16px 22px;
  box-shadow: var(--shadow);
}
.auth-banner-img { max-height: 52px; max-width: 150px; width: auto; height: auto; object-fit: contain; }
.auth-banner-initial {
  width: 46px; height: 46px; flex: 0 0 46px; border-radius: 13px;
  display: grid; place-items: center; font-size: 1.15rem; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, #2f81f7, #1e40af);
}
.auth-banner-name { font-size: 1.05rem; font-weight: 600; margin: 0; line-height: 1.2; }

.auth-body { display: block; }

/* 2 e 3. Credenciais (esquerda) e criar nova conta (direita) */
.auth-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: stretch; }
.auth-columns-single { grid-template-columns: 1fr; max-width: 560px; margin: 0 auto; width: 100%; }
.auth-panel {
  background: var(--surface); border-radius: 14px; padding: 22px 20px;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.auth-panel-title {
  font-size: .92rem; text-transform: uppercase; letter-spacing: .09em;
  margin: 0 0 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line);
  text-align: center; font-weight: 700;
}
/* As duas colunas ficam com a mesma altura; «Recuperar a conta» assenta no fundo. */
.auth-panel-login { min-height: 0; }
.auth-panel-foot { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--line); text-align: center; }

/* Formulário de criação de conta: fechado até clicar em «Criar conta» */
.auth-register .collapsible { margin-top: 16px; }
.auth-register .when-open { display: none; }
.auth-register.is-open .when-open { display: inline; }
.auth-register.is-open .when-closed { display: none; }
.auth-register .collapsible[hidden] { display: none; }
.auth-form .btn { margin-top: 6px; }
.auth-form .hint.error { color: var(--danger); }
.auth-footnote { text-align: center; color: #cbd5e1; margin: 4px 0 0; }

/* 3. Caixa inferior de observações e orientações */
.auth-notes {
  background: var(--surface); border-radius: 14px; padding: 18px 22px;
  box-shadow: var(--shadow); border-left: 4px solid var(--brand);
}
.auth-notes-title { font-weight: 700; margin-bottom: 8px; font-size: .95rem; }
.auth-notes-text { color: var(--muted); font-size: .84rem; line-height: 1.65; }

@media (max-width: 860px) {
  /* Em ecrãs estreitos os 4 blocos ficam empilhados: logotipo, credenciais, nova conta, observações. */
  .auth-shell { align-items: flex-start; padding: 16px 12px 28px; }
  .auth-columns { grid-template-columns: 1fr; }
  .auth-frame { max-width: 560px; }
  .auth-banner { padding: 14px 18px; }
  .auth-banner-img { max-height: 46px; max-width: 130px; }
}

/* Compatibilidade com as telas de recuperação de conta */
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: 18px; padding: 30px 28px; box-shadow: var(--shadow-lg); }
.auth-card .brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.auth-card .brand .sidebar-logo { width: 42px; height: 42px; flex-basis: 42px; font-size: 1.1rem; }
.auth-card h1 { font-size: 1.25rem; margin: 0; }
.auth-card .sub { color: var(--muted); font-size: .84rem; }
.auth-card .btn { width: 100%; padding: 12px; font-size: .95rem; margin-top: 6px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 14px; font-size: .84rem; }

/* ----------------------------- Mobile ----------------------------- */
@media (max-width: 640px) {
  .content { padding: 12px 10px 40px; }
  .card-body { padding: 14px; }
  .card-head { padding: 12px 14px; }
  .kpi .value { font-size: 1.28rem; }
  .topbar h1 { font-size: .98rem; }
  .topbar .sub { display: none; }
  .hide-sm { display: none !important; }
  .btn { padding: 9px 12px; font-size: .84rem; }
  .modal-card { max-height: 96vh; }
  .doc-sheet { width: 100%; padding: 16px; font-size: 11px; }
}
@media (min-width: 641px) { .only-sm { display: none !important; } }
