/* IOMI — app.iomi.pt
   As cores da marca vivem só no bloco :root. Quando o logotipo chegar,
   basta ajustar --brand, --brand-strong, --brand-tint e --seal. */

:root {
  --paper: #F2F4F3;
  --surface: #FFFFFF;
  --ink: #16262B;
  --ink-soft: #4B5B60;
  --ink-faint: #75858A;
  --line: #D6DDDB;
  --line-strong: #B7C2BF;

  --brand: #0E5A5C;
  --brand-strong: #0A4547;
  --brand-tint: #E2EEED;
  --on-brand: #F4FAF9;
  --seal: #B8923A;

  --ok: #2E6A4E;
  --ok-tint: #E3F0E8;
  --warn: #7E5B0E;
  --warn-tint: #F7EFD9;
  --danger: #A33A2B;
  --danger-tint: #F8E6E2;

  --radius: 6px;
  --radius-lg: 14px;
  --font: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 700; letter-spacing: -0.015em; }
p { margin: 0; }
a { color: var(--brand); text-underline-offset: 0.18em; }
a:hover { color: var(--brand-strong); }
:focus-visible { outline: 3px solid var(--seal); outline-offset: 2px; border-radius: 3px; }
.mono { font-family: var(--mono); font-size: 0.95em; letter-spacing: 0.01em; }
.skip-link { position: absolute; left: -999px; top: 0.5rem; background: var(--surface); padding: 0.5rem 0.9rem; border-radius: var(--radius); z-index: 100; }
.skip-link:focus { left: 0.5rem; }

/* Marca */
.brand {
  display: inline-flex; align-items: center; gap: 0.55rem;
  font-weight: 800; font-size: 1.3rem; letter-spacing: 0.05em;
  color: var(--ink); text-decoration: none;
}
.brand:hover { color: var(--ink); }
.brand-seal {
  width: 0.8rem; height: 0.8rem; border-radius: 2px; background: var(--seal);
  transform: rotate(45deg);
}

/* ---------- Páginas públicas (entrar, criar conta) ---------- */
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) {
  .auth-shell { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
}
.auth-main { display: flex; flex-direction: column; gap: 2.5rem; padding: 1.5rem 1.25rem 2rem; }
@media (min-width: 600px) { .auth-main { padding: 2.25rem 3rem 2.5rem; } }
.auth-form-wrap {
  width: 100%; max-width: 27rem; margin: 0 auto; flex: 1;
  display: flex; flex-direction: column; justify-content: center;
}
.auth-form-wrap.wide { max-width: 34rem; }
.auth-title { font-size: clamp(1.75rem, 1.4rem + 1.2vw, 2.25rem); font-weight: 800; margin-bottom: 0.5rem; }
.auth-lede { color: var(--ink-soft); margin-bottom: 1.75rem; max-width: 34em; }
.auth-legal { width: 100%; max-width: 27rem; margin: 0 auto; font-size: 0.8125rem; color: var(--ink-faint); }
.auth-legal a { color: inherit; }
.auth-alt { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--line); display: grid; gap: 0.45rem; }
.auth-alt p { color: var(--ink-soft); font-size: 0.9375rem; }
.auth-alt a { font-weight: 600; }

