/* TVDE+ · Portal do Operador */
:root {
  --ink: #0f0f10;
  --ink-soft: #3d3d42;
  --muted: #6b6b72;
  --line: #e6e6e9;
  --paper: #ffffff;
  --cream: #f4f1ec;
  --night: #0b0b0c;
  --graphite: #161618;
  --brand: #ff9019;
  --brand-dark: #8a4a00;
  --brand-soft: #fff1e2;
  --hairline: #d9d5cd;
  --ok: #1e8e4e;
  --ok-bg: #e7f6ec;
  --warn: #c76a00;
  --info: #1b5fb8;
  --info-bg: #e8f0fb;
  --neutral: #9a9aa1;
  --danger: #c62828;
  --danger-bg: #fdecec;
  --danger-line: #f3b9b9;
  --radius: 12px;
  --btn-h: 46px;
  --font: "General Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; letter-spacing: -0.02em; line-height: 1.15; }
p { margin: 0; }
.muted { color: var(--muted); }
.eyebrow {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brand-dark);
}
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Logo ---------- */
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 22px; letter-spacing: -0.02em; }
.logo b { color: var(--brand); font-weight: 700; }
.logo-light { color: #fff; }
.logo-dark { color: var(--ink); }
.logo img { border-radius: 9px; }

/* ---------- Spinner (linha circular laranja) ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 26px;
  height: 26px;
  max-height: 100%;
  aspect-ratio: 1;
  border: 3px solid rgba(255, 144, 25, 0.22);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
.spinner-lg { width: 40px; height: 40px; border-width: 4px; }

/* ---------- Botões ---------- */
/* O slot mantém o espaço do botão; durante o pedido o botão fica invisível e o loading aparece no mesmo sítio */
.btn-slot { position: relative; display: inline-flex; }
.btn-slot-block { display: flex; width: 100%; }
.btn-loading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.btn-loading .spinner { width: auto; height: min(26px, 100%); }
.btn-slot.is-loading > .btn { visibility: hidden; }
.btn-slot.is-loading > .btn-loading { display: flex; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--btn-h);
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn svg { width: 18px; height: 18px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #2a2a2e; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink); }
.btn:focus-visible { outline: 3px solid rgba(255, 144, 25, 0.5); outline-offset: 2px; }

/* ---------- Alerta de erro ---------- */
.alert {
  position: fixed;
  z-index: 50;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 14px 14px 16px;
  background: var(--danger-bg);
  border: 1px solid var(--danger-line);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}
.alert-icon { flex: none; width: 20px; height: 20px; margin-top: 1px; stroke-width: 2; }
.alert-text { flex: 1; font-weight: 500; }
.alert-close {
  flex: none;
  width: 28px; height: 28px;
  margin: -4px -4px 0 0;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--danger);
  font-size: 22px; line-height: 1;
  cursor: pointer;
}
.alert-close:hover { background: rgba(198, 40, 40, 0.1); }

/* ---------- Ecrãs ---------- */
.screen-boot { min-height: 100vh; display: grid; place-items: center; }

/* Login */
.screen-login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-brand {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 40px 48px;
  background:
    radial-gradient(circle at 85% 15%, rgba(255, 144, 25, 0.22), transparent 45%),
    var(--night);
  color: #fff;
}
.login-pitch { max-width: 460px; }
.login-pitch .eyebrow { color: var(--brand); margin-bottom: 14px; }
.login-pitch h1 { font-size: clamp(34px, 4vw, 52px); font-weight: 600; margin-bottom: 16px; }
.login-pitch p:last-child { color: rgba(244, 241, 236, 0.68); font-size: 17px; }
.login-foot { color: rgba(244, 241, 236, 0.45); font-size: 13px; }

.login-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px 24px;
  background: var(--paper);
}
.login-form { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.login-form h2 { font-size: 30px; font-weight: 600; }
.login-form .muted { margin-top: -8px; margin-bottom: 8px; }
.logo-mobile { display: none; margin-bottom: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.field input {
  height: var(--btn-h);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(255, 144, 25, 0.2); }
.login-form .btn-slot { margin-top: 8px; }

.env-badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 600;
}
.env-badge-dark { background: rgba(255, 144, 25, 0.14); color: var(--brand); align-self: flex-start; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; padding-top: 16px; border-top: 1px solid rgba(244, 241, 236, 0.1); }
.btn-sidebar { justify-content: flex-start; padding: 0 12px; border-radius: 10px; background: transparent; color: rgba(244, 241, 236, 0.72); font-weight: 500; }
.btn-sidebar svg { width: 20px; height: 20px; }
.btn-sidebar:hover { background: var(--graphite); color: #fff; }

@media (max-width: 860px) {
  .screen-login { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .logo-mobile { display: inline-flex; }
}

/* Portal */
.screen-app { min-height: 100vh; display: grid; grid-template-columns: 248px 1fr; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px 16px;
  background: var(--night);
  color: #fff;
}
.sidebar .logo { padding: 0 8px; margin-bottom: 4px; }
.sidebar-label { padding: 0 8px; margin-bottom: 16px; font-size: 13px; color: rgba(244, 241, 236, 0.5); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: rgba(244, 241, 236, 0.72);
  text-decoration: none;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-item:hover { background: var(--graphite); color: #fff; }
.nav-item.is-active { background: rgba(255, 144, 25, 0.14); color: var(--brand); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 32px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 22px; font-weight: 600; }
.view { padding: 32px; }
.welcome {
  max-width: 720px;
  padding: 36px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.welcome .eyebrow { margin-bottom: 12px; }
.welcome h2 { font-size: 30px; font-weight: 600; margin-bottom: 12px; }

@media (max-width: 860px) {
  .screen-app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; padding: 16px; }
  .sidebar-label, .env-badge-dark { display: none; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav-item { white-space: nowrap; padding: 8px 12px; }
  .topbar { padding: 16px; }
  .view { padding: 16px; }
  .welcome { padding: 24px; }
  .welcome h2 { font-size: 24px; }
}

/* ---------- Botão pequeno ---------- */
.btn-sm { height: 38px; padding: 0 16px; font-size: 14px; }
.btn-sm + .btn-loading .spinner { height: min(22px, 100%); }

/* ---------- Estados genéricos ---------- */
.view-intro { max-width: 720px; }
.view-head { display: flex; justify-content: space-between; align-items: center; gap: 16px 24px; max-width: 980px; margin-bottom: 20px; }
.view-head .btn-slot { flex: none; }
.field-hint { font-size: 13px; color: var(--muted); }.view-loading { display: grid; place-items: center; padding: 64px 0; }
.empty {
  display: flex; flex-direction: column; align-items: flex-start; gap: 12px;
  max-width: 720px; padding: 32px;
  background: var(--paper); border: 1px dashed var(--hairline); border-radius: 18px;
}
.empty h3 { margin: 0; font-size: 20px; font-weight: 600; }

/* ---------- Empresas ---------- */
.companies { display: flex; flex-direction: column; gap: 24px; max-width: 980px; }
.company { background: var(--paper); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.company-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 24px;
  padding: 24px 28px; border-bottom: 1px solid var(--line);
}
.company-name { margin: 0 0 4px; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.company-nipc { color: var(--muted); font-variant-numeric: tabular-nums; }
.company-state { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; text-align: right; max-width: 300px; }
.company-state-help { font-size: 13px; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-bad { background: var(--danger-bg); color: var(--danger); }

.company-docs-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 28px 6px; }
.company-docs-head h4 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.company-docs-count { font-size: 13px; font-weight: 600; color: var(--ok); }
.company-docs-count.has-issues { color: var(--warn); }

.docs { list-style: none; margin: 0; padding: 0 28px 12px; }
.doc { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.doc:first-child { border-top: 0; }
.doc-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--neutral); align-self: flex-start; margin-top: 7px; }
.doc-ok .doc-dot { background: var(--ok); }
.doc-warn .doc-dot { background: var(--brand); }
.doc-bad .doc-dot { background: var(--danger); }
.doc-info .doc-dot { background: var(--info); }
.doc-main { flex: 1; min-width: 0; }
.doc-name { font-weight: 600; }
.doc-person { font-size: 13px; color: var(--ink-soft); }
.doc-msg { font-size: 14px; color: var(--muted); }
.doc-ok .doc-msg { color: var(--ok); }
.doc-warn .doc-msg { color: var(--warn); }
.doc-bad .doc-msg { color: var(--danger); }
.doc-info .doc-msg { color: var(--info); }
.doc-notes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.doc-note { padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.doc-note-info { background: var(--info-bg); color: var(--info); }
.doc-note-bad { background: var(--danger-bg); color: var(--danger); }
.doc .btn-slot { flex: none; }
.doc .btn { min-width: 112px; }

/* ---------- Paginação ---------- */
.btn:disabled { cursor: not-allowed; }
.btn-primary:disabled, .btn-primary:disabled:hover { background: #d9d9de; color: #8a8a90; }
.btn-ghost:disabled, .btn-ghost:disabled:hover { background: #f1f1f3; border-color: var(--line); color: #b4b4ba; }

.pager {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px 24px;
  padding: 14px 20px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 14px;
}
.pager-total { color: var(--muted); }
.pager-total strong { color: var(--ink); font-weight: 600; }
.pager-nav { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.pager-status { padding: 0 8px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Popup ---------- */
body.modal-open { overflow: hidden; }
.modal {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(11, 11, 12, 0.55);
}
.modal-card {
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--paper); border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 24px 24px 0; }
.modal-head h2 { font-size: 20px; font-weight: 600; }
.modal-head .muted { margin-top: 4px; font-size: 14px; }
.modal-close {
  flex: none; width: 34px; height: 34px; margin: -6px -6px 0 0;
  border: 0; border-radius: 10px; background: transparent;
  font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer;
}
.modal-close:hover { background: var(--cream); color: var(--ink); }
.modal-body { padding: 20px 24px 24px; }
.modal-form { display: flex; flex-direction: column; gap: 16px; }

.doc-example { position: relative; margin: 0; }
.doc-example img { display: block; width: 60%; max-width: 228px; margin: 0 auto; border-radius: 9px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12); }
.partner { display: flex; align-items: center; gap: 16px; padding: 16px; background: var(--cream); border-radius: 14px; }
.partner-logo { flex: none; box-sizing: content-box; width: 60px; height: auto; padding: 8px; background: #fff; border-radius: 10px; }
.partner-text { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--ink-soft); }
.partner-free { font-weight: 600; color: var(--ok); }

.step { display: flex; gap: 14px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; }
.step-num {
  flex: none; display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand); color: #fff; font-weight: 700;
}
.step-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.step-title { margin: 4px 0 0; font-size: 16px; font-weight: 700; }
.step-body p { color: var(--ink-soft); font-size: 14px; }
.step-body .step-note { color: var(--muted); font-size: 13px; }
.step-company { color: var(--ink); font-weight: 700; }
.step-body .btn-slot { margin-top: 4px; }

.doc-owner {
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px 16px;
  background: var(--brand-soft); border-left: 4px solid var(--brand); border-radius: 10px;
}
.doc-owner-label { font-size: 13px; color: var(--brand-dark); }
.doc-owner-name { font-size: 18px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
.doc-owner-nif { font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.upload-grid { display: grid; gap: 12px; }
.upload-col { display: flex; flex-direction: column; gap: 15px; min-width: 0; }
.upload-col .upload { flex: 1; }
.upload-example { display: block; width: 100%; max-width: 220px; margin: 0 auto; border-radius: 8px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); }
.upload-grid-2 { grid-template-columns: 1fr 1fr; gap: 32px; }
.upload {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  min-height: 170px; padding: 16px;
  border: 1.5px dashed var(--hairline); border-radius: 14px;
  background: var(--cream);
  text-align: center; cursor: pointer; overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
}
.upload:hover, .upload.is-drag { border-color: var(--brand); background: var(--brand-soft); }
.upload-input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload:focus-within { outline: 3px solid rgba(255, 144, 25, 0.5); outline-offset: 2px; }
.upload-hint { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.upload-icon svg { width: 28px; height: 28px; color: var(--brand-dark); }
.upload-sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.upload-preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0.25; }
.upload.has-file { border-style: solid; border-color: var(--ok); }
.upload.has-file .upload-sub { color: var(--ink); font-weight: 500; }

@media (max-width: 860px) {
  .view-head { flex-direction: column; align-items: stretch; }
  .sidebar-foot { margin-top: 8px; padding-top: 8px; }
  .company-head { flex-direction: column; padding: 20px; }
  .company-state { align-items: flex-start; text-align: left; }
  .company-docs-head { padding: 16px 20px 6px; }
  .docs { padding: 0 20px 8px; }
  .doc { flex-wrap: wrap; }
  .doc .btn-slot { margin-left: 24px; }
  .upload-grid-2 { grid-template-columns: 1fr; }
}
