/* Components: every reusable piece once. Pages compose these; they add no colours or sizes of their own.
   Index: card · hero · stat · button · segmented · badge · dot · bar · dial · track · approval · table · timeline
   · field · dialog · toast · empty · skeleton · code · kv · origin */

/* card */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-card); padding: 18px; min-width: 0; }
.card.flat { box-shadow: none; }
.card.link { display: block; color: inherit; transition: transform var(--t-card) var(--ease), box-shadow var(--t-card) var(--ease), border-color var(--t-card) var(--ease); }
.card.link:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-raised); border-color: var(--line-strong); }
.card-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.card-head > h3 { flex: 1 1 auto; min-width: 0; }
.app-ico { width: 40px; height: 40px; flex: none; border-radius: var(--r-md); display: grid; place-items: center; font-weight: 800; color: #fff; font-family: var(--font-en); font-size: 15px; }

/* hero: the dashboard's mission banner (art on the start side mirrored for LTR) */
.hero { position: relative; overflow: hidden; border-radius: var(--r-xl); min-height: 200px; display: flex; align-items: center; color: #F3FAFB; background: #0C242C; box-shadow: var(--shadow-card); }
/* the art is 3:1 with its scene in the left 45%: full height keeps the scene at the start and the calm part under the text */
.hero::before { content: ''; position: absolute; inset: 0; background: url('../img/hero.webp') left center / auto 100% no-repeat; }
html[dir="ltr"] .hero::before { transform: scaleX(-1); }
.hero::after { content: ''; position: absolute; inset: 0; background: var(--hero-scrim); }
html[dir="ltr"] .hero::after { transform: scaleX(-1); }
/* text on the start side (right in Persian, left in English); the art sits on the end side */
.hero-body { position: relative; z-index: 1; width: min(54%, 580px); padding: var(--sp-8); display: flex; flex-direction: column; gap: var(--sp-2); }
.hero h1 { font-size: 30px; line-height: 40px; }
.hero p { color: #A0BAC2; }
.hero .telemetry { position: absolute; z-index: 1; inset-inline: 0; bottom: 0; height: 2px; background: linear-gradient(90deg, transparent, #31E6CA, transparent); opacity: 0; animation: sweep 1.6s var(--ease-enter) 0.3s 1 both; }
@keyframes sweep { 0% { opacity: 0; transform: translateX(-60%); } 30% { opacity: 1; } 100% { opacity: 0; transform: translateX(60%); } }

/* stat */
.stat { display: flex; align-items: center; gap: var(--sp-3); min-height: 100px; padding: var(--sp-4); border-radius: 16px; border: 1px solid var(--line); background: var(--neutral-soft); }
.stat .stat-ico { width: 40px; height: 40px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--surface); color: var(--text-muted); flex: none; }
.stat .stat-ico .ico { width: 22px; height: 22px; }
.stat .value { font-family: var(--font-num); font-size: 28px; line-height: 34px; font-weight: 800; }
html[lang="fa"] .stat .value { font-family: var(--font-fa); }
.stat .label { font-size: var(--fs-small); line-height: var(--lh-small); color: var(--text-muted); }
.stat.live { background: var(--live-soft); } .stat.live .stat-ico { color: var(--live); }
.stat.warning { background: var(--warning-soft); } .stat.warning .stat-ico { color: var(--warning); }
.stat.danger { background: var(--danger-soft); } .stat.danger .stat-ico { color: var(--danger); }
.stat.primary { background: var(--primary-soft); } .stat.primary .stat-ico { color: var(--primary-ink); }

/* button */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); height: 40px; padding: 0 var(--sp-4);
  border-radius: var(--r-md); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 700; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background var(--t-button) var(--ease), border-color var(--t-button) var(--ease), transform var(--t-button) var(--ease), box-shadow var(--t-button) var(--ease);
}
.btn:hover { text-decoration: none; border-color: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
/* busy: an action is running (ui.js busy()); a spinner after the label, the button stays readable */
.btn[aria-busy="true"] { opacity: 0.85; cursor: progress; }
.btn[aria-busy="true"]::after { content: ''; width: 14px; height: 14px; flex: none; border-radius: 50%; border: 2px solid currentColor; border-inline-end-color: transparent; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn .ico { width: 18px; height: 18px; }
.btn.primary { background: var(--primary-strong); border-color: var(--primary-strong); color: #fff; box-shadow: 0 6px 16px -8px var(--primary); }
.btn.primary:hover { background: var(--primary); border-color: var(--primary); }
:root[data-theme="dark"] .btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 55%, transparent); background: var(--danger-soft); }
.btn.danger:hover { border-color: var(--danger); }
.btn.danger.solid { background: var(--danger-solid); color: #fff; border-color: var(--danger-solid); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--nav-hover-bg); color: var(--text); }
.btn.sm { height: 32px; padding: 0 var(--sp-3); font-size: var(--fs-small); border-radius: var(--r-sm); }
.btn.lg { height: 48px; padding: 0 var(--sp-6); font-size: 15px; }
.btn.block { width: 100%; }
.btn.icon { width: 40px; padding: 0; }

/* segmented switch (language, theme) */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--line); }
.seg button { height: 28px; min-width: 34px; padding: 0 10px; border: 0; border-radius: var(--r-pill); background: transparent; color: var(--text-muted); font-weight: 700; font-size: var(--fs-small); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: background var(--t-hover) var(--ease), color var(--t-hover) var(--ease); }
.seg button .ico { width: 16px; height: 16px; }
.seg button[aria-pressed="true"] { background: var(--primary-strong); color: #fff; box-shadow: 0 2px 8px -2px var(--primary); }
:root[data-theme="dark"] .seg button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }

/* badge (state pill) */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: var(--r-pill); font-size: var(--fs-small); font-weight: 700; white-space: nowrap; background: var(--neutral-soft); color: var(--text-muted); }
.badge .ico { width: 14px; height: 14px; }
.badge.live { background: var(--live-soft); color: var(--live); }
.badge.waiting, .badge.paused, .badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger, .badge.rolledBack, .badge.refused, .badge.expired { background: var(--danger-soft); color: var(--danger); }
.badge.info, .badge.replicating, .badge.internal { background: var(--info-soft); color: var(--info); }
.badge.primary { background: var(--primary-soft); color: var(--primary-ink); }
.count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--danger-solid); color: #fff; font-size: 11px; font-weight: 800; font-family: var(--font-num); }

