/* ============================================================
   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; }
}

/* ---------------- compact persistent header ---------------- */

:root { --dashboard-header-height: 124px; }
html { scroll-padding-top: calc(var(--dashboard-header-height) + 16px); }
html, body { overflow-x: clip; }
#header-sentinel { height: 1px; margin-top: -1px; pointer-events: none; }
.dashboard-header {
  position: sticky; top: 0; z-index: 50; margin-bottom: 16px;
  padding: 10px 12px 6px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel); box-shadow: 0 2px 8px #0002;
  transition: box-shadow .18s ease, border-color .18s ease;
}
.dashboard-header.is-stuck { border-color: #354153; box-shadow: 0 10px 28px #0006; }
.header-main { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 20px; padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 700; font-size: 16px; color: var(--text); white-space: nowrap; }
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); flex-shrink: 0; }
.bot-status { display: flex; align-items: center; gap: 8px; min-width: 0; --status-color: var(--amber); }
.bot-status[data-state="running"] { --status-color: var(--green); }
.bot-status[data-state="stopped"] { --status-color: var(--text-dim); }
.bot-status[data-state="error"] { --status-color: var(--red); }
.bot-status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--status-color); flex-shrink: 0; box-shadow: 0 0 0 4px color-mix(in srgb, var(--status-color) 12%, transparent); }
.bot-status-text { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
#bot-status-label { color: var(--status-color); font-size: 13px; white-space: nowrap; }
#bot-activity { color: var(--text-dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; gap: 8px; }
.dashboard-header .header-start { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: auto; min-width: 136px; min-height: 40px; padding: 8px 14px; margin: 0; font-size: 13px; }
.dashboard-header .header-start:disabled { opacity: .65; cursor: not-allowed; }
.dashboard-header .header-start[aria-busy="true"] > span:first-child { display: none; }
.header-secondary { display: flex; align-items: center; gap: 16px; border-top: 1px solid var(--border-soft); padding-top: 5px; }
.page-nav { display: flex; align-items: center; flex: 1; gap: 4px; min-width: 0; }
.nav-link { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 6px 14px; color: var(--text-dim); text-decoration: none; border-radius: 6px; border: 1px solid transparent; font-size: 13px; white-space: nowrap; transition: color .15s, background .15s; }
.nav-link:hover { background: var(--panel-2); color: var(--text); }
.nav-link[aria-current="page"] { color: var(--cyan); background: var(--cyan-dim); border-color: #22d3ee30; font-weight: 700; }
.nav-icon { line-height: 1; font-size: 16px; }
.header-details { position: relative; flex-shrink: 0; }
.header-details summary { display: flex; align-items: center; gap: 6px; list-style: none; cursor: pointer; font-size: 12px; color: var(--text-dim); min-height: 40px; border-radius: 6px; padding: 6px; }
.header-details summary::-webkit-details-marker { display: none; }
.header-details[open] summary { color: var(--cyan); background: var(--panel-2); }
.header-details-popover { position: absolute; inset-inline-end: 0; top: calc(100% + 10px); width: min(360px, calc(100vw - 32px)); padding: 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 32px #0007; }
.header-details-popover .chip-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.dashboard-header .header-logout { width: 100%; margin: 12px 0 0; font-size: 13px; min-height: 40px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
[id] { scroll-margin-top: 16px; }
@media (max-width: 639px) {
  .header-main { gap: 12px; }
  .brand-text { display: none; }
  .bot-status-text { display: block; }
  #bot-activity { display: block; max-width: 150px; font-size: 10px; }
  .dashboard-header .header-start { min-width: 110px; padding: 8px 10px; font-size: 12px; }
  .header-secondary { gap: 6px; }
  .nav-link { flex: 1; padding: 6px 3px; font-size: 12px; }
  .nav-icon { display: none; }
  .header-details summary { font-size: 11px; padding: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  .dashboard-header, .nav-link { transition: none; }
}

.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); }

.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); }

/* ---------------- persistent navigation and dashboard pages ---------------- */

.workspace { display: grid; gap: var(--gutter); align-items: start; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-heading h1 { margin: 0; font-size: 21px; font-weight: 700; }
.page-heading p { color: var(--text-dim); font-size: 12px; margin: 4px 0 0; }
.page-panels { display: grid; gap: var(--gutter); align-items: start; }
.page-narrow { max-width: 760px; }
.trading-action-row { display: flex; gap: 10px; flex-wrap: wrap; }
.trading-action-row .btn { flex: 1 1 220px; margin: 0; }
.trading-controls .tuning-note { margin: 12px 0 0; }
.skip-link { position: fixed; top: -100px; inset-inline-start: 12px; z-index: 300; padding: 10px 16px; background: var(--cyan); color: var(--bg); border-radius: 6px; }
.skip-link:focus { top: 10px; }
@media (min-width: 640px) {
  .page-heading h1 { font-size: 24px; }
}
@media (min-width: 1000px) {
  .trading-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .trading-controls, .trading-logs, .trading-system { grid-column: 1 / -1; }
  .trading-system .panel-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 20px; }
  .trading-system .tuning-note { grid-row: 1; margin: 0 !important; }
  .trading-system .btn { grid-row: 2; }
}

.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); }
.page-panels > .panel { margin: 0; }

