@font-face {
  font-family: 'Vazirmatn';
  src: url('../fonts/vazirmatn-fa.woff2') format('woff2');
  font-display: swap;
}

:root { --radius: 6px; --top: 46px; --foot: 24px; }
.theme-dark {
  --bg: #131722; --panel: #1E222D; --panel2: #2A2E39; --line: #2A2E39; --text: #D1D4DC; --muted: #787B86;
  --hover: #2A2E39; --accent: #2962FF; --accent-bg: rgba(41, 98, 255, 0.16); --danger: #F23645; --up: #089981;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45); --back: rgba(0, 0, 0, 0.5); color-scheme: dark;
}
.theme-light {
  --bg: #FFFFFF; --panel: #FFFFFF; --panel2: #F0F3FA; --line: #E0E3EB; --text: #131722; --muted: #6A6D78;
  --hover: #F0F3FA; --accent: #2962FF; --accent-bg: rgba(41, 98, 255, 0.1); --danger: #F23645; --up: #089981;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.14); --back: rgba(19, 23, 34, 0.35); color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: 'Vazirmatn', -apple-system, 'Segoe UI', Roboto, Tahoma, sans-serif;
  font-size: 14px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; color: var(--text); }
.ic { display: block; flex: none; }
.mono, [dir="ltr"] { font-variant-numeric: tabular-nums; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* top bar */
#topbar {
  height: var(--top); flex: none; display: flex; align-items: center; gap: 4px;
  padding: 0 8px; border-bottom: 1px solid var(--line); background: var(--bg);
  overflow-x: auto; scrollbar-width: none;
}
#topbar::-webkit-scrollbar { display: none; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; padding-left: 8px; margin-left: 4px; border-left: 1px solid var(--line); white-space: nowrap; }
.logo { width: 28px; height: 28px; border-radius: 7px; background: #D4A017; color: #131722; display: grid; place-items: center; font-weight: 800; font-size: 13px; font-family: -apple-system, 'Segoe UI', sans-serif; }
.brand-txt { font-size: 13px; color: var(--muted); }
.brand-txt b { color: var(--text); font-weight: 600; }
#topbar > * { flex-shrink: 0; }
.spacer { flex: 1; }
.tb-btn {
  height: 32px; padding: 0 8px; border-radius: var(--radius); display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap; color: var(--text); font-size: 13px;
}
.tb-btn:hover, .icon-btn:hover, .db-btn:hover, .menu-item:hover { background: var(--hover); }
.tb-btn.on { color: var(--accent); background: var(--accent-bg); }
.tb-btn.symbol { min-width: 150px; justify-content: flex-start; }
.tb-btn.symbol b { font-size: 14px; font-weight: 700; }
.tb-btn.symbol .sym-fa { color: var(--muted); font-size: 12px; }
.periods { display: flex; align-items: center; gap: 1px; padding: 0 6px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.periods .tb-btn { padding: 0 7px; font-family: -apple-system, 'Segoe UI', Roboto, sans-serif; font-size: 13px; }
.icon-btn { width: 32px; height: 32px; border-radius: var(--radius); display: inline-grid; place-items: center; color: var(--text); flex: none; }
.icon-btn.on { color: var(--accent); }
.icon-btn.danger { color: var(--danger); }

/* main area */
#main { flex: 1; min-height: 0; display: flex; position: relative; }
#drawbar {
  width: 46px; flex: none; border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 6px 0; overflow-y: auto; scrollbar-width: none;
}
#drawbar::-webkit-scrollbar { display: none; }
.db-btn { width: 36px; height: 34px; border-radius: var(--radius); display: grid; place-items: center; color: var(--text); }
.db-btn.on { color: var(--accent); background: var(--accent-bg); }
.db-btn.mag-weak_magnet, .db-btn.mag-strong_magnet { color: var(--accent); }
.db-btn.mag-strong_magnet { background: var(--accent-bg); }
.db-group { position: relative; }
.db-more { position: absolute; right: -4px; top: 0; bottom: 0; width: 10px; display: grid; place-items: center; border-radius: 3px; }
.db-more i { width: 0; height: 0; border-left: 4px solid var(--muted); border-top: 3px solid transparent; border-bottom: 3px solid transparent; }
.db-more:hover { background: var(--hover); }
.db-sep { width: 26px; height: 1px; background: var(--line); margin: 6px 0; }

#grid { flex: 1; min-width: 0; display: grid; grid-template-columns: 1fr; grid-auto-rows: 1fr; gap: 1px; background: var(--line); }
#grid.layout-2v { grid-template-columns: 1fr 1fr; }
#grid.layout-2h { grid-template-rows: 1fr 1fr; }
#grid.layout-3 { grid-template-columns: 3fr 2fr; grid-template-rows: 1fr 1fr; }
#grid.layout-3 .view:first-child { grid-row: span 2; }
#grid.layout-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
#grid.layout-6 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
.lay-ic { width: 22px; height: 16px; display: grid; gap: 2px; flex: none; }
.lay-ic i { border: 1.5px solid currentColor; border-radius: 2px; display: none; }
.lay-1 i:nth-child(-n+1), .lay-2v i:nth-child(-n+2), .lay-2h i:nth-child(-n+2), .lay-3 i:nth-child(-n+3), .lay-4 i:nth-child(-n+4), .lay-6 i:nth-child(-n+6) { display: block; }
.lay-2v { grid-template-columns: 1fr 1fr; }
.lay-2h { grid-template-rows: 1fr 1fr; }
.lay-3 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.lay-3 i:first-child { grid-row: span 2; }
.lay-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.lay-6 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
.view { position: relative; background: var(--bg); min-width: 0; min-height: 0; }
.view.active { box-shadow: inset 0 0 0 1px var(--accent); }
.kc-box { position: absolute; inset: 0; }
.view::after {
  content: 'IMAN PROFIT'; position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%);
  font: 800 clamp(22px, 6vw, 64px) -apple-system, 'Segoe UI', sans-serif; letter-spacing: 0.12em; color: var(--text);
  opacity: 0.045; pointer-events: none; white-space: nowrap;
}
#grid:not(.layout-1) .view::after { font-size: clamp(14px, 3vw, 34px); }
.view-status { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: none; padding: 10px 16px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 13px; text-align: center; max-width: 86%; z-index: 3; direction: rtl; }
.view-status.is-loading, .view-status.is-error, .view-status.is-empty { display: block; }
.view-reset { position: absolute; right: 78px; bottom: 40px; z-index: 4; display: none; width: 30px; height: 30px; border-radius: 50%;
  align-items: center; justify-content: center; background: var(--panel); border: 1px solid var(--line); color: var(--text); box-shadow: var(--shadow); cursor: pointer; }