/* dot: a live beacon */
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.dot.beacon { position: relative; }
.dot.beacon::after { content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid currentColor; opacity: 0; animation: beacon 2.4s var(--ease-enter) infinite; }
@keyframes beacon { 0% { opacity: 0.6; transform: scale(0.6); } 100% { opacity: 0; transform: scale(1.6); } }

/* bar: health (confirmed / rolled back / failed) and rollout */
.bar { position: relative; height: 6px; border-radius: var(--r-pill); background: var(--neutral-soft); overflow: hidden; display: flex; min-width: 60px; }
.bar > i { display: block; height: 100%; transition: width var(--t-bar) var(--ease-enter); }
.bar > i.ok { background: var(--live); } .bar > i.back { background: var(--warning-solid); } .bar > i.bad { background: var(--danger-solid); }
.bar > i.fill { background: linear-gradient(90deg, var(--primary-strong), var(--accent)); border-radius: var(--r-pill); }
.bar.warn > i.fill { background: var(--warning-solid); }
.health { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.health .bar { flex: 1 1 auto; }

/* dial: the rollout instrument (an SVG ring) */
.dial { position: relative; width: 132px; height: 132px; flex: none; }
.dial svg { width: 100%; height: 100%; transform: rotate(-90deg); }
html[dir="rtl"] .dial svg { transform: rotate(-90deg) scaleY(-1); }
.dial .track { stroke: var(--neutral-soft); }
.dial .arc { stroke: var(--primary); transition: stroke-dashoffset var(--t-dial) var(--ease-enter); filter: drop-shadow(0 0 6px color-mix(in srgb, var(--primary) 45%, transparent)); }
.dial.paused .arc { stroke: var(--warning-solid); filter: none; }
.dial .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.dial .center .num { font-size: 28px; line-height: 32px; font-weight: 800; }
.dial .center .label { font-size: var(--fs-small); color: var(--text-muted); }

/* range input (rollout) */
/* range: drawn here (Chrome derives a dark track from accent-color); --fill is the value in %, set by the view */
.range { width: 100%; height: 28px; -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer; }
.range::-webkit-slider-runnable-track { height: 6px; border-radius: var(--r-pill); background: linear-gradient(to right, var(--primary) var(--fill, 0%), var(--neutral-soft) var(--fill, 0%)); box-shadow: inset 0 0 0 1px var(--line); }
html[dir="rtl"] .range::-webkit-slider-runnable-track { background: linear-gradient(to left, var(--primary) var(--fill, 0%), var(--neutral-soft) var(--fill, 0%)); }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%; background: var(--primary); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--primary), var(--shadow-card); }
.range::-moz-range-track { height: 6px; border-radius: var(--r-pill); background: var(--neutral-soft); }
.range::-moz-range-progress { height: 6px; border-radius: var(--r-pill); background: var(--primary); }
.range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--primary); border: 3px solid var(--surface); }
.range:focus-visible { outline: none; }
.range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--focus); }

