/* =====================================================================
   UX layer — accessibility, touch, feedback, navigation, responsive data
   ===================================================================== */
:root { --focus: 0 0 0 3px #10110f, 0 0 0 5px var(--lime); --tap: 44px; --ease-out: cubic-bezier(.16,1,.3,1); --dur: 200ms; --z-nav: 40; --z-drawer: 90; --z-toast: 100; }
body { font-size: 16px; }

/* Skip link + focus rings */
.skip-link { position: absolute; top: -100px; inset-inline-start: 16px; z-index: 300; background: var(--lime); color: #10110f; font-weight: 800; padding: 12px 18px; border-radius: 12px; transition: top var(--dur) var(--ease-out); }
.skip-link:focus { top: 12px; }
:focus { outline: none; }
a:focus-visible, button:focus-visible, summary:focus-visible, [tabindex]:not(main):focus-visible { box-shadow: var(--focus); border-radius: 10px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { box-shadow: 0 0 0 3px #c8ff5540; border-color: var(--lime); }

/* Icons */
.icon { width: 20px; height: 20px; flex-shrink: 0; display: inline-block; vertical-align: middle; }
.button .icon { width: 18px; height: 18px; }
html[dir=rtl] .back-link .icon, html[dir=rtl] .icon-arrow { transform: scaleX(-1); }
.icon-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: var(--tap); min-height: var(--tap); padding: 0 10px; border-radius: 12px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; transition: color var(--dur), background var(--dur); }
.icon-button:hover { color: var(--text); background: #ffffff0a; }
.icon-button:active { transform: scale(.96); }
.bell { position: relative; font-size: inherit; padding: 0 10px; }
.bell b { top: 4px; inset-inline-end: 2px; }

/* Nav with icon + label */
.main-nav a { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; }
.main-nav a .icon { width: 17px; height: 17px; opacity: .8; }
.main-nav a.active .icon { opacity: 1; }
.is-public .main-nav a .icon { display: none; }

/* Buttons: states + loading feedback */
.button { min-height: var(--tap); cursor: pointer; transition: transform var(--dur) var(--ease-out), background var(--dur), border-color var(--dur), opacity var(--dur); }
.button:active { transform: scale(.97); }
.button-sm { min-height: 36px; }
.button[disabled], .button[aria-disabled=true] { opacity: .45; cursor: not-allowed; transform: none; }
.button.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.button.is-loading::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; border: 2px solid; border-color: var(--text) transparent var(--text) transparent; animation: spin .7s linear infinite; }
.button-primary.is-loading::after { border-color: #10110f transparent #10110f transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.remove-row { min-width: var(--tap); min-height: var(--tap); display: inline-grid; place-items: center; border-radius: 10px; }
.remove-row:hover { background: #3a211e; }

/* Back link */
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; margin-bottom: 10px; min-height: 32px; padding-inline-end: 8px; }
.back-link:hover { color: var(--lime); }
.back-link .icon { width: 16px; height: 16px; }

/* Readable small text (≥12px) + contrast */
.eyebrow { font-size: 11px; } .tiny { font-size: 12px; } .badge { font-size: 12px; } .table th { font-size: 11.5px; }
.footer { color: #8d9384; font-size: 12px; }
.metric-card small { color: #9aa08f; font-size: 12px; }

/* Forms: 16px inputs (no iOS zoom), required marker, errors, password toggle */
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=url], input[type=tel], input[type=file], select, textarea { font-size: 16px; min-height: var(--tap); }
textarea { min-height: 96px; }
label.req > .label-text::after { content: " *"; color: var(--lime); }
.field-error { display: flex; align-items: center; gap: 6px; color: var(--danger); font-size: 12.5px; font-weight: 500; }
.field-error .icon { width: 15px; height: 15px; }
[aria-invalid=true] { border-color: #c46a5c !important; box-shadow: 0 0 0 3px #ff8a7a22 !important; }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-inline-end: 52px; }
.pw-toggle { position: absolute; inset-inline-end: 2px; top: 50%; transform: translateY(-50%); }
.pw-toggle:active { transform: translateY(-50%) scale(.96); }

/* Flash & toasts */
.flash { display: flex; align-items: center; gap: 10px; }
.flash .icon { width: 18px; height: 18px; }
.toast { display: flex; align-items: center; gap: 10px; }
.toast .toast-x { margin-inline-start: auto; min-width: 32px; min-height: 32px; display: grid; place-items: center; background: none; border: 0; color: inherit; opacity: .7; cursor: pointer; border-radius: 8px; }
.toast-stack { z-index: var(--z-toast); bottom: calc(20px + env(safe-area-inset-bottom)); }

/* Marquee separator dot (the logo is never skewed) */
.mq-dot { display: inline-block; width: .32em; height: .32em; border-radius: 50%; background: var(--lime); flex-shrink: 0; }

/* Metric icon chips */
.metric-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: #c8ff5512; opacity: 1; }
.metric-icon .icon { width: 20px; height: 20px; }
.inline-icon { display: inline-flex; align-items: center; gap: 6px; }
.inline-icon .icon { width: 16px; height: 16px; }
.notice, .milestone, .file-row { transition: border-color var(--dur); }
@media (hover: hover) { a.milestone:hover, .notice:hover { border-color: #4a5142; } }

/* ---------- Navigation drawer (≤860px) ---------- */
.nav-backdrop { position: fixed; inset: 0; background: #000a; backdrop-filter: blur(4px); z-index: calc(var(--z-drawer) - 1); }
.nav-toggle { display: none; }
@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; position: relative; z-index: calc(var(--z-drawer) + 1); }
  .main-nav { display: flex !important; position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(320px, 86vw); flex-direction: column; align-items: stretch; gap: 4px; padding: calc(84px + env(safe-area-inset-top)) 16px 24px; background: #141513; border-inline-start: 1px solid var(--line); z-index: var(--z-drawer); transform: translateX(105%); transition: transform .32s var(--ease-out), visibility 0s .32s; overflow-y: auto; visibility: hidden; flex-basis: auto; order: 0; }
  html[dir=rtl] .main-nav { transform: translateX(-105%); }
  html[dir] .main-nav.open { transform: none; visibility: visible; transition: transform .32s var(--ease-out); }
  .topbar { gap: 8px; padding-inline: 12px; }
  .top-actions .icon-button { min-width: 42px; padding: 0 8px; }
  .top-actions .logout-form { display: none; }
  .nav-logout { display: block; margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); }
  .nav-logout button { width: 100%; justify-content: flex-start; min-height: 48px; color: var(--danger); font-size: 15px; padding: 10px 14px; }
  .main-nav a { min-height: 48px; font-size: 15px; padding: 10px 14px; border-radius: 12px; }
  .is-public .main-nav a .icon { display: inline-block; }
  /* backdrop-filter would make the topbar the containing block of the fixed drawer — so no blur here,
     and the topbar (which holds the drawer) sits above the backdrop. */
  .topbar { flex-wrap: nowrap; padding-top: 0; padding-bottom: 0; min-height: 68px; backdrop-filter: none; -webkit-backdrop-filter: none; background: #10110f; z-index: calc(var(--z-drawer) + 2); }
  html, body { overflow-x: clip; }
  .user-chip, .lang-link span, .hide-xs { display: none; }
  .top-actions { margin-inline-start: auto; gap: 4px; }
  .brand-wordmark { height: 16px; }
}
@media (min-width: 861px) { .nav-backdrop { display: none !important; } }

/* ---------- Client bottom tab bar (≤860px) ---------- */
.tabbar { display: none; }
@media (max-width: 860px) {
  .area-client .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0; z-index: var(--z-nav); background: #10110ff2; backdrop-filter: blur(16px); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { display: grid; justify-items: center; gap: 3px; min-height: 52px; padding: 6px 2px; border-radius: 12px; color: var(--muted); font-size: 11px; font-weight: 600; text-align: center; }
  .tabbar a .icon { width: 22px; height: 22px; }
  .tabbar a.active { color: var(--lime); }
  .area-client .page-shell { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .area-client .footer { padding-bottom: calc(90px + env(safe-area-inset-bottom)); }
  .area-client .toast-stack { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

/* ---------- Data tables become cards on phones ---------- */
@media (max-width: 640px) {
  .table-wrap { overflow: visible; margin: 0; }
  .table-wrap:has(> table.table:not(.stackable)) { overflow-x: auto; } /* tables without a header row scroll instead of spilling */
  table.table.stackable thead { display: none; }
  table.table.stackable, table.table.stackable tbody, table.table.stackable tr, table.table.stackable td { display: block; width: 100%; }
  table.table.stackable tr { border: 1px solid var(--line); border-radius: 16px; padding: 4px 14px; margin-bottom: 10px; background: #ffffff03; }
  table.table.stackable td { display: flex; justify-content: space-between; align-items: center; gap: 14px; border-bottom: 1px solid #ffffff08; padding: 10px 0; text-align: end; min-height: 44px; }
  table.table.stackable td:last-child { border-bottom: 0; }
  table.table.stackable td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; text-align: start; flex-shrink: 0; }
  table.table.stackable td:empty { display: none; }
}

/* ---------- Calm app area ---------- */
.is-app .page-heading h1 { font-size: clamp(28px, 3.4vw, 42px); letter-spacing: -.04em; }
.is-app main > * { animation: app-in .28s var(--ease-out) both; }
@keyframes app-in { from { opacity: 0; transform: translateY(6px); } }
@media (pointer: coarse) { .button-sm { min-height: var(--tap); } .filters a { min-height: 40px; display: inline-flex; align-items: center; } }
@media (prefers-reduced-motion: reduce) { .is-app main > * { animation: none; } .main-nav { transition: none !important; } }

/* Screen-reader-only text */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
/* Currency picker */
.currency-picker { display: inline-flex; }
.currency-picker select { min-height: 40px; padding: 8px 34px 8px 12px; border-radius: 12px; font-size: 14px; width: auto; max-width: 220px; background: #10110f; }
html[dir=rtl] .currency-picker select { padding: 8px 12px 8px 34px; }
.top-currency select { min-height: 40px; font-size: 13px; max-width: 120px; color: var(--muted); border-color: transparent; background: transparent; }
.top-currency select:hover { border-color: var(--line); color: var(--text); }
@media (max-width: 860px) { .top-currency select { max-width: none; width: 74px; padding: 6px 4px; font-size: 13px; } }

.nav-logout { display: none; }
@media (max-width: 860px) { .nav-logout { display: block; } }

/* Back to top */
.to-top { position: fixed; inset-inline-end: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 70; width: 52px; height: 52px; border-radius: 50%; border: 0; padding: 0; display: grid; place-items: center; background: #181a17ee; color: var(--lime); cursor: pointer; box-shadow: 0 10px 30px #0007; transition: transform var(--dur) var(--ease-out), opacity var(--dur); animation: to-top-in .3s var(--ease-out); }
.to-top[hidden] { display: none; }
.to-top:hover { transform: translateY(-3px); }
.to-top:active { transform: scale(.94); }
.to-top .icon { width: 20px; height: 20px; position: relative; }
.to-top-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.to-top-ring circle { fill: none; stroke: var(--line); stroke-width: 2.5; }
.to-top-ring .bar { stroke: var(--lime); stroke-dasharray: 100; stroke-dashoffset: 100; stroke-linecap: round; transition: stroke-dashoffset .15s linear; }
@keyframes to-top-in { from { opacity: 0; transform: translateY(10px); } }
@media (max-width: 860px) { .area-client .to-top { bottom: calc(88px + env(safe-area-inset-bottom)); } .to-top { inset-inline-end: 14px; width: 48px; height: 48px; } }
@media (prefers-reduced-motion: reduce) { .to-top { animation: none; } }

/* =====================================================================
   MuSelect — branded dropdowns (select.js). Native <select> stays hidden underneath.
   ===================================================================== */
.ms { position: relative; display: block; width: 100%; }
.inline-form .ms, .row > .ms, .filters .ms, .ms-compact { display: inline-block; width: auto; }
.ms-native { position: absolute !important; width: 1px !important; height: 1px !important; min-height: 0 !important; padding: 0 !important; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0 !important; opacity: 0; pointer-events: none; }
.ms-trigger { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); padding: 10px 14px; border: 1px solid #373b32; background: #10110f; border-radius: 12px; color: var(--text); font: inherit; font-size: 15px; text-align: start; cursor: pointer; transition: border-color var(--dur), background var(--dur), box-shadow var(--dur); }
.ms-trigger:hover { border-color: #4f5646; }
.ms.open .ms-trigger { border-color: var(--lime); box-shadow: 0 0 0 3px #c8ff5520; }
.ms-trigger[aria-invalid=true] { border-color: #c46a5c; box-shadow: 0 0 0 3px #ff8a7a22; }
.ms-trigger:disabled { opacity: .45; cursor: not-allowed; }
.ms-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-value.ms-placeholder { color: var(--muted); }
.ms-chev { width: 18px; height: 18px; flex-shrink: 0; color: var(--muted); transition: transform .2s var(--ease-out), color .2s; }
.ms.open .ms-chev { transform: rotate(180deg); color: var(--lime); }
.ms-panel { position: absolute; top: calc(100% + 6px); inset-inline-start: 0; z-index: 85; min-width: 100%; width: max-content; max-width: min(380px, calc(100vw - 32px)); padding: 6px; background: #181a17; border: 1px solid #3a3f33; border-radius: 14px; box-shadow: 0 24px 60px #000c, 0 0 0 1px #00000040; transform-origin: top center; animation: ms-in .16s var(--ease-out); }
.ms.up .ms-panel { top: auto; bottom: calc(100% + 6px); transform-origin: bottom center; }
@keyframes ms-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.ms-list { max-height: 300px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #3a3f33 transparent; }
.ms-option { display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 10px; min-height: 42px; padding: 8px 10px; border-radius: 10px; cursor: pointer; font-size: 14px; color: #d9ddcf; }
.ms-option.active { background: #ffffff0f; color: var(--text); }
.ms-option .ms-check { width: 16px; height: 16px; color: var(--lime); visibility: hidden; }
.ms-option.selected .ms-check { visibility: visible; }
.ms-option.selected .ms-main { color: var(--lime); font-weight: 700; }
.ms-option .ms-sub { color: var(--muted); font-size: 12px; white-space: nowrap; }
.ms-option[aria-disabled=true] { opacity: .4; cursor: not-allowed; }
.ms-search { width: 100%; min-height: 38px !important; margin-bottom: 6px; padding: 8px 12px !important; font-size: 14px !important; border-radius: 10px !important; }
.ms-empty { padding: 12px; color: var(--muted); font-size: 13px; text-align: center; }
/* compact variant (top-bar currency) */
.ms-compact .ms-trigger { min-height: 40px; padding: 6px 10px; border-color: transparent; background: transparent; font-size: 13px; font-weight: 700; color: var(--muted); gap: 6px; }
.ms-compact .ms-trigger:hover, .ms-compact.open .ms-trigger { color: var(--text); border-color: var(--line); box-shadow: none; }
.ms-compact .ms-panel { inset-inline-start: auto; inset-inline-end: 0; width: 270px; }
@media (max-width: 860px) { .ms-compact .ms-trigger { padding: 6px; } .ms-compact .ms-panel { position: fixed; top: 70px; inset-inline: 12px; width: auto; max-width: none; } }
@media (prefers-reduced-motion: reduce) { .ms-panel { animation: none; } .ms-chev { transition: none; } }

/* Calmer app-wide headings and spacing */
.page-heading { margin-bottom: 36px; }
.page-heading h1 { font-size: clamp(28px, 3.4vw, 44px); }
.panel h2 { font-size: 20px; }
.metric-card strong { font-size: 30px; }
.service-grid, .work-grid, .grid-2, .grid-3, .content-grid { gap: 24px; }
.package-grid { gap: 20px; }

/* Phones: keep the top bar inside the screen */
@media (max-width: 860px) {
  .top-actions .button-primary.button-sm span { display: none; }
  .top-actions .button-primary.button-sm { padding: 0 10px; min-width: 40px; }
  .top-actions .button-ghost.button-sm { padding: 0 10px; }
}
@media (max-width: 400px) { .brand-wordmark { display: none; } }

/* Live currency switch: prices roll in when they update */
.money.fx-tick .amt { display: inline-block; animation: fx-tick .45s cubic-bezier(.16,1,.3,1); }
@keyframes fx-tick { from { opacity: 0; transform: translateY(40%); filter: blur(2px); } }
@media (prefers-reduced-motion: reduce) { .money.fx-tick .amt { animation: none; } }

.row-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.row-actions .button .icon { width: 15px; height: 15px; }

/* ---------- Mobile legibility & touch targets (audit pass) ---------- */
.deck-cat, .featured-flag, .eyebrow { font-size: 11px; }
@media (max-width: 700px) { .deck-cat { font-size: 11px; } }
/* Product names: ~44px tap area without changing the card layout */
.pc-body h3 a { display: inline-block; padding-block: 10px; margin-block: -10px; }
.forgot-link { align-self: flex-end; margin-top: -4px; padding-block: 8px; }

/* ---------- Fixes: deck spacing, price tag in Arabic, iOS date inputs ---------- */
.deck-foot { padding-top: 18px; position: relative; z-index: 20; }
/* Deck grid at 3 per row: smaller titles on phones so they fit the narrower cards */
@media (max-width: 700px) { .deck.is-grid .deck-title { font-size: 11px; top: 10px; inset-inline: 10px; } .deck.is-grid .deck-cat { font-size: 9px; bottom: 9px; inset-inline: 10px; letter-spacing: .02em; } .deck.is-grid .deck-frame { inset: 5px; border-radius: 10px; } .deck-card { border-radius: 14px; } }
@media (prefers-reduced-motion: reduce) { .deck-field { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; } }
/* Price tag: the punch hole sits beside the tip in both directions, never on top of the number */
.pc-tag { max-width: 100%; }
.pc-tag .money { white-space: nowrap; }
@media (max-width: 420px) { .pc-tag { font-size: 13px; padding: 7px 10px 7px 22px; } html[dir=rtl] .pc-tag { padding: 7px 22px 7px 10px; } .pc-tag small { font-size: 9px; } }
/* iOS Safari: date inputs ignore width:100% and spill out of the card */
input[type=date], input[type=datetime-local], input[type=time] { -webkit-appearance: none; appearance: none; display: block; width: 100%; max-width: 100%; min-width: 0; min-height: 46px; text-align: start; }
input[type=date]::-webkit-date-and-time-value { text-align: start; margin: 0; }

/* ---------- Status badges (whole system): compact pill, status dot, tinted by meaning ---------- */
.badge {
  --bc: #b4b6ad; --bg: rgba(180, 182, 173, .1); --bd: rgba(180, 182, 173, .28);
  display: inline-flex; align-items: center; gap: 7px; width: max-content !important; max-width: 100%; flex: none;
  justify-self: start; align-self: center; vertical-align: middle;
  padding: 5px 11px 5px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; line-height: 1.1; letter-spacing: .01em;
  color: var(--bc); background: var(--bg); border: 1px solid var(--bd); white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px var(--bd); flex: none; }
/* success */
.badge-paid, .badge-confirmed, .badge-accepted, .badge-approved, .badge-completed, .badge-published, .badge-active { --bc: #c8ff55; --bg: rgba(200, 255, 85, .1); --bd: rgba(200, 255, 85, .32); }
.badge-paid { --bc: #10110f; --bg: #c8ff55; --bd: #c8ff55; }
.badge-paid::before { box-shadow: none; }
/* in motion */
.badge-issued, .badge-sent, .badge-in_progress, .badge-submitted, .badge-review, .badge-requested { --bc: #8fcbff; --bg: rgba(143, 203, 255, .09); --bd: rgba(143, 203, 255, .3); }
/* waiting on someone */
.badge-partially_paid, .badge-pending_review, .badge-pending, .badge-on_hold, .badge-draft { --bc: #ffcf6b; --bg: rgba(255, 207, 107, .09); --bd: rgba(255, 207, 107, .3); }
.badge-draft { --bc: #c9cbc2; --bg: rgba(201, 203, 194, .07); --bd: rgba(201, 203, 194, .25); }
/* problems */
.badge-overdue, .badge-rejected, .badge-cancelled, .badge-refunded, .badge-blocked, .badge-suspended, .badge-expired { --bc: #ff8a7a; --bg: rgba(255, 138, 122, .09); --bd: rgba(255, 138, 122, .3); }
/* live states breathe a little */
.badge-pending_review::before, .badge-in_progress::before, .badge-overdue::before { animation: badge-pulse 1.8s ease-in-out infinite; }
@keyframes badge-pulse { 50% { box-shadow: 0 0 0 5px transparent; opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .badge::before { animation: none !important; } }
/* never stretch inside grids, stacked table cells or meta blocks */
.doc-meta .badge, .kv .badge, table.table.stackable td .badge, .rcpt-head .badge, .inv-due .badge, .metric-card .badge { display: inline-flex; width: max-content !important; font-size: 12px; color: var(--bc); margin-top: 2px; }
.doc-meta > div div { padding: 0; border: 0; border-radius: 0; background: none; margin-top: 4px; color: var(--muted); }