.view-reset.show { display: flex; }
.view-reset:hover { background: var(--hover); }
.chart-menu .menu-item kbd { margin-inline-start: auto; padding-inline-start: 16px; font: 11px -apple-system, 'Segoe UI', sans-serif; color: var(--muted); }
.chart-menu .menu-item b { font-weight: 600; }
.view-status.is-error { color: var(--danger); }

#foot { height: var(--foot); flex: none; display: flex; align-items: center; gap: 12px; padding: 0 10px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }
#live { display: inline-flex; align-items: center; gap: 6px; }
#live::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
#live.on { color: var(--up); }
#live.on::before { background: var(--up); box-shadow: 0 0 0 3px rgba(8, 153, 129, 0.2); }
.muted { color: var(--muted); }

/* hint + selected drawing bar */
#hint {
  position: absolute; top: 10px; left: 50%; transform: translate(-50%, -8px); z-index: 20; opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 12px; border-radius: 8px; background: var(--panel);
  border: 1px solid var(--line); box-shadow: var(--shadow); transition: opacity 0.15s, transform 0.15s; font-size: 13px; max-width: calc(100% - 20px);
}
#hint.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#hint b { white-space: nowrap; }
#hint span { color: var(--muted); flex: 1 1 auto; min-width: 0; line-height: 1.6; }
#hint .btn { flex: none; }
#ovbar {
  position: absolute; top: 10px; left: 50%; transform: translate(-50%, -8px); z-index: 19; opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 8px; background: var(--panel);
  border: 1px solid var(--line); box-shadow: var(--shadow); transition: opacity 0.15s, transform 0.15s; max-width: calc(100% - 20px); overflow-x: auto;
}
#ovbar.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.ob-colors, .ob-group { display: flex; align-items: center; gap: 3px; padding-right: 6px; border-right: 1px solid var(--line); }
.swatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent; flex: none; }
.swatch.on { border-color: var(--text); }
.ob-size { width: 28px; height: 28px; border-radius: var(--radius); display: grid; place-items: center; }
.ob-size i { display: block; width: 16px; background: var(--text); border-radius: 2px; }
.ob-size i.dash { height: 2px; background: repeating-linear-gradient(90deg, var(--text) 0 4px, transparent 4px 7px); }
.ob-size.on, .ob-size:hover { background: var(--hover); }

