/* PALX — olive & brass ledger. Logical properties throughout so Arabic (RTL) mirrors automatically. */
:root {
  --paper: #F3F4EF;
  --surface: #FFFFFF;
  --sunk: #E9EBE3;
  --ink: #18221D;
  --muted: #5F6A5A;
  --line: #D6DACE;
  --olive: #2F4A22;
  --olive-2: #46663A;
  --olive-tint: #E2E9D8;
  --brass: #A07A1A;
  --brass-tint: #F4ECD6;
  --pos: #23744A;
  --pos-tint: #E0F0E6;
  --neg: #B0352C;
  --neg-tint: #F8E3E0;
  --focus: #C99A2E;
  --font: "Segoe UI", "Noto Sans", "Noto Sans Arabic", Tahoma, system-ui, -apple-system, sans-serif;
  --r-panel: 10px;
  --r-ctl: 7px;
  --side: 236px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111613; --surface: #19201B; --sunk: #222A24; --ink: #E4E9E0; --muted: #9AA595;
    --line: #2E3830; --olive: #8DB467; --olive-2: #A6C885; --olive-tint: #243321;
    --brass: #D6AF4F; --brass-tint: #33290F; --pos: #6CC891; --pos-tint: #17301F;
    --neg: #F0857A; --neg-tint: #3A1C19; color-scheme: dark;
  }
  .logo-light { display: none; }
}
@media (prefers-color-scheme: light) { .logo-dark { display: none; } }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper); color: var(--ink); font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--olive); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.55rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.08rem; font-weight: 650; }
.num, td.n, .amount { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
td.n, th.n { text-align: end; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side {
  background: var(--surface); border-inline-end: 1px solid var(--line);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
}
.side .brand img { height: 34px; display: block; }
.side .biz { font-size: .82rem; color: var(--muted); padding-inline: 4px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r-ctl);
  color: var(--ink); text-decoration: none; font-weight: 500;
}
.nav a svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; }
.nav a:hover { background: var(--sunk); }
.nav a[aria-current="page"] { background: var(--olive-tint); color: var(--olive); font-weight: 650; }
.nav .sep { height: 1px; background: var(--line); margin: 8px 4px; }
.side .foot { margin-top: auto; font-size: .82rem; color: var(--muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  display: flex; align-items: center; gap: 12px; padding: 12px 28px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 88%, transparent); position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(6px);
}
.top .grow { flex: 1; }
.menu-btn { display: none; }
.content { padding: 26px 28px 60px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .grow { flex: 1; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 70ch; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .92rem; line-height: 1; padding: 10px 15px;
  border-radius: var(--r-ctl); border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--olive); border-color: var(--olive); color: #F6F7F2; }
.btn.primary:hover { background: var(--olive-2); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #10160F; } }
.btn.danger { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, var(--line)); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--sunk); }
.btn.sm { padding: 6px 9px; font-size: .82rem; }
.btn[disabled] { opacity: .55; cursor: progress; }

.seg { display: inline-flex; background: var(--sunk); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  font: inherit; font-size: .84rem; font-weight: 600; border: 0; background: transparent; color: var(--muted);
  padding: 6px 12px; border-radius: 999px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(20, 30, 20, .14); }

label.f { display: flex; flex-direction: column; gap: 5px; font-size: .86rem; font-weight: 600; color: var(--muted); }
label.f .hint { font-weight: 400; font-size: .8rem; }
input, select, textarea {
  font: inherit; font-size: .95rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 9px 11px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--olive); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--olive) 22%, transparent); }
input[type="checkbox"] { width: auto; }
input.num { text-align: end; }
textarea { min-height: 70px; resize: vertical; }
.err { color: var(--neg); font-size: .8rem; font-weight: 500; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: 1 / -1; }

