/* RAPSON Despesas — design tokens alinhados com Inventário. */

:root {
  --bg-page:#03060f; --bg-deep:#001040; --bg-main:#001a52; --bg-header:#002270;
  --surface:rgba(255,255,255,.06); --surface-hv:rgba(255,255,255,.10);
  --border:rgba(255,255,255,.10); --border-s:rgba(255,255,255,.20);
  --text:#ffffff; --text-dim:rgba(255,255,255,.55); --text-faint:rgba(255,255,255,.30);
  --accent:#60a5fa; --accent-dim:rgba(96,165,250,.15); --accent-b:rgba(96,165,250,.30);
  --ok:#4ade80; --warn:#fbbf24; --err:#f87171;
  --nav-h:64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  font-family: 'Outfit', system-ui, sans-serif;
  background: var(--bg-page);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ── Login ────────────────────────────────────────────────── */
.login-shell {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--bg-header) 0%, var(--bg-main) 55%, var(--bg-deep) 100%);
}
.login-shell form {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 24px 20px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-shell h1 { font-size: 16px; font-weight: 800; letter-spacing: .04em; margin-bottom: 6px; }
.login-shell label { display: flex; flex-direction: column; gap: 6px; font-size: 10px; color: var(--text-dim); font-weight: 700; text-transform: uppercase; letter-spacing: .1em; }
.login-shell input {
  height: 44px; background: var(--bg-main); border: 1px solid var(--border);
  border-radius: 10px; padding: 0 12px; font-size: 14px; color: var(--text); outline: none;
}
.login-shell input:focus { border-color: var(--accent-b); }
.login-shell button[type="submit"] {
  height: 46px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), rgba(96,165,250,.65));
  color: #fff; font-size: 14px; font-weight: 800; margin-top: 6px;
  box-shadow: 0 4px 16px rgba(96,165,250,.35);
}
.login-shell .error { color: var(--err); font-size: 12px; font-weight: 600; }

/* ── Layout mobile-first ───────────────────────────────────── */
.app-shell {
  min-height: 100vh; background: var(--bg-main);
  display: flex; flex-direction: column;
  padding-bottom: var(--nav-h);
}
.app-header {
  background: var(--bg-header); border-bottom: 1px solid var(--border);
  padding: 14px 16px; display: flex; align-items: center; gap: 12px;
  position: sticky; top: 0; z-index: 5;
}
.app-header .back {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 18px;
}
.app-header h1 { font-size: 15px; font-weight: 700; flex: 1; }
.app-header .role { font-size: 10px; color: var(--text-faint); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }

.content { flex: 1; padding: 16px; }

/* ── Lista de despesas ─────────────────────────────────────── */
.section-h {
  font-size: 10px; font-weight: 800; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .12em; padding: 4px 4px 10px;
}
.exp-list { display: flex; flex-direction: column; gap: 8px; }
.exp-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
}
.exp-thumb {
  width: 44px; height: 44px; border-radius: 10px; flex-shrink: 0;
  background: var(--bg-main); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--text-faint);
  background-size: cover; background-position: center;
}
.exp-body { flex: 1; min-width: 0; }
.exp-supplier { font-size: 13px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.exp-amount { font-size: 14px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.exp-status {
  display: inline-block; font-size: 9px; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; padding: 2px 6px; border-radius: 5px; margin-left: 6px;
}
.exp-status.registered { background: var(--accent-dim); color: var(--accent); }
.exp-status.delivered  { background: rgba(251,191,36,.15); color: var(--warn); }
.exp-status.accounted  { background: rgba(74,222,128,.15); color: var(--ok); }

.empty {
  text-align: center; padding: 40px 20px; color: var(--text-faint);
  font-size: 13px;
}

/* ── FAB ────────────────────────────────────────────────────── */
.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  width: calc(100% - 32px); max-width: 420px;
  height: 56px; border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), rgba(96,165,250,.7));
  color: #fff; font-size: 15px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: 0 8px 28px rgba(96,165,250,.45);
  border: 1px solid rgba(96,165,250,.5);
  z-index: 20;
}
.fab:active { transform: translateX(-50%) scale(.98); }

