:root {
  --paper: #EDE7D8;
  --paper-deep: #E4DCC8;
  --line: rgba(27, 42, 61, 0.10);
  --ink: #1B2A3D;
  --ink-soft: #5B6B7A;
  --ink-faint: #8B96A3;
  --gold: #B8873A;
  --gold-deep: #8F6524;
  --gold-light: #D4A574;
  --teal: #2F6F63;
  --teal-deep: #1F4E45;
  --rust: #A63D40;
  --rust-deep: #7E2C2E;
  --card: #F8F4E9;
  --card-border: rgba(27, 42, 61, 0.10);
  --navy: #3B5B7A;
  --shadow: 0 2px 10px rgba(27, 42, 61, 0.08);
  --sidebar-bg: linear-gradient(180deg, #1B2A3D 0%, #223247 100%);
  --sidebar-text: #EFE9D8;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --input-bg: #fff;
  --input-border: rgba(27, 42, 61, 0.10);
  --text-primary: #1B2A3D;
  --text-secondary: #5B6B7A;
  --text-muted: #8B96A3;
  --chart-grid: rgba(27, 42, 61, 0.08);
  --hover-bg: rgba(27, 42, 61, 0.04);
  --bg-gradient: repeating-linear-gradient(var(--paper), var(--paper) 37px, var(--line) 38px);
  --auth-bg: linear-gradient(135deg, #1B2A3D 0%, #1F4E45 55%, #8F6524 100%);
  --auth-card-bg: rgba(248, 244, 233, 0.88);
  --auth-border: rgba(255, 255, 255, 0.5);
  --loading-bg: rgba(237, 231, 216, 0.85);
  --trend-loading-bg: rgba(248, 244, 233, 0.94);
  --badge-ok: rgba(47, 111, 99, 0.14);
  --badge-over: rgba(166, 61, 64, 0.13);
  --badge-under: rgba(184, 135, 58, 0.15);
  --legend-hover: rgba(184, 135, 58, 0.08);
  --drill-active: rgba(184, 135, 58, 0.12);
}

/* ================= DARK THEME ================= */
[data-theme="dark"] {
  --paper: #1A1A2E;
  --paper-deep: #16213E;
  --line: rgba(255, 255, 255, 0.08);
  --ink: #EAEAEA;
  --ink-soft: #A8A8B8;
  --ink-faint: #6A6A7A;
  --gold: #D4A574;
  --gold-deep: #B8873A;
  --gold-light: #E8C99B;
  --teal: #4A9E8E;
  --teal-deep: #2F6F63;
  --rust: #D45A5A;
  --rust-deep: #A63D40;
  --card: #1E1E3A;
  --card-border: rgba(255, 255, 255, 0.08);
  --navy: #5A7A9A;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  --sidebar-bg: linear-gradient(180deg, #0D0D1A 0%, #16213E 100%);
  --sidebar-text: #EAEAEA;
  --sidebar-hover: rgba(255, 255, 255, 0.08);
  --input-bg: #2A2A4A;
  --input-border: rgba(255, 255, 255, 0.12);
  --text-primary: #EAEAEA;
  --text-secondary: #A8A8B8;
  --text-muted: #6A6A7A;
  --chart-grid: rgba(255, 255, 255, 0.06);
  --hover-bg: rgba(255, 255, 255, 0.05);
  --bg-gradient: repeating-linear-gradient(var(--paper), var(--paper) 37px, var(--line) 38px);
  --auth-bg: linear-gradient(135deg, #0D0D1A 0%, #1A1A2E 55%, #16213E 100%);
  --auth-card-bg: rgba(30, 30, 58, 0.92);
  --auth-border: rgba(255, 255, 255, 0.15);
  --loading-bg: rgba(26, 26, 46, 0.85);
  --trend-loading-bg: rgba(30, 30, 58, 0.94);
  --badge-ok: rgba(74, 158, 142, 0.2);
  --badge-over: rgba(212, 90, 90, 0.2);
  --badge-under: rgba(212, 165, 116, 0.2);
  --legend-hover: rgba(212, 165, 116, 0.12);
  --drill-active: rgba(212, 165, 116, 0.15);
}

* {
  box-sizing: border-box;
  font-family: 'Vazirmatn', sans-serif;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

.num-en {
  font-family: 'JetBrains Mono', 'Vazirmatn', monospace;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: right;
}

.num-fa {
  font-family: 'Vazirmatn', sans-serif;
  direction: rtl;
  unicode-bidi: isolate;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* ================= SIDEBAR ================= */
.sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 28px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width .2s ease, padding .2s ease, transform .25s ease, background 0.3s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 34px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 46px;
}

.brand-text {
  flex: 1;
  min-width: 0;
}

.brand-text h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 800;
  letter-spacing: .2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--sidebar-text);
}

.brand-text span {
  font-size: 11px;
  color: #B7C2CE;
  font-family: 'JetBrains Mono', monospace;
  direction: ltr;
  display: block;
  letter-spacing: 1px;
}

[data-theme="dark"] .brand-text span {
  color: #6A6A7A;
}

.sidebar-toggle {
  all: unset;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 30px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--sidebar-text);
  font-size: 15px;
  transition: background 0.2s;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.16);
}

nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  all: unset;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #CBD5DE;
  border-inline-start: 3px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}

[data-theme="dark"] .nav-item {
  color: #A8A8B8;
}

.nav-item .ic {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex: 0 0 20px;
}

.nav-item .label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.nav-item.active {
  background: rgba(184, 135, 58, 0.16);
  color: #F3E4C4;
  border-inline-start-color: var(--gold);
  font-weight: 700;
}

[data-theme="dark"] .nav-item.active {
  background: rgba(212, 165, 116, 0.15);
  color: var(--gold-light);
}

.sidebar-footer {
  font-size: 11.5px;
  color: #8FA0AE;
  line-height: 1.9;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 14px;
  margin-top: 10px;
}

[data-theme="dark"] .sidebar-footer {
  color: #6A6A7A;
  border-top-color: rgba(255, 255, 255, 0.06);
}

.sidebar.collapsed {
  width: 76px;
  flex-basis: 76px;
  padding: 28px 12px;
}

.sidebar.collapsed .brand {
  justify-content: center;
}

.sidebar.collapsed .brand-text {
  display: none;
}

.sidebar.collapsed .sidebar-toggle {
  position: absolute;
  top: 14px;
  left: 8px;
}

.sidebar.collapsed nav .nav-item {
  justify-content: center;
  padding: 12px 0;
}

.sidebar.collapsed .nav-item .label {
  display: none;
}

.sidebar.collapsed .sidebar-footer {
  display: none;
}

/* ================= CONTENT ================= */
.content {
  flex: 1;
  padding: 36px 44px;
  max-width: 1180px;
  background-image: var(--bg-gradient);
  background-attachment: local;
  transition: background-image 0.3s ease;
}

.page {
  display: none;
  animation: fade .25s ease;
}

