/* ============================================================
   EasyTrader Precision Bot — Instrument Panel Design System
   Mobile-first: base styles target narrow viewports; wider
   layouts are added via min-width media queries. No element is
   allowed to force page-level horizontal scroll — anything
   inherently wide (tables, JSON, long log lines) scrolls only
   within its own contained box.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700&family=Space+Grotesk:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg: #0A0D11;
  --panel: #10151B;
  --panel-2: #161D26;
  --panel-3: #1C2530;
  --border: #232B36;
  --border-soft: #1A212B;

  --text: #E7ECF2;
  --text-dim: #8994A3;
  --text-faint: #565F6C;

  --cyan: #22D3EE;
  --cyan-dim: #103A44;
  --violet: #A78BFA;
  --violet-dim: #2C2450;
  --green: #34D399;
  --green-dim: #103828;
  --amber: #F5B942;
  --amber-dim: #3A2C0C;
  --red: #F1594A;
  --red-dim: #3A1512;

  /* Vazirmatn first everywhere — this is a Persian-first panel now.
     Latin fallback fonts stay listed for the rare untranslated string. */
  --f-display: 'Vazirmatn', 'Space Grotesk', sans-serif;
  --f-body: 'Vazirmatn', 'Inter', sans-serif;
  --f-mono: 'IBM Plex Mono', monospace;

  --radius: 8px;
  --gutter: 14px;
}

* { box-sizing: border-box; min-width: 0; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--f-body);
  direction: rtl;
  /* Bumped up from 14px — this panel is designed to be comfortably
     readable without zooming, including for users who prefer larger
     text. Everything else in this file scales off this base. */
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  /* Belt-and-suspenders: even if a child misbehaves, the page itself
     never grows a horizontal scrollbar. */
  overflow-x: hidden;
  width: 100%;
}

body {
  background-image:
    radial-gradient(circle at 15% 0%, rgba(34, 211, 238, 0.05), transparent 40%),
    radial-gradient(circle at 85% 100%, rgba(167, 139, 250, 0.04), transparent 40%);
  min-height: 100vh;
}

::selection { background: var(--cyan); color: #001014; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
a { color: var(--cyan); }
button { font-family: var(--f-body); cursor: pointer; }
img, svg { max-width: 100%; }
/* Codes, prices, timestamps and IDs are always Latin/Western-numeral —
   force them left-to-right even inside an RTL page so "IRO1DALZ0001" or
   "12:30:00" never gets visually scrambled next to Persian text. */
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
[hidden] { display: none !important; }

/* ---------------- layout shell ---------------- */

.shell {
  max-width: 1600px;
  margin: 0 auto;
  padding: 10px 10px 32px;
  width: 100%;
}

@media (min-width: 640px) {
  .shell { padding: 16px 20px 40px; }
}

/* ---------------- topbar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}

.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); flex-shrink: 0; }

@media (max-width: 420px) {
  .brand-text { display: none; } /* icon-only brand on very narrow phones */
}

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }

.status-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px;
  background: var(--panel-3); border: 1px solid var(--border);
  font-family: var(--f-body); font-size: 13px; color: var(--text-dim);
  white-space: nowrap;
}
.status-chip .led { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex-shrink: 0; }
.status-chip.on .led { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-chip.off .led { background: var(--red); box-shadow: 0 0 6px var(--red); }
.status-chip.warn .led { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.status-chip.idle .led { background: var(--text-faint); }
.status-chip strong { color: var(--text); font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; unicode-bidi: isolate; }
.status-chip-auth { min-width: 0; max-width: min(100%, 280px); }
.status-chip-auth strong { flex: 1 1 auto; max-width: 220px; }
@media (max-width: 639px) {
  .status-chip-auth { max-width: 100%; }
  .status-chip-auth strong { max-width: 160px; }
}

.time-chip strong { color: var(--cyan); }

.topbar-spacer { flex: 1 1 100%; order: 3; height: 0; }
@media (min-width: 900px) { .topbar-spacer { flex: 1; order: 0; height: auto; } }

.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }
.btn-auto { width: auto; flex: 0 0 auto; }

/* ---------------- state stepper ---------------- */

.stepper-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 12px;
  border-radius: var(--radius);
}
.stepper {
  display: flex; gap: 3px;
  font-family: var(--f-body); font-size: 12px; font-weight: 600;
  width: max-content;
  min-width: 100%;
}
.stepper .step { padding: 7px 10px; background: var(--panel-3); color: var(--text-faint); border-radius: 4px; transition: all 0.25s ease; white-space: nowrap; }
.stepper .step.active { color: var(--bg); background: var(--cyan); box-shadow: 0 0 10px rgba(34, 211, 238, 0.5); }
.stepper .step.failed { color: var(--bg); background: var(--red); }
.stepper .step.done { color: var(--green); background: var(--green-dim); }