/* ── Form (nova despesa) ───────────────────────────────────── */
.form-stack { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 10px; color: var(--text-dim); font-weight: 800;
  text-transform: uppercase; letter-spacing: .1em;
}
.field input, .field select, .field textarea {
  background: var(--bg-page); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; font-size: 14px;
  color: var(--text); outline: none; min-height: 44px;
}
.field textarea { min-height: 80px; resize: vertical; font-family: inherit; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent-b); }

.photo-drop {
  border: 1.5px dashed var(--border-s); border-radius: 14px;
  padding: 20px; text-align: center; color: var(--text-dim);
  background: var(--surface); position: relative; overflow: hidden;
}
.photo-drop input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-drop .ph-icon { font-size: 28px; margin-bottom: 6px; }
.photo-drop .ph-text { font-size: 13px; font-weight: 700; color: var(--text); }
.photo-drop .ph-hint { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.photo-preview {
  width: 100%; max-height: 280px; object-fit: contain;
  border-radius: 12px; background: var(--bg-page);
  border: 1px solid var(--border); display: block;
}
.photo-actions {
  display: flex; gap: 8px; margin-top: 8px;
}
.btn {
  height: 44px; padding: 0 16px; border-radius: 10px;
  font-size: 13px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), rgba(96,165,250,.7));
  color: #fff; box-shadow: 0 4px 14px rgba(96,165,250,.35);
}
.btn-ghost {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.submit-row { margin-top: 8px; }
.submit-row .btn-primary { width: 100%; height: 52px; font-size: 15px; }

.ocr-spinner {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; background: var(--accent-dim);
  border: 1px solid var(--accent-b); border-radius: 10px;
  font-size: 12px; font-weight: 700; color: var(--accent);
}
.spinner-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--accent); border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: calc(var(--nav-h) + 10px); left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: rgba(0,16,64,.95); border: 1px solid var(--border-s);
  border-radius: 12px; padding: 10px 16px; font-size: 12px; font-weight: 700;
  color: var(--text); z-index: 50; opacity: 0;
  transition: transform .25s, opacity .25s; backdrop-filter: blur(10px);
  white-space: nowrap; max-width: 90vw;
}
.toast.on { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.err { color: var(--err); border-color: rgba(248,113,113,.4); }
.toast.ok  { color: var(--ok);  border-color: rgba(74,222,128,.4); }

/* ── Escritório / Admin (desktop-first) ────────────────────── */
.office-shell {
  min-height: 100vh; background: var(--bg-page);
  display: flex; flex-direction: column;
}
.office-header {
  background: var(--bg-header); border-bottom: 1px solid var(--border);
  padding: 14px 22px; display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 5;
}
.office-header h1 { font-size: 16px; font-weight: 800; flex: 1; }
.office-header .role { font-size: 10px; color: var(--text-faint); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.office-content { padding: 20px 22px 80px; max-width: 1400px; width: 100%; margin: 0 auto; }

.alert-stale {
  display: flex; align-items: center; gap: 10px;
  background: rgba(251,191,36,.10); border: 1px solid rgba(251,191,36,.35);
  color: var(--warn); border-radius: 12px;
  padding: 12px 16px; font-size: 13px; font-weight: 700;
  margin-bottom: 18px;
}
.alert-stale .ico { font-size: 18px; }

.kpi-grid {
  display: grid; gap: 14px; margin-bottom: 22px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px 16px;
}
.kpi-card h3 {
  font-size: 10px; font-weight: 800; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .12em; margin-bottom: 12px;
}
.kpi-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; font-size: 13px;
}
.kpi-row + .kpi-row { border-top: 1px solid var(--border); }
.kpi-label { color: var(--text-dim); font-weight: 600; }
.kpi-value { color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi-value.accent { color: var(--accent); }

.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: end;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px; margin-bottom: 16px;
}
.filters .field { flex: 1; min-width: 140px; }
.filters .field label { font-size: 9px; }
.filters .field input, .filters .field select {
  height: 36px; padding: 0 10px; font-size: 13px; background: var(--bg-page);
}
.filters .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.filters .actions .btn { height: 36px; padding: 0 14px; font-size: 12px; }

.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden;
}
.table-scroll { overflow-x: auto; }
table.exp-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.exp-table thead th {
  background: var(--bg-header); color: var(--text-dim);
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em;
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.exp-table tbody td {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: middle;
}
table.exp-table tbody tr { cursor: pointer; transition: background .12s; }
table.exp-table tbody tr:hover { background: var(--surface-hv); }
table.exp-table .col-amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); }
table.exp-table .col-actions { text-align: right; white-space: nowrap; }
table.exp-table .col-actions .btn { height: 28px; padding: 0 10px; font-size: 11px; }
table.exp-table .empty-row td {
  text-align: center; color: var(--text-faint); padding: 40px 16px;
}