/* track: one row of an app card, and the big track panel of the app page */
.trackrow { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; border-top: 1px solid var(--line); min-width: 0; }
.trackrow:first-of-type { border-top: 0; }
.trackrow .where { min-width: 0; flex: 1 1 auto; }
.trackrow .where .mono { color: var(--text-muted); font-size: var(--fs-small); }
.trackrow .ver { font-size: 15px; font-weight: 800; }
.trackrow .bar { width: 72px; }
.trackrow.internal { margin-top: var(--sp-2); padding: var(--sp-3); border: 1px dashed color-mix(in srgb, var(--info) 55%, transparent); border-radius: var(--r-md); background: var(--info-soft); }
.tabs { display: flex; gap: var(--sp-2); overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; display: flex; flex-direction: column; gap: 2px; min-width: 200px; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; text-align: start; transition: border-color var(--t-hover) var(--ease), box-shadow var(--t-hover) var(--ease); }
.tab:hover { border-color: var(--line-strong); text-decoration: none; }
.tab[aria-selected="true"] { border: 2px solid var(--primary); box-shadow: 0 0 0 4px var(--focus); padding: calc(var(--sp-3) - 1px) calc(var(--sp-4) - 1px); }
.tab.internal { background: var(--info-soft); border-style: dashed; }
.trackpanel { display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(240px, 320px); gap: var(--sp-6); align-items: center; }
.trackpanel .controls { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
.slider { display: flex; align-items: center; gap: var(--sp-3); max-width: 420px; }
.slider > span:first-child { white-space: nowrap; }
.slider b { min-width: 3.5em; text-align: end; }
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
.metric { padding: var(--sp-3); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); text-align: center; }
.metric .num { font-size: 20px; line-height: 28px; font-weight: 800; }
.metric .label { font-size: var(--fs-micro); line-height: var(--lh-micro); color: var(--text-muted); font-weight: 600; }

/* approval: a waiting release, big and unmissable */
.approval { border-radius: var(--r-lg); padding: var(--sp-4) 18px; background: var(--warning-soft); border: 1px solid color-mix(in srgb, var(--warning-solid) 45%, transparent); display: flex; flex-direction: column; gap: var(--sp-3); }
.approval .what { display: flex; flex-direction: column; gap: 2px; }
.approval .actions { display: flex; gap: var(--sp-2); }
.approval .actions .btn { flex: 1 1 0; }
.approval .match { font-family: var(--font-num); font-weight: 800; font-size: 22px; }

/* table */
.table-wrap { overflow-x: auto; margin: 0 calc(-1 * var(--sp-1)); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th { text-align: start; color: var(--text-muted); font-weight: 600; font-size: var(--fs-small); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: var(--sp-3); border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--t-hover) var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table .wide { min-width: 200px; }

/* timeline: release history on phones (and a leading rail in the table) */
.rail { position: relative; width: 14px; }
.rail::before { content: ''; position: absolute; top: -14px; bottom: -14px; inset-inline-start: 6px; width: 2px; background: var(--line); }
.rail .node { position: relative; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--surface); }
.rail .node.live { border-color: var(--live); background: var(--live); box-shadow: 0 0 0 4px var(--live-soft); }
.rail .node.danger { border-color: var(--danger-solid); }
.timeline { display: none; flex-direction: column; }
.tl-item { display: grid; grid-template-columns: 14px minmax(0, 1fr); gap: var(--sp-3); padding: var(--sp-3) 0; }
.tl-item .tl-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
@media (max-width: 760px) {
  .history .table-wrap { display: none; }
  .timeline { display: flex; }
  /* the hero stacks on phones: the art as a band on top, the text under it */
  .hero { flex-direction: column; align-items: stretch; min-height: 0; }
  .hero::before { background-position: left top; background-size: auto 160px; }
  .hero::after { background: linear-gradient(180deg, #0C242C00 70px, #0C242C 160px); }
  .hero-body { width: 100%; padding: 128px var(--sp-5) var(--sp-5); }
  .hero h1 { font-size: 24px; line-height: 32px; }
  .trackpanel { grid-template-columns: minmax(0, 1fr); justify-items: stretch; }
  .trackpanel .dial { justify-self: center; }
}

/* field */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.row > .field { flex: 1 1 0; }
.field > span { font-size: var(--fs-small); color: var(--text-muted); font-weight: 600; }
.input, .select, .textarea {
  width: 100%; height: 44px; padding: 0 var(--sp-3); border-radius: var(--r-md); border: 1px solid var(--line-strong);
  background: var(--surface-2); color: var(--text); transition: border-color var(--t-hover) var(--ease), box-shadow var(--t-hover) var(--ease);
}
.textarea { height: auto; min-height: 120px; padding: var(--sp-3); resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--focus); }
.input.ltr, .textarea.ltr { direction: ltr; text-align: left; font-family: var(--font-num); }
.check { display: flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.otp { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--sp-2); direction: ltr; }
.otp input { height: 52px; text-align: center; font-family: var(--font-num); font-size: 22px; font-weight: 800; border-radius: var(--r-md); border: 1px solid var(--line-strong); background: var(--surface-2); }
.otp input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--focus); }
.error { color: var(--danger); font-size: var(--fs-small); min-height: 20px; }