.page.active {
  display: block;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h2 {
  font-size: 22px;
  margin: 0;
  font-weight: 800;
  color: var(--text-primary);
}

.page-header .eyebrow {
  font-size: 12px;
  color: var(--ink-soft);
  font-family: 'JetBrains Mono', monospace;
  direction: ltr;
  letter-spacing: 1px;
}

/* ================= CARDS ================= */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 22px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.card h3 {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.card h3 small {
  font-weight: 400;
  color: var(--ink-faint);
  font-size: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}

/* ================= HERO TOTAL ================= */
.hero-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(120deg, var(--ink) 0%, #28405A 100%);
  color: #F3ECD8;
  border-radius: 14px;
  padding: 26px 30px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  transition: background 0.3s ease;
}

[data-theme="dark"] .hero-total {
  background: linear-gradient(120deg, #0D0D1A 0%, #1A1A2E 100%);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.hero-total .label {
  font-size: 13px;
  color: #C9D2DA;
  margin-bottom: 6px;
}

[data-theme="dark"] .hero-total .label {
  color: #A8A8B8;
}

.hero-total .value {
  font-size: 34px;
  font-weight: 800;
}

.hero-total .value small {
  font-size: 15px;
  font-weight: 500;
  color: #D9B36A;
  margin-inline-start: 6px;
}

[data-theme="dark"] .hero-total .value small {
  color: var(--gold-light);
}

.hero-inline-metrics {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.hero-metric {
  flex: 1;
  min-width: 200px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-right: 4px solid #2F6F63;
  border-radius: 12px;
  padding: 16px 20px;
  box-shadow: var(--shadow);
  transition: background 0.3s ease, border-color 0.3s ease;
}

.hero-metric#usdMetric {
  border-right-color: #2F6F63;
}

.hero-metric#goldMetric {
  border-right-color: #D4A574;
}

.hero-metric .label {
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 500;
}

.hero-metric .value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
}

.hero-total .mark {
  font-size: 40px;
  opacity: .35;
}

/* ================= TABLES ================= */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th {
  text-align: right;
  padding: 9px 8px;
  color: var(--ink-soft);
  font-weight: 600;
  border-bottom: 2px solid var(--line);
  font-size: 12.5px;
}

td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  color: var(--text-primary);
}

tr:last-child td {
  border-bottom: none;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -2px;
}

.table-scroll table {
  min-width: 680px;
}

.table-scroll.holdings-scroll table {
  min-width: 520px;
}

/* ================= INPUTS ================= */
input[type=text],
input[type=number],
input[type=password] {
  font-family: inherit;
  font-size: 13.5px;
  padding: 7px 9px;
  border: 1px solid var(--input-border);
  border-radius: 7px;
  background: var(--input-bg);
  color: var(--text-primary);
  width: 100%;
  transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

input[type=text]:focus,
input[type=number]:focus,
input[type=password]:focus {
  border-color: var(--gold);
  outline: none;
}

input[type=number] {
  font-family: 'Vazirmatn', sans-serif;
  direction: rtl;
}

select {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--input-border);
  border-radius: 7px;
  background: var(--input-bg);
  color: var(--text-primary);
  width: 100%;
  cursor: pointer;
  transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

select:focus {
  border-color: var(--gold);
  outline: none;
}

[data-theme="dark"] select option {
  background: #1A1A2E;
  color: #EAEAEA;
}

input[type=color] {
  width: 38px;
  height: 30px;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  padding: 2px;
  background: var(--input-bg);
  transition: background 0.3s ease, border-color 0.3s ease;
}

/* ================= BUTTONS ================= */
button.btn {
  all: unset;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 8px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, background .15s, color .15s;
  display: inline-block;
}

button.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(27, 42, 61, 0.16);
}

button.btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow);
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-deep)) !important;
  color: #fff !important;
}

.btn-gold:hover {
  background: linear-gradient(135deg, var(--gold-deep), var(--gold-deep)) !important;
}

.btn-green {
  background: #8FD3B0 !important;
  color: #12362A !important;
}

[data-theme="dark"] .btn-green {
  background: #4A9E8E !important;
  color: #fff !important;
}

.btn-green:hover {
  background: #7BC9A0 !important;
}

[data-theme="dark"] .btn-green:hover {
  background: #3A8E7E !important;
}

.btn-lg {
  padding: 11px 22px;
  font-size: 14px;
}

.btn-outline {
  background: #D9E7F5 !important;
  border: 1px solid #7FA5C9 !important;
  color: #2A4A66 !important;
}

[data-theme="dark"] .btn-outline {
  background: #2A2A4A !important;
  border-color: #5A7A9A !important;
  color: #A8A8B8 !important;
}

.btn-outline:hover {
  background: #C6DAEE !important;
}

[data-theme="dark"] .btn-outline:hover {
  background: #3A3A5A !important;
}

.btn-danger {
  background: transparent;
  color: var(--rust);
  border: 1px solid var(--rust);
  padding: 5px 10px;
  font-size: 12px;
}

.btn-danger:hover {
  background: rgba(166, 61, 64, 0.08);
}