/* Painel do registo IORI */
.ledger { display: none; }
@media (min-width: 960px) {
  .ledger {
    display: flex; flex-direction: column; justify-content: center; gap: 2.25rem;
    padding: 3rem clamp(2rem, 5vw, 5rem);
    background: var(--brand); color: var(--on-brand);
    position: relative; overflow: hidden;
  }
  .ledger::before {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background-image: repeating-linear-gradient(0deg, rgba(255,255,255,0.045) 0 1px, transparent 1px 32px);
  }
}
.ledger-intro { position: relative; max-width: 25rem; font-size: 1.1875rem; line-height: 1.45; font-weight: 500; }
.ledger-card {
  position: relative; max-width: 26rem;
  background: var(--surface); color: var(--ink);
  border-radius: var(--radius-lg); padding: 1.75rem 1.75rem 1.25rem;
  box-shadow: 0 40px 70px -40px rgba(3, 28, 29, 0.75);
}
.ledger-kind { font-size: 0.875rem; color: var(--ink-soft); }
.ledger-code { font-family: var(--mono); font-weight: 500; font-size: 1.45rem; letter-spacing: 0.02em; margin: 0.2rem 0 0.35rem; }
.ledger-prop { font-weight: 600; }
.ledger-stamp {
  position: absolute; top: 1.2rem; right: 1.2rem;
  width: 4.4rem; height: 4.4rem; border-radius: 50%;
  border: 2px solid var(--seal); color: var(--seal);
  display: grid; place-items: center; text-align: center;
  font-weight: 800; font-size: 0.6875rem; line-height: 1.1; letter-spacing: 0.06em;
  transform: rotate(-12deg);
}
.ledger-stamp::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; border: 1px dashed var(--seal); }
.ledger-list { list-style: none; margin: 1.5rem 0 0; padding: 0 0 0 0.35rem; }
.ledger-list li { position: relative; padding: 0 0 1.05rem 1.35rem; border-left: 2px solid var(--line); }
.ledger-list li:last-child { border-left-color: transparent; padding-bottom: 0.25rem; }
.ledger-list li::before {
  content: ""; position: absolute; left: -7px; top: 0.3em;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--brand);
}
.ledger-list li:last-child::before { background: var(--seal); border-color: var(--seal); }
.ledger-list strong { display: block; font-weight: 600; font-size: 0.9375rem; line-height: 1.3; }
.ledger-list span { font-size: 0.8125rem; color: var(--ink-faint); }

@media (prefers-reduced-motion: no-preference) {
  .ledger-list li { opacity: 0; transform: translateY(6px); animation: ledger-in 0.45s ease-out forwards; }
  .ledger-list li:nth-child(1) { animation-delay: 0.2s; }
  .ledger-list li:nth-child(2) { animation-delay: 0.45s; }
  .ledger-list li:nth-child(3) { animation-delay: 0.7s; }
  .ledger-list li:nth-child(4) { animation-delay: 0.95s; }
  .ledger-stamp { opacity: 0; animation: stamp-in 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.25) 1.45s forwards; }
}
@keyframes ledger-in { to { opacity: 1; transform: none; } }
@keyframes stamp-in {
  from { opacity: 0; transform: rotate(-12deg) scale(1.7); }
  to { opacity: 1; transform: rotate(-12deg) scale(1); }
}