.fab { display: none; }

/* replay */
.rp-badge { display: none; position: absolute; top: 6px; left: 50%; transform: translateX(-50%); z-index: 4; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 10px; background: #FF9800; color: #131722; font-size: 11px; font-weight: 600; pointer-events: none; direction: rtl; }
.view.replaying .rp-badge { display: inline-flex; }
.view.replaying { box-shadow: inset 0 0 0 1px #FF9800; }
.rp-shade { display: none; position: absolute; top: 0; bottom: 0; right: 0; left: 100%; background: rgba(41, 98, 255, 0.10); border-left: 2px solid var(--accent); z-index: 3; pointer-events: none; }
.view.rp-picking .rp-shade { display: block; }
.view.rp-picking .kc-box { cursor: col-resize; }
#rpbar {
  position: absolute; bottom: 14px; left: 50%; transform: translate(-50%, 8px); z-index: 18; opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 4px; padding: 5px 8px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line);
  box-shadow: var(--shadow); transition: opacity 0.15s, transform 0.15s; max-width: calc(100% - 20px);
}
#rpbar.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#rpbar .play { background: var(--accent); color: #fff; }
#btn-alert { position: relative; }
#btn-alert .badge { min-width: 16px; height: 16px; font-size: 10px; font-style: normal; background: #FF9800; color: #131722; }
.btn.big { height: 44px; font-size: 14px; text-decoration: none; }
.alert-sym { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--panel2); }
.alert-sym b { font-family: -apple-system, 'Segoe UI', sans-serif; }
.alert-sym .spacer { flex: 1; }
.rp-speed { height: 30px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); padding: 0 6px; }
.rp-time { font-size: 12px; color: var(--muted); padding: 0 6px; white-space: nowrap; }

/* popups */
.menu-back { position: fixed; inset: 0; z-index: 40; }
.menu, .flyout {
  position: fixed; z-index: 41; min-width: 180px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); padding: 4px; overflow-y: auto; direction: rtl;
}
.flyout { min-width: 220px; max-height: calc(100vh - 16px); }
.menu-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius); text-align: right; justify-content: flex-start; }
.menu-item.on { color: var(--accent); background: var(--accent-bg); }
.menu-item .mono { min-width: 34px; font-family: -apple-system, 'Segoe UI', sans-serif; }
.list-head { font-size: 11px; color: var(--muted); padding: 10px 10px 4px; }

.dlg-back { position: fixed; inset: 0; z-index: 50; background: var(--back); display: grid; place-items: center; padding: 16px; }
.dlg {
  width: min(440px, 100%); max-height: min(640px, calc(100dvh - 32px)); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.dlg.wide { width: min(560px, 100%); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 8px 8px; }
.dlg-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.dlg-body { overflow-y: auto; padding: 0 14px 14px; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-start; padding: 10px 14px 14px; border-top: 1px solid var(--line); }
.search { width: 100%; height: 38px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); outline: none; margin: 4px 0 6px; }
.search:focus, .field input:focus, .field select:focus, textarea:focus { border-color: var(--accent); }
.sym-row, .ind-row { width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius); text-align: right; }
.sym-row:hover, .ind-row:hover { background: var(--hover); }
.sym-row.on { background: var(--accent-bg); }
.sym-row b { min-width: 76px; text-align: left; font-family: -apple-system, 'Segoe UI', sans-serif; font-size: 13px; }
.ind-row .nm { flex: 1; }
.ind-row .en { color: var(--muted); font-size: 12px; font-family: -apple-system, 'Segoe UI', sans-serif; }
.ind-row .ic { color: var(--muted); }
.ind-row.active-row { padding: 4px 4px 4px 10px; }
.ind-row.active-row:hover { background: none; }
.ind-row.off .nm, .ind-row.off .en { opacity: 0.5; }
.acts { display: flex; gap: 2px; }
.tabs { display: flex; width: 100%; margin-bottom: 8px; }
.tabs .seg-btn { flex: 1; }
.ind-active { min-height: 120px; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; display: inline-grid; place-items: center; }
.empty { color: var(--muted); padding: 10px; font-size: 13px; }

