/* POS Approvals portal.
   No framework and no CDN - the CSP in index.js is 'self' only, deliberately. */

:root {
  --bg: #0f1720;
  --panel: #16212d;
  --panel-2: #1d2b3a;
  --line: #2b3b4d;
  --ink: #e8eef5;
  --ink-dim: #93a4b8;
  --accent: #2f81f7;
  --ok: #2ea043;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.55 "Segoe UI", Tahoma, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.hidden { display: none !important; }
.grow { flex: 1; }
.sub { color: var(--ink-dim); font-size: 13px; margin: 4px 0 12px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 24px 0 8px; font-weight: 600; }

/* ---------------------------------------------------------------- sign in */

.signin {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  width: 340px;
}

.card label { display: block; margin: 14px 0 0; font-size: 13px; color: var(--ink-dim); }
.card input { width: 100%; margin-top: 5px; }

input, select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
}

input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  padding: 8px 14px;
}

button:hover { background: #24364a; }

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.primary:hover { background: #1f6feb; }

.card .primary { width: 100%; margin-top: 20px; padding: 10px; }

.link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 4px 6px;
}
.link:hover { background: none; text-decoration: underline; }

.danger { color: var(--bad); }

.error { color: var(--bad); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* ----------------------------------------------------------------- layout */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { display: flex; flex-direction: column; line-height: 1.2; }
.brand .sub { margin: 0; font-size: 11px; }

.tabs { display: flex; gap: 2px; flex-wrap: wrap; }

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--ink-dim);
  padding: 8px 12px;
}
.tab:hover { background: none; color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }

.who { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-dim); }

.tabpanel { padding: 18px 22px 60px; max-width: 1500px; }

.filters {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--ink-dim); gap: 4px; }

.row { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.row input { min-width: 260px; flex: 1; }

/* ------------------------------------------------------------------ table */

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13px;
}

.table th, .table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.table th {
  background: var(--panel-2);
  font-weight: 600;
  font-size: 12px;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: .03em;
  white-space: nowrap;
}

.table tbody tr:hover { background: #1a2836; }
.table tr:last-child td { border-bottom: none; }
.table td input, .table td select { padding: 5px 7px; font-size: 13px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.clickable { cursor: pointer; }

.wrap { overflow-x: auto; }

/* Codes are read aloud and typed at a till - monospace, spaced, unmistakable. */
.code {
  font-family: Consolas, "Courier New", monospace;
  letter-spacing: .08em;
  font-size: 13px;
  white-space: nowrap;
}

.muted { color: var(--ink-dim); }
.empty { padding: 30px; text-align: center; color: var(--ink-dim); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }

/* ------------------------------------------------------------------ pills */

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
}
.pill-PENDING   { background: #3d2f00; color: #e3b341; }
.pill-APPROVED  { background: #10331b; color: #56d364; }
.pill-REDEEMED  { background: #0d2d4a; color: #58a6ff; }
.pill-REJECTED,
.pill-EXPIRED,
.pill-CANCELLED { background: #3d1418; color: #ff7b72; }
.pill-yes { background: #10331b; color: #56d364; }
.pill-no  { background: #3d1418; color: #ff7b72; }

.summary {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--ink-dim);
}

.key-shown {
  font-family: Consolas, monospace;
  font-size: 13px;
  background: #10331b;
  border: 1px solid var(--ok);
  color: #7ee787;
  padding: 12px;
  border-radius: var(--radius);
  margin-top: 14px;
  word-break: break-all;
}
.key-shown:empty { display: none; }

/* ----------------------------------------------------------------- viewer */

.viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .72);
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow: auto;
}

.viewer-inner {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  max-width: 900px;
  width: 100%;
  position: relative;
}

.close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  color: var(--ink-dim);
  padding: 4px 10px;
}
.close:hover { color: var(--ink); background: none; }

.kv { display: grid; grid-template-columns: 190px 1fr; gap: 6px 14px; font-size: 13px; margin: 14px 0; }
.kv dt { color: var(--ink-dim); }
.kv dd { margin: 0; }

.timeline { list-style: none; padding: 0; margin: 10px 0; }
.timeline li {
  border-left: 2px solid var(--line);
  padding: 6px 0 12px 14px;
  margin-left: 6px;
  font-size: 13px;
  position: relative;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: -6px; top: 11px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--line);
}
.timeline li.done::before { background: var(--ok); }
.timeline li.rejected::before { background: var(--bad); }
.timeline li.current::before { background: var(--warn); }

/* ------------------------------------------------ manager screens (Arabic) */

/*
  The manager screens are right-to-left; the administrator ones stay left-to-right.
  Branch managers work in Arabic, head office reads English, and one language for
  both would be wrong for somebody. The English is kept alongside as a smaller
  second line rather than hidden behind a toggle nobody would find.
*/
.tab-en { display: block; font-size: 10px; opacity: .65; letter-spacing: .02em; }

/* A run of Latin text inside an Arabic sentence. */
.ltr { unicode-bidi: isolate; direction: ltr; display: inline-block; }

/* Numbers read aloud against a POS screen: Latin digits, isolated so the
   surrounding Arabic cannot reorder them. */
.num-ltr { unicode-bidi: isolate; direction: ltr; font-variant-numeric: tabular-nums; }

[dir="rtl"] .filters label,
[dir="rtl"] .kv { text-align: right; }

[dir="rtl"] .table th,
[dir="rtl"] .table td { text-align: right; }

.req-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.req-card:hover { border-color: var(--accent); }

.req-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

/* The money is the headline, never the percentage - "18%" and "774 EGP" prompt
   very different amounts of thought. */
.req-money { font-size: 24px; font-weight: 700; color: var(--ink); }
.req-money small { font-size: 13px; font-weight: 400; color: var(--ink-dim); margin-inline-start: 6px; }
.req-meta { font-size: 13px; color: var(--ink-dim); line-height: 1.7; }
.req-reason { font-size: 13px; color: var(--ink); margin-top: 6px; }

.money-line {
  background: var(--brandSoft, #10331b);
  border: 1px solid var(--ok);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 8px 0 16px;
}
.money-line .big { font-size: 22px; font-weight: 700; color: #7ee787; }
.money-line.warn { background: #3d2f00; border-color: var(--warn); }
.money-line.warn .big { color: #e3b341; }

.code-ready {
  background: #10331b;
  border: 1px solid var(--ok);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 10px;
  text-align: center;
}
.code-ready .digits {
  font-family: Consolas, "Courier New", monospace;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .14em;
  color: #7ee787;
  direction: ltr;
  unicode-bidi: isolate;
}

.group-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-dim);
  margin: 20px 0 8px;
  font-weight: 700;
}

/* Attached photographs and documents. */
.thumbs { display: flex; flex-wrap: wrap; gap: var(--gap, 12px); margin: 12px 0; }

.thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 140px;
  text-decoration: none;
  color: var(--ink-dim);
  font-size: 12px;
}

.thumb img {
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
}

.thumb span {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.thumb:hover { color: var(--ink); }
.thumb:hover img { border-color: var(--accent); }

.doc-icon {
  width: 140px;
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: .06em;
  color: var(--ink-dim);
}

pre.json {
  background: #0b1119;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  font-size: 12px;
  overflow: auto;
  max-height: 320px;
  color: #b9c6d4;
}

@media (max-width: 820px) {
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: 8px; }
  .tabpanel { padding: 14px 12px 50px; }
}
