@font-face { font-family: "El Messiri"; src: url(fonts/ElMessiri.ttf) format("truetype"); font-weight: 400 700; font-display: swap; }
@font-face { font-family: "Plex Arabic"; src: url(fonts/IBMPlexSansArabic-Regular.ttf) format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Arabic"; src: url(fonts/IBMPlexSansArabic-Medium.ttf) format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex Arabic"; src: url(fonts/IBMPlexSansArabic-Bold.ttf) format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --bg: #EEF2EC;          /* sage mist */
  --surface: #FBFCFA;
  --surface-2: #E3EAE2;
  --ink: #18261E;
  --muted: #5E6F64;
  --line: #CBD6CB;
  --basil: #2F5D46;       /* sell */
  --basil-ink: #F2F7F2;
  --oud: #A86A24;         /* buy */
  --oud-ink: #FFF7EC;
  --gold: #D9B26F;
  --danger: #B3413A;
  --focus: #3C7FB0;
  --radius-sm: 8px;
  --radius: 14px;
  --font-display: "El Messiri", "Plex Arabic", Georgia, serif;
  --font-body: "Plex Arabic", "Segoe UI", Tahoma, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0F1813;
  --surface: #16221B;
  --surface-2: #1E2C24;
  --ink: #E5EDE6;
  --muted: #95A89B;
  --line: #2C3D33;
  --basil: #3F7A5C;
  --basil-ink: #F2F7F2;
  --oud: #B97A30;
  --oud-ink: #FFF7EC;
  --gold: #E3C17F;
  --danger: #E0736A;
  --focus: #7FB6DD;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.6 var(--font-body);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.25; margin: 0 0 .6em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; margin-top: 1.4em; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); margin-top: 0; }
.num, .money { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 44px; padding: 0 1.1em; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer; font-weight: 500; text-decoration: none;
  transition: background-color .15s, border-color .15s;
}
.btn-primary { background: var(--basil); color: var(--basil-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-text { background: none; color: var(--basil); padding: 0 .4em; }
:root[data-theme="dark"] .btn-text { color: #8CCAA5; }
.btn-danger { background: none; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); min-height: 36px; padding: 0 .8em; }
.btn-wide { width: 100%; }

.field, .login-card input, .login-card select {
  min-height: 44px; padding: 0 .8em; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); width: 100%;
}
.field:focus, .login-card input:focus, .login-card select:focus { border-color: var(--basil); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--basil) 25%, transparent); }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); cursor: pointer; padding: 0;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .glyph { font-weight: 700; font-size: .95rem; line-height: 1; }
.currency-btn { width: auto; min-width: 44px; padding: 0 .8em; border-radius: 22px; background: var(--gold); border-color: transparent; color: #2A1D08; }
.currency-btn:hover { background: var(--gold); filter: brightness(1.05); }

.form-error { color: var(--danger); min-height: 1.4em; margin: .4em 0; font-size: .92rem; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(400px, 100%); background: var(--surface); padding: 40px 32px 24px;
  border-radius: 200px 200px var(--radius) var(--radius);
  border: 1px solid var(--line); text-align: center;
}
.login-logo { width: 88px; height: 88px; object-fit: contain; }
.login-card .brand-title { font-size: 2rem; margin: .2em 0 0; }
.login-sub { color: var(--muted); margin: 0 0 1.4em; }
.login-card form { display: grid; gap: 12px; text-align: start; }
.login-card label { display: grid; gap: 4px; font-size: .92rem; color: var(--muted); }
.login-tools { display: flex; justify-content: center; gap: 10px; margin-top: 18px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px clamp(12px, 3vw, 32px); background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; margin-inline-end: auto; }
.brand-logo { width: 44px; height: 44px; object-fit: contain; }
.brand-title { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; letter-spacing: .01em; }
.brand-sub { font-size: .85rem; color: var(--muted); line-height: 1.2; }
.tools { display: flex; gap: 8px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.tab { border: 0; background: none; padding: 8px 16px; border-radius: 9px; cursor: pointer; font-weight: 500; color: var(--muted); }
.tab.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(20, 40, 30, .12); }

main { max-width: 1120px; margin: 0 auto; padding: 24px clamp(12px, 3vw, 32px) 64px; }

/* ---------- desk ---------- */
.desk-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.hello { font-family: var(--font-display); font-size: 1.5rem; margin: 0; }
.clock { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; }

.portals { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(14px, 3vw, 32px); }
.portal {
  position: relative; border: 0; cursor: pointer; overflow: hidden;
  min-height: clamp(300px, 54vh, 470px);
  border-radius: 999px 999px 22px 22px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding: 28px 20px 34px; gap: 4px;
  transition: transform .18s ease, filter .18s ease;
}
.portal::before { /* inner arch outline, echoing the logo */
  content: ""; position: absolute; inset: 14px 14px 0;
  border: 1.5px solid currentColor; border-bottom: 0; opacity: .35;
  border-radius: 999px 999px 0 0;
  pointer-events: none;
}
.portal-sell { background: var(--basil); color: var(--basil-ink); }
.portal-buy { background: var(--oud); color: var(--oud-ink); }
.portal:hover { filter: brightness(1.07); transform: translateY(-3px); }
.portal:active { transform: translateY(0); }
.portal-icon svg { width: 72px; height: 72px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.portal-word { font-family: var(--font-display); font-size: clamp(2.4rem, 6vw, 3.6rem); font-weight: 700; line-height: 1.1; }
.portal-hint { font-size: .95rem; opacity: .85; }

.recent { margin-top: 36px; }
.recent-list { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.recent-list li { display: grid; grid-template-columns: auto 1fr auto auto; gap: 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.recent-list li:first-child { border-top: 0; }
.recent-list .empty { display: block; color: var(--muted); text-align: center; padding: 22px; }
.kind { font-size: .8rem; font-weight: 700; padding: 2px 10px; border-radius: 99px; }
.kind-sell { background: color-mix(in srgb, var(--basil) 16%, transparent); color: var(--basil); }
.kind-buy { background: color-mix(in srgb, var(--oud) 18%, transparent); color: var(--oud); }
:root[data-theme="dark"] .kind-sell { color: #8CCAA5; }
:root[data-theme="dark"] .kind-buy { color: #E8B26B; }
.recent-items { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-time { color: var(--muted); font-size: .88rem; font-variant-numeric: tabular-nums; }

/* ---------- entry dialog ---------- */
.entry {
  width: min(760px, calc(100% - 20px)); max-height: calc(100% - 20px); padding: 0; border: 0;
  border-radius: 180px 180px var(--radius) var(--radius) / 60px 60px var(--radius) var(--radius);
  background: var(--surface); color: var(--ink); overflow: hidden;
}
.entry::backdrop { background: rgba(10, 20, 15, .55); }
.entry[open] { animation: rise .2s ease-out; }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
.entry form { display: flex; flex-direction: column; max-height: calc(100vh - 20px); }
.entry-head { padding: 30px 28px 16px; text-align: center; color: var(--basil-ink); background: var(--basil); }
.entry.is-buy .entry-head { background: var(--oud); color: var(--oud-ink); }
.entry-head h2 { font-size: 1.8rem; margin: 0; }
.entry-meta { display: flex; justify-content: center; align-items: center; gap: 12px; flex-wrap: wrap; font-size: .92rem; opacity: .95; font-variant-numeric: tabular-nums; }
.cur-badge { background: var(--gold); color: #2A1D08; font-weight: 700; padding: 2px 12px; border-radius: 99px; }
.entry-body { padding: 18px 24px; overflow-y: auto; }
.lines-head, .line { display: grid; grid-template-columns: minmax(0, 2.6fr) minmax(64px, .8fr) minmax(90px, 1.2fr) minmax(90px, 1.2fr) 40px; gap: 8px; align-items: center; }
.lines-head { font-size: .85rem; color: var(--muted); padding-bottom: 6px; }
.line { margin-bottom: 8px; }
.line .sub { text-align: end; font-weight: 500; padding-inline-end: 4px; }
.line .rm { width: 40px; height: 40px; border-radius: 50%; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1.3rem; }
.line .rm:hover { background: var(--surface-2); color: var(--danger); }
.add-line { margin-top: 2px; }
.note { display: grid; gap: 4px; margin-top: 14px; font-size: .9rem; color: var(--muted); }
.entry-foot { padding: 14px 24px 20px; border-top: 1px solid var(--line); background: var(--surface-2); }
.grand { display: flex; justify-content: space-between; align-items: baseline; font-size: 1.1rem; }
.grand strong { font-family: var(--font-display); font-size: 2rem; font-variant-numeric: tabular-nums; }
.entry-actions { display: flex; gap: 10px; justify-content: flex-end; }
.entry.is-buy .btn-primary { background: var(--oud); color: var(--oud-ink); }

/* ---------- history ---------- */
.hist-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 20px; }
.hist-controls > select { width: auto; min-width: 180px; }
.seg { display: inline-flex; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg button { border: 0; background: none; padding: 8px 16px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg button.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(20, 40, 30, .12); }
.date-search { display: flex; gap: 6px; }
.date-search .field { width: auto; }

.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 24px; }
.total-cell { background: var(--surface); padding: 16px 20px; }
.total-cell .lbl { color: var(--muted); font-size: .9rem; }
.total-cell .val { font-family: var(--font-display); font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.total-cell.sell .val { color: var(--basil); }
.total-cell.buy .val { color: var(--oud); }
:root[data-theme="dark"] .total-cell.sell .val { color: #8CCAA5; }
:root[data-theme="dark"] .total-cell.buy .val { color: #E8B26B; }
.neg { color: var(--danger) !important; }

.hist-title { margin-top: 8px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 14px; text-align: start; border-top: 1px solid var(--line); white-space: nowrap; }
.table thead th { border-top: 0; font-size: .85rem; color: var(--muted); font-weight: 500; background: var(--surface-2); }
.table td.money { text-align: end; }
.table th.money, .table th.num, .table td.num { text-align: end; }
.table tbody tr.period { cursor: pointer; }
.table tbody tr.period:hover { background: var(--surface-2); }
.table tbody tr.period.is-open { background: var(--surface-2); }
.table tr.detail td { padding: 0 14px 14px; white-space: normal; background: var(--surface-2); }
.empty-row td { text-align: center; color: var(--muted); padding: 28px; }

.tx-list { display: grid; gap: 10px; }
.tx { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; border-inline-start: 4px solid var(--basil); }
.tx.buy { border-inline-start-color: var(--oud); }
.tx-top { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.tx-top .when { color: var(--muted); font-size: .88rem; font-variant-numeric: tabular-nums; }
.tx-top .by { color: var(--muted); font-size: .88rem; }
.tx-top .sum { margin-inline-start: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.tx-items { margin: 8px 0 0; padding: 0; list-style: none; font-size: .93rem; }
.tx-items li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.tx-items .q { color: var(--muted); }
.tx-note { font-size: .88rem; color: var(--muted); margin: 6px 0 0; }
.tx-actions { display: flex; justify-content: flex-end; margin-top: 8px; }

.day-detail { margin-top: 28px; }
.day-detail .totals { margin-bottom: 16px; }

/* ---------- rate chip ---------- */
.rate-chip { display: inline-flex; align-items: center; min-height: 36px; direction: ltr; unicode-bidi: isolate; font-size: .85rem; color: var(--muted); background: var(--surface-2); border-radius: 99px; padding: 4px 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- reports ---------- */
.report-controls .ctl { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.report-controls .ctl .field, .report-controls > select { width: auto; }
.report-empty { padding: 40px 0; text-align: center; }
.report { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.report-head { display: flex; gap: 16px; align-items: center; border-bottom: 2px solid var(--line); padding-bottom: 16px; margin-bottom: 20px; }
.report-head img { width: 64px; height: 64px; object-fit: contain; }
.report-head h2 { margin: 0; font-size: 1.5rem; }
.report-head .meta { color: var(--muted); font-size: .9rem; }
.report-head .meta strong { color: var(--ink); }
.report-actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.report h3 { margin: 24px 0 10px; }
.report .table-wrap { border-radius: var(--radius-sm); }
.report .table td.items { white-space: normal; min-width: 220px; font-size: .9rem; }
.report .totals { grid-template-columns: repeat(4, 1fr); margin-bottom: 8px; }
.report-foot { color: var(--muted); font-size: .85rem; margin-top: 20px; }
.kind-cell.sell { color: var(--basil); font-weight: 600; }
.kind-cell.buy { color: var(--oud); font-weight: 600; }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.panel-wide { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form .field { width: 140px; }
.rate-pre { font-weight: 500; }
.logo-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.logo-preview { width: 72px; height: 72px; object-fit: contain; background: var(--surface-2); border-radius: 12px; padding: 6px; }
.file-btn { cursor: pointer; }
.stack { display: grid; gap: 10px; }
.stack .pair { display: grid; gap: 6px; padding-bottom: 10px; border-bottom: 1px dashed var(--line); }
.user-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.role-tag { font-size: .8rem; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); }
.role-tag.master { background: var(--gold); color: #2A1D08; }
.role-tag.supervisor { background: color-mix(in srgb, var(--focus) 22%, var(--surface)); }
.table select.field { min-height: 36px; padding-block: 4px; width: auto; min-width: 150px; }
.user-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- toast ---------- */
.toast {
  position: fixed; inset-inline: 0; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); margin: 0 auto; width: max-content; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 99px; font-weight: 500;
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: none; }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .tabs { order: 3; width: 100%; justify-content: stretch; }
  .tab { flex: 1; }
  .brand-title { font-size: 1.1rem; }
  .portals { grid-template-columns: 1fr 1fr; }
  .portal { min-height: 250px; padding-bottom: 24px; }
  .portal-icon svg { width: 52px; height: 52px; }
  .portal-hint { display: none; }
  .lines-head { display: none; }
  .line { grid-template-columns: 1fr 1fr 40px; grid-template-areas: "name name rm" "qty price price" "sub sub sub"; padding: 10px 0; border-bottom: 1px dashed var(--line); }
  .line .n { grid-area: name; } .line .q { grid-area: qty; } .line .p { grid-area: price; } .line .sub { grid-area: sub; } .line .rm { grid-area: rm; }
  .totals, .report .totals { grid-template-columns: 1fr; }
  .rate-chip { display: none; }
  .report { padding: 16px; }
  .report-head { flex-wrap: wrap; }
  .recent-list li { grid-template-columns: auto 1fr auto; }
  .recent-time { display: none; }
  .entry { border-radius: 90px 90px var(--radius) var(--radius) / 40px 40px var(--radius) var(--radius); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* print: history only */
@media print {
  .topbar, .hist-controls, .tx-actions, .toast, .report-actions { display: none !important; }
  body { background: #fff; color: #000; }
  .report { border: 0; padding: 0; }
  .table-wrap { overflow: visible; }
  .table th, .table td { white-space: normal; }
  h3, .report-head { break-after: avoid; }
  tr { break-inside: avoid; }
}

/* ---------- install as app ---------- */
.install-btn { margin-top: 12px; }
.install-dlg {
  width: min(420px, calc(100% - 24px)); border: 0; border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--ink);
}
.install-dlg::backdrop { background: rgba(10, 20, 15, .55); }
.install-dlg form { padding: 24px; text-align: center; }
.install-dlg h2 { font-family: var(--font-display); margin: 8px 0 12px; font-size: 1.4rem; }
.install-icon { width: 72px; height: 72px; border-radius: 18px; }
.install-dlg ol { text-align: start; margin: 0 0 12px; padding-inline-start: 1.4em; line-height: 1.8; }
.install-note { color: var(--muted); font-size: .88rem; margin: 0 0 14px; }
.install-note:empty { display: none; }
@media (display-mode: standalone) { .js-install { display: none !important; } }