/* sign-in pieces */
.steps { display: flex; flex-direction: column; gap: var(--sp-3); }
.step { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface-2); }
.step .n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-ink); font-weight: 800; font-size: var(--fs-small); flex: none; }
.step.done .n { background: var(--live); color: #fff; }
.match-box { display: flex; align-items: center; justify-content: center; gap: var(--sp-4); padding: var(--sp-5); border-radius: var(--r-lg); border: 2px solid var(--primary); background: var(--primary-soft); }
.match-box .num { font-size: 56px; line-height: 60px; font-weight: 900; color: var(--primary-ink); letter-spacing: 2px; }
.match-box .ico { width: 34px; height: 34px; color: var(--primary-ink); }
.or { display: flex; align-items: center; gap: var(--sp-3); color: var(--text-subtle); font-size: var(--fs-small); }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* dialog */
.dialog { width: min(560px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: var(--r-xl); padding: var(--sp-6); background: var(--surface); color: var(--text); box-shadow: var(--shadow-overlay); }
.dialog::backdrop { background: #06171D99; backdrop-filter: blur(4px); }
.dialog form { display: flex; flex-direction: column; gap: var(--sp-4); }

/* toast */
.toasts { position: fixed; z-index: 60; inset-inline: 0; bottom: var(--sp-6); display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: var(--sp-2); max-width: min(520px, calc(100vw - 32px)); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); background: var(--surface-raised); border: 1px solid var(--line); box-shadow: var(--shadow-raised); font-weight: 600; animation: toast-in 260ms var(--ease-enter); }
.toast .ico { width: 18px; height: 18px; color: var(--live); flex: none; }
.toast.bad .ico { color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
@media (max-width: 760px) { .toasts { bottom: calc(var(--bottomnav-h) + 16px + env(safe-area-inset-bottom)); } }

/* empty, skeleton */
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); padding: var(--sp-8) var(--sp-4); text-align: center; color: var(--text-muted); }
.empty .ico { width: 36px; height: 36px; color: var(--text-subtle); }
.skeleton { border-radius: var(--r-lg); background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; min-height: 120px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* code, key-value lists */
.code { direction: ltr; text-align: left; font-family: var(--font-num); font-size: 12.5px; line-height: 20px; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); overflow-x: auto; white-space: pre; margin: 0; }
.pairs { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-4); font-size: var(--fs-small); white-space: normal; }
.pairs > span { display: inline-flex; gap: 6px; align-items: baseline; }
.kv { display: flex; flex-direction: column; }
.kv > div { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) 0; border-top: 1px solid var(--line); }
.kv > div:first-child { border-top: 0; }
.kv .k { color: var(--text-muted); font-size: var(--fs-small); flex: none; min-width: 120px; }
.kv .v { min-width: 0; flex: 1 1 auto; }
details.fold > summary { display: flex; align-items: center; gap: var(--sp-2); cursor: pointer; color: var(--text-muted); font-size: var(--fs-small); list-style: none; }
/* a chevron that points along the reading direction when closed and down when open */
details.fold > summary::before { content: ''; flex: none; width: 7px; height: 7px; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(-45deg); transition: transform var(--t-hover) var(--ease); }
html[dir="rtl"] details.fold:not([open]) > summary::before { transform: rotate(135deg); }
details.fold[open] > summary::before { transform: rotate(45deg); }
details.card.fold > summary { color: var(--text); font-size: var(--fs-body); font-weight: 700; }
details.card.fold[open] > summary { margin-bottom: var(--sp-4); }
details.fold > summary::-webkit-details-marker { display: none; }
.files { max-height: 200px; overflow: auto; margin-top: var(--sp-2); }

/* origin card */
.origin .big { display: flex; align-items: flex-start; gap: var(--sp-3); }
.origin .figure .value small { font-size: var(--fs-small); font-weight: 600; color: var(--text-muted); }
.origin .logo { width: 48px; height: 48px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--surface-2); }
.origin .logo .ico { width: 28px; height: 28px; }
.origin .figures { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); padding: var(--sp-3) 0; border-block: 1px solid var(--line); }
.origin .figure .value { font-size: 20px; line-height: 30px; font-weight: 800; }
.origin .figure .label { font-size: var(--fs-small); color: var(--text-muted); }
.origin .copies { display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow: auto; }
.origin .copies > div { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.origin.reference { background: linear-gradient(160deg, var(--surface), var(--surface-2)); border-style: dashed; }