.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; }
.accounts-panel h2 { font-size: 15px; margin: 0; color: var(--text); display: flex; align-items: center; gap: 8px; }
.account-count { color: var(--text-dim); font-size: 12px; background: var(--panel-3); border-radius: 20px; padding: 1px 8px; }
.accounts-panel .panel-title-actions { gap: 6px; }
.accounts-panel .panel-title .btn { margin: 0; width: auto; font-size: 13px; min-height: 40px; padding: 8px 12px; }
.accounts-feedback { font-size: 13px; color: var(--text-dim); padding: 12px 0; }
.account-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 10px; padding: 12px; }
.account-row:hover { border-color: var(--border); }
.account-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: currentColor; }
.account-info { min-width: 0; }
.account-row .account-label { font-size: 15px; font-weight: 600; margin: 0; color: var(--text); overflow-wrap: anywhere; }
.account-broker { color: var(--text-dim); font-size: 12px; text-align: right; overflow-wrap: anywhere; margin: 3px 0 6px; }
.account-status { display: inline-flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 11px; }
.account-status[data-tone="on"] { color: var(--green); }
.account-status[data-tone="off"] { color: var(--red); }
.account-actions { display: flex; gap: 4px; flex-shrink: 0; }
.account-actions .btn-edit { color: var(--cyan); }
.account-actions .btn-delete { color: var(--red); }
.account-actions .icon-btn { min-height: 44px; padding: 8px; }
.app-dialog.account-dialog { width: min(520px, calc(100% - 24px)); }
.field-hint { display: block; font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.delete-warning { font-size: 13px; color: var(--text-dim); }
@media (max-width: 480px) {
  .account-row { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .account-actions { justify-content: flex-end; }
  .accounts-panel .panel-title { align-items: flex-start; }
}
.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 ---------------- */

/* Stocks use the full content width, with independent order/timing columns. */
.stocks-panel { container-type: inline-size; grid-column: 1 / -1; }
.stocks-panel h2 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; font-size: 18px; color: var(--text); }
.stock-count { font-size: 12px; color: var(--text-dim); font-weight: 400; }
.stocks-panel .panel-title .btn { width: auto; margin: 0; min-height: 40px; padding: 8px 14px; font-size: 13px; }
.stocks-panel .panel-title-actions { gap: 6px; }
.msym-list { gap: 12px; margin: 0; }
.msym-row { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; transition: border-color .15s; }
.msym-row:hover { border-color: #3a4656; }
.msym-row.selected { border-color: var(--cyan); }
.stock-card-header { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 10px 14px; }
.msym-select-wrap { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; font-size: 12px; color: var(--text-dim); }
.msym-select-wrap input { accent-color: var(--cyan); width: 18px; height: 18px; margin: 0; flex-shrink: 0; }
.msym-row .msym-label { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.5; overflow-wrap: anywhere; }
.stock-code { display: block; font-family: var(--f-mono); font-size: 12px; color: var(--text-dim); margin-top: 3px; overflow-wrap: anywhere; }
.stock-enabled { display: inline-flex; align-items: center; justify-content: flex-end; gap: 8px; font-size: 12px; color: var(--text-dim); min-height: 44px; cursor: pointer; }
.stock-enabled input { appearance: none; direction: ltr; position: relative; width: 32px; height: 18px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel-3); margin: 0; cursor: pointer; flex-shrink: 0; }
.stock-enabled input::before { content: ""; position: absolute; left: 2px; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--text-dim); transition: transform .15s; }
.stock-enabled input:checked { background: var(--green-dim); border-color: #34d39960; }
.stock-enabled input:checked::before { transform: translateX(14px); background: var(--green); }
.stock-enabled input:disabled { opacity: .45; cursor: wait; }
.stock-card-body { display: grid; gap: 16px; padding: 14px; border-top: 1px solid var(--border-soft); }
.stock-order-details { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-content: start; gap: 14px; margin: 0; }
.stock-order-details .stock-account { grid-column: 1 / -1; }
.stock-order-details dt { font-size: 11px; color: var(--text-dim); }
.stock-order-details dd { margin: 3px 0 0; color: var(--text); font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.stock-order-details .stock-number { font-size: 16px; font-variant-numeric: tabular-nums; }
.stock-timing { container-type: inline-size; min-width: 0; padding: 12px; border: 1px solid var(--border-soft); border-radius: 8px; background: var(--panel-2); }
.stock-timing-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.stock-timing-title { font-size: 12px; font-weight: 600; color: var(--text-dim); }
.stock-time-edit { min-height: 36px; padding: 4px 8px; border: 0; border-radius: 5px; color: var(--cyan); background: transparent; font-size: 12px; }
.stock-time-edit:hover { background: var(--panel-3); }
.execution-equation { display: grid; grid-template-columns: minmax(0, 1fr) 16px minmax(0, 1fr); align-items: start; gap: 10px 6px; }
.time-cell { min-width: 0; text-align: left; }
.time-label { display: block; color: var(--text-dim); font-size: 11px; margin-bottom: 5px; text-align: start; }
.time-value, .time-offset { display: block; font-family: var(--f-mono); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.5; overflow-wrap: anywhere; }
.time-unit { color: var(--text-dim); font-size: 11px; font-weight: 400; }
.time-note { display: block; color: var(--text-dim); font-size: 10px; font-family: var(--f-mono); margin-top: 4px; overflow-wrap: anywhere; }
.math-operator { color: var(--text-dim); font-family: var(--f-mono); margin-top: 22px; font-size: 15px; text-align: center; }
.math-operator.equals { display: none; }
.final-time { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--border); }
.final-time .time-value { color: var(--cyan); font-size: 19px; }
.final-time .time-note { flex-basis: 100%; text-align: right; }
.timing-message { margin: 8px 0 0; font-size: 11px; color: var(--text-dim); }
.msym-actions { display: flex; justify-content: flex-end; align-items: center; gap: 6px; padding: 5px 12px; border-top: 1px solid var(--border-soft); }
.msym-actions .icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 6px 12px; font-size: 13px; color: var(--text-dim); }
.msym-actions .btn-edit { color: var(--text); }
.msym-actions .btn-delete { color: var(--red); }
.bulk-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 8px; padding: 6px 10px; margin-bottom: 14px; }
.bulk-bar input[type="time"] { width: auto; max-width: 100%; min-width: 110px; flex: 1; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; min-height: 40px; font-size: 14px; }
.bulk-bar .btn { width: auto; margin: 0; font-size: 12px; min-height: 40px; padding: 8px 12px; }
@container (min-width: 760px) {
  .stock-card-body { grid-template-columns: minmax(200px, .7fr) minmax(0, 1.3fr); align-items: stretch; gap: 24px; }
  .stock-order-details { align-content: center; }
}
@container (min-width: 520px) {
  .execution-equation { grid-template-columns: minmax(0, 1fr) 16px minmax(80px, .8fr) 16px minmax(0, 1.15fr); gap: 8px; }
  .math-operator.equals { display: block; }
  .final-time { grid-column: auto; display: block; padding: 0; border: 0; }
  .final-time .time-note { text-align: left; }
}
@media (min-width: 1000px) {
  .trading-layout > .accounts-panel { grid-column: 1 / -1; }
  .trading-layout .accounts-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}