[data-theme="dark"] .btn-danger:hover {
  background: rgba(212, 90, 90, 0.15);
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

/* Theme toggle button */
.btn-theme {
  all: unset;
  cursor: pointer;
  font-size: 18px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--sidebar-text);
  transition: background 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-theme:hover {
  background: rgba(255, 255, 255, 0.16);
  transform: scale(1.05);
}

.btn-theme:active {
  transform: scale(0.95);
}

/* ================= BADGES ================= */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
}

.badge-buy {
  background: var(--badge-ok);
  color: var(--teal-deep);
}

[data-theme="dark"] .badge-buy {
  color: #4A9E8E;
}

.badge-sell {
  background: var(--badge-over);
  color: var(--rust-deep);
}

[data-theme="dark"] .badge-sell {
  color: #D45A5A;
}

.badge-ok {
  background: rgba(139, 150, 163, 0.16);
  color: var(--ink-soft);
}

/* ================= MISC ================= */
.muted {
  color: var(--ink-faint);
  font-size: 12.5px;
}

.warn-line {
  font-size: 12.5px;
  color: var(--rust-deep);
  margin-top: 10px;
}

[data-theme="dark"] .warn-line {
  color: #D45A5A;
}

.ok-line {
  font-size: 12.5px;
  color: var(--teal-deep);
  margin-top: 10px;
}

[data-theme="dark"] .ok-line {
  color: #4A9E8E;
}

.empty {
  text-align: center;
  padding: 40px 10px;
  color: var(--ink-faint);
}

.empty .mark {
  font-size: 30px;
  margin-bottom: 8px;
}

.file-input-wrap {
  position: relative;
  display: inline-block;
}

.file-input-wrap input[type=file] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
}

.file-input-wrap:hover button.btn {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(27, 42, 61, 0.16);
}

.file-input-wrap:hover .btn-outline {
  background: #C6DAEE !important;
}

[data-theme="dark"] .file-input-wrap:hover .btn-outline {
  background: #3A3A5A !important;
}

canvas {
  max-width: 100%;
}

.chart-box {
  position: relative;
  height: 280px;
}

/* ================= PERCENT BARS ================= */
.pct-bars {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-top: 4px;
}

.pct-row-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.pct-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 10px;
}

.pct-name {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.pct-values {
  font-size: 12px;
  color: var(--ink-soft);
  font-family: 'Vazirmatn', sans-serif;
  direction: rtl;
  margin-right: auto;
}

.pct-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 20px;
}

.pct-badge.ok {
  background: var(--badge-ok);
  color: var(--teal-deep);
  border: 1px solid rgba(47, 111, 99, 0.3);
}

[data-theme="dark"] .pct-badge.ok {
  color: #4A9E8E;
  border-color: rgba(74, 158, 142, 0.3);
}

.pct-badge.over {
  background: var(--badge-over);
  color: var(--rust-deep);
  border: 1px solid rgba(166, 61, 64, 0.35);
}

[data-theme="dark"] .pct-badge.over {
  color: #D45A5A;
  border-color: rgba(212, 90, 90, 0.35);
}

.pct-badge.under {
  background: var(--badge-under);
  color: var(--gold-deep);
  border: 1px solid rgba(184, 135, 58, 0.4);
}

[data-theme="dark"] .pct-badge.under {
  color: var(--gold-light);
  border-color: rgba(212, 165, 116, 0.4);
}

.pct-track {
  position: relative;
  height: 14px;
  border-radius: 7px;
  background: rgba(27, 42, 61, 0.08);
  overflow: visible;
  direction: ltr;
}

[data-theme="dark"] .pct-track {
  background: rgba(255, 255, 255, 0.08);
}

.pct-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  border-radius: 7px;
  transition: width .3s ease;
}

.pct-target-line {
  position: absolute;
  top: -4px;
  width: 2px;
  height: 22px;
  background: var(--ink);
  border-radius: 1px;
}

.pct-target-line::after {
  content: '';
  position: absolute;
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--ink);
}

