@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Vazirmatn:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #0f0f13;
  --bg-elevated: #18181f;
  --bg-card: #1c1c24;
  --bg-hover: #252530;
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --border: #27272a;
  --accent: #8b5cf6;
  --accent-2: #6366f1;
  --accent-soft: rgba(139, 92, 246, 0.12);
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg: #fafafa;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f4f4f5;
  --text: #09090b;
  --text-muted: #71717a;
  --border: #e4e4e7;
  --accent: #7c3aed;
  --accent-soft: rgba(124, 58, 237, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', 'Vazirmatn', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
}
.loading-overlay.show { display: flex; }
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: white; font-weight: 500; font-size: 0.95rem; }

/* Toast Alerts */
.toast-container {
  position: fixed;
  top: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 420px;
  padding: 0.9rem 1.2rem;
  border-radius: 12px;
  font-weight: 500;
  font-size: 0.92rem;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: toastIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(12px);
}
.toast.success { background: rgba(34, 197, 94, 0.95); color: white; }
.toast.error { background: rgba(239, 68, 68, 0.95); color: white; }
.toast.info { background: rgba(139, 92, 246, 0.95); color: white; }
.toast.warning { background: rgba(245, 158, 11, 0.95); color: white; }
.toast .close {
  margin-right: auto;
  background: none;
  border: none;
  color: inherit;
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0.8;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-20px) scale(0.95); }
  to { opacity: 1; transform: none; }
}