@media (max-width: 400px) {
  .stock-card-header { padding: 8px 10px; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 6px; }
  .stock-enabled { flex-direction: column; gap: 4px; font-size: 10px; }
  .stock-card-body { padding: 10px; }
  .msym-row .msym-label { font-size: 16px; }
  .stock-order-details { gap: 8px; }
}
@media (prefers-reduced-motion: reduce) { .msym-row, .stock-enabled input::before { transition: none; } }

/* ---------------- 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; }

/* Shared dialogs and compact stock cards. */
.app-dialog {
  width: min(560px, calc(100% - 24px)); max-height: calc(100dvh - 32px);
  margin: auto; padding: 24px; overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 24px 80px #0008; font-family: var(--f-body);
}
.app-dialog::backdrop { background: #020617b8; backdrop-filter: blur(4px); }
body:has(.app-dialog[open]) { overflow: hidden; }
.app-dialog h2 { margin: 0 0 18px; font-size: 19px; }
.app-dialog-small { width: min(420px, calc(100% - 24px)); }
.app-dialog p { overflow-wrap: anywhere; }
.app-dialog .account-form { margin: 0; padding: 0; border: 0; }
.app-dialog .field, .app-dialog input, .app-dialog select { min-width: 0; }
.app-dialog .btn-row { margin-top: 12px; }
.stock-lookup { display: flex; align-items: stretch; gap: 8px; }
.stock-lookup input { flex: 1; width: 0; }
.stock-lookup .btn { width: auto; margin: 0; white-space: nowrap; }
.lookup-status { margin: 8px 0; font-size: 13px; color: var(--text-dim); }
.form-error, .lookup-status[data-state="error"] { color: var(--red); }
.lookup-status[data-state="success"] { color: var(--green); }
.app-dialog :focus-visible, .msym-row :focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
@media (max-width: 480px) {
  .app-dialog { padding: 18px; }
  .app-dialog .field-row { display: flex; flex-direction: column; gap: 0; }
  .app-dialog .field-row .field { flex: 0 0 auto; }
  .app-dialog input, .app-dialog select { font-size: 16px; }
}

/* The copy action shares the stock actions' touch target and dialog styles. */
.msym-actions .btn-duplicate { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; padding: 8px; }
.duplicate-stock-name { font-size: 13px; color: var(--text-dim); margin: -6px 0 18px; overflow-wrap: anywhere; }

#msym-dialog { width: min(700px, calc(100% - 24px)); }
.stock-form-group { min-width: 0; border: 0; padding: 0; margin: 0 0 18px; }
.stock-form-group legend { font-size: 13px; font-weight: 700; color: var(--text-dim); padding: 0 0 12px; }
.timing-form-group { border-top: 1px solid var(--border); padding-top: 16px; }
.editor-timing-preview .stock-timing-title { margin-bottom: 12px; }
.input-with-unit { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2); }
.input-with-unit input { border: 0; background: transparent; flex: 1; }
.input-with-unit > span { color: var(--text-dim); font: 12px var(--f-mono); padding: 0 14px; }
.stock-form-actions { position: sticky; bottom: -24px; padding: 12px 0 0; background: var(--panel); }
@media (max-width: 480px) { .stock-form-actions { bottom: -18px; } }