/* ---------- Panels & tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); }
.panel > header { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel > header .grow { flex: 1; }
.panel .body { padding: 16px 18px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.filters label.f { min-width: 140px; }
.filters .search { flex: 1 1 220px; }

.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th {
  text-align: start; font-weight: 600; font-size: .78rem; color: var(--muted);
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface); white-space: nowrap;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover td { background: color-mix(in srgb, var(--sunk) 55%, transparent); }
td .sub { display: block; font-size: .78rem; color: var(--muted); }
td.actions { white-space: nowrap; text-align: end; }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 18px; font-size: .86rem; color: var(--muted); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--sunk); color: var(--muted); }
.pill.pos { background: var(--pos-tint); color: var(--pos); }
.pill.neg { background: var(--neg-tint); color: var(--neg); }
.pill.brass { background: var(--brass-tint); color: var(--brass); }
.ccy { font-weight: 700; color: var(--brass); font-size: .78em; margin-inline-start: 4px; }

/* ---------- Dashboard: the balance rail is the signature element ---------- */
.rail {
  display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; margin-bottom: 22px;
}
.rail > div { padding: 20px 22px; border-inline-end: 1px solid var(--line); min-width: 0; }
.rail > div:last-child { border-inline-end: 0; background: var(--olive); color: #EEF1E8; }
@media (prefers-color-scheme: dark) { .rail > div:last-child { background: var(--olive-tint); color: var(--ink); } }
.rail .code { font-weight: 800; font-size: .95rem; color: var(--brass); letter-spacing: .04em; }
.rail > div:last-child .code { color: #E6C770; }
.rail .big { font-size: clamp(1.4rem, 2.4vw, 2.05rem); font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; font-variant-numeric: tabular-nums; direction: ltr; text-align: start; overflow-wrap: anywhere; }
[dir="rtl"] .rail .big { text-align: end; }
.rail .note { font-size: .8rem; opacity: .8; margin-top: 4px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; }
.stats > div { padding: 16px 18px; border-inline-end: 1px solid var(--line); }
.stats > div:last-child { border-inline-end: 0; }
.stats .k { font-size: .82rem; color: var(--muted); font-weight: 600; }
.stats .v { font-size: 1.3rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; margin-top: 20px; align-items: start; }

.statement { width: 100%; }
.statement td { border: 0; padding: 7px 0; }
.statement td:last-child { text-align: end; font-variant-numeric: tabular-nums; direction: ltr; }
.statement tr.total td { border-top: 2px solid var(--ink); font-weight: 750; padding-top: 10px; font-size: 1.05rem; }
.statement tr.minor td { color: var(--muted); font-size: .86rem; padding-inline-start: 14px; }

.rates-line { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: .86rem; color: var(--muted); }
.rates-line strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.warn { background: var(--brass-tint); color: var(--ink); border: 1px solid color-mix(in srgb, var(--brass) 35%, var(--line)); padding: 10px 14px; border-radius: var(--r-ctl); font-size: .88rem; margin-bottom: 16px; }

/* ---------- Exchange preview ---------- */
.preview { background: var(--sunk); border-radius: var(--r-ctl); padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; }
.preview .rate { font-weight: 700; font-size: 1.02rem; }
.preview .exp { color: var(--muted); }
.preview .diff { font-weight: 600; }

/* ---------- Dialog ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 24px));
  background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgba(10, 20, 10, .28);
}
dialog::backdrop { background: rgba(14, 22, 16, .45); }
dialog[open] { animation: pop .16s ease-out; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
dialog > form, dialog > .dlg { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
dialog header { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
dialog header h2 { flex: 1; }
dialog .dbody { padding: 18px 20px; overflow-y: auto; }
dialog footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
dialog.wide { width: min(900px, calc(100vw - 24px)); }

.diff-table td { font-size: .82rem; }
.diff-table .was { color: var(--neg); text-decoration: line-through; }
.diff-table .now { color: var(--pos); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; inset-block-end: 18px; inset-inline-end: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--ink); color: var(--paper); padding: 11px 16px; border-radius: var(--r-ctl);
  font-size: .9rem; max-width: 380px; box-shadow: 0 8px 22px rgba(0, 0, 0, .22); animation: pop .18s ease-out;
}
.toast.error { background: var(--neg); color: #fff; }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth .art {
  background: var(--olive); color: #EEF1E8; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.auth .art .ticker { font-variant-numeric: tabular-nums; direction: ltr; font-size: clamp(2rem, 4vw, 3.4rem); font-weight: 750; letter-spacing: -0.02em; line-height: 1.15; }
.auth .art .ticker span { color: #E6C770; }
.auth .art p { max-width: 38ch; opacity: .85; }
.auth .form { display: flex; align-items: center; justify-content: center; padding: 32px; }
.auth .card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; }
.auth .card img { height: 42px; align-self: flex-start; }
.flash { padding: 10px 14px; border-radius: var(--r-ctl); font-size: .9rem; }
.flash.error { background: var(--neg-tint); color: var(--neg); }
.flash.ok { background: var(--pos-tint); color: var(--pos); }
.lang-switch { display: flex; gap: 6px; }
.lang-switch form { margin: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .rail { grid-template-columns: repeat(3, 1fr); }
  .rail > div:last-child { grid-column: auto; }
  .rail > div:nth-child(3) { border-inline-end: 0; }
  .cols { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed; inset-block: 0; inset-inline-start: 0; width: 270px; z-index: 50; height: 100%;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 40px rgba(0,0,0,.25);
  }
  [dir="rtl"] .side { transform: translateX(100%); }
  body.nav-open .side { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .menu-btn { display: inline-flex; }
  .top { padding: 10px 14px; flex-wrap: wrap; }
  .content { padding: 18px 14px 50px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats > div:nth-child(2) { border-inline-end: 0; }
  .stats > div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .g2, .g3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .auth { grid-template-columns: 1fr; }
  .auth .art { padding: 28px; min-height: 220px; }
}
@media (max-width: 560px) {
  .rail { grid-template-columns: 1fr; }
  .rail > div { border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .top .hide-sm { display: none; }
  /* Tables become stacked cards on phones */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.stack td { border: 0; padding: 4px 16px; display: flex; justify-content: space-between; gap: 12px; text-align: end; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 600; text-align: start; }
  table.stack td.actions { justify-content: flex-end; }
  table.stack td.actions::before { content: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print {
  .side, .top, .btn, .filters, .pager { display: none !important; }
  .shell { display: block; }
}
.mb { margin-bottom: 12px; }
.mt { margin-top: 20px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--ink); }
.grow { flex: 1; }
.explain { font-size: .86rem; color: var(--muted); line-height: 1.55; }
.explain p { margin: 0 0 8px; }
.branding-preview { min-height: 110px; display: flex; align-items: center; justify-content: center; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-ctl); }
.branding-preview img { max-width: 100%; max-height: 90px; object-fit: contain; }
.branding-preview img.favicon-preview { width: 48px; height: 48px; }
.side .brand img { max-width: 100%; object-fit: contain; }
.auth .card img { max-width: 100%; object-fit: contain; }
@media (prefers-color-scheme: dark) { .side .brand img.logo-light { display: none; } }
@media (prefers-color-scheme: light) { .side .brand img.logo-dark { display: none; } }
