/* =========================================================================
   Sajjel Ministry Console — V3 "السجل" — archival-institutional stylesheet
   Brand: paper #FBF9F3 · ink #23201A · seal green #1A5632 · tint #E9F1EA
          line #E4DFD2 · brass #B08B2E (at most once per view)
   ========================================================================= */

:root {
  --ink: #23201A;
  --ink-muted: #6E675B;
  --paper: #FBF9F3;
  --paper-raised: #FFFFFF;
  --line: #E4DFD2;
  --primary: #1A5632;
  --primary-deep: #0F3D23;
  --tint: #E9F1EA;
  --brass: #B08B2E;
  --warning: #8A5A0B;
  --warning-tint: #F6EEDC;
  --danger: #96342B;
  --danger-tint: #F5E7E5;
  --info: #2C5A78;
  --radius-sm: 4px;
  --radius-md: 6px;
  --font: "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, sans-serif;
  --mono-nums: "tnum" 1, "lnum" 1;
}

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

html { background: var(--paper); }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.8;
  font-size: 15px;
}

[dir="ltr"] body, body[data-lang="en"] { line-height: 1.6; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

.num { font-feature-settings: var(--mono-nums); font-variant-numeric: tabular-nums lining-nums; direction: ltr; unicode-bidi: embed; }

/* ---------- Header ---------- */
.topbar {
  background: var(--paper-raised);
  border-bottom: 3px double var(--line);
  padding: 0 24px;
  display: flex; align-items: center; gap: 16px;
  height: 64px;
  position: sticky; top: 0; z-index: 50;
}
.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-lockup img { height: 36px; width: 36px; }
.brand-word { font-size: 22px; font-weight: 700; color: var(--ink); }
.brand-word .shadda { color: var(--primary); }
.brand-sep { width: 1px; height: 32px; background: var(--line); }
.ministry-name { font-size: 13px; color: var(--ink-muted); font-weight: 500; line-height: 1.4; }
.ministry-name strong { display: block; color: var(--ink); font-weight: 600; font-size: 13.5px; }
.topbar-spacer { flex: 1; }
.demo-ribbon {
  background: var(--warning-tint); color: var(--warning);
  border: 1px solid var(--warning);
  font-size: 11.5px; font-weight: 600;
  padding: 3px 12px; border-radius: var(--radius-sm);
  letter-spacing: 0.2px; white-space: nowrap;
}
.lang-toggle {
  background: none; border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 5px 14px;
  font-size: 13px; font-weight: 600; color: var(--ink);
}
.lang-toggle:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: calc(100vh - 64px); }
.sidenav {
  width: 232px; flex-shrink: 0;
  background: var(--paper-raised);
  border-inline-end: 1px solid var(--line);
  padding: 20px 0;
}
.sidenav .nav-section {
  font-size: 11px; font-weight: 600; color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: 0.6px;
  padding: 14px 22px 6px;
}
.sidenav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 22px; color: var(--ink); font-size: 14px; font-weight: 500;
  border-inline-start: 3px solid transparent;
}
.sidenav a:hover { background: var(--paper); text-decoration: none; }
.sidenav a.active {
  background: var(--tint); color: var(--primary-deep);
  border-inline-start-color: var(--primary); font-weight: 600;
}
.sidenav a .badge-count {
  margin-inline-start: auto;
  background: var(--primary); color: #fff;
  font-size: 11px; font-weight: 600;
  border-radius: 10px; padding: 0 7px; line-height: 18px;
}
.nav-icon { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }

main { flex: 1; padding: 28px 34px 60px; max-width: 1180px; }

/* ---------- Page headers ---------- */
.page-title { font-size: 24px; font-weight: 700; line-height: 1.4; }
.page-sub { color: var(--ink-muted); font-size: 13.5px; margin-top: 2px; }
.page-head { margin-bottom: 22px; padding-bottom: 14px; border-bottom: 2px solid var(--ink); }
.page-head .rule-note { font-size: 12px; color: var(--ink-muted); margin-top: 6px; }