.form { display: flex; flex-direction: column; gap: 10px; }
.form p { margin: 0; line-height: 1.8; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field > span { color: var(--muted); font-size: 13px; }
.field input, .field select { width: 150px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); padding: 0 10px; outline: none; direction: ltr; }
.field select { direction: rtl; }
textarea { width: 100%; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); padding: 10px; outline: none; resize: vertical; }
.form-err { color: var(--danger); font-size: 12px; min-height: 16px; }
.note { color: var(--muted); font-size: 12px; }
.cloud-box { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--panel2); }
.cloud-box p { margin: 0; line-height: 1.8; }
.cloud-box .btn { align-self: flex-start; }
.seg { display: inline-flex; background: var(--panel2); border-radius: 8px; padding: 2px; }
.seg-btn { padding: 6px 14px; border-radius: 6px; font-size: 13px; }
.seg-btn.on { background: var(--panel); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.alert-mode { margin-inline-start: auto; }
.alert-tag { display: inline-block; margin-inline-start: 6px; padding: 0 6px; border-radius: 4px; font-size: 11px; line-height: 18px; background: var(--panel2); color: var(--muted); }
.alert-tag.tg { color: #2AABEE; }
.btn { height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 13px; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: rgba(242, 54, 69, 0.4); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }

.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 4px; }
.tool-cell { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px; border-radius: 8px; font-size: 12px; text-align: center; line-height: 1.4; }
.tool-cell:hover, .tool-cell.on { background: var(--accent-bg); color: var(--accent); }
.sheet-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }

#toast {
  position: fixed; left: 50%; bottom: 40px; transform: translate(-50%, 10px); z-index: 60; opacity: 0; pointer-events: none;
  background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 8px 14px; border-radius: 8px; font-size: 13px;
  transition: opacity 0.2s, transform 0.2s; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* phones */
@media (max-width: 760px) {
  #topbar .brand { display: none; } /* the way back to the site is in Settings */
  #topbar { overflow-x: auto; scrollbar-width: none; } /* very small phones: swipe, nothing is cut off */
  #topbar::-webkit-scrollbar { display: none; }
  :root { --top: 48px; }
  .brand-txt, .tb-btn.symbol .sym-fa, #btn-indicators span, #btn-replay span, #btn-alert span, #btn-full, #btn-theme { display: none; }
  .tb-btn.symbol { min-width: 0; }
  #topbar { gap: 2px; padding: 0 6px; }
  #topbar .tb-btn { padding: 0 6px; }
  #topbar .icon-btn { width: 30px; }
  #btn-shot { display: none; }
  .periods { padding: 0 3px; }
  #rpbar { bottom: 40px; left: auto; right: 10px; transform: none; }
  #rpbar.show { transform: none; }
  .rp-time { display: none; }
  .brand { padding-left: 6px; margin-left: 2px; }
  #drawbar { display: none; }
  .fab {
    display: grid; place-items: center; position: absolute; left: 12px; bottom: 38px; z-index: 15; width: 46px; height: 46px; border-radius: 50%;
    background: var(--accent); color: #fff; box-shadow: 0 4px 14px rgba(41, 98, 255, 0.45);
  }
  #foot .muted { display: none; }
  .dlg-back { place-items: end stretch; padding: 0; }
  .dlg, .dlg.wide { width: 100%; max-height: 82dvh; border-radius: 14px 14px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
  #hint { top: 8px; font-size: 12px; }
  #hint span { display: block; }
}

/* position tool: lot calculator + TP lines */
.ob-calc { display: flex; align-items: center; gap: 4px; height: 28px; padding: 0 8px; border-radius: var(--radius); font-size: 12px; white-space: nowrap; }
.ob-calc:hover { background: var(--hover); }
.calc-ic { font-size: 14px; }
.pos-calc .num { width: 130px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); text-align: left; direction: ltr; }
.pos-calc .chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: -4px; }
.pos-calc .chip { flex: 1; min-width: 56px; padding: 6px 0; border-radius: 6px; background: var(--panel2); font-size: 12px; }
.pos-calc .chip.on { background: var(--accent); color: #fff; }
.calc-out { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 10px; background: var(--panel2); }
.calc-out p { margin: 0; line-height: 1.8; font-size: 13px; }
.calc-lot { display: flex; align-items: baseline; justify-content: space-between; }
.calc-lot b { font-size: 22px; color: var(--accent); }
.calc-tps { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; }
.pos-calc .pos { color: var(--up); }
.pos-calc .neg { color: var(--danger); }
.pos-calc .check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.calc-out [dir="ltr"], .alert-sym [dir="ltr"], .chart-menu [dir="ltr"] { display: inline-block; direction: ltr; unicode-bidi: isolate; }