.badge {
  display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; padding: 3px 8px; border-radius: 6px;
}
.badge.registered { background: rgba(251,191,36,.15); color: var(--warn); }
.badge.delivered  { background: var(--accent-dim); color: var(--accent); }
.badge.accounted  { background: rgba(74,222,128,.15); color: var(--ok); }

.btn-mini {
  height: 28px; padding: 0 10px; border-radius: 8px; font-size: 11px;
  font-weight: 700; background: var(--surface); border: 1px solid var(--border);
  color: var(--text-dim); transition: .12s;
}
.btn-mini:hover { background: var(--surface-hv); color: var(--text); border-color: var(--border-s); }
.btn-mini.go { color: var(--accent); border-color: var(--accent-b); background: var(--accent-dim); }
.btn-mini.go:hover { background: rgba(96,165,250,.25); }
.btn-mini.green { color: var(--ok); border-color: rgba(74,222,128,.35); background: rgba(74,222,128,.10); }

/* ── Modal de detalhe ─────────────────────────────────────── */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity .15s;
  backdrop-filter: blur(4px);
}
.modal-mask.on { opacity: 1; pointer-events: auto; }
.modal {
  width: 100%; max-width: 720px; max-height: 90vh; overflow-y: auto;
  background: var(--bg-main); border: 1px solid var(--border-s); border-radius: 16px;
  padding: 22px; transform: translateY(10px); transition: transform .15s;
}
.modal-mask.on .modal { transform: none; }
.modal-h {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.modal-h h2 { font-size: 16px; font-weight: 800; flex: 1; }
.modal-close {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 18px;
}
.modal-photo {
  width: 100%; max-height: 50vh; object-fit: contain;
  border-radius: 12px; background: var(--bg-page);
  border: 1px solid var(--border); margin-bottom: 14px;
}
.modal-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.modal-grid .cell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px;
}
.modal-grid .lbl { font-size: 9px; color: var(--text-faint); font-weight: 800; text-transform: uppercase; letter-spacing: .1em; }
.modal-grid .val { font-size: 13px; font-weight: 700; color: var(--text); margin-top: 2px; word-break: break-word; }

@media (max-width: 720px) {
  .office-content { padding: 14px 12px 80px; }
  .filters { padding: 10px; }
  table.exp-table thead { display: none; }
  table.exp-table tbody td { display: block; padding: 6px 14px; border: none; }
  table.exp-table tbody tr {
    display: block; margin-bottom: 8px; border: 1px solid var(--border);
    border-radius: 12px; padding: 10px 0; background: var(--surface);
  }
  table.exp-table .col-amount { text-align: left; }
  table.exp-table .col-actions { text-align: left; padding-top: 8px; }
}

/* ── Reconciliação e-Fatura ────────────────────────────────── */
.office-tabs {
  display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap;
}
.office-tabs a {
  padding: 8px 14px; border-radius: 10px; font-size: 12px; font-weight: 700;
  color: var(--text-dim); background: var(--surface); border: 1px solid var(--border);
}
.office-tabs a.on { color: var(--accent); border-color: var(--accent-b); background: var(--accent-dim); }