/* ---------- Stats strip ---------- */
.stats-strip { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.stat-card {
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: 12px 20px; min-width: 150px;
}
.stat-card .v { font-size: 24px; font-weight: 700; line-height: 1.3; }
.stat-card .k { font-size: 12px; color: var(--ink-muted); font-weight: 500; }
.stat-card.brass .v { color: var(--brass); }

/* ---------- Controls row ---------- */
.controls {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  margin-bottom: 16px;
}
.search-box {
  flex: 1; min-width: 260px;
  display: flex; align-items: center; gap: 8px;
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: 8px 14px;
}
.search-box:focus-within { border-color: var(--primary); }
.search-box input {
  border: none; outline: none; background: none; flex: 1;
  font-family: inherit; font-size: 14px; color: var(--ink);
}
select.filter {
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: 8px 12px;
  font-family: inherit; font-size: 13px; color: var(--ink);
}

/* View toggle (public / internal) */
.view-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; }
.view-toggle button {
  background: var(--paper-raised); border: none; padding: 8px 18px;
  font-size: 13px; font-weight: 600; color: var(--ink-muted);
}
.view-toggle button.on { background: var(--primary); color: #fff; }

/* Register tabs (two registers) */
.register-tabs { display: flex; gap: 0; border-bottom: 2px solid var(--ink); margin-bottom: 0; }
.register-tabs button {
  background: none; border: none; padding: 10px 22px;
  font-size: 14px; font-weight: 600; color: var(--ink-muted);
  border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.register-tabs button.on { color: var(--ink); border-bottom-color: var(--primary); }

/* ---------- Ledger table ---------- */
.ledger-wrap { background: var(--paper-raised); border: 1px solid var(--line); border-top: none; overflow-x: auto; }
table.ledger { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.ledger th {
  text-align: start; font-size: 11.5px; font-weight: 600;
  color: var(--ink-muted); letter-spacing: 0.3px;
  padding: 10px 14px; border-bottom: 2px solid var(--ink);
  background: var(--paper); white-space: nowrap;
}
table.ledger td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.ledger tr:hover td { background: var(--tint); cursor: pointer; }
table.ledger tr.struck td { color: var(--ink-muted); }
table.ledger tr.struck .ent-name { text-decoration: line-through; text-decoration-color: var(--danger); text-decoration-thickness: 1px; }
.rec-no { font-weight: 600; white-space: nowrap; }
.ent-name { font-weight: 600; color: var(--ink); }
.ent-sub { font-size: 12px; color: var(--ink-muted); }

/* Status chips */
.chip {
  display: inline-block; font-size: 11.5px; font-weight: 600;
  padding: 1px 10px; border-radius: 3px; white-space: nowrap; line-height: 1.7;
}
.chip.active { background: var(--tint); color: var(--primary-deep); border: 1px solid var(--primary); }
.chip.struck { background: var(--danger-tint); color: var(--danger); border: 1px solid var(--danger); }
.chip.pending { background: var(--warning-tint); color: var(--warning); border: 1px solid var(--warning); }
.chip.migrated { background: var(--paper); color: var(--ink-muted); border: 1px dashed var(--ink-muted); }
.chip.info { background: #E8EFF4; color: var(--info); border: 1px solid var(--info); }

.internal-note-cell { font-size: 12px; color: var(--ink-muted); max-width: 260px; }
.footnote { font-size: 12px; color: var(--ink-muted); margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.real-context {
  margin-top: 20px; font-size: 12.5px; color: var(--ink-muted);
  background: var(--paper-raised); border: 1px solid var(--line);
  border-inline-start: 3px solid var(--info);
  padding: 10px 16px; border-radius: var(--radius-sm);
}

/* ---------- Entity record page ---------- */
.record-header {
  background: var(--paper-raised); border: 1px solid var(--line);
  border-top: 4px solid var(--primary);
  padding: 24px 28px; margin-bottom: 22px; position: relative;
}
.record-header.struck { border-top-color: var(--danger); }
.record-header .rec-id-line { font-size: 12.5px; color: var(--ink-muted); font-weight: 600; letter-spacing: 0.3px; }
.record-header h1 { font-size: 22px; font-weight: 700; margin: 6px 0 2px; line-height: 1.5; }
.record-header .form-line { color: var(--ink-muted); font-size: 14px; }
.record-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0; margin-top: 18px; border-top: 1px solid var(--line);
}
.record-grid .cell { padding: 12px 4px 4px; border-bottom: 1px dotted var(--line); }
.record-grid .cell .k { font-size: 11.5px; color: var(--ink-muted); font-weight: 600; }
.record-grid .cell .v { font-size: 14.5px; font-weight: 600; }
.strike-banner {
  background: var(--danger-tint); border: 1px solid var(--danger);
  color: var(--danger); font-weight: 600; font-size: 13.5px;
  padding: 10px 16px; border-radius: var(--radius-sm); margin-bottom: 18px;
}
.record-actions { display: flex; gap: 10px; margin: 18px 0 26px; flex-wrap: wrap; }
.btn {
  border-radius: var(--radius-sm); padding: 9px 20px;
  font-size: 13.5px; font-weight: 600; border: 1px solid var(--line);
  background: var(--paper-raised); color: var(--ink);
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-deep); }
.btn.ghost-danger { color: var(--danger); border-color: var(--danger); background: none; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.section-h {
  font-size: 15px; font-weight: 700; margin: 30px 0 12px;
  padding-bottom: 6px; border-bottom: 1px solid var(--ink);
  display: flex; align-items: baseline; gap: 10px;
}
.section-h .side { font-size: 12px; color: var(--ink-muted); font-weight: 500; }

/* Filings timeline — ledger style */
.filings { background: var(--paper-raised); border: 1px solid var(--line); }
.filing-row {
  display: grid; grid-template-columns: 30px 110px 1fr auto;
  gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line);
  align-items: baseline;
}
.filing-row:last-child { border-bottom: none; }
.filing-row .idx { color: var(--ink-muted); font-size: 12px; font-weight: 600; }
.filing-row .fdate { font-size: 13px; font-weight: 600; white-space: nowrap; }
.filing-row .ftype { font-weight: 600; font-size: 13.5px; }
.filing-row .fsum { font-size: 13px; color: var(--ink-muted); }
.filing-row .fref { font-size: 12px; color: var(--ink-muted); white-space: nowrap; }
.filing-row .fgaz { font-size: 11.5px; color: var(--primary); }
.filing-row.mig { background: var(--paper); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.kv-table { width: 100%; border-collapse: collapse; font-size: 13.5px; background: var(--paper-raised); border: 1px solid var(--line); }
.kv-table td { padding: 9px 14px; border-bottom: 1px solid var(--line); }
.kv-table td:first-child { color: var(--ink-muted); width: 42%; font-weight: 500; }
.kv-table tr:last-child td { border-bottom: none; }

.internal-panel {
  background: var(--paper-raised); border: 1px dashed var(--ink-muted);
  padding: 14px 18px; border-radius: var(--radius-sm); font-size: 13px;
}
.internal-panel .tag { font-size: 11px; font-weight: 700; color: var(--info); letter-spacing: 0.5px; }

/* ---------- Certified extract (the wow moment) ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(35, 32, 26, 0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 30px 16px; z-index: 100; overflow-y: auto;
}
.extract-shell { max-width: 760px; width: 100%; }
.extract-toolbar {
  display: flex; gap: 10px; justify-content: flex-end; margin-bottom: 12px;
}
.extract-toolbar .btn { background: var(--paper); }

.certificate {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  outline: 2px solid var(--primary);
  outline-offset: -10px;
  padding: 52px 58px 44px;
  position: relative;
  box-shadow: 0 18px 50px rgba(35,32,26,0.28);
  animation: cert-in 0.45s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes cert-in {
  from { opacity: 0; transform: translateY(26px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}
.cert-head { text-align: center; border-bottom: 3px double var(--ink); padding-bottom: 18px; margin-bottom: 22px; }
.cert-head .state { font-size: 13px; font-weight: 600; letter-spacing: 1px; }
.cert-head .ministry { font-size: 15px; font-weight: 700; margin-top: 2px; }
.cert-head .office { font-size: 12.5px; color: var(--ink-muted); margin-top: 2px; }
.cert-title { text-align: center; margin: 20px 0 6px; }
.cert-title h2 { font-size: 26px; font-weight: 700; letter-spacing: 0.5px; }
.cert-title .sub { font-size: 12.5px; color: var(--ink-muted); }
.cert-serial {
  text-align: center; font-size: 12px; color: var(--ink-muted);
  margin-bottom: 24px;
}
.cert-serial strong { color: var(--ink); }

.cert-body table { width: 100%; border-collapse: collapse; font-size: 14px; }
.cert-body td { padding: 8px 4px; border-bottom: 1px dotted var(--line); vertical-align: top; }
.cert-body td.k { width: 38%; color: var(--ink-muted); font-weight: 500; }
.cert-body td.v { font-weight: 600; }

.cert-clause {
  margin-top: 24px; font-size: 13px; line-height: 2;
  text-align: justify; color: var(--ink);
}
.cert-footer {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-top: 36px; gap: 20px;
}
.cert-qr { text-align: center; }
.cert-qr svg { display: block; margin: 0 auto 6px; }
.cert-qr .vc { font-size: 11px; color: var(--ink-muted); letter-spacing: 0.5px; }
.cert-sign { text-align: center; flex: 1; }
.cert-sign .role { font-size: 12.5px; font-weight: 600; }
.cert-sign .name { font-size: 14px; font-weight: 700; margin-top: 30px; }
.cert-sign .sig-line { border-top: 1px solid var(--ink); width: 200px; margin: 6px auto 0; padding-top: 4px; font-size: 11px; color: var(--ink-muted); }
.cert-seal { position: relative; width: 118px; text-align: center; }
.cert-seal img { width: 108px; height: 108px; transform: rotate(-7deg); opacity: 0.92; }
.cert-note { margin-top: 28px; font-size: 10.5px; color: var(--ink-muted); text-align: center; border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- Gazette ---------- */
.gazette-doc {
  background: var(--paper-raised); border: 1px solid var(--line);
  padding: 40px 48px; max-width: 820px;
}
.gazette-head { text-align: center; border-bottom: 3px double var(--ink); padding-bottom: 16px; margin-bottom: 8px; }
.gazette-head h2 { font-size: 24px; font-weight: 700; }
.gazette-head .meta { font-size: 12.5px; color: var(--ink-muted); }
.gazette-section-title {
  font-size: 15px; font-weight: 700; margin: 26px 0 4px;
  border-bottom: 1px solid var(--ink); padding-bottom: 4px;
}
.gazette-item { padding: 12px 0; border-bottom: 1px dotted var(--line); font-size: 13.5px; }
.gazette-item .gi-head { font-weight: 700; }
.gazette-item .gi-body { color: var(--ink); font-size: 13px; }
.gazette-item .gi-ref { font-size: 11.5px; color: var(--ink-muted); }
.gazette-actions { display: flex; gap: 10px; margin: 16px 0 22px; }

/* ---------- Intake ---------- */
.intake-card {
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: 18px 22px; margin-bottom: 14px;
  display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center;
}
.intake-card .app-no { font-size: 12px; color: var(--ink-muted); font-weight: 600; }
.intake-card h3 { font-size: 15.5px; font-weight: 700; line-height: 1.5; }
.intake-card .meta { font-size: 12.5px; color: var(--ink-muted); }
.check-strip { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.check-pill {
  font-size: 11px; font-weight: 600; padding: 1px 9px;
  border-radius: 3px; border: 1px solid var(--primary);
  color: var(--primary-deep); background: var(--tint);
}
.check-pill.miss { border-color: var(--warning); color: var(--warning); background: var(--warning-tint); }
.intake-side { text-align: center; min-width: 170px; }
.born-note {
  background: var(--tint); border: 1px solid var(--primary);
  color: var(--primary-deep); font-weight: 600; font-size: 13px;
  padding: 10px 16px; border-radius: var(--radius-sm); margin-bottom: 16px;
  animation: cert-in 0.4s ease;
}

/* ---------- Integrity panel ---------- */
.integrity-intro {
  background: var(--paper-raised); border: 1px solid var(--line);
  border-inline-start: 4px solid var(--primary);
  padding: 16px 20px; margin-bottom: 20px; font-size: 13.5px;
}
.hash-chain { background: var(--paper-raised); border: 1px solid var(--line); }
.hash-row {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 14px;
  padding: 12px 18px; border-bottom: 1px solid var(--line); position: relative;
}
.hash-row:last-child { border-bottom: none; }
.hash-row .link-col { display: flex; flex-direction: column; align-items: center; }
.link-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); margin-top: 6px; }
.link-stem { flex: 1; width: 2px; background: var(--line); }
.hash-row:last-child .link-stem { display: none; }
.hash-row .h-title { font-weight: 600; font-size: 13.5px; }
.hash-row .h-meta { font-size: 12px; color: var(--ink-muted); }
.hash-row code {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 11px; color: var(--primary-deep);
  background: var(--tint); padding: 1px 8px; border-radius: 3px;
  direction: ltr; unicode-bidi: embed; display: inline-block;
}
.hash-row .prev { color: var(--ink-muted); background: var(--paper); }
.verify-result {
  margin-top: 16px; padding: 12px 18px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 13.5px; display: none;
}
.verify-result.ok { display: block; background: var(--tint); border: 1px solid var(--primary); color: var(--primary-deep); }

/* ---------- Print: only the certificate ---------- */
@media print {
  body * { visibility: hidden; }
  .overlay { position: static; background: none; padding: 0; overflow: visible; }
  .certificate, .certificate * { visibility: visible; }
  .certificate {
    box-shadow: none; outline-offset: -10px;
    position: absolute; inset-inline-start: 0; top: 0; width: 100%;
    animation: none;
    padding: 34px 42px 26px;
  }
  .cert-footer { margin-top: 22px; }
  .cert-note { margin-top: 16px; }
  .extract-toolbar { display: none; }
}

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidenav { width: 100%; border-inline-end: none; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; padding: 8px; }
  .sidenav .nav-section { display: none; }
  .sidenav a { border-inline-start: none; border-radius: var(--radius-sm); padding: 7px 12px; }
  main { padding: 20px 16px 50px; }
  .certificate { padding: 30px 22px; }
  .ministry-name { display: none; }
}
