/*
 * Transfers portal — base styles. RTL, mobile first (375px), 44px touch targets,
 * light/dark via prefers-color-scheme. Served as /app.css (CSP style-src 'self':
 * no inline styles anywhere; screens style themselves with classes).
 *
 * Shared building blocks for wave-2 screens: .panel .card .stack .row .chip(--red|--orange|--green|--gray)
 * .btn(--primary|--ghost|--danger|--small|--block) .field .input .num .table-wrap .table
 * .sticky-actions .notice(--warn|--error|--info) .kv .empty .muted .small .sr-only
 */

:root {
  --brand: #F83018;
  --accent: #C22813;
  --accent-hover: #A8200F;
  --accent-text: #FFFFFF;
  --text: #101010;
  --muted: #5F6E70;          /* #6E7E80 darkened a little for 4.5:1 on white */
  --secondary: #6E7E80;
  --bg: #F6F6F4;
  --surface: #FFFFFF;
  --surface-2: #F0F0EE;
  --border: #D9DCDC;
  --focus: #1A5FD0;
  --red: #C22813;
  --red-bg: #FDE8E5;
  --orange: #9A5200;
  --orange-bg: #FFF1DC;
  --green: #1E6B34;
  --green-bg: #E3F4E7;
  --gray-bg: #ECEEEE;
  --shadow: 0 1px 2px rgba(16, 16, 16, 0.06), 0 4px 16px rgba(16, 16, 16, 0.06);
  --radius: 10px;
  --radius-sm: 6px;
  --gutter: 16px;
  --touch: 44px;
  --topbar-h: 56px;
  --nav-w: 232px;
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Hebrew", "Arial Hebrew", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #FF5A43;
    --accent: #D83A22;
    --accent-hover: #EE4A30;
    --accent-text: #FFFFFF;
    --text: #EDEDEB;
    --muted: #A3B0B2;
    --secondary: #8E9C9E;
    --bg: #121212;
    --surface: #1C1C1C;
    --surface-2: #262626;
    --border: #3A3D3E;
    --focus: #7AA7FF;
    --red: #FF8A78;
    --red-bg: #3A1813;
    --orange: #FFB861;
    --orange-bg: #3A2A12;
    --green: #7FD597;
    --green-bg: #15301D;
    --gray-bg: #2A2C2D;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;            /* >= 16px keeps iOS from zooming into inputs */
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 12px; }
p { margin: 0 0 12px; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; }
code { font-family: var(--mono); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; inset-inline-start: 8px; top: -60px; z-index: 100;
  background: var(--surface); color: var(--text); padding: 10px 14px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.skip-link:focus { top: 8px; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.num, [dir="ltr"].num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  min-height: var(--topbar-h);
  padding: 6px var(--gutter);
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--touch);
  color: var(--text); text-decoration: none; font-weight: 700; font-size: 17px;
}
.brand:hover { color: var(--text); }
.brand-icon { width: 28px; height: 28px; border-radius: 6px; }
.topbar-spacer { flex: 1; }
.user-chip {
  max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 14px; color: var(--muted);
}
.net-status {
  font-size: 13px; padding: 4px 10px; border-radius: 999px;
  background: var(--orange-bg); color: var(--orange); font-weight: 600;
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--touch); height: var(--touch);
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text);
  cursor: pointer; padding: 0;
}
.icon-btn:hover { background: var(--surface-2); }
.menu-bars, .menu-bars::before, .menu-bars::after {
  display: block; width: 20px; height: 2px; border-radius: 1px; background: currentColor; position: relative;
}
.menu-bars::before, .menu-bars::after { content: ""; position: absolute; inset-inline-start: 0; }
.menu-bars::before { top: -6px; }
.menu-bars::after { top: 6px; }

/* ---------------------------------------------------------------- layout + nav */
.layout { display: block; }

.main {
  min-width: 0;
  padding: var(--gutter);
  padding-bottom: calc(var(--gutter) + env(safe-area-inset-bottom));
  max-width: 1100px;
  margin: 0 auto;
}
.main:focus { outline: none; }

.nav {
  position: fixed; z-index: 40; top: 0; bottom: 0; inset-inline-start: 0;
  width: min(84vw, 300px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  padding: max(12px, env(safe-area-inset-top)) 8px max(12px, env(safe-area-inset-bottom));
  overflow-y: auto;
  transform: translateX(100%);          /* RTL: the drawer slides in from the right */
  transition: transform 0.2s ease;
  visibility: hidden;
}
.nav.nav--open { transform: none; visibility: visible; box-shadow: var(--shadow); }
.nav-backdrop {
  position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, 0.35);
}
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-link {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: var(--touch); padding: 8px 12px; margin: 2px 0;
  border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.is-current { background: var(--red-bg); color: var(--accent); font-weight: 700; }
.nav-footer { margin-top: auto; padding: 12px 4px 0; border-top: 1px solid var(--border); }

.badge {
  min-width: 22px; height: 22px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; background: var(--accent); color: var(--accent-text);
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  .nav { transition: none; }
}

@media (min-width: 960px) {
  .menu-btn { display: none !important; }
  .nav-backdrop { display: none !important; }
  .layout { display: flex; align-items: flex-start; }
  .nav {
    position: sticky; top: var(--topbar-h); z-index: 1;
    height: calc(100vh - var(--topbar-h));
    width: var(--nav-w); flex: 0 0 var(--nav-w);
    transform: none; visibility: visible; transition: none;
    padding: 12px 8px;
  }
  .nav.nav--open { box-shadow: none; }
  .main { flex: 1; padding: 24px; margin: 0; }
}

/* ---------------------------------------------------------------- screens + panels */
.screen-title { font-size: 22px; font-weight: 700; }
.boot-msg, .noscript { color: var(--muted); padding: 24px 0; }

.panel, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 16px;
}
.panel { scroll-margin-top: calc(var(--topbar-h) + 8px); }
.panel-title { font-size: 17px; font-weight: 700; margin-bottom: 12px; }