/* ================= ASSET TOGGLE ================= */
.asset-toggle {
  all: unset;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: rgba(59, 91, 122, 0.12);
  color: var(--navy);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  line-height: 1;
  transition: background .15s;
}

[data-theme="dark"] .asset-toggle {
  background: rgba(90, 122, 154, 0.15);
  color: #5A7A9A;
}

.asset-toggle:hover {
  background: rgba(59, 91, 122, 0.22);
}

.asset-toggle.open {
  background: var(--navy);
  color: #fff;
}

[data-theme="dark"] .asset-toggle.open {
  background: #5A7A9A;
  color: #fff;
}

.readonly-amount {
  font-family: 'Vazirmatn', sans-serif;
  direction: rtl;
  color: var(--ink-soft);
  background: rgba(27, 42, 61, 0.05);
  padding: 8px 10px;
  border-radius: 7px;
  display: block;
  width: 100%;
}

[data-theme="dark"] .readonly-amount {
  background: rgba(255, 255, 255, 0.05);
  color: #A8A8B8;
}

/* ================= HOLDINGS ================= */
.holdings-row td {
  background: rgba(184, 135, 58, 0.06);
  padding: 16px 18px 20px;
  border-bottom: 1px solid var(--line);
}

[data-theme="dark"] .holdings-row td {
  background: rgba(212, 165, 116, 0.06);
}

table.holdings-table {
  width: 100%;
  font-size: 12.5px;
}

table.holdings-table th {
  font-size: 11px;
  padding: 5px 6px;
  color: var(--ink-soft);
}

table.holdings-table td {
  padding: 5px 6px;
  color: var(--text-primary);
}

.holdings-line-total {
  font-family: 'Vazirmatn', sans-serif;
  direction: rtl;
  color: var(--ink-soft);
}

.holdings-total-line {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: right;
  direction: rtl;
  font-family: 'Vazirmatn', sans-serif;
}

/* ================= LOADING ================= */
.page-loading {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  background: var(--loading-bg);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  border-radius: 12px;
  transition: background 0.3s ease;
}

.trend-chart-shell {
  position: relative;
  overflow: hidden;
}

.trend-loading {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 5;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--trend-loading-bg);
  backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
  transition: background 0.3s ease;
}

.trend-loading.show {
  display: flex;
}

.trend-loading .spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(27, 42, 61, 0.15);
  border-top-color: var(--gold-deep);
  animation: spin .8s linear infinite;
}

[data-theme="dark"] .trend-loading .spinner {
  border-color: rgba(255, 255, 255, 0.1);
  border-top-color: var(--gold-light);
}

.trend-loading .spinner-text {
  display: block;
  text-align: center;
  line-height: 1.6;
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 700;
}

.page-loading.show {
  display: flex;
}

.page-loading .spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(27, 42, 61, 0.15);
  border-top-color: var(--gold-deep);
  animation: spin .8s linear infinite;
}

[data-theme="dark"] .page-loading .spinner {
  border-color: rgba(255, 255, 255, 0.1);
  border-top-color: var(--gold-light);
}

.page-loading .spinner-text {
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 600;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.page-relative {
  position: relative;
  min-height: 120px;
}

/* ================= AUTH SCREEN ================= */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: var(--auth-bg);
  padding: 24px;
  transition: background 0.3s ease;
}

.auth-backdrop {
  position: absolute;
  inset: -15%;
  z-index: 0;
  background:
    radial-gradient(circle at 18% 25%, rgba(184, 135, 58, 0.65), transparent 42%),
    radial-gradient(circle at 82% 18%, rgba(47, 111, 99, 0.60), transparent 45%),
    radial-gradient(circle at 30% 85%, rgba(122, 92, 158, 0.35), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(27, 42, 61, 0.7), transparent 50%);
  filter: blur(70px);
  transition: opacity 0.3s ease;
}