/* ---------------- grid (mobile-first: single column) ---------------- */

.grid { display: grid; grid-template-columns: 1fr; gap: var(--gutter); align-items: start; }

@media (min-width: 900px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .col-left { grid-column: 1; }
  .col-center { grid-column: 2; grid-row: 1 / span 2; }
  .col-right { grid-column: 1; }
}

@media (min-width: 1280px) {
  .grid { grid-template-columns: 320px 1fr 340px; }
  .col-left { grid-column: 1; grid-row: auto; }
  .col-center { grid-column: 2; grid-row: 1; }
  .col-right { grid-column: 3; grid-row: 1; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  max-width: 100%;
  overflow: hidden;
}
@media (min-width: 640px) { .panel { padding: 16px; } }
.panel + .panel { margin-top: var(--gutter); }

.panel-title {
  font-family: var(--f-display); font-size: 15px; font-weight: 700; letter-spacing: 0;
  color: var(--text-dim); margin: 0 0 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
}
.panel-title-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; letter-spacing: 0; }
.muted-label { font-size: 12.5px; color: var(--text-faint); }

.btn-link {
  background: none; border: none; color: var(--cyan); font-size: 13px;
  letter-spacing: 0; padding: 0; font-family: var(--f-body);
}
.btn-link:hover { text-decoration: underline; }

/* ---------------- collapsible panels (item 8) ---------------- */

.panel-collapse {
  width: auto; margin: 0; padding: 4px 10px; flex: 0 0 auto; line-height: 1.4;
  background: transparent; border: 1px solid var(--border); border-radius: 4px;
  color: var(--text-dim); font-family: var(--f-mono); font-size: 15px;
  min-height: 32px;
}
.panel-collapse:hover { color: var(--cyan); border-color: var(--cyan); }
.panel.collapsed .panel-title { margin-bottom: 0; }
.panel.collapsed .panel-body { display: none; }

/* ---------------- forms ---------------- */

.field { margin-bottom: 14px; min-width: 0; }
.field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; font-weight: 500; }
.field input, .field select, input[type="datetime-local"] {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-family: var(--f-body); font-size: 16px; padding: 11px 13px; min-width: 0;
  min-height: 46px;
}
.field input:focus, .field select:focus { border-color: var(--cyan); }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row .field { flex: 1 1 140px; min-width: 0; }
.field-row.seq-row { margin-top: 6px; flex-wrap: nowrap; }
.grow { flex: 1; min-width: 0; }
.samples-input { width: 76px; flex: 0 0 76px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-family: var(--f-mono); font-size: 16px; padding: 11px; min-height: 46px; }

/* datetime-local's calendar icon needs a filter to read on dark bg */
input[type="datetime-local"]::-webkit-calendar-picker-indicator { filter: invert(1) opacity(0.6); cursor: pointer; }

.detail-box {
  color: var(--red); background: var(--red-dim); border: 1px solid var(--red);
  border-radius: 6px; padding: 12px 14px; font-size: 13.5px; line-height: 1.6; word-break: break-word;
  white-space: pre-wrap; margin: 10px 0; font-family: var(--f-body);
}

