:root {
  color-scheme: dark;
  --ink: #e5edf6;
  --muted: #94a3b8;
  --line: #253245;
  --panel: #111827;
  --panel-soft: #162235;
  --bg: #0b1120;
  --accent: #14b8a6;
  --accent-dark: #5eead4;
  --warn: #f59e0b;
  --bad: #f87171;
  --good: #4ade80;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  direction: rtl;
}
body.busy {
  cursor: progress;
}
body.busy button {
  cursor: progress;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: #0f172a;
  border-bottom: 1px solid var(--line);
}

.topbar h1 { margin: 0; font-size: 20px; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 10px; }
a { color: var(--accent-dark); text-decoration: none; }
main { width: 100%; max-width: none; margin: 18px auto; padding: 0 16px; }

.band {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 18px;
}
.collapsible {
  padding: 0;
  overflow: hidden;
}
.collapsible summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
}
.collapsible summary::after {
  content: "فتح";
  min-width: 54px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent-dark);
  background: #0b1220;
  text-align: center;
  font-size: 12px;
}
.collapsible[open] summary::after {
  content: "طي";
}
.collapsible summary h2 {
  margin: 0;
}
.collapsible > :not(summary) {
  margin: 0 20px 20px;
}
h2 { margin: 0 0 16px; font-size: 20px; }
h3 { margin: 20px 0 8px; font-size: 15px; }
.actions, .filters, .upload {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin: 12px 0;
}
label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
input, select {
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b1220;
  color: var(--ink);
  direction: rtl;
}
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
}
.small { min-height: 30px; padding: 4px 8px; font-size: 12px; }
.ghost { background: #fff; color: var(--accent-dark); }
.ghost {
  background: transparent;
  color: var(--accent-dark);
  border-color: #2dd4bf;
}
.danger {
  background: #7f1d1d;
  border-color: #ef4444;
  color: #fee2e2;
}
.danger:hover { background: #991b1b; }
.toast {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 1000;
  max-width: min(420px, calc(100vw - 36px));
  padding: 10px 14px;
  border: 1px solid #2dd4bf;
  border-radius: 8px;
  background: #0f172a;
  color: #e5edf6;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast[data-kind="error"] {
  border-color: #ef4444;
  color: #fecaca;
}

table {
  width: 100%;
  border-collapse: collapse;
  direction: rtl;
  background: #0f172a;
}
th, td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: right;
}
th { background: #1e293b; font-size: 12px; color: #cbd5e1; }
small { display: block; color: var(--muted); margin-top: 3px; }
.num { text-align: left; white-space: nowrap; direction: ltr; }
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
}
.metrics div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-soft);
}
.metrics strong { display: block; font-size: 24px; }
.metrics span { color: var(--muted); font-size: 13px; }
.report-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(190px, 1fr));
  gap: 10px;
}
.report-card {
  min-height: 118px;
  display: grid;
  align-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: var(--panel-soft);
}
.report-card span {
  color: var(--muted);
  font-size: 13px;
}
.report-card strong {
  direction: ltr;
  text-align: right;
  font-size: 24px;
  line-height: 1.15;
}
.report-card.good { border-color: #22c55e; background: #082f25; }
.report-card.warn { border-color: #f59e0b; background: #2d220d; }
.report-card.bad { border-color: #ef4444; background: #2b151b; }
.report-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}
.report-columns .band {
  margin-bottom: 0;
}
.report-bars {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 14px;
}
.report-bar {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #0f172a;
}
.report-bar div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}
.report-bar strong {
  direction: ltr;
  white-space: nowrap;
}
.report-bar i {
  display: block;
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #1e293b;
}
.report-bar b {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #14b8a6, #22c55e);
}
.cash-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}
.cash-form .wide {
  grid-column: 1 / -1;
}
.cash-form textarea {
  min-height: 170px;
}
.cash-high-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
}
.preview-ok {
  border-color: #22c55e;
  background: #08251f;
}
.signature-box {
  margin-top: 64px;
  width: 190px;
  border-bottom: 1px solid #334155;
  padding-bottom: 8px;
}
.signature-box span {
  display: block;
  color: #475569;
  font-size: 12px;
  margin-bottom: 8px;
}
.signature-box img {
  max-width: 150px;
  max-height: 70px;
  display: block;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.chip, .badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  background: #eef2f7;
  color: #cbd5e1;
  background: #1e293b;
  font-size: 12px;
}
.badge-invoiced, .badge-match_accepted { background: #064e3b; color: #bbf7d0; }
.badge-needs_review, .badge-matched_suggestion { background: #451a03; color: #fde68a; }
.badge-excluded, .badge-expense { background: #3f1d24; color: #fecaca; }
.badge-supplier_invoice_done { background: #1e1b4b; color: #c7d2fe; }
.badge-atm { background: #1c2a1c; color: #86efac; }
.badge-manual_done { background: #042f2e; color: #5eead4; }
.txns tr.invoiced { background: #0b2f27; }
.txns tr.needs_review, .txns tr.matched_suggestion { background: #271c0b; }
.txns tr.excluded, .txns tr.expense { background: #111827; color: #94a3b8; }
.txns tr.supplier_invoice_done { background: #1a1833; color: #c7d2fe; }
.txns tr.supplier_invoice_done .muted { color: #7c6fab; }
.txns tr.manual_done { background: #0d2b2a; color: #5eead4; }
.txns tr.manual_done .muted { color: #2d9990; }
.candidate {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 6px;
  background: #101a2b;
}
.score-high { border-color: #22c55e; background: #082f25; }
.score-good { border-color: #84cc16; background: #1c2a12; }
.score-mid { border-color: #f59e0b; background: #2d220d; }
.score-low { border-color: #f87171; background: #2b151b; }
.selected-match {
  display: grid;
  gap: 4px;
  border: 1px solid #22c55e;
  background: #052e2b;
  color: #d1fae5;
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 8px;
}
.muted-match {
  border-color: #64748b;
  background: #111827;
  color: #cbd5e1;
}
.shipment-match {
  border-color: #38bdf8;
  background: #0c2233;
  color: #bae6fd;
}
a.shipment-link {
  display: grid;
  text-decoration: none;
  cursor: pointer;
}
a.shipment-link:hover {
  border-color: #7dd3fc;
  background: #0f2d45;
}
.sup-inv-area {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #1e293b;
}
.sup-inv-upload { display: contents; }
.file-pick {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.file-pick input[type="file"] { display: none; }
.sup-inv-bulk-upload {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.cash-inv-upload {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.notice-warn {
  background: #2d2200;
  color: #fde68a;
  border: 1px solid #78350f;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}
/* ── Ledger tracking table ───────────────────────────────────────────────── */
.ledger-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.ledger-table th {
  background: var(--surface2);
  padding: 8px 10px;
  text-align: right;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}
.ledger-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.ledger-table tr.row-odd td  { background: #141a22; }
.ledger-table tr.row-even td { background: #0e1319; }
.ledger-table tr.ledger-done td {
  background: #0b1f0d;
  color: #6bb87a;
  text-decoration: line-through;
  text-decoration-color: #3a6b3f;
}
.ledger-table tr.ledger-done td a { color: #4a9e5a; }
.ledger-check {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: #4ade80;
}
.ledger-progress {
  font-size: 0.82em;
  color: var(--text-muted);
  font-weight: 400;
  margin-right: 8px;
}
.ledger-table .num { text-align: left; font-variant-numeric: tabular-nums; }

.candidate-details summary {
  cursor: pointer;
  color: var(--accent-dark);
  margin-bottom: 8px;
}
.note-form {
  display: grid;
  gap: 6px;
  min-width: 180px;
}
textarea {
  min-height: 64px;
  resize: vertical;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b1220;
  color: var(--ink);
  font: inherit;
  direction: rtl;
}
.row-actions { min-width: 150px; }
.row-actions form { margin: 0 0 6px; }
.muted { color: var(--muted); }
.inline-form { display: inline-flex; margin-inline-start: 8px; }
.danger-zone {
  border-color: #7f1d1d;
  background: #1f1418;
}
.delete-period {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
  align-items: end;
}
.check {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}
.check input { min-height: auto; }
.file-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 14px;
}
.file-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  color: #cbd5e1;
  background: #111827;
  font-size: 12px;
}
.scroll-table {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.raw-table {
  min-width: 1100px;
}
.raw-table td, .raw-table th {
  font-size: 12px;
  white-space: nowrap;
}
.orders-table {
  min-width: 1050px;
}
.orders-table td, .orders-table th {
  white-space: nowrap;
}
.orders-table tr.order-linked {
  background: #0b2f27;
}
.orders-table tr.order-unlinked {
  background: #111827;
}
.search-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.search-preview span {
  display: inline-flex;
  gap: 4px;
  border: 1px solid #e2e8f0;
  border-color: var(--line);
  background: #111827;
  border-radius: 6px;
  padding: 5px 7px;
  font-size: 12px;
}
.gls-bad td {
  background: #2b151b;
  color: #fecaca;
}
.gls-warn td {
  background: #2d220d;
  color: #fde68a;
}
.gls-info td {
  background: #082f25;
  color: #bbf7d0;
}

.invoice-page {
  background: #dbe2ea;
  direction: ltr;
  color: #111827;
}
.invoice-sheet {
  width: 794px;
  min-height: 1123px;
  margin: 24px auto;
  padding: 58px;
  background: #fff;
  color: #111827;
}
.invoice-head, .invoice-meta {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid #cbd5e1;
  padding-bottom: 18px;
}
.invoice-head h1 { font-size: 18px; margin: 0 0 6px; }
.invoice-head p { margin: 0; color: #475569; line-height: 1.4; }
.invoice-title { font-size: 30px; font-weight: 700; align-self: center; }
.invoice-meta { margin-top: 28px; border-bottom: 0; }
.invoice-page table {
  direction: ltr;
  background: #fff;
  color: #111827;
}
.invoice-page th,
.invoice-page td {
  color: #111827;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}
.invoice-table {
  margin-top: 34px;
  table-layout: fixed;
}
.invoice-table th {
  background: #f1f5f9;
  color: #334155;
  font-weight: 700;
}
.invoice-table tbody td {
  background: #fff;
}
.invoice-table tbody tr:nth-child(even) td {
  background: #f8fafc;
}
.invoice-table .num,
.invoice-page .num {
  direction: ltr;
  text-align: right;
}
.totals {
  margin: 28px 0 0 auto;
  width: 280px;
  display: grid;
  gap: 9px;
  text-align: right;
}
.grand { font-size: 18px; }
.thanks { margin-top: 70px; }
footer {
  margin-top: 40px;
  padding-top: 12px;
  border-top: 1px dashed #94a3b8;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  font-size: 12px;
}

@media (max-width: 760px) {
  .topbar, .metrics, .candidate, .report-columns, .report-bars, .cash-form, .cash-high-grid { display: block; }
  .report-grid { grid-template-columns: 1fr; }
  .report-columns .band, .report-bar { margin-bottom: 12px; }
  table { font-size: 13px; }
  .invoice-sheet { width: auto; margin: 0; padding: 28px; }
}