.empty { padding: 32px 0; text-align: center; }
.empty .btn { margin-top: 8px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.notice {
  padding: 10px 14px; border-radius: var(--radius-sm); margin: 0 0 12px;
  background: var(--gray-bg); color: var(--text);
}
.notice--warn { background: var(--orange-bg); color: var(--orange); }
.notice--error { background: var(--red-bg); color: var(--red); }
.notice--info { background: var(--gray-bg); }

/* ---------------------------------------------------------------- chips (warnings) */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; line-height: 1.6;
  background: var(--gray-bg); color: var(--text);
  white-space: nowrap;
}
.chip--red { background: var(--red-bg); color: var(--red); }
.chip--orange { background: var(--orange-bg); color: var(--orange); }
.chip--green { background: var(--green-bg); color: var(--green); }
.chip--gray { background: var(--gray-bg); color: var(--muted); }

/* ---------------------------------------------------------------- forms */
.form { display: block; }
.form > * + * { margin-top: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-weight: 600; font-size: 15px; }
.field-hint { margin: 0; font-size: 13px; color: var(--muted); }

.input, select.input, textarea.input {
  width: 100%;
  min-height: var(--touch);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
textarea.input { min-height: 88px; resize: vertical; }
.input:focus { border-color: var(--focus); outline: 2px solid var(--focus); outline-offset: 0; }
.input[dir="ltr"] { text-align: left; }
.input--code { font-family: var(--mono); font-size: 22px; letter-spacing: 0.2em; text-align: center !important; }
.input[aria-invalid="true"] { border-color: var(--red); }

.check {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--touch); cursor: pointer;
}
.checkbox { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex: 0 0 auto; }

.form-error {
  margin: 0; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--red-bg); color: var(--red); font-weight: 600;
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--touch); min-width: var(--touch);
  padding: 10px 18px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; font-size: 16px; line-height: 1.2;
  text-decoration: none; cursor: pointer;
  background: var(--surface-2); color: var(--text);
  touch-action: manipulation;
}
.btn:hover { filter: brightness(0.96); color: inherit; }
.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--primary:hover { background: var(--accent-hover); color: var(--accent-text); filter: none; }
.btn--danger { background: var(--red); color: #FFFFFF; }
.btn--ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: var(--surface-2); filter: none; }
.btn--small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn--block { display: flex; width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; filter: none; }
.btn.is-busy { cursor: progress; }
.btn.is-busy::after {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-inline-end-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn.is-busy::after { animation: none; } }

.sticky-actions {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 8px;
  margin: 16px calc(-1 * var(--gutter)) 0;
  padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}

/* ---------------------------------------------------------------- tables */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: start; vertical-align: top; }
.table th { font-weight: 600; color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ---------------------------------------------------------------- auth screens */
.screen--auth { display: flex; justify-content: center; padding-top: 8px; }
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px 20px; box-shadow: var(--shadow);
}
.auth-logo { display: block; width: 56px; height: 56px; border-radius: 12px; margin: 0 0 16px; }
.auth-card > .form + * { margin-top: 16px; }
.auth-card > :last-child { margin-bottom: 0; }

/* ---------------------------------------------------------------- settings bits */
.codes {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px;
  margin: 0; padding: 12px 32px; background: var(--surface-2); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 16px;
}
.secret {
  display: inline-block; padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: 16px; letter-spacing: 0.06em; overflow-wrap: anywhere;
}
.steps { margin: 0; padding-inline-start: 22px; }
.steps > li + li { margin-top: 10px; }

/* ---------------------------------------------------------------- toasts */
.toasts {
  position: fixed; z-index: 60;
  inset-inline: var(--gutter); bottom: calc(var(--gutter) + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; align-items: stretch;
  pointer-events: none;
}
.toasts--alert { bottom: auto; top: calc(var(--topbar-h) + 8px + env(safe-area-inset-top)); }
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 8px;
  padding-block: 6px; padding-inline: 14px 4px;
  border-radius: var(--radius); box-shadow: var(--shadow);
  background: var(--text); color: var(--bg);
  font-weight: 500;
}
.toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-close {
  flex: 0 0 auto; width: var(--touch); height: var(--touch);
  border: 0; background: transparent; color: inherit; font-size: 22px; cursor: pointer; border-radius: var(--radius-sm);
}
.toast--success { background: var(--green); color: #FFFFFF; }
.toast--warn { background: var(--orange-bg); color: var(--orange); border: 1px solid currentColor; }
.toast--error { background: var(--red); color: #FFFFFF; }
@media (prefers-color-scheme: dark) {
  .toast--success { background: var(--green-bg); color: var(--green); border: 1px solid currentColor; }
  .toast--error { background: var(--red-bg); color: var(--red); border: 1px solid currentColor; }
}
@media (min-width: 640px) {
  .toasts { inset-inline: auto var(--gutter); width: 380px; }
}

/* ---------------------------------------------------------------- dialogs */
.dialog {
  width: min(440px, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100vh - 2 * var(--gutter));
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-body { padding: 20px; }
.dialog-body > * + * { margin-top: 12px; }
.dialog-title { font-size: 18px; margin: 0; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }

/* full-screen sheet for pickers on phones (e.g. payee search) */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  background: var(--surface); overflow-y: auto;
  padding: max(12px, env(safe-area-inset-top)) var(--gutter) calc(12px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .sheet { inset: 10vh auto auto 50%; transform: translateX(-50%); width: 560px; max-height: 80vh;
           border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
}
