/* ===================================================================
   ارزکس — Mini App
   جهت‌گیری طراحی: «تابلوی صرافی» — الهام از تابلوهای فلپ مکانیکی
   صرافی‌های خیابان فردوسی: تخت، خطی، بدون سایه‌ی اضافه، اعداد در
   مرکز توجه. هر ردیف قیمت یک خط از آن تابلوست؛ وقتی عدد عوض می‌شود،
   مثل یک تیغه‌ی فلزی می‌چرخد و جای خودش می‌نشیند.

   پالت (۶ رنگ نام‌گذاری‌شده):
     --ink      #0D0F13   زمینه‌ی اصلی (مشکی گرم، نه خالص)
     --panel    #14171D   نوار تابلو / هدر / اسکلتون
     --brass    #CDA43B   رنگ برند — برنج/طلای مات تابلوهای قدیمی
     --rise     #4FAE7A   افزایش (سبز پتینه، نه سبز اشباع)
     --fall     #D6604A   کاهش (قرمزآجری گرم)
     --paper    #F1EEE7   متن اصلی (سفید کاغذی، نه سفید خالص)
   =================================================================== */

:root {
  --bg:     var(--tg-theme-bg-color, #0D0F13);
  --panel:  var(--tg-theme-secondary-bg-color, #14171D);
  --raised: var(--tg-theme-section-bg-color, #191D24);
  --text:   var(--tg-theme-text-color, #F1EEE7);
  --hint:   var(--tg-theme-hint-color, #8B887F);
  --line:   rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);

  --brass:      #CDA43B;
  --brass-soft: rgba(205, 164, 59, 0.15);
  --rise:       #4FAE7A;
  --rise-soft:  rgba(79, 174, 122, 0.15);
  --fall:       #D6604A;
  --fall-soft:  rgba(214, 96, 74, 0.15);

  --bar: 58px;
  --radius: 12px;
  --radius-full: 999px;
  --vh: 100dvh;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  overscroll-behavior-y: contain;
}

#app {
  min-height: var(--vh);
  display: flex;
  flex-direction: column;
}

button { font-family: inherit; }

/* ---------------- Topbar ---------------- */

.topbar {
  height: var(--bar);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 8px; }

.brand-word {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .4px;
  background: linear-gradient(90deg, var(--brass), #E9CD84 55%, var(--brass));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.pulse {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--rise-soft);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.pulse-core {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--rise);
  animation: pulse-beat 2.2s ease-in-out infinite;
}
@keyframes pulse-beat {
  0%, 100% { transform: scale(1); opacity: 1; box-shadow: 0 0 0 0 rgba(79,174,122,.5); }
  50%      { transform: scale(1.15); opacity: .85; box-shadow: 0 0 0 4px rgba(79,174,122,0); }
}

.updated {
  font-size: 10.5px;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
}

/* ---------------- Board strip (نبض بازار / سیگنیچر) ---------------- */

.board-strip {
  flex-shrink: 0;
  overflow: hidden;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 6px 0;
  position: relative;
  mask-image: linear-gradient(to left, transparent 0, black 22px, black calc(100% - 22px), transparent 100%);
}

/* بافت ظریفِ خطوط افقی، یادآور صفحه‌نمایش‌های LED تابلوهای قدیمی */
.board-strip::after {
  content: '';
  position: absolute; inset: 0;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,.18) 0 1px, transparent 1px 3px);
  pointer-events: none;
  opacity: .35;
}

.board-track {
  display: flex;
  width: max-content;
  gap: 0;
  animation: board-scroll 26s linear infinite;
}
.board-strip.paused .board-track { animation-play-state: paused; }

@keyframes board-scroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

.board-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--hint);
  padding: 0 14px;
  border-inline-start: 1px dotted var(--line-2);
}
.board-item:first-child { border-inline-start: none; }
.board-item b { color: var(--text); font-weight: 700; }
.board-item i { font-style: normal; }
.board-item .chg { font-weight: 700; }
.board-item .chg.up { color: var(--rise); }
.board-item .chg.down { color: var(--fall); }