.stock-identity .stock-code { text-align: right; }
.stock-time-edit { min-height: 44px; }
.bulk-time-field { display: flex; align-items: center; gap: 8px; flex: 1 1 230px; color: var(--text-dim); font-size: 12px; }
.bulk-time-field > span { white-space: nowrap; }
.stocks-panel input[type="time"] { color-scheme: dark; }
.field:has(#msym-target[type="text"]) { flex-basis: 100%; }
#msym-target[type="text"] { font-family: var(--f-mono); font-size: 14px; }
@media (max-width: 480px) { .bulk-bar .btn { width: 100%; } }

/* Sequential submissions share the stock editor, but own execution/history. */
#standard-stock-dock { grid-column: 1 / -1; min-width: 0; }
#sequential-stock-dock { margin: var(--gutter) 0; min-width: 0; }
.operation-notice { padding: 10px 14px; border: 1px solid var(--amber); border-radius: 8px; color: var(--amber); font-size: 13px; margin-bottom: 14px; background: var(--panel); }
.sequential-launch .btn-row { align-items: center; margin-top: 12px; }
#sequential-phase { color: var(--cyan); font-size: 13px; }
.sequential-history h2, #sequential-settings-heading { margin: 0; font-size: 16px; }
.sequential-requests { display: grid; gap: 8px; margin: 12px 0; }
.sequential-request { border: 1px solid var(--border); background: var(--panel-2); border-radius: 8px; min-width: 0; }
.sequential-request summary { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr) auto; gap: 8px 16px; padding: 12px; cursor: pointer; font-size: 12px; overflow-wrap: anywhere; }
.sequential-request summary bdi { grid-column: 1 / -1; font-size: 11px; color: var(--text-dim); }
.sequential-request pre { white-space: pre-wrap; overflow-wrap: anywhere; direction: ltr; text-align: left; padding: 12px; margin: 0; font: 12px/1.8 var(--f-mono); border-top: 1px solid var(--border); }
.sequential-request [data-state="ACCEPTED"] { color: var(--green); }
.sequential-request [data-state="REJECTED"] { color: var(--red); }
.sequential-request [data-state*="UNKNOWN"] { color: var(--amber); }
#sequential-settings-form { max-width: none; }
#page-sequential .page-heading { flex-wrap: wrap; }
#sequential-page-label { font-size: 12px; align-self: center; }
@media(max-width:639px) {
 .sequential-request summary { grid-template-columns: minmax(0,1fr) auto; }
 .sequential-request summary .badge { grid-column: 2; grid-row: 1 / 3; align-self: center; }
 .page-nav { flex-wrap: wrap; }
 .nav-link { min-width: 54px; }
 #sequential-settings-form .field-row { flex-direction: column; }
 #sequential-settings-form .field-row .field { flex-basis: auto; }
}