/* ---------- Formulários ---------- */
.form { display: grid; gap: 1.15rem; }
.field { display: grid; gap: 0.4rem; }
.field > label, .field-label { font-weight: 600; font-size: 0.9375rem; }
.field-label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.optional { font-weight: 400; color: var(--ink-faint); }
.input {
  width: 100%; min-height: 2.9rem; padding: 0.7rem 0.85rem;
  font: inherit; font-size: 1rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea.input { min-height: 6rem; resize: vertical; }
.input:hover { border-color: var(--ink-faint); }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.hint { font-size: 0.8125rem; color: var(--ink-soft); }
.field-error { font-size: 0.875rem; font-weight: 500; color: var(--danger); }
.input-group { position: relative; }
.input-group .input { padding-right: 5.75rem; }
.reveal {
  position: absolute; right: 0.35rem; top: 50%; transform: translateY(-50%);
  padding: 0.45rem 0.65rem; border: 0; border-radius: 4px; background: none; cursor: pointer;
  font: inherit; font-size: 0.8125rem; font-weight: 600; color: var(--brand);
}
.reveal:hover { background: var(--brand-tint); }
fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 1.15rem; min-width: 0; }
fieldset + fieldset { margin-top: 0.75rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
legend { float: left; width: 100%; padding: 0; margin-bottom: 0.1rem; font-weight: 700; font-size: 1.0625rem; }
legend + * { clear: left; }
.check { display: flex; align-items: flex-start; gap: 0.65rem; font-size: 0.9375rem; cursor: pointer; }
.check input { flex: none; width: 1.15rem; height: 1.15rem; margin: 0.2rem 0 0; accent-color: var(--brand); }
.field-row { display: grid; gap: 1.15rem; }
@media (min-width: 560px) { .field-row { grid-template-columns: 1fr 1fr; } }

/* Botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 2.9rem; padding: 0.75rem 1.25rem;
  font: inherit; font-weight: 600; font-size: 1rem; line-height: 1.2;
  border: 1px solid transparent; border-radius: var(--radius);
  text-decoration: none; cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-strong); color: var(--on-brand); }
.btn-quiet { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-quiet:hover { border-color: var(--ink-soft); color: var(--ink); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: currentColor; }
.btn-danger:hover { background: var(--danger-tint); color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 2.25rem; padding: 0.4rem 0.8rem; font-size: 0.875rem; }
.link-small { font-size: 0.875rem; font-weight: 500; }
.linklike { padding: 0; border: 0; background: none; font: inherit; color: var(--brand); text-decoration: underline; text-underline-offset: 0.18em; cursor: pointer; }
.linklike:hover { color: var(--brand-strong); }

/* Avisos */
.alert { margin-bottom: 1.25rem; padding: 0.9rem 1rem; border-radius: var(--radius); border-left: 4px solid; font-size: 0.9375rem; }
.alert strong { display: block; margin-bottom: 0.15rem; }
.alert-ok { background: var(--ok-tint); border-color: var(--ok); }
.alert-error { background: var(--danger-tint); border-color: var(--danger); }
.alert-warn { background: var(--warn-tint); border-color: var(--seal); }

/* ---------- Área autenticada ---------- */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1024px) { .app-shell { grid-template-columns: 16.5rem minmax(0, 1fr); } }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.8rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line);
}
@media (min-width: 1024px) { .topbar { display: none; } }
.nav-toggle {
  min-height: 2.5rem; padding: 0.45rem 0.9rem; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 0.9375rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
}

.sidebar {
  display: none; flex-direction: column; gap: 1.75rem;
  padding: 1.5rem 1rem 1.25rem; background: var(--surface); border-right: 1px solid var(--line);
}
.sidebar > .brand { padding: 0 0.75rem; }
@media (min-width: 1024px) {
  .sidebar { display: flex; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
}
body.nav-open .sidebar {
  display: flex; position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
  width: min(19rem, 85vw); overflow-y: auto; box-shadow: 0 0 40px rgba(22, 38, 43, 0.25);
}
.nav-backdrop { display: none; }
body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(22, 38, 43, 0.4); }
@media (min-width: 1024px) { body.nav-open .nav-backdrop { display: none; } }

.nav { display: grid; gap: 2px; }
.nav a {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.55rem 0.75rem; border-radius: var(--radius);
  font-size: 0.9375rem; font-weight: 500; color: var(--ink); text-decoration: none;
}
.nav a:hover { background: var(--paper); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--brand-tint); color: var(--brand-strong); font-weight: 600; }
.nav a[aria-current="page"]::before {
  content: ""; position: absolute; left: -1rem; top: 0.45rem; bottom: 0.45rem;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--seal);
}
.nav-title { padding: 1rem 0.75rem 0.35rem; font-size: 0.8125rem; font-weight: 500; color: var(--ink-faint); }
.nav-soon { font-size: 0.75rem; font-weight: 500; color: var(--ink-faint); }
.nav-count {
  min-width: 1.4rem; padding: 0.05rem 0.4rem; border-radius: 999px; text-align: center;
  font-size: 0.75rem; font-weight: 700; background: var(--seal); color: #fff;
}
.user-box { margin-top: auto; padding: 1rem 0.75rem 0; border-top: 1px solid var(--line); display: grid; gap: 0.15rem; font-size: 0.875rem; }
.user-box strong { font-size: 0.9375rem; }
.user-box span { color: var(--ink-soft); }
.user-box form { margin-top: 0.6rem; }