[data-theme="dark"] .auth-backdrop {
  opacity: 0.6;
}

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  background: var(--auth-card-bg);
  border: 1px solid var(--auth-border);
  border-radius: 18px;
  padding: 36px 30px;
  box-shadow: 0 20px 60px rgba(15, 20, 28, 0.35);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  transition: background 0.3s ease, border-color 0.3s ease;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.auth-brand .brand-mark {
  width: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-brand h1 {
  font-size: 19px;
  margin: 0;
  font-weight: 800;
  color: var(--text-primary);
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 22px;
  background: rgba(27, 42, 61, 0.07);
  padding: 4px;
  border-radius: 10px;
}

[data-theme="dark"] .auth-tabs {
  background: rgba(255, 255, 255, 0.06);
}

.auth-tab {
  all: unset;
  flex: 1;
  text-align: center;
  cursor: pointer;
  padding: 9px 0;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink-soft);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.auth-tab.active {
  background: var(--card);
  color: var(--text-primary);
  box-shadow: var(--shadow);
}

.auth-field {
  margin-bottom: 16px;
}

.auth-field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.auth-field input {
  background: var(--input-bg);
  color: var(--text-primary);
  border-color: var(--input-border);
}

.auth-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.auth-remember input {
  width: 15px;
  height: 15px;
  accent-color: var(--gold-deep);
  cursor: pointer;
}

.auth-remember label {
  cursor: pointer;
}

.auth-msg {
  font-size: 12.5px;
  margin-bottom: 12px;
  min-height: 1px;
}

.auth-submit {
  display: block;
  box-sizing: border-box;
  width: 100% !important;
  text-align: center;
  margin-top: 6px;
  padding: 16px 0 !important;
  font-size: 16px;
  border-radius: 10px;
}

.user-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 10px;
  font-size: 12.5px;
  color: var(--sidebar-text);
}

.logout-btn {
  all: unset;
  cursor: pointer;
  color: #E8B98F;
  font-size: 11.5px;
  font-weight: 700;
}

[data-theme="dark"] .logout-btn {
  color: var(--gold-light);
}

.logout-btn:hover {
  text-decoration: underline;
}

/* ================= QUIZ ================= */
.quiz-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 20, 28, 0.55);
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.quiz-overlay.show {
  display: flex;
}

.quiz-card {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 16px;
  padding: 30px 26px;
  box-shadow: 0 24px 70px rgba(15, 20, 28, 0.4);
  transition: background 0.3s ease;
}

.quiz-close {
  all: unset;
  position: absolute;
  top: 14px;
  left: 14px;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  font-size: 17px;
  transition: background .15s;
}

.quiz-close:hover {
  background: var(--hover-bg);
}

.quiz-progress {
  font-size: 12px;
  color: var(--ink-faint);
  font-weight: 600;
  margin-bottom: 16px;
}

.quiz-question {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 20px;
  line-height: 1.9;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quiz-option {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  width: 100%;
  padding: 13px 16px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--input-bg);
  line-height: 1.7;
  transition: background .15s, border-color .15s;
}

.quiz-option:hover {
  background: var(--legend-hover);
  border-color: var(--gold);
}

.quiz-result-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.quiz-result-score {
  font-size: 12px;
  color: var(--ink-faint);
  font-family: 'Vazirmatn', sans-serif;
  margin-bottom: 16px;
}

.quiz-result-text {
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.95;
  margin-bottom: 20px;
}

.quiz-alloc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.quiz-alloc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--hover-bg);
  border-radius: 9px;
  font-size: 13px;
  color: var(--text-primary);
}

.quiz-alloc-row .num {
  font-weight: 800;
  color: var(--gold-deep);
}

[data-theme="dark"] .quiz-alloc-row .num {
  color: var(--gold-light);
}

.rsi-cell input {
  min-width: 64px;
  width: 100%;
  padding: 7px 6px;
  text-align: center;
}

/* ================= AUTH VISIBILITY ================= */
body.pre-auth .mobile-topbar,
body.pre-auth .mobile-overlay,
body.pre-auth .app {
  display: none !important;
}

body:not(.pre-auth) .auth-screen {
  display: none !important;
}

/* ================= HERO INLINE METRICS ================= */
.hero-metric .value small {
  font-size: 13px;
  font-weight: 500;
  color: #888;
  margin-inline-start: 4px;
}