/* ---------------- Content ---------------- */

.content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  touch-action: pan-y;
}

/* ---------------- Board list & rows ---------------- */

.board-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0;
  padding: 2px 12px 18px;
  list-style: none;
  transition: transform .25s cubic-bezier(.22,.9,.32,1);
}

.content.dragging .board-list,
.content.dragging .empty { transition: none; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 2px;
  position: relative;
  opacity: 0;
  transform: translateY(6px);
  animation: row-in .32s cubic-bezier(.22,.9,.32,1) forwards;
}
.row:not(:first-child) { border-top: 1px dotted var(--line-2); }
.row:active { background: rgba(255,255,255,.025); }

@keyframes row-in { to { opacity: 1; transform: translateY(0); } }

.row .id { display: flex; align-items: center; gap: 10px; min-width: 0; }

.tag {
  flex-shrink: 0;
  min-width: 34px;
  height: 26px;
  padding: 0 6px;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--brass);
  letter-spacing: .2px;
}

.names { min-width: 0; }
.name { display: block; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.code { display: block; font-size: 10.5px; color: var(--hint); direction: ltr; text-align: right; }

.figures { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.fav {
  appearance: none; border: none; background: transparent;
  color: var(--line-2);
  padding: 6px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  border-radius: 50%;
}
.fav svg { width: 18px; height: 18px; transition: transform .25s cubic-bezier(.34,1.56,.64,1), color .2s ease; }
.fav.active svg { color: var(--brass); fill: var(--brass-soft); transform: scale(1.1); }
.fav:active svg { transform: scale(.82); }

/* زنگوله‌ی هشدار قیمت — همان قاعده‌ی بصری fav، رنگ متفاوت وقتی فعاله */
.bell {
  appearance: none; border: none; background: transparent;
  color: var(--line-2);
  padding: 6px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  border-radius: 50%;
}
.bell svg { width: 17px; height: 17px; transition: transform .2s cubic-bezier(.34,1.56,.64,1), color .2s ease; }
.bell.active svg { color: var(--rise); fill: var(--rise-soft); }
.bell:active svg { transform: scale(.82); }
.bell.active::after {
  content: '';
  position: absolute; top: 5px; left: 7px;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--rise);
  box-shadow: 0 0 0 2px var(--panel);
}

/* حلقه‌ی مهرِ برنجی — لحظه‌ی افزودن به برگزیده، شبیه مهر خوردن روی تابلو */
.fav.stamp::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--brass);
  opacity: .9;
  animation: stamp-ring .5s ease-out forwards;
}
@keyframes stamp-ring {
  from { transform: scale(.5); opacity: .9; }
  to   { transform: scale(1.9); opacity: 0; }
}