.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); border-radius: 6px;
  padding: 13px 16px; font-size: 15.5px; font-weight: 600; transition: all 0.15s ease; width: 100%; margin-top: 8px;
  min-height: 48px;
}
.btn:hover:not(:disabled) { border-color: var(--cyan); color: var(--cyan); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--cyan-dim); border-color: var(--cyan); color: var(--cyan); }
.btn-primary:hover:not(:disabled) { background: var(--cyan); color: #001014; }
.btn-danger { background: var(--red-dim); border-color: var(--red); color: var(--red); }
.btn-danger:hover:not(:disabled) { background: var(--red); color: #1a0503; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { margin-top: 0; flex: 1 1 140px; }

/* ---------------- login overlay ---------------- */

.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px 26px; display: flex; flex-direction: column; gap: 14px;
}
.login-brand { display: flex; align-items: center; gap: 8px; font-family: var(--f-display); font-weight: 700; font-size: 18px; }
.login-brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.login-sub { color: var(--text-dim); font-size: 14.5px; margin: 0 0 4px; line-height: 1.7; }
.login-card input { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-family: var(--f-body); font-size: 16px; padding: 12px 14px; width: 100%; min-height: 48px; }
.login-card input:focus { border-color: var(--cyan); }
.login-error { color: var(--red); font-size: 13.5px; min-height: 18px; }

/* ---------------- toast notifications ---------------- */

.toast-container {
  position: fixed; z-index: 200;
  bottom: 12px; right: 12px; left: 12px;
  display: flex; flex-direction: column-reverse; gap: 8px;
  pointer-events: none;
  max-width: 100%;
}
@media (min-width: 640px) {
  .toast-container { right: 12px; left: auto; width: 360px; }
}
.toast {
  pointer-events: auto;
  background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--cyan);
  border-radius: 4px; padding: 10px 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toast-in 0.2s ease-out;
  display: flex; flex-direction: column; gap: 2px;
  max-width: 100%;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.warning { border-left-color: var(--amber); }
.toast .toast-title { font-size: 14px; font-weight: 700; font-family: var(--f-display); }
.toast.success .toast-title { color: var(--green); }
.toast.error .toast-title { color: var(--red); }
.toast.warning .toast-title { color: var(--amber); }
.toast.info .toast-title { color: var(--cyan); }
.toast .toast-msg { font-size: 13.5px; color: var(--text-dim); word-break: break-word; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateY(-4px); } }
.toast.closing { animation: toast-out 0.2s ease-in forwards; }

/* ---------------- accounts panel ---------------- */

.accounts-list, .msym-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.account-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 4px;
  padding: 8px 10px; transition: border-color 0.15s;
}
.account-row:hover { border-color: var(--border); }
.account-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--text-faint); }
.account-dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.account-dot.off { background: var(--red); box-shadow: 0 0 6px var(--red); }
.account-dot.idle { background: var(--text-faint); }
.account-row .account-info { flex: 1; min-width: 0; }
.account-row .account-label { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-row .account-sub { font-size: 13px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-row .account-actions { display: flex; gap: 4px; flex-shrink: 0; }
.icon-btn {
  background: none; border: none; color: var(--text-faint); font-size: 14px; padding: 8px 10px; border-radius: 4px; width: auto; margin: 0;
  min-height: 40px;
}
.icon-btn:hover { color: var(--text); background: var(--panel-3); }
.account-form { display: flex; flex-direction: column; gap: 0; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-soft); }

/* ---------------- multi-symbol order configurations ---------------- */

.msym-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 4px;
  padding: 8px 10px; transition: border-color 0.15s, opacity 0.15s;
}
.msym-row:hover { border-color: var(--border); }
.msym-row.disabled { opacity: 0.5; }
.msym-row input[type="checkbox"] { accent-color: var(--green); flex-shrink: 0; width: 22px; height: 22px; }
.msym-row input.msym-select { accent-color: var(--cyan); }
.msym-row .msym-info { flex: 1; min-width: 0; }
.msym-row .msym-label { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msym-row .msym-sub { font-size: 13px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msym-row .msym-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* ---------------- bulk target-time toolbar ---------------- */

.bulk-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--panel-2); border: 1px solid var(--cyan); border-radius: 6px;
  padding: 10px 12px; margin-bottom: 10px;
}
.msym-select-wrap { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--text-dim); white-space: nowrap; flex-shrink: 0; }
.msym-select-wrap input[type="checkbox"] { accent-color: var(--cyan); width: 20px; height: 20px; flex-shrink: 0; }
.bulk-bar input[type="time"] { flex: 1 1 130px; min-width: 110px; margin: 0; }
.bulk-bar .btn { width: auto; margin: 0; flex: 0 0 auto; }