[data-theme="dark"] .hero-metric .value small {
  color: #6A6A7A;
}

/* ================= TREND CHART ================= */
.chart-box-tall {
  height: 220px;
}

.trend-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 12px;
  justify-content: center;
}

.trend-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
}

.trend-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 10px;
}

.trend-msg {
  text-align: center;
  margin-top: 8px;
  color: var(--ink-faint);
}

/* ================= PIE CHART CUSTOM LEGEND ================= */
.pie-legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 4px;
  border-bottom: 1px solid var(--card-border);
  transition: background 0.15s, transform 0.15s;
  cursor: pointer;
  border-radius: 4px;
}

.pie-legend-item:hover {
  background: var(--legend-hover);
  transform: translateX(-3px);
}

.pie-legend-item:active {
  transform: scale(0.98);
}

.pie-legend-item:last-child {
  border-bottom: none;
}

.pie-legend-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pie-legend-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pie-legend-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pie-legend-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.pie-legend-pct {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 40px;
  text-align: left;
}

.pie-legend-value {
  font-size: 12px;
  color: var(--ink-soft);
  font-family: 'Vazirmatn', sans-serif;
  min-width: 60px;
  text-align: left;
}

/* ================= DRILL-DOWN BACK BUTTON ================= */
#drillBackBtn {
  transition: all 0.2s ease;
}

#drillBackBtn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(27, 42, 61, 0.16);
}

/* ================= DRILL-DOWN HIGHLIGHT ================= */
.pie-legend-item.drill-active {
  background: var(--drill-active);
  border-right: 3px solid var(--gold);
  padding-right: 8px;
}

/* ================= SCROLLBAR (Dark Theme) ================= */
[data-theme="dark"] ::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
  background: #1A1A2E;
  border-radius: 4px;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: #3A3A5A;
  border-radius: 4px;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: #5A5A7A;
}

/* ================= TREND CHART - DARK THEME FIXES ================= */
[data-theme="dark"] .trend-chart-shell canvas {
  filter: brightness(0.95);
}

/* اطمینان از سفید بودن متن لیبل‌ها در تم دارک */
[data-theme="dark"] .chart-box canvas + .chartjs-tooltip,
[data-theme="dark"] .chart-box .chartjs-legend {
  color: #FFFFFF !important;
}

/* استایل پس‌زمینه کارت نمودار در تم دارک */
[data-theme="dark"] #trendCard {
  background: #1E1E3A;
  border-color: rgba(255, 255, 255, 0.08);
}

/* استایل متن عنوان نمودار در تم دارک */
[data-theme="dark"] #trendCard h3 {
  color: #EAEAEA;
}

[data-theme="dark"] #trendCard h3 small {
  color: #6A6A7A;
}

/* استایل Legend در تم دارک */
[data-theme="dark"] .trend-legend-item {
  color: #A8A8B8;
}

/* استایل پیام‌های نمودار در تم دارک */
[data-theme="dark"] .trend-msg {
  color: #6A6A7A;
}

/* ================= CHART.JS OVERRIDES FOR DARK THEME ================= */
[data-theme="dark"] .chartjs-tooltip {
  background: #2A2A4A !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
  color: #EAEAEA !important;
}

[data-theme="dark"] .chartjs-tooltip-header {
  color: #A8A8B8 !important;
}

[data-theme="dark"] .chartjs-tooltip-body {
  color: #EAEAEA !important;
}

/* ================= RESPONSIVE OVERRIDES ================= */
@media (max-width: 768px) {
  .mobile-topbar {
    background: var(--ink);
    color: var(--sidebar-text);
  }
  
  [data-theme="dark"] .mobile-topbar {
    background: #0D0D1A;
  }
  
  .sidebar {
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.3);
  }
  
  .grid-2 {
    grid-template-columns: 1fr;
  }
  
  .hero-total .value {
    font-size: 26px;
  }
  
  .hero-metric .value {
    font-size: 20px;
  }
}
