/* Mini bourse — design tokens and components.
   Direction "Clair": a calm, simple money app. White page, soft grouped cards, one big number per
   screen, a dark card for the shop's total. Logical properties throughout: Darija (right to left)
   is the main language. */

/* Self-hosted fonts (SIL Open Font License, see static/fonts/README.md): no third-party requests. */
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/atkinson-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/atkinson-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Readex Pro";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/readex-arabic.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC7, U+10EC9-10EEE, U+10EF0-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22, U+1EE24, U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42, U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54, U+1EE57, U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64, U+1EE67-1EE6A, U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E, U+1EE80-1EE89, U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9, U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}

:root {
  /* The login cover's palette, used by every screen (one theme: night blue). */
  --paper: #0e101c; /* the page: the cover's night blue */
  --surface: #1a1d2a; /* cards and fields: white at 6 % over the night */
  --surface-raised: #232737; /* what floats above the page (toast) */
  --pressed: #262a3b; /* a card row being touched or open, the selected segment */
  --edge: rgb(255 255 255 / 0.08); /* the thin light edge of cards and fields */
  --ink: #63a1ff; /* accent for text and icons: links, the selected tab */
  --ink-deep: #ffffff; /* text */
  --muted: #a3acc4; /* labels, secondary text */
  --rule: rgb(255 255 255 / 0.10);
  --rule-faint: rgb(255 255 255 / 0.05);
  --margin: #ff6b7a; /* errors, losses */
  --gain: #34d27b;
  --on-ink: #ffffff; /* text on the accent gradient */
  /* the cover's button: a diagonal sky-to-royal blue, with a soft glow under it */
  --accent-gradient: linear-gradient(135deg, #66a3ff 0%, #4a80ff 55%, #3567ff 100%);
  --accent-glow: 0 10px 28px -10px rgb(74 128 255 / 0.65);
  /* ownership ring: distinct, calm hues that stay apart for most color vision */
  --pie-1: #748ffc;
  --pie-2: #40c057;
  --pie-3: #ffa94d;
  --pie-4: #da77f2;
  --pie-5: #3bc9db;
  --pie-6: #f783ac;
  --pie-7: #ffd43b;
  --pie-8: #adb5bd;

  /* Latin glyphs from Atkinson, Arabic glyphs fall through to Readex Pro (both built for legibility). */
  --font: "Atkinson Hyperlegible Next", "Readex Pro", system-ui, sans-serif;
  --text-sm: 0.875rem;
  --text-base: 1.0625rem;
  --text-lg: 1.3125rem;
  --text-xl: 1.5rem;
  --text-amount: 3.5rem;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  --radius-control: 1rem;
  --radius-card: 1.125rem;
  --radius-pill: 999px;
  --tabbar-height: 4rem;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink-deep);
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

h1 {
  margin: 0 0 var(--space-5);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.3;
}

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

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.page {
  max-inline-size: 34rem;
  margin-inline: auto;
  padding: var(--space-5) var(--space-4)
    calc(var(--tabbar-height) + var(--space-6) + env(safe-area-inset-bottom));
}

/* --- Top bar: language switch + logout --------------------------------- */

.topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--space-2);
  max-inline-size: 34rem;
  margin-inline: auto;
  padding: var(--space-2) var(--space-2) 0;
}

.topbar form {
  margin: 0;
}

.topbar-action {
  display: inline-block;
  padding: var(--space-2) var(--space-3);
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: var(--text-sm);
  text-decoration: none;
  cursor: pointer;
}

.topbar-action:hover {
  color: var(--ink);
}

.page > h1 {
  margin-block-start: var(--space-2);
}

.intro {
  margin: 0 0 var(--space-5);
  color: var(--muted);
}

.form-error {
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-inline-start: 3px solid var(--margin);
  color: var(--margin);
  font-weight: 600;
}

/* --- Form controls ------------------------------------------------------ */

.field {
  display: grid;
  gap: var(--space-1);
  margin-block-end: var(--space-4);
  font-size: var(--text-sm);
  color: var(--muted);
}

.optional {
  font-weight: 400;
}

input:not([type="radio"]) {
  inline-size: 100%;
  min-block-size: 3.25rem;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink-deep);
  font: inherit;
  font-size: var(--text-base);
}

input:not([type="radio"]):focus-visible {
  outline-offset: 0;
  border-color: var(--ink);
}

.input-suffix {
  position: relative;
  display: block;
}

.input-suffix input {
  padding-inline-end: 3rem;
  text-align: end;
}

.input-suffix span {
  position: absolute;
  inset-inline-end: var(--space-3);
  inset-block: 0;
  display: flex;
  align-items: center;
  color: var(--muted);
}