.upload-zone {
  background: var(--surface); border: 1.5px dashed var(--border-s);
  border-radius: 14px; padding: 24px; text-align: center;
  margin-bottom: 18px; position: relative; overflow: hidden;
}
.upload-zone .ico { font-size: 32px; margin-bottom: 8px; }
.upload-zone .ttl { font-size: 14px; font-weight: 800; }
.upload-zone .hint { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.upload-zone input[type="file"] { display: none; }
.upload-zone .pick {
  display: inline-flex; align-items: center; justify-content: center;
  margin-top: 12px; height: 38px; padding: 0 18px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), rgba(96,165,250,.7));
  color: #fff; font-weight: 800; font-size: 13px;
  box-shadow: 0 4px 14px rgba(96,165,250,.35);
}
.upload-zone.busy { opacity: .6; pointer-events: none; }

.imports-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 18px; font-size: 13px;
}
.imports-row label { font-size: 10px; color: var(--text-dim); font-weight: 800; text-transform: uppercase; letter-spacing: .1em; }
.imports-row select {
  height: 36px; padding: 0 10px; min-width: 260px;
  background: var(--bg-page); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font-size: 13px;
}
.imports-row .meta { color: var(--text-faint); font-size: 12px; }

.recon-summary {
  display: grid; gap: 12px; margin-bottom: 18px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.summary-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px; text-align: center;
}
.summary-card.green  { border-color: rgba(74,222,128,.40);  background: rgba(74,222,128,.06); }
.summary-card.amber  { border-color: rgba(251,191,36,.40);  background: rgba(251,191,36,.06); }
.summary-card.red    { border-color: rgba(248,113,113,.40); background: rgba(248,113,113,.06); }
.summary-card .lbl { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; color: var(--text-dim); }
.summary-card .num { font-size: 30px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.summary-card.green .num { color: var(--ok); }
.summary-card.amber .num { color: var(--warn); }
.summary-card.red   .num { color: var(--err); }
.summary-card .sub { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

.recon-section { margin-bottom: 22px; }
.recon-section h2 {
  font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em;
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.recon-section h2 .dot { width: 10px; height: 10px; border-radius: 50%; }
.recon-section.green h2 { color: var(--ok); }      .recon-section.green h2 .dot { background: var(--ok); }
.recon-section.amber h2 { color: var(--warn); }    .recon-section.amber h2 .dot { background: var(--warn); }
.recon-section.red   h2 { color: var(--err); }     .recon-section.red   h2 .dot { background: var(--err); }
.recon-section h2 .desc {
  margin-left: auto; color: var(--text-faint); font-weight: 600;
  text-transform: none; letter-spacing: 0; font-size: 11px;
}

.recon-list {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden;
}
.recon-list .row {
  display: grid; gap: 8px;
  grid-template-columns: 110px 1fr 110px 90px 90px;
  align-items: center; padding: 10px 14px;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.recon-list .row:last-child { border-bottom: none; }
.recon-list .row.head {
  background: var(--bg-header); color: var(--text-dim);
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em;
}
.recon-list .row .nif { font-family: 'JetBrains Mono', monospace; color: var(--text-dim); font-size: 12px; }
.recon-list .row .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recon-list .row .amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 800; color: var(--accent); }
.recon-list .row .date { color: var(--text-dim); }
.recon-list .empty { padding: 24px; text-align: center; color: var(--text-faint); font-size: 13px; }

@media (max-width: 720px) {
  .recon-list .row { grid-template-columns: 1fr 1fr; }
  .recon-list .row.head { display: none; }
  .recon-list .row > * { font-size: 12px; }
}

.confirm-bar {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px 16px; margin-top: 18px;
}
.confirm-bar .info { flex: 1; font-size: 12px; color: var(--text-dim); }
.confirm-bar .info strong { color: var(--text); }
.confirm-bar .closed { color: var(--ok); font-weight: 700; }

/* ── Error pages ───────────────────────────────────────────── */
.error-shell {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 32px; gap: 8px;
}
.error-shell h1 { font-size: 56px; color: var(--accent); font-weight: 800; }
.error-shell a { color: var(--accent); font-weight: 700; }