/* App Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  height: 100vh;
  position: fixed;
  top: 0; right: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-header { padding: 1.35rem 1.15rem; border-bottom: 1px solid var(--border); }
.brand, .topbar-brand { display: flex; align-items: center; gap: 0.7rem; }
.brand img { width: 44px; height: 44px; border-radius: 12px; }
.brand strong { display: block; font-size: 1rem; line-height: 1.2; }
.brand small { color: var(--text-muted); font-size: 0.72rem; }
.topbar-brand img { width: 36px; height: 36px; border-radius: 10px; }
.topbar-brand span { font-weight: 800; font-size: 1.05rem; }
.nav { padding: 1rem 0.75rem; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.8rem 1rem; margin-bottom: 0.25rem;
  border-radius: 12px; color: var(--text-muted);
  text-decoration: none; font-weight: 500; cursor: pointer;
  transition: var(--transition); border: none; background: transparent;
  width: 100%; text-align: right; font-size: 0.95rem; font-family: inherit;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.main { flex: 1; margin-right: 260px; padding: 1.5rem 2rem 3rem; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.75rem; }
.menu-btn, .theme-btn {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; width: 42px; height: 42px; font-size: 1.15rem;
  cursor: pointer; color: var(--text); display: none;
}
.theme-btn { display: flex; align-items: center; justify-content: center; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 90; opacity: 0; visibility: hidden; transition: 0.3s; }
.overlay.show { opacity: 1; visibility: visible; }

.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.25rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.5rem; }
.stat.accent { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: white; }
.stat .label { font-size: 0.85rem; opacity: 0.8; margin-bottom: 0.35rem; }
.stat .value { font-size: 1.75rem; font-weight: 800; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.7rem 1.4rem; border-radius: var(--radius-sm); font-weight: 600; border: none; cursor: pointer; font-size: 0.9rem; font-family: inherit; transition: var(--transition); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.form-group { margin-bottom: 1.2rem; }
.form-label { display: block; font-weight: 600; margin-bottom: 0.45rem; font-size: 0.88rem; color: var(--text-muted); }
.form-control, .form-select, textarea { width: 100%; padding: 0.8rem 1rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); font-size: 0.95rem; font-family: inherit; }
.form-control:focus, .form-select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }

.page-title { font-size: 1.6rem; font-weight: 800; margin-bottom: 1.5rem; }
.profit { color: var(--success); font-weight: 700; }
.loss { color: var(--danger); font-weight: 700; }
.steps { display: flex; gap: 0.4rem; margin-bottom: 1.5rem; overflow-x: auto; }
.step { flex: 1; min-width: 70px; text-align: center; padding: 0.55rem 0.3rem; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); font-size: 0.75rem; font-weight: 600; color: var(--text-muted); cursor: pointer; }
.step.active { background: var(--accent); color: white; border-color: var(--accent); }
.step.done { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.step-panel { display: none; }
.step-panel.active { display: block; }
.wizard-actions { display: flex; justify-content: space-between; margin-top: 1.5rem; gap: 0.75rem; flex-wrap: wrap; }
.checklist { background: var(--accent-soft); border-radius: 12px; padding: 1rem 1.25rem; margin: 1rem 0; }
.check-item { display: flex; align-items: center; gap: 0.7rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.check-item:last-child { border-bottom: none; }
.badge { display: inline-block; padding: 0.25rem 0.65rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-long { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-short { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.8rem 1rem; text-align: right; }
th { font-size: 0.75rem; color: var(--text-muted); border-bottom: 1px solid var(--border); }
td { border-bottom: 1px solid var(--border); }
@media (max-width: 800px) { .wizard-actions { flex-direction: column; } .wizard-actions .btn { width: 100%; } }

@media (max-width: 800px) {
  .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-right: 0; padding: 1rem; }
  .menu-btn { display: flex; align-items: center; justify-content: center; }
  .form-row { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
}

.check-view { margin: 0.45rem 0 0; padding-right: 1.1rem; color: var(--text); }
.check-view li { margin: 0.25rem 0; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
tr.detail-row td { background: var(--bg); padding: 0.85rem 1rem 1.15rem; }
.whatif-box { margin: 0.4rem 0 1rem; padding: 0.9rem 1rem 0.2rem; border: 1px dashed var(--accent); border-radius: 12px; background: var(--accent-soft); }
.trade-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.modal-back { position: fixed; inset: 0; z-index: 10003; display: none; align-items: center; justify-content: center; padding: 1rem; background: rgba(8, 8, 12, 0.72); }
.modal-back.show { display: flex; }
.whatif-modal { width: min(440px, 100%); margin: 0; }
.whatif-modal h3 { margin-bottom: 0.8rem; }
.edit-modal { width: min(760px, 100%); max-height: min(92vh, 920px); overflow: auto; margin: 0; position: relative; }
.edit-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.edit-head h3 { margin: 0; }
.edit-head .shot-close { position: static; }
.edit-sub { color: var(--text-muted); margin: 0.35rem 0 1rem; }
.edit-section { margin-bottom: 0.4rem; }
.edit-section h4 { font-size: 0.78rem; letter-spacing: 0.02em; color: var(--accent); margin-bottom: 0.7rem; }
.edit-shot-wrap { margin-bottom: 0.55rem; }
.edit-shot { display: block; width: 100%; padding: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--bg); cursor: zoom-in; }
.edit-shot img { display: block; width: 100%; height: 160px; object-fit: cover; }
.edit-empty, .edit-hint { color: var(--text-muted); font-size: 0.78rem; }
.edit-hint { display: block; margin-top: 0.35rem; }
.td-whatif strong { font-size: 0.82rem; }
.td-whatif span { font-weight: 700; }
.td-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 0.6rem; }
.td-metric { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 0.7rem 0.85rem; }
.td-metric span { display: block; color: var(--text-muted); font-size: 0.72rem; margin-bottom: 0.28rem; }
.td-metric strong { font-size: 0.95rem; font-weight: 700; }
.td-split { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 0.75rem; }
.td-block { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 0.9rem 1rem; }
.td-block h4 { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.65rem; }
.td-checks { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.28rem 0.6rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-size: 0.78rem; }
.chip.ok { background: rgba(34, 197, 94, 0.12); color: var(--success); border-color: transparent; }
.chip.no { background: rgba(239, 68, 68, 0.12); color: var(--danger); border-color: transparent; }
.td-notes { white-space: pre-wrap; line-height: 1.7; color: var(--text); font-size: 0.9rem; }
.td-shots { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.td-shot { margin: 0; background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.td-shot figcaption { padding: 0.55rem 0.8rem; font-size: 0.75rem; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.td-shot img { display: block; width: 100%; height: 220px; object-fit: cover; background: var(--bg); }
.shot-open { display: block; width: 100%; padding: 0; border: 0; background: transparent; cursor: zoom-in; }
.shot-lightbox {
  position: fixed; inset: 0; z-index: 10002; display: none;
  align-items: center; justify-content: center; flex-direction: column; gap: 0.75rem;
  background: rgba(8, 8, 12, 0.88); padding: 1.25rem;
}
.shot-lightbox.show { display: flex; }
.shot-lightbox img { max-width: min(960px, 94vw); max-height: 82vh; object-fit: contain; border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.45); }
.shot-lightbox p { color: #fff; font-size: 0.9rem; }
.shot-close {
  position: absolute; top: 0.8rem; left: 0.8rem; width: 42px; height: 42px;
  border: 0; border-radius: 12px; background: rgba(255,255,255,0.12); color: #fff;
  font-size: 1.6rem; cursor: pointer;
}
.td-shot.empty div { height: 120px; display: grid; place-items: center; color: var(--text-muted); font-size: 0.85rem; }
@media (max-width: 800px) {
  .td-split, .td-shots { grid-template-columns: 1fr; }
}
.jalali-popup {
  position: fixed; z-index: 10001; display: none; width: 280px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.75rem; box-shadow: 0 16px 40px rgba(0,0,0,.28);
}
.jalali-popup.show { display: block; }
.jalali-head, .jalali-actions, .jalali-time { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; }
.jalali-head button, .jd {
  background: transparent; color: var(--text); border: 0; cursor: pointer; border-radius: 8px;
}
.jalali-head button { font-size: 1.3rem; width: 32px; height: 32px; }
.jalali-week, .jalali-days { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; gap: 2px; margin-top: 0.4rem; }
.jalali-week span { color: var(--text-muted); font-size: 0.75rem; }
.jd { height: 32px; }
.jd.on { background: var(--accent); color: #fff; }
.jalali-time { margin-top: 0.6rem; }
.jalali-time input { width: 64px; margin-right: 0.3rem; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 0.3rem; }
.jalali-actions { margin-top: 0.6rem; }
[data-jalali] { cursor: pointer; }