#page-sequential .stock-timing, #page-sequential #bulk-bar, #page-sequential .msym-select-wrap { display: none !important; }
#page-sequential .stock-card-header { grid-template-columns: minmax(0,1fr) auto; }
#page-sequential .stock-card-body { display: block; }
#page-sequential .stock-order-details { grid-template-columns: repeat(4,minmax(0,1fr)); }
#page-sequential .stock-order-details .stock-account { grid-column: auto; }
@media(max-width:639px) { #page-sequential .stock-order-details { grid-template-columns: repeat(2,minmax(0,1fr)); } }

#sequential-run-select { width: 100%; min-width: 0; max-width: 100%; text-overflow: ellipsis; }

#page-sequential .stock-order-details .stock-target { grid-column: 1 / -1; }
/* Read-only outgoing API logs */
.page-nav { flex-wrap: wrap; }
.api-log-panel { padding: 16px; min-width: 0; }
.api-log-toolbar, .api-log-monitor, .api-log-dialog-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.api-log-toolbar .field { margin: 0; }
.api-log-toolbar .btn { margin-top: 22px; }
.api-log-filter-details { margin: 16px 0; }
.api-log-filter-details > summary { cursor: pointer; padding: 8px 0; color: var(--text-dim); font-size: 13px; }
.api-log-filter-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px 12px; padding-top: 12px; }
.api-log-monitor { font-size: 12px; color: var(--text-dim); }
.api-log-monitor select { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 8px; min-height: 40px; font: inherit; }
#api-log-updated { margin-inline-start: auto; font-size: 11px; }
.api-log-table-wrap { overflow: auto; min-width: 0; }
.api-log-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 11px; }
.api-log-table th, .api-log-table td { padding: 10px 6px; text-align: start; vertical-align: top; overflow-wrap: anywhere; border-bottom: 1px solid var(--border); }
.api-log-table th { color: var(--text-dim); font-weight: 500; }
.api-log-table td .btn { margin: 0; padding: 6px 8px; min-height: 40px; font-size: 11px; }
.api-log-table th:first-child { width: 16%; }
.api-log-table th:nth-child(3) { width: 16%; }
.api-log-table th:nth-child(7) { width: 17%; }
.api-log-table tbody tr:hover { background: var(--panel-2); }
.api-log-outcome { display: inline-block; color: var(--text-dim); border: 1px solid var(--border); background: var(--panel-2); padding: 4px 6px; border-radius: 5px; font-size: 11px; overflow-wrap: anywhere; }
.api-log-outcome[data-tone="success"] { color: var(--green); }
.api-log-outcome[data-tone="failure"] { color: var(--red); }
.api-log-outcome[data-tone="unknown"] { color: var(--amber); }
.api-log-outcome[data-tone="pending"] { color: var(--cyan); }
.api-log-pagination { margin-top: 16px; }
.api-log-dialog { width: min(1000px,calc(100vw - 24px)); max-width: 1000px; }
.api-log-dialog-head { justify-content: space-between; }
.api-log-dialog-head h2 { margin: 0; }
#api-log-detail-content { max-height: 60vh; overflow: auto; overscroll-behavior: contain; margin: 12px 0; min-width: 0; }
.api-log-metadata { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; margin: 16px 0; }
.api-log-metadata > div { min-width: 0; }
.api-log-metadata dt { color: var(--text-dim); font-size: 11px; }
.api-log-metadata dd { direction: ltr; text-align: left; unicode-bidi: isolate; margin: 4px 0 0; overflow-wrap: anywhere; font: 12px/1.6 var(--f-mono); }
.api-log-payloads { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.api-log-payloads section { min-width: 0; }
.api-log-payloads h3 { font-size: 12px; }
.api-log-dialog pre { font: 12px/1.7 var(--f-mono); direction: ltr; text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; padding: 12px; border: 1px solid var(--border); background: var(--panel-2); border-radius: 6px; max-height: 280px; overflow: auto; }
@media(max-width:1000px) { .api-log-filter-grid { grid-template-columns: repeat(2,minmax(0,1fr)); } }
@media(max-width:1000px) {
 .api-log-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
 .api-log-table, .api-log-table tbody { display: block; }
 .api-log-table tr { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px 12px; border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
 .api-log-table td { display: block; border: 0; padding: 0; }
 .api-log-table td::before { content: attr(data-label); display: block; color: var(--text-dim); font-family: var(--f-body); font-size: 10px; margin-bottom: 3px; }
 .api-log-table td:nth-child(3), .api-log-table td:first-child, .api-log-table td:last-child { grid-column: 1 / -1; }
 .api-log-table td:last-child::before { display: none; }
 .api-log-table td:last-child .btn { width: 100%; }
}
@media(max-width:640px) {
 .api-log-toolbar .field { flex-basis: 100%; }
 .api-log-toolbar .btn { margin-top: 0; flex: 1; }
 .api-log-filter-grid, .api-log-metadata, .api-log-payloads { grid-template-columns: minmax(0,1fr); }
 #api-log-updated { flex-basis: 100%; }
 .api-log-dialog { padding: 16px; }
}
/* Scoped width rules outrank the shared full-width .btn rule. */
.api-log-panel .btn-auto, #page-api-logs > .page-heading > .btn, .api-log-dialog-head .btn { width: auto; flex: 0 0 auto; }
#page-api-logs > .page-heading { flex-wrap: wrap; }
#page-api-logs > .page-heading > div { flex: 1 1 220px; min-width: 0; }
.api-log-toolbar .grow { flex: 1 1 260px; }
@media(max-width:640px) { .api-log-toolbar .field { flex-basis: 100%; } .api-log-toolbar .btn { flex: 1 1 120px; } }

.api-log-table th:first-child { width: 17%; }
.api-log-table th:nth-child(2) { width: 5%; }
.api-log-table th:nth-child(3) { width: 17%; }
.api-log-table th:nth-child(4), .api-log-table th:nth-child(5) { width: 10%; }
.api-log-table th:nth-child(6) { width: 5%; }
.api-log-table th:nth-child(8) { width: 7%; }
.api-log-table th:nth-child(9) { width: 4%; }
.api-log-table th:nth-child(10) { width: 8%; }

.api-log-payloads p { font-size: 11px; color: var(--text-dim); }