/* ---------------- multi-symbol report ---------------- */

.batch-run-select {
  background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 6px;
  color: var(--text); font-size: 13px; font-family: var(--f-body); padding: 6px 8px; width: auto; margin: 0;
  min-height: 40px;
}
.table-wrap { overflow-x: auto; margin: 10px 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: start; font-family: var(--f-body); font-weight: 700;
  color: var(--text-faint); font-size: 12px; padding: 8px 10px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td {
  padding: 9px 10px; border-bottom: 1px solid var(--border-soft); font-family: var(--f-mono);
  white-space: nowrap; color: var(--text-dim); direction: ltr; text-align: right;
}
.data-table td:first-child { font-family: var(--f-body); direction: rtl; text-align: start; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--panel-2); }
.data-table .badge { padding: 2px 9px; border-radius: 999px; font-size: 11.5px; }
.data-table .badge.ok { background: var(--green-dim); color: var(--green); }
.data-table .badge.fail { background: var(--red-dim); color: var(--red); }

/* ---------------- execution report table subsections ---------------- */

.timeline-subtitle { font-family: var(--f-body); font-weight: 700; font-size: 12px; color: var(--text-faint); margin: 16px 0 8px; }
.timeline-subtitle:first-of-type { margin-top: 0; }
.tuning-note { font-size: 13px; color: var(--text-faint); margin: 4px 0 10px; line-height: 1.7; }

/* ---------------- calibration ---------------- */

.histogram { display: flex; align-items: flex-end; gap: 3px; height: 90px; margin: 10px 0; }
.histogram .bar { flex: 1; background: var(--amber-dim); border-top: 2px solid var(--amber); border-radius: 2px 2px 0 0; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
@media (min-width: 420px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
.stat { background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 6px; padding: 10px 12px; min-width: 0; }
.stat .k { font-size: 12px; color: var(--text-faint); }
.stat .v { font-family: var(--f-mono); font-size: 16px; font-weight: 700; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; direction: ltr; unicode-bidi: isolate; }
.recommendation { margin-top: 12px; padding: 12px 14px; background: var(--amber-dim); border: 1px solid var(--amber); border-radius: 6px; font-size: 13.5px; color: var(--amber); word-break: break-word; }

/* ---------------- live log ---------------- */

.log-stream { height: 280px; overflow-y: auto; background: var(--bg); border: 1px solid var(--border-soft); border-radius: 6px; padding: 10px 12px; font-family: var(--f-mono); font-size: 12.5px; line-height: 1.7; direction: ltr; text-align: left; }
@media (min-width: 1280px) { .log-stream { height: 340px; } }
.log-line { white-space: pre-wrap; word-break: break-word; }
.log-line .t { color: var(--text-faint); }
.log-line .c { color: var(--cyan); }
.log-line .msg { color: var(--text-dim); }
.log-line.level-ERROR .msg { color: var(--red); }
.log-line.level-WARNING .msg { color: var(--amber); }
.log-line.status-COMPLETED .msg, .log-line.status-ACCEPTED .msg, .log-line.status-WARM .msg, .log-line.status-OK .msg { color: var(--green); }

/* ---------------- history table (contained scroll only) ---------------- */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.history-table { width: 100%; min-width: 480px; border-collapse: collapse; font-family: var(--f-mono); font-size: 12px; }
.history-table th { text-align: left; color: var(--text-faint); font-weight: 500; text-transform: uppercase; font-size: 10px; letter-spacing: 0.04em; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.history-table td { padding: 8px 10px; border-bottom: 1px solid var(--border-soft); color: var(--text-dim); white-space: nowrap; }
.history-table tr:hover td { background: var(--panel-2); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10px; text-transform: uppercase; }
.pill.ACCEPTED, .pill.COMPLETED { background: var(--green-dim); color: var(--green); }
.pill.REJECTED, .pill.FAILED { background: var(--red-dim); color: var(--red); }
.pill.UNKNOWN, .pill.SENT_NO_RESPONSE { background: var(--amber-dim); color: var(--amber); }

.empty-state { color: var(--text-faint); font-size: 13.5px; text-align: center; padding: 26px 0; line-height: 1.7; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