.field-error {
  margin: var(--space-2) 0 0;
  color: var(--margin);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* --- Buttons ------------------------------------------------------------ */

.primary {
  inline-size: 100%;
  min-block-size: 3.375rem;
  box-shadow: var(--accent-glow);
  border: 0;
  border-radius: var(--radius-control);
  background: var(--accent-gradient);
  color: var(--on-ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.primary:active {
  transform: scale(0.98);
}

.primary[aria-busy="true"] {
  opacity: 0.7;
  cursor: progress;
}

.link-button {
  padding: var(--space-2);
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* --- Type chips: radio buttons styled as a swipeable row ---------------- */

.chips {
  display: flex;
  gap: var(--space-2);
  margin: 0 calc(-1 * var(--space-4)) var(--space-5);
  padding: 0 var(--space-4) var(--space-1);
  min-inline-size: 0; /* fieldsets default to min-content and would widen the page */
  border: 0;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scroll-padding-inline: var(--space-4); /* snap chips to the page gutter, not the screen edge */
  scrollbar-width: none;
  mask-image: linear-gradient(to right, #000 85%, transparent);
}

[dir="rtl"] .chips {
  mask-image: linear-gradient(to left, #000 85%, transparent);
}

.chip {
  position: relative; /* contains the hidden radio, which would otherwise widen the page */
  flex: none;
  scroll-snap-align: start;
}

.chip input {
  position: absolute;
  opacity: 0;
}

.chip span {
  display: block;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink-deep);
  white-space: nowrap;
  cursor: pointer;
}

.chip input:checked + span {
  background: var(--accent-gradient);
  color: var(--on-ink);
  font-weight: 700;
}

.chip input:focus-visible + span {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

.chip span:active {
  transform: scale(0.96);
}

.chip-link {
  flex: none;
  scroll-snap-align: start;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink-deep);
  white-space: nowrap;
  text-decoration: none;
}

.chip-link[aria-current] {
  background: var(--accent-gradient);
  color: var(--on-ink);
  font-weight: 700;
}

/* --- The amount: one big centered number -------------------------------
   The phone's own number keypad opens on it (inputmode="numeric"). */

.cahier {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  margin-block: var(--space-6) var(--space-5);
}

.cahier-date {
  display: none; /* the date is in "change the date" below */
}

.cahier-label {
  order: 2;
  color: var(--muted);
  font-size: var(--text-base);
  text-align: center;
}

.cahier-label > span {
  display: none;
}

.cahier-amount {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: var(--space-2);
  max-inline-size: 100%;
}

.cahier-amount input {
  inline-size: 100%;
  min-inline-size: 0;
  min-block-size: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--ink-deep);
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
}

/* the digits are what's centered; the currency follows them */
@supports (field-sizing: content) {
  .cahier-amount input {
    field-sizing: content;
    inline-size: auto;
    min-inline-size: 1ch;
  }
}

.cahier-amount input:focus-visible {
  outline: none;
}

.cahier-amount input::placeholder {
  color: rgb(255 255 255 / 0.25);
}

.cahier-currency {
  color: var(--muted);
  font-size: var(--text-xl);
  font-weight: 600;
}

.cahier[data-invalid] .cahier-amount input {
  color: var(--margin);
}

/* --- Type-dependent visibility (pure CSS, no JS) ------------------------ */

[data-only] {
  display: none;
}

.op-form:has(input[name="type"][value="sale"]:checked) [data-type="sale"],
.op-form:has(input[name="type"][value="stock_purchase"]:checked) [data-type="stock_purchase"],
.op-form:has(input[name="type"][value="expense"]:checked) [data-type="expense"],
.op-form:has(input[name="type"][value="inventory"]:checked) [data-type="inventory"],
.op-form:has(input[name="type"][value="loan"]:checked) [data-type="loan"],
.op-form:has(input[name="type"][value="repayment"]:checked) [data-type="repayment"],
.op-form:has(input[name="type"][value="distribution"]:checked) [data-type="distribution"] {
  display: inline;
}

.op-form:has(input[name="type"][value="sale"]:checked) [data-only="sale"] {
  display: grid;
}

.op-form:has(#amount:placeholder-shown) .primary {
  opacity: 0.45;
}

/* --- Folded extras ------------------------------------------------------ */

.more {
  margin-block-end: var(--space-5);
}

.more summary {
  padding-block: var(--space-2);
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

.more[open] summary {
  margin-block-end: var(--space-3);
}

/* --- Toast: confirmation with undo ------------------------------------- */

.toast {
  position: fixed;
  inset-inline: var(--space-4);
  inset-block-end: calc(var(--tabbar-height) + var(--space-3) + env(safe-area-inset-bottom));
  max-inline-size: 32rem;
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-block: var(--space-2);
  padding-inline: var(--space-4) var(--space-2);
  border-radius: var(--radius-card);
  background: var(--surface-raised);
  box-shadow: inset 0 0 0 1px var(--edge), 0 12px 32px -12px rgb(0 0 0 / 0.6);
  color: var(--ink-deep);
  animation: toast-in 200ms ease-out;
}

.toast form {
  margin: 0;
}

@keyframes toast-in {
  from {
    transform: translateY(0.75rem);
    opacity: 0;
  }
}

/* --- Bottom tab bar ----------------------------------------------------- */

.tabbar {
  position: fixed;
  inset-inline: 0;
  inset-block-end: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  block-size: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
  padding-block-end: env(safe-area-inset-bottom);
  border-block-start: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(12px);
}

.tabbar a {
  flex: 1;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  min-block-size: 3rem;
  padding-inline: var(--space-1);
  color: var(--muted);
  font-size: 0.75rem;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.tabbar a svg {
  inline-size: 1.5rem;
  block-size: 1.5rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tabbar a[aria-current="page"] {
  color: var(--ink);
  font-weight: 700;
}

.tabbar .tabbar-add {
  flex: none;
  inline-size: 3.25rem;
  block-size: 3.25rem;
  min-block-size: 0;
  margin-block-start: -1.25rem;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: var(--on-ink);
  box-shadow: 0 0 0 4px var(--paper);
}

.tabbar .tabbar-add[aria-current="page"] {
  color: var(--on-ink);
}

.tabbar .tabbar-add svg {
  stroke-width: 2.5;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .primary:active,
  .chip span:active {
    transform: none;
  }
}

/* --- Operations list: the notebook page -------------------------------- */

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-block-end: var(--space-3);
}

.month-nav h2 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
}

.month-step {
  display: grid;
  place-items: center;
  inline-size: 2.75rem;
  block-size: 2.75rem;
  border-radius: 50%;
  color: var(--ink);
}

.month-step svg {
  inline-size: 1.5rem;
  block-size: 1.5rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[dir="rtl"] .month-step svg {
  transform: scaleX(-1);
}

.ledger {
  --margin-x: 3.75rem;
  position: relative;
  margin: 0 calc(-1 * var(--space-4));
  padding: 0;
  list-style: none;
  border-block-start: 1px solid var(--rule);
}

.ledger-row {
  border-block-end: 1px solid var(--rule);
}

.ledger-row summary {
  display: grid;
  grid-template-columns: var(--margin-x) 1fr auto;
  align-items: baseline;
  gap: var(--space-3);
  min-block-size: 3.5rem;
  padding-block: var(--space-3);
  padding-inline-end: var(--space-4);
  list-style: none;
  cursor: pointer;
}

.ledger-row summary::-webkit-details-marker {
  display: none;
}

.ledger-row summary:focus-visible {
  outline-offset: -3px;
}

.ledger-row details[open] summary {
  background: var(--surface);
}

.ledger-date {
  color: var(--muted);
  font-size: var(--text-sm);
  text-align: center;
}

.ledger-what {
  display: grid;
  min-inline-size: 0;
}

.ledger-type {
  font-weight: 600;
}

.ledger-note,
.ledger-flag {
  overflow: hidden;
  color: var(--muted);
  font-size: var(--text-sm);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-flag {
  color: var(--margin);
  font-weight: 600;
}

/* money in is green, money out stays neutral (spending is normal, not an alarm) */
.ledger-amount {
  color: var(--ink-deep);
  font-weight: 700;
  white-space: nowrap;
}

.ledger-amount.sign-sale,
.ledger-amount.sign-loan {
  color: var(--gain);
}

.ledger-amount.sign-inventory {
  color: var(--muted);
}

/* A cancelled entry is crossed out, as it would be in the paper notebook. */
.is-reversed .ledger-type,
.is-reversed .ledger-amount {
  color: var(--muted);
  font-weight: 400;
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

.ledger-detail {
  padding-block: var(--space-2) var(--space-4);
  padding-inline: calc(var(--margin-x) + var(--space-3)) var(--space-4);
  font-size: var(--text-sm);
}

.ledger-detail p {
  margin: 0 0 var(--space-2);
}

.ledger-detail form {
  margin-block-start: var(--space-3);
}

.danger-button {
  min-block-size: 2.75rem;
  padding: var(--space-2) var(--space-4);
  border: 1.5px solid var(--margin);
  border-radius: var(--radius-control);
  background: none;
  color: var(--margin);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.hint {
  color: var(--muted);
  font-size: var(--text-sm);
}

.empty {
  padding-block: var(--space-6);
  text-align: center;
  color: var(--muted);
}

.as-link {
  display: inline-grid;
  place-items: center;
  inline-size: auto;
  padding-inline: var(--space-5);
  text-decoration: none;
}

/* --- Investors and shares --------------------------------------------- */

.share-price {
  display: grid;
  gap: var(--space-1);
  margin: 0 0 var(--space-5);
  color: var(--muted);
}

.share-price strong {
  color: var(--ink);
  font-size: var(--text-lg);
}

.holders .ledger-date {
  color: var(--ink);
  font-weight: 700;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-block: var(--space-3);
}

.actions.stacked {
  display: grid;
  margin-block: var(--space-5);
}

.secondary-button {
  display: inline-grid;
  place-items: center;
  min-block-size: 2.75rem;
  padding: var(--space-2) var(--space-4);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-control);
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.link-button.quiet {
  padding-inline: 0;
  color: var(--muted);
  font-weight: 600;
}

.primary.full {
  display: grid;
  inline-size: 100%;
  margin-block-start: var(--space-5);
}

.back-link {
  display: inline-block;
  margin-block-start: var(--space-4);
  padding-block: var(--space-2);
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* The temporary password is shown once: large, unambiguous characters, easy to read aloud. */
.temp-password {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4);
  border-radius: var(--radius-card);
  background: var(--surface);
  text-align: center;
}

.temp-label {
  color: var(--muted);
  font-size: var(--text-sm);
}

.temp-password output {
  color: var(--ink);
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  overflow-wrap: anywhere;
}

.wide-suffix input {
  padding-inline-end: 6.5rem;
}

.mv-form [data-kind] {
  display: none;
}

.mv-form:not(:has(input[name="kind"][value="sell"]:checked)) [data-kind="buy"],
.mv-form:has(input[name="kind"][value="sell"]:checked) [data-kind="sell"] {
  display: inline;
}

.preview {
  display: grid;
  gap: var(--space-1);
  margin: 0 0 var(--space-5);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.preview[hidden] {
  display: none;
}

.preview strong {
  color: var(--ink);
  font-size: var(--text-lg);
}

/* --- Ownership ring (investors page) ----------------------------------- */

.pie {
  position: relative;
  display: grid;
  place-items: center;
  inline-size: min(15rem, 100%);
  aspect-ratio: 1;
  margin: var(--space-2) auto var(--space-5);
}

.pie-ring {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  transform: rotate(-90deg); /* first slice starts at the top */
  animation: pie-in 700ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes pie-in {
  from {
    opacity: 0;
    transform: rotate(-150deg) scale(0.9);
  }
}

.pie-ring circle {
  fill: none;
  stroke-width: 5;
}

.pie-track {
  stroke: var(--surface);
}

.pie-c1 { --c: var(--pie-1); }
.pie-c2 { --c: var(--pie-2); }
.pie-c3 { --c: var(--pie-3); }
.pie-c4 { --c: var(--pie-4); }
.pie-c5 { --c: var(--pie-5); }
.pie-c6 { --c: var(--pie-6); }
.pie-c7 { --c: var(--pie-7); }
.pie-c8 { --c: var(--pie-8); }

.pie-slice {
  stroke: var(--c);
}

.pie-center {
  display: grid;
  justify-items: center;
  gap: 2px;
  max-inline-size: 62%;
  text-align: center;
}

.pie-center span,
.pie-center small {
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.3;
}

.pie-center strong {
  font-size: var(--text-lg);
  font-weight: 700;
  white-space: nowrap;
}

.pie-dot {
  display: inline-block;
  inline-size: 0.625rem;
  block-size: 0.625rem;
  margin-inline-end: 0.375rem;
  border-radius: 50%;
  background: var(--c);
}

.ledger.holders {
  --margin-x: 5.5rem; /* room for the color dot and the percentage */
}

.holders .ledger-date {
  white-space: nowrap;
}

/* --- Portfolio ---------------------------------------------------------- */

.hero-value {
  display: grid;
  gap: var(--space-1);
  margin-block-end: var(--space-5);
}

.hero-label,
.hero-sub {
  color: var(--muted);
  font-size: var(--text-sm);
}

.hero-value strong {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  color: var(--ink-deep);
  font-size: 2.875rem;
  font-weight: 700;
  line-height: 1.3; /* room for Arabic descenders */
  justify-self: start;
}

.hero-currency {
  color: var(--muted);
  font-size: var(--text-xl);
  font-weight: 600;
}

.hero-gain > summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2);
  justify-self: start;
  inline-size: fit-content;
  margin-inline: calc(-1 * var(--space-2));
  padding: 2px var(--space-2);
  border-radius: 8px;
  font-size: var(--text-sm);
}

.hero-change {
  display: flex;
  gap: var(--space-2);
  font-weight: 700;
}

.hero-gain.is-gain .hero-change {
  color: var(--gain);
}

.hero-gain.is-loss .hero-change {
  color: var(--margin);
}

.hero-since {
  color: var(--muted);
}

/* --- Portfolio tiles: two by two; tap one to read what it means -------- */

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: start;
  gap: 0.625rem;
  margin-block: var(--space-5);
}

.tile {
  border-radius: var(--radius-card);
  background: var(--surface);
}

.tile > summary {
  display: grid;
  gap: var(--space-1);
  padding: 0.875rem var(--space-4);
  border-radius: inherit;
}

.tile-label {
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.35;
}

.tile-value {
  font-size: 1.1875rem;
  font-weight: 700;
  white-space: nowrap;
}

.tile[open] {
  box-shadow: inset 0 0 0 1.5px var(--ink);
}

.tile .explain-text {
  margin: 0;
  padding: 0 var(--space-4) var(--space-3);
  border: 0;
  color: var(--muted);
}

/* Rows of label + value (portfolio, shop). Each row is a native <details>: tapping it opens
   its explanation right below, pushing the next rows down (never covering them). */
.facts {
  margin: 0 0 var(--space-5);
  padding-inline: var(--space-4);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.fact,
.fact-row {
  border-block-end: 1px solid var(--rule);
}

.facts > :last-child {
  border-block-end: 0;
}

.fact > summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  min-block-size: 3.25rem; /* comfortable touch row */
  padding-block: var(--space-3);
  align-items: center;
  list-style: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.fact > summary::-webkit-details-marker {
  display: none;
}

.fact-label {
  color: var(--ink-deep);
  /* the only hint that a term can be explained: a faint dotted underline */
  text-decoration: underline dotted var(--rule);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.3em;
}

.fact-value {
  font-weight: 700;
  white-space: nowrap;
}

.fact.is-gain .fact-value {
  color: var(--gain);
}

.fact.is-loss .fact-value {
  color: var(--margin);
}

/* A row with a button just before its value:  label ........ [button] value
   The summary reserves an invisible slot; the real button sits in an overlay whose
   invisible value copy pushes it exactly onto that slot. */
.fact-row {
  position: relative;
}

.fact-row > .fact {
  border-block-end: 0;
}

.fact-row .fact > summary {
  align-items: center;
}

.fact-row .fact-label {
  flex: 1;
}

.fact-action {
  flex: none;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--paper);
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.6;
  text-decoration: none;
}

.fact-action-slot,
.fact-value-ghost {
  visibility: hidden;
}

.fact-action-layer {
  position: absolute;
  inset-block-start: 0;
  inset-inline-end: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3); /* same gap as inside the summary */
  min-block-size: 3.25rem; /* same height as the summary row */
  pointer-events: none; /* taps on the value still open the explanation */
}

.fact-action-layer .fact-action {
  pointer-events: auto;
}

.fact-action-layer .fact-action:active {
  background: var(--pressed);
}

/* --- Business statement: an accounting column with a double-ruled total -- */

.statement {
  margin-block-end: var(--space-6);
}

.statement h2 {
  margin: 0 var(--space-1) var(--space-2);
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* the shop's total: one dark card under the rows it adds up */
.facts-total {
  margin-block: calc(-1 * var(--space-2)) var(--space-3);
  background: var(--accent-gradient);
  color: var(--on-ink);
}

.fact.is-total > summary {
  min-block-size: 4rem;
}

.fact.is-total .fact-label {
  color: inherit;
  text-decoration-color: rgb(255 255 255 / 0.45);
}

.fact.is-total .fact-value {
  font-size: var(--text-lg);
}

.facts-total .explain > summary:active,
.facts-total .explain[open] > summary {
  background: rgb(255 255 255 / 0.12);
}

.facts-total .explain-text {
  border-inline-start-color: #ffffff;
  color: inherit;
}

.statement > .hint {
  margin: 0 var(--space-1);
}

/* --- The shop's latest operations (everyone sees them) ----------------- */

.recent {
  margin: 0;
  padding: 0 var(--space-4);
  list-style: none;
  border-radius: var(--radius-card);
  background: var(--surface);
}

.recent-op {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  min-block-size: 3.5rem;
  padding-block: var(--space-2);
}

.recent-op + .recent-op {
  border-block-start: 1px solid var(--rule);
}

.recent-what {
  display: grid;
}

.recent-what small {
  color: var(--muted);
  font-size: var(--text-sm);
}

/* --- Chart: smooth line, interval control, header follows the pointer ---- */

.chart {
  margin: 0 0 var(--space-5);
}

.chart-head {
  display: grid;
  gap: var(--space-1);
  margin-block-end: var(--space-3);
}

.chart-title,
.chart-caption {
  color: var(--muted);
  font-size: var(--text-sm);
}

.chart-value {
  justify-self: start;
  color: var(--ink-deep);
  font-size: var(--text-lg);
  font-weight: 700;
}

.chart-change {
  display: flex;
  gap: var(--space-2);
  justify-self: start;
  font-weight: 700;
}

.chart-change.is-up {
  color: var(--gain);
}

.chart-change.is-down {
  color: var(--margin);
}

/* Without JavaScript the header and the table carry the numbers; the plot needs the script. */
.chart:not(.is-live) .chart-plot,
.chart:not(.is-live) .chart-ranges {
  display: none;
}

.chart-plot svg {
  display: block;
  inline-size: 100%;
  block-size: auto;
  overflow: visible;
  touch-action: pan-y;
  direction: ltr; /* time runs left to right in both languages */
  unicode-bidi: isolate;
}

.chart-plot svg {
  color: var(--ink);
}

.chart.is-up .chart-plot svg {
  color: var(--gain);
}

.chart.is-down .chart-plot svg {
  color: var(--margin);
}

.chart-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart.is-up .chart-line {
  stroke: var(--gain);
}

.chart.is-down .chart-line {
  stroke: var(--margin);
}

/* y-axis: faint dashed rules at round values, the values at the end of each rule */
.chart-rule {
  stroke: var(--rule);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}

.chart-baseline {
  stroke: var(--rule);
  stroke-width: 1.5;
}

.chart-tick {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-crosshair {
  stroke: var(--ink-deep);
  stroke-width: 1;
}

.chart-dot {
  fill: var(--paper);
  stroke: var(--ink-deep);
  stroke-width: 2;
}

.chart-hover[hidden] {
  display: none;
}

.chart-ranges {
  display: flex;
  gap: var(--space-1);
  margin-block-start: var(--space-3);
  padding: var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--surface);
}

.chart-ranges button {
  flex: 1;
  min-block-size: 2.5rem;
  border: 0;
  border-radius: var(--radius-pill);
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: var(--text-sm);
  white-space: nowrap;
  cursor: pointer;
}

.chart-ranges button[aria-pressed="true"] {
  background: var(--pressed);
  color: var(--ink-deep);
  font-weight: 700;
}

.chart-table summary {
  padding-block: var(--space-2);
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

.chart-table table {
  inline-size: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.chart-table th,
.chart-table td {
  padding: var(--space-2) 0;
  border-block-end: 1px solid var(--rule);
  text-align: start;
}

.chart-table th:last-child,
.chart-table td:last-child {
  text-align: end;
}

/* --- Explanations: tap the element itself (no icon) ------------------- */

.explain > summary {
  list-style: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.explain > summary::-webkit-details-marker {
  display: none;
}

/* touch feedback, and a quiet mark on the row that is open */
.explain > summary:active,
.explain[open] > summary {
  background: var(--pressed);
}

.tile > summary:active,
.tile[open] > summary {
  background: none;
}

.fact > summary {
  margin-inline: calc(-1 * var(--space-2));
  padding-inline: var(--space-2);
  border-radius: 6px;
}

.explain > summary:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.explain-text {
  margin: 0 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-inline-start: 3px solid var(--ink);
  color: var(--ink-deep);
  font-size: var(--text-sm);
  line-height: 1.6;
}

.explain[open] > .explain-text {
  animation: explain-in 160ms ease-out;
}

@keyframes explain-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

/* titles and single lines that explain themselves */
.chart-title > summary,
.share-price-line > summary,
.title-explain > summary {
  display: inline-block;
  border-radius: 6px;
}

.chart-title > summary,
.share-price-line > summary strong {
  text-decoration: underline dotted var(--rule);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.3em;
}

.title-explain {
  margin-block-end: var(--space-5);
}

.title-explain h1 {
  display: inline;
  margin: 0;
  text-decoration: underline dotted var(--rule);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.25em;
}

.title-explain .explain-text {
  margin-block-start: var(--space-3);
}

.share-price {
  position: relative;
}

/* Always-visible explanation of the selected operation type (forms use visible hints, not "?"). */
.type-help {
  margin: calc(-1 * var(--space-3)) 0 var(--space-4);
  color: var(--muted);
  font-size: var(--text-sm);
}

.type-help > span {
  display: none;
}

/* --- Super admin: accounts and system ----------------------------------- */

.accounts {
  margin: 0 0 var(--space-5);
  padding: 0;
  list-style: none;
  border-block-start: 1px solid var(--rule);
}

.accounts > li {
  border-block-end: 1px solid var(--rule);
}

.account > summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  min-block-size: 3.5rem;
  padding: var(--space-3) var(--space-2);
  margin-inline: calc(-1 * var(--space-2));
  border-radius: 6px;
  list-style: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.account > summary::-webkit-details-marker {
  display: none;
}

.account > summary:active,
.account[open] > summary {
  background: var(--surface);
}

.account-main {
  display: grid;
  min-inline-size: 0;
}

.account-name {
  font-weight: 700;
}

.account-you,
.account-meta {
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 400;
}

.account.is-blocked .account-name {
  color: var(--muted);
}

.badge {
  flex: none;
  padding: 2px var(--space-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-pill);
  color: var(--muted);
  font-size: var(--text-sm);
}

.badge.is-danger {
  border-color: var(--margin);
  color: var(--margin);
}

.account-panel {
  display: grid;
  gap: var(--space-4);
  padding-block: var(--space-2) var(--space-4);
}

.account-panel form,
.account-panel .hint {
  margin: 0;
}

.account-panel .hint {
  margin-block-start: var(--space-2);
}

.account-phone {
  margin: 0;
  color: var(--muted);
}

.account-role {
  display: grid;
  gap: var(--space-1);
  font-size: var(--text-sm);
  color: var(--muted);
}

.account-role-row {
  display: flex;
  gap: var(--space-2);
}

.account-role select {
  flex: 1;
  min-block-size: 2.75rem;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink-deep);
  font: inherit;
}

.field-legend {
  margin-block-end: var(--space-2);
  padding: 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

.admin-new [data-role] {
  display: none;
}

.admin-new:has(input[name="role"][value="investor"]:checked) [data-role="investor"],
.admin-new:has(input[name="role"][value="manager"]:checked) [data-role="manager"],
.admin-new:has(input[name="role"][value="superadmin"]:checked) [data-role="superadmin"] {
  display: inline;
}

.fact-static {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  padding-block: var(--space-3);
  border-block-end: 1px solid var(--rule);
}

.fact-label-static {
  color: var(--muted);
}

.section-title {
  margin: var(--space-6) 0 var(--space-2);
  font-size: var(--text-base);
  font-weight: 700;
}

.backups {
  margin: 0 0 var(--space-3);
  padding: 0;
  list-style: none;
  border-block-start: 1px solid var(--rule);
}

.backups li {
  display: flex;
  justify-content: space-between;
  padding-block: var(--space-2);
  border-block-end: 1px solid var(--rule);
}

/* --- Right-to-left (Arabic) ---------------------------------------------
   Numeric inputs stay dir="ltr" so "50 000" is not reordered to "000 50";
   physical alignment keeps them next to their currency on the left. */

[dir="rtl"] input[dir="ltr"] {
  text-align: right;
}

[dir="rtl"] .input-suffix input {
  padding-left: 3.5rem;
  padding-right: var(--space-3);
  text-align: left;
}

[dir="rtl"] .wide-suffix input {
  padding-left: 6.5rem;
}

[dir="rtl"] .cahier-amount input {
  text-align: center;
}

/* a short input with its button on the same line (new password for an investor) */
.inline-field {
  display: flex;
  gap: var(--space-2);
}

.inline-field input {
  flex: 1;
  min-inline-size: 0;
}

.inline-field .secondary-button {
  min-block-size: 3.25rem;
}

/* Page title with its main action on the same line (investors: add one) */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-block: var(--space-2) var(--space-5);
}

.page-head h1 {
  margin: 0;
}

.head-action {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-block-size: 2.75rem;
  padding-inline: var(--space-3) var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--accent-gradient);
  color: var(--on-ink);
  font-size: var(--text-sm);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.head-action svg {
  inline-size: 1.25rem;
  block-size: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.head-action:active {
  transform: scale(0.97);
}

/* --- Settings: the avatar in the top bar, everything else on its page ----- */

/* On the first line of the page, at the end of the title. The title line is h1 (or the
   investors' title + button row); both keep room for it. */
.page {
  position: relative;
  --title-line: calc(1.75rem * 1.3); /* h1 font size × line height */
}

.page > .topbar-avatar {
  position: absolute;
  inset-inline-end: var(--space-4);
  inset-block-start: calc(var(--space-5) + var(--space-2) + (var(--title-line) - 2.5rem) / 2);
}

.page > h1,
.page > .page-head,
.page > .title-explain {
  padding-inline-end: 3.25rem;
}

/* same vertical center as a plain h1: the row is as tall as its button */
.page > .page-head {
  margin-block-start: calc(var(--space-2) - (2.75rem - var(--title-line)) / 2);
}

.page > .title-explain {
  margin-block-start: var(--space-2);
}

.topbar-avatar {
  display: grid;
  place-items: center;
  inline-size: 2.5rem;
  block-size: 2.5rem;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: var(--on-ink);
  font-weight: 700;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.topbar-avatar:active {
  transform: scale(0.94);
}

.topbar-avatar[aria-current="page"] {
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--ink);
}

.account-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.account-avatar {
  display: grid;
  place-items: center;
  flex: none;
  inline-size: 3rem;
  block-size: 3rem;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: var(--on-ink);
  font-size: var(--text-lg);
  font-weight: 700;
}

.lang-switch {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--surface);
}

.lang-switch a {
  flex: 1;
  display: grid;
  place-items: center;
  min-block-size: 2.75rem;
  border-radius: var(--radius-pill);
  color: var(--muted);
  text-decoration: none;
}

.lang-switch a[aria-current] {
  background: var(--pressed);
  color: var(--ink-deep);
  font-weight: 700;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-block-size: 3.25rem;
  color: var(--ink-deep);
  text-decoration: none;
}

.setting-chevron {
  inline-size: 1.25rem;
  block-size: 1.25rem;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[dir="rtl"] .setting-chevron {
  transform: scaleX(-1);
}

.logout-button {
  inline-size: 100%;
  min-block-size: 3.25rem;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--margin);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* --- Login: a cover illustration (two gradient rings), the form on a sheet over it ---
   Phones: the cover runs edge to edge from the top of the screen. Wider screens: a card. */

.login-hero {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  min-block-size: min(26rem, 58svh);
  margin-block: var(--space-2) var(--space-5);
  border-radius: 1.75rem;
  background: #0e101c; /* the cover's own night blue, the same in light and dark mode */
  color: #ffffff;
  isolation: isolate;
}

.login-art {
  position: absolute;
  inset: 0;
  z-index: -1;
  inline-size: 100%;
  block-size: 100%;
  /* the rings melt into the night at the cover's foot instead of stopping on a line */
  mask-image: linear-gradient(to bottom, #000 62%, transparent 96%);
  animation: login-art-in 900ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes login-art-in {
  from {
    opacity: 0;
    transform: scale(1.06);
  }
}

.login-lang {
  position: absolute;
  inset-block-start: calc(var(--space-3) + env(safe-area-inset-top));
  inset-inline-end: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: rgb(255 255 255 / 0.12);
  backdrop-filter: blur(8px);
  color: #ffffff;
  font-size: var(--text-sm);
  text-decoration: none;
}

.login-copy {
  inline-size: 100%;
  padding: var(--space-6) var(--space-5) var(--space-5);
}

.login-copy h1 {
  margin: 0 0 var(--space-2);
  font-size: 2.5rem;
  line-height: 1.15;
}

.login-copy p {
  margin: 0;
  color: #a3acc4;
  font-size: var(--text-base);
}

@media (max-width: 40rem) {
  .page:has(> .login-hero) {
    padding-block-start: 0;
  }

  /* edge to edge from the top of the screen; its foot melts into the page */
  .login-hero {
    min-block-size: min(34rem, 60svh);
    margin-block: 0 var(--space-4);
    margin-inline: calc(-1 * var(--space-4));
    border-radius: 0;
  }
}

/* --- Cards: the login fields' thin light edge, on every card ------------ */

.facts,
.tile,
.recent,
.account-card,
.temp-password,
.preview,
.chart-ranges,
.lang-switch {
  box-shadow: inset 0 0 0 1px var(--edge);
}

.facts-total {
  box-shadow: var(--accent-glow);
}

.tile[open] {
  box-shadow: inset 0 0 0 1.5px var(--ink);
}

/* --- Settings: the app's signature at the foot of the page -------------- */

.app-signature {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  margin-block: var(--space-6) var(--space-2);
  color: var(--muted);
  font-size: var(--text-sm);
}

.app-signature img {
  inline-size: 3rem;
  block-size: 3rem;
  border-radius: 23.4%; /* the icon tile's own corner (15 / 64) */
  box-shadow: 0 0 0 1px var(--edge);
}