.pct {
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 3px 6px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.pct.up   { color: var(--rise); background: var(--rise-soft); }
.pct.down { color: var(--fall); background: var(--fall-soft); }

.amounts { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; min-width: 76px; }

.amount {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 14.5px;
  transform-origin: 50% 100%;
}
.amount.flip-up   { animation: flip-tile .5s ease; color: var(--rise); }
.amount.flip-down { animation: flip-tile .5s ease; color: var(--fall); }

/* سیگنیچر: افکت «فلپ» یک تیغه‌ی تابلوی مکانیکی هنگام تغییر قیمت */
@keyframes flip-tile {
  0%   { transform: perspective(240px) rotateX(0deg); }
  45%  { transform: perspective(240px) rotateX(-18deg); }
  100% { transform: perspective(240px) rotateX(0deg); }
}

.usd {
  font-size: 10px;
  font-weight: 500;
  color: var(--hint);
  direction: ltr;
}

/* ---------------- Skeleton ---------------- */

.skeleton-row {
  height: 46px;
  margin: 8px 2px;
  border-radius: 8px;
  background: linear-gradient(100deg, var(--panel) 30%, var(--raised) 50%, var(--panel) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  list-style: none;
}
@keyframes shimmer {
  from { background-position: 150% 0; }
  to   { background-position: -50% 0; }
}

/* ---------------- Empty & error states ---------------- */

.empty, .fetch-error {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  padding: 30px;
  color: var(--hint);
  transition: transform .25s cubic-bezier(.22,.9,.32,1);
}
.empty-icon { color: var(--brass); margin-bottom: 4px; }
.empty p, .fetch-error p { color: var(--text); font-weight: 600; font-size: 13.5px; margin: 0; }
.empty span { font-size: 12px; }

.fetch-error button {
  margin-top: 10px;
  border: 1px solid var(--brass);
  color: var(--brass);
  background: transparent;
  padding: 8px 18px;
  border-radius: var(--radius-full);
  font-size: 12.5px;
  font-weight: 700;
}
.fetch-error button:active { background: var(--brass-soft); }

/* ---------------- Tabbar ---------------- */

.tabbar {
  height: calc(var(--bar) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  flex-shrink: 0;
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--line);
  z-index: 5;
}

.tab {
  appearance: none; border: none; background: transparent;
  color: var(--hint);
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  position: relative;
}

.tab-icon-wrap { display: flex; transition: transform .2s cubic-bezier(.34,1.56,.64,1); }
.tab-label { font-size: 10px; font-weight: 600; transition: color .2s ease; }

.tab.active { color: var(--brass); }
.tab.active .tab-label { color: var(--brass); font-weight: 700; }
.tab.active .tab-icon-wrap { transform: translateY(-1px); }
.tab:active .tab-icon-wrap { transform: scale(.88); }

/* خط شاخص زیر تب فعال، به‌جای پس‌زمینه‌ی پیل — سازگارتر با زبان بصری تابلو */
.tab::before {
  content: '';
  position: absolute; top: -1px; left: 20%; right: 20%;
  height: 2px;
  background: var(--brass);
  border-radius: 2px;
  transform: scaleX(0);
  transition: transform .22s cubic-bezier(.4,0,.2,1);
}
.tab.active::before { transform: scaleX(1); }

/* ---------------- Compact mode (Telegram viewport کوچک) ---------------- */

@media (max-height: 480px) {
  .board-strip { display: none; }
  :root { --bar: 48px; }
}

/* ---------------- کاهش انیمیشن ---------------- */

@media (prefers-reduced-motion: reduce) {
  .board-track { animation: none; }
  .row { animation: none; opacity: 1; transform: none; }
  .skeleton-row { animation: none; }
  .amount.flip-up, .amount.flip-down { animation: none; }
  .pulse-core { animation: none; }
  .fav.stamp::after { animation: none; display: none; }
}

/* ---------------- شیت هشدار قیمت ---------------- */

.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end;
  z-index: 20;
  opacity: 0;
  transition: opacity .2s ease;
}
.sheet-overlay.show { opacity: 1; }

.sheet {
  width: 100%;
  background: var(--panel);
  border-top: 1px solid var(--line-2);
  border-radius: 18px 18px 0 0;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.22,.9,.32,1);
}
.sheet-overlay.show .sheet { transform: translateY(0); }

.sheet-handle {
  width: 36px; height: 4px;
  background: var(--line-2);
  border-radius: 2px;
  margin: 4px auto 14px;
}

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.sheet-title { font-size: 15px; font-weight: 700; }
.sheet-sub { font-size: 12px; color: var(--hint); margin: 0 0 14px; }

.sheet-input {
  width: 100%;
  background: var(--raised);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 13px 14px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  text-align: center;
  margin-bottom: 14px;
}
.sheet-input:focus { outline: none; border-color: var(--brass); }

.sheet-actions { display: flex; gap: 8px; }
.sheet-btn {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 13.5px;
  font-weight: 700;
  font-family: inherit;
}
.sheet-btn.primary { background: var(--brass); color: #1a1406; }
.sheet-btn.primary:active { opacity: .85; }
.sheet-btn.danger { background: var(--fall-soft); color: var(--fall); }
.sheet-btn.danger:active { opacity: .85; }

.sheet-cancel {
  display: block;
  width: 100%;
  background: transparent; border: none;
  color: var(--hint);
  font-family: inherit;
  font-size: 13px;
  padding: 12px;
  margin-top: 2px;
}