.main { width: 100%; max-width: 70rem; padding: 1.75rem 1.25rem 4rem; }
@media (min-width: 600px) { .main { padding: 2.5rem 2.75rem 5rem; } }
.page-head { max-width: 44rem; margin-bottom: 2rem; }
.page-head h1 { font-size: clamp(1.75rem, 1.45rem + 1vw, 2.35rem); font-weight: 800; }
.page-lede { margin-top: 0.5rem; color: var(--ink-soft); }
.back { display: inline-block; margin-bottom: 1rem; font-size: 0.9375rem; font-weight: 500; }

.section { margin-top: 2.5rem; }
.section:first-of-type { margin-top: 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.section h2 { font-size: 1.25rem; }
.section-lede { margin: -0.5rem 0 1rem; color: var(--ink-soft); font-size: 0.9375rem; }
.section-action { margin-top: 1rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.35rem; }

.facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(11.5rem, 1fr)); gap: 1px; margin: 0;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.facts > div { background: var(--surface); padding: 1rem 1.25rem; }
.facts dt { font-size: 0.8125rem; color: var(--ink-soft); }
.facts dd { margin: 0.2rem 0 0; font-weight: 600; font-size: 1.0625rem; }
.facts dd.big { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.facts a { color: inherit; }

.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.rows > li { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding: 1rem 1.25rem; border-top: 1px solid var(--line); }
.rows > li:first-child { border-top: 0; }
.row-title { font-weight: 600; }
.row-desc { margin-top: 0.15rem; max-width: 40rem; font-size: 0.9375rem; color: var(--ink-soft); }
.row-aside { flex: none; padding-top: 0.15rem; font-size: 0.8125rem; color: var(--ink-faint); white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.15rem 0.55rem; border-radius: 999px;
  font-size: 0.8125rem; font-weight: 600; white-space: nowrap;
  background: var(--paper); color: var(--ink-soft);
}
.badge::before { content: ""; width: 0.45rem; height: 0.45rem; border-radius: 50%; background: currentColor; }
.badge-active, .badge-approved { background: var(--ok-tint); color: var(--ok); }
.badge-pending { background: var(--warn-tint); color: var(--warn); }
.badge-rejected, .badge-suspended { background: var(--danger-tint); color: var(--danger); }

.empty { padding: 1.75rem 1.5rem; border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--ink-soft); max-width: 44rem; }
.empty strong { display: block; margin-bottom: 0.35rem; color: var(--ink); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.table th { padding: 0.75rem 1rem; text-align: left; white-space: nowrap; font-size: 0.8125rem; font-weight: 600; color: var(--ink-soft); border-bottom: 1px solid var(--line); }
.table td { padding: 0.8rem 1rem; vertical-align: top; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: 0; }
.table .sub { display: block; font-size: 0.8125rem; color: var(--ink-soft); }
.meta-json { font-family: var(--mono); font-size: 0.8125rem; color: var(--ink-soft); word-break: break-word; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; margin-bottom: 1.25rem; }
.filters .field { flex: 1 1 12rem; max-width: 20rem; }

.pager { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: 1.25rem; font-size: 0.9375rem; }
.pager-off { color: var(--ink-faint); }
.pager-info { color: var(--ink-soft); }

.review { display: grid; gap: 1rem; }
.review-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.review-head h3 { font-size: 1.125rem; }
.review-grid { display: grid; gap: 0.75rem 2rem; margin: 1rem 0 0; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }
.review-grid dt { font-size: 0.8125rem; color: var(--ink-soft); }
.review-grid dd { margin: 0.1rem 0 0; }
.review-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0.75rem; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.reject { flex: 1 1 18rem; }
.reject summary { display: inline-flex; list-style: none; }
.reject summary::-webkit-details-marker { display: none; }
.reject[open] summary { margin-bottom: 0.75rem; }
.reject .form { max-width: 32rem; }
.meta { font-size: 0.8125rem; color: var(--ink-soft); }

/* Páginas de erro */
.error-shell { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1.25rem; }
.error-box { max-width: 30rem; }
.error-box .brand { margin-bottom: 2.5rem; }
.error-code { margin-bottom: 0.5rem; font-family: var(--mono); color: var(--ink-faint); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
