:root {
  --green: #4a6b3f; --green-dark: #2c4a2a; --green-light: #e8f5e9; --bg: #f5f7f2; --line: #dfe5da;
  --text: #1f2a1d; --muted: #6b7768; --red: #c62828; --red-bg: #ffebee; --amber: #b76e0b; --amber-bg: #fff3e0;
  --chart: #4a7f3a; --chart-hover: #2f5d24;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Tajawal', sans-serif; background: var(--bg); color: var(--text); direction: rtl; font-size: 15px; }
a { color: var(--green); }
.hidden { display: none !important; }
.topbar { background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 18px; padding: 10px 20px; position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--green); font-size: 18px; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a { text-decoration: none; color: var(--text); padding: 6px 12px; border-radius: 20px; }
.topbar nav a.active { background: var(--green-light); color: var(--green-dark); font-weight: 700; }
.me { color: var(--muted); font-size: 14px; }
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 22px; color: var(--green-dark); margin-bottom: 14px; }
h2 { font-size: 17px; color: var(--green); margin: 18px 0 10px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 16px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.toolbar > * { flex: 0 0 auto; }
.toolbar .grow { flex: 1 1 220px; }
label.f { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cfd8ca; border-radius: 10px; background: #fff; width: 100%; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #9dbb8e; border-color: #9dbb8e; }
input[readonly] { background: #f3f5f1; }
textarea { min-height: 120px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; direction: ltr; text-align: left; }
button, .btn { font: inherit; border: none; border-radius: 10px; padding: 8px 16px; background: var(--green); color: #fff; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { background: var(--green-dark); }
button:disabled { background: #bbb; cursor: not-allowed; }
button.secondary, .btn.secondary { background: #fff; color: var(--green-dark); border: 1px solid var(--green); }
button.danger { background: var(--red); }
button.link { background: none; color: var(--green); padding: 0; text-decoration: underline; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
th { background: #f7faf5; font-weight: 700; color: var(--green-dark); font-size: 14px; position: sticky; top: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f7faf5; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
.num { direction: ltr; unicode-bidi: embed; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 13px; background: #eef2ea; }
.pill.new { background: #e3f2fd; color: #0d47a1; }
.pill.under_review { background: var(--amber-bg); color: var(--amber); }
.pill.approved { background: var(--green-light); color: var(--green-dark); }
.pill.rejected { background: var(--red-bg); color: var(--red); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 16px; }
.field .err { color: var(--red); font-size: 13px; margin-top: 3px; }
.field.invalid input, .field.invalid select { border-color: var(--red); background: var(--red-bg); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: none; color: var(--muted); border-radius: 10px 10px 0 0; padding: 10px 16px; }
.tabs button.active { background: #fff; color: var(--green-dark); border: 1px solid var(--line); border-bottom-color: #fff; margin-bottom: -1px; font-weight: 700; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 12px; color: var(--muted); }
.meta { color: var(--muted); font-size: 14px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.changes { margin-top: 4px; font-size: 13px; }
.changes div { padding: 2px 0; }
.changes .from { color: var(--red); text-decoration: line-through; }
.changes .to { color: var(--green-dark); }
.changes .field-name { color: var(--muted); }
.clip { max-width: 360px; display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.lands-table input, .lands-table select { min-width: 70px; }
.files-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.file-card { border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: #fafcf8; }
.file-card img { width: 100%; height: 140px; object-fit: contain; background: #fff; border-radius: 8px; border: 1px solid var(--line); }
.file-card.replaced { opacity: 0.55; }
.contract-frame { width: 100%; height: 80vh; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.warn-box { background: var(--amber-bg); border-right: 4px solid var(--amber); padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; color: #6d4300; }
.login { max-width: 380px; margin: 10vh auto; }
.login .card { padding: 28px; }
.login h1 { text-align: center; }
.login .field { margin-bottom: 12px; }
.error { color: var(--red); background: var(--red-bg); padding: 8px 12px; border-radius: 10px; margin: 8px 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--green-dark); color: #fff; padding: 10px 20px; border-radius: 20px; z-index: 100; box-shadow: 0 4px 16px rgba(0,0,0,0.2); }
.toast.bad { background: var(--red); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin-bottom: 0; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px 12px; }
.topbar nav a.nav-cta { background: var(--green); color: #fff; }
.topbar nav a.nav-cta:hover { background: var(--green-dark); }
.value { font-weight: 500; overflow-wrap: anywhere; }
.modal-back { position: fixed; inset: 0; background: rgba(20, 30, 18, 0.45); display: flex; align-items: flex-start; justify-content: center; padding: 12vh 16px 16px; z-index: 50; }
.modal { width: 100%; max-width: 420px; margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 13px; }
.tile .big { font-size: 26px; font-weight: 700; color: var(--green-dark); margin-top: 4px; }
.tile .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
a.tile-link { text-decoration: none; color: inherit; display: block; }
a.tile-link:hover { border-color: var(--green); background: var(--green-light); }
.status-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chart { width: 100%; height: auto; display: block; }
.chart-wrap { position: relative; }
.chart .bar { fill: var(--chart); }
.chart .bar.on { fill: var(--chart-hover); }
.chart rect[tabindex]:focus { outline: none; }
.chart rect[tabindex]:focus-visible { stroke: var(--chart-hover); stroke-width: 1; }
.chart-tip { position: absolute; transform: translate(-50%, calc(-100% - 8px)); background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; box-shadow: 0 4px 14px rgba(0,0,0,0.12); pointer-events: none; white-space: nowrap; font-size: 14px; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .count { fill: var(--text); font-size: 11px; font-weight: 700; font-family: inherit; }
.bar-cell { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.bar-cell .track { flex: 1; height: 8px; background: #eef2ea; border-radius: 4px; overflow: hidden; }
.bar-cell .fill { height: 100%; background: var(--chart); border-radius: 4px; }
.total-cell { font-weight: 700; color: var(--green-dark); font-variant-numeric: tabular-nums; }
tr.changed td { background: #fffbea; }
input.invalid { border-color: var(--red); background: var(--red-bg); }
.save-bar { position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; margin: 12px 0 16px; box-shadow: 0 -4px 14px rgba(0,0,0,0.06); }
.menu-btn { display: none; background: #fff; color: var(--green-dark); border: 1px solid var(--line); font-size: 20px; line-height: 1; padding: 6px 12px; }
.menu-btn:hover { background: var(--green-light); }
.filters-toggle { display: none; }

/* Tablets and phones: the menu folds behind ☰. */
@media (max-width: 800px) {
  .split { grid-template-columns: 1fr; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .menu-btn { display: inline-block; margin-inline-start: auto; }
  .topbar nav, .topbar .me { display: none; flex-basis: 100%; }
  .topbar.open nav { display: flex; flex-direction: column; gap: 2px; }
  .topbar.open nav a { padding: 10px 12px; border-radius: 10px; }
  .topbar.open .me { display: block; padding: 10px 12px 4px; border-top: 1px solid var(--line); }
}

/* Phones: filters fold away, tables become cards. */
@media (max-width: 700px) {
  main { padding: 14px 12px 48px; }
  h1 { font-size: 20px; }
  .card { padding: 14px; border-radius: 14px; }
  input, select, textarea { font-size: 16px; } /* 16px stops iOS zooming into a field on focus */
  .toolbar .grow { flex-basis: 100%; }
  .filters-toggle { display: block; width: 100%; }
  .fold { display: none; margin-top: 12px; }
  .filters-open .fold { display: block; }
  .filters { grid-template-columns: 1fr 1fr; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile { padding: 12px; }
  .tile .big { font-size: 20px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; }
  .tabs button { white-space: nowrap; }
  .contract-frame { height: 70vh; }
  .modal-back { padding-top: 8vh; }
  .table-wrap { overflow-x: visible; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  table.stack tr:last-child { border-bottom: none; }
  table.stack td { border: none; padding: 3px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px;
    white-space: normal !important; min-width: 0 !important; text-align: left; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: right; flex: 0 0 auto; max-width: 45%; }
  table.stack td[data-label=""]::before { content: none; }
  table.stack td[data-label=""] { justify-content: flex-start; }
  table.stack .bar-cell { min-width: 0; flex: 0 1 60%; }
}
