:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #e2e5ea;
  --text: #0f1419;
  --muted: #5d6673;
  --faint: #8b93a0;
  --accent: #2856d6;
  --accent-ink: #ffffff;
  --safe: #1d7f55;
  --caution: #a36a00;
  --warning: #c2510f;
  --danger: #c4314b;
  --safe-bg: #e4f4ec;
  --caution-bg: #fbf1dc;
  --warning-bg: #fde9dd;
  --danger-bg: #fbe4e8;
  --long: #1d7f55;
  --short: #c4314b;
  --shadow: 0 1px 2px rgba(15, 20, 25, .05), 0 4px 16px rgba(15, 20, 25, .04);
  --radius: 16px;
  --font: "Changa", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Changa", system-ui, -apple-system, sans-serif; /* numbers use tabular figures */
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0e13; --surface: #12161d; --surface-2: #1a1f28; --line: #242b36;
    --text: #e8ebf0; --muted: #9aa3b0; --faint: #6b7482;
    --accent: #6d93ff; --accent-ink: #0b0e13;
    --safe: #4cc38a; --caution: #e5b34a; --warning: #f08a4b; --danger: #f06a7e;
    --safe-bg: #12281f; --caution-bg: #2a2313; --warning-bg: #2c1c12; --danger-bg: #2d1519;
    --long: #4cc38a; --short: #f06a7e;
    --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 6px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0e13; --surface: #12161d; --surface-2: #1a1f28; --line: #242b36;
  --text: #e8ebf0; --muted: #9aa3b0; --faint: #6b7482;
  --accent: #6d93ff; --accent-ink: #0b0e13;
  --safe: #4cc38a; --caution: #e5b34a; --warning: #f08a4b; --danger: #f06a7e;
  --safe-bg: #12281f; --caution-bg: #2a2313; --warning-bg: #2c1c12; --danger-bg: #2d1519;
  --long: #4cc38a; --short: #f06a7e;
  --shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 6px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select { font: inherit; color: inherit; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
[hidden] { display: none !important; }

.app { max-width: 1040px; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 16px 96px; }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
h1 { font-size: 20px; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  min-width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; cursor: pointer; font-weight: 600; font-size: 14px;
}

/* Layout */
.grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.col { display: grid; gap: 12px; align-content: start; min-width: 0; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 860px) {
  .grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 16px; }
  .col:first-child { position: sticky; top: 16px; }
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 12px; letter-spacing: .02em; text-transform: uppercase; }
.mini-title { font-size: 12px; font-weight: 600; color: var(--faint); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; }

/* Segmented controls */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; margin-bottom: 10px; }
.seg button {
  height: 44px; border: 0; border-radius: 9px; background: transparent; cursor: pointer;
  font-weight: 600; color: var(--muted); transition: background .15s, color .15s;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg.dir button.on.long { background: var(--long); color: #fff; }
.seg.dir button.on.short { background: var(--short); color: #fff; }

/* Fields */
.fields { display: grid; gap: 10px; }
.fields.two { grid-template-columns: 1fr 1fr; }
.fields.three { grid-template-columns: 1fr 1fr 1fr; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field input, .field select {
  width: 100%; height: 48px; padding: 0 12px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface-2);
  font-family: var(--mono); font-size: 17px; font-weight: 500; outline: none;
  transition: border-color .15s, background .15s;
}
.field select { font-family: var(--font); font-size: 15px; }
[dir="rtl"] .field input { text-align: right; }
.field input:focus, .field select:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.field input::placeholder { color: var(--faint); }
@media (max-width: 380px) { .fields.three { grid-template-columns: 1fr 1fr; } .fields.three .field:first-child { grid-column: 1 / -1; } }

.hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); min-height: 1em; }
.hint:empty { display: none; }

.risk-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: end; margin-top: 10px; }
.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.chips button {
  height: 48px; border-radius: 11px; border: 1px solid var(--line); background: transparent;
  font-family: var(--mono); font-size: 14px; font-weight: 500; cursor: pointer; color: var(--muted);
}
.chips button.on { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }

details.more { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details.more summary { font-size: 13px; color: var(--accent); font-weight: 600; padding: 6px 0; }
details.more[open] summary { margin-bottom: 8px; }

/* Hero result */
.hero { padding: 18px; }
.hero-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.eyebrow { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.lot-line { display: flex; align-items: baseline; gap: 10px; margin-top: 6px; }
.lot { font-family: var(--mono); font-size: 54px; font-weight: 600; line-height: 1.05; letter-spacing: -.03em; }
.lot-unit { font-size: 15px; font-weight: 600; color: var(--muted); }
.qty { font-family: var(--mono); color: var(--muted); font-size: 14px; margin-top: 2px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.kpis > div { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; display: grid; gap: 2px; min-width: 0; }
.kpis span { font-size: 11px; color: var(--muted); font-weight: 500; }
.kpis b { font-family: var(--mono); font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hero.invalid .lot { color: var(--faint); }
.hero.invalid .kpis { opacity: .5; }

.pill {
  display: inline-flex; align-items: center; height: 28px; padding: 0 12px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .03em; white-space: nowrap;
}
.pill:empty { display: none; }
.pill.sm { height: 22px; padding: 0 8px; font-size: 11px; }
.s-safe { background: var(--safe-bg); color: var(--safe); }
.s-caution { background: var(--caution-bg); color: var(--caution); }
.s-warning { background: var(--warning-bg); color: var(--warning); }
.s-notExecutable { background: var(--danger-bg); color: var(--danger); }

.l-safe { color: var(--safe); } .l-caution { color: var(--caution); } .l-warning { color: var(--warning); } .l-high { color: var(--danger); }

.msgs { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.msgs:empty { display: none; }
.msgs li { font-size: 13px; padding: 9px 12px; border-radius: 10px; border-inline-start: 3px solid; }
.m-error { background: var(--danger-bg); border-color: var(--danger) !important; }
.m-warn { background: var(--warning-bg); border-color: var(--warning) !important; }
.m-info { background: var(--surface-2); border-color: var(--faint) !important; color: var(--muted); }

/* Rows */
.rows { margin: 0; display: grid; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); min-height: 40px; }
.row:last-child { border-bottom: 0; }
.row dt { color: var(--muted); font-size: 14px; }
.row dd { margin: 0; font-family: var(--mono); font-size: 14px; text-align: end; }
.row dd b { font-weight: 600; font-size: 16px; }
.row dd small { color: var(--muted); font-size: 12px; margin-inline-start: 6px; }
.row.sub dt, .row.sub dd { font-size: 13px; }
.row.sub dt { color: var(--faint); }
.row.hl { background: color-mix(in srgb, var(--accent) 8%, transparent); margin: 0 -8px; padding-inline: 8px; border-radius: 8px; }
.row.total { border-top: 1px solid var(--line); border-bottom: 0; padding-top: 12px; margin-top: 2px; }
.row.total dt { color: var(--text); font-weight: 600; }
.tag { font-style: normal; font-family: var(--font); font-size: 11px; color: var(--accent); font-weight: 600; margin-inline-start: 6px; }
.neg { color: var(--danger); } .pos { color: var(--safe); }

/* Meters */
.meters { display: grid; gap: 12px; }
.meter-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.meter-top b { font-family: var(--mono); color: var(--text); font-weight: 600; }
.track { position: relative; height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; direction: ltr; }
[dir="rtl"] .track { direction: rtl; }
.track i { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--line); z-index: 1; }
.fill { height: 100%; border-radius: 99px; background: currentColor; transition: width .25s ease; }
.fill.l-safe { color: var(--safe); } .fill.l-caution { color: var(--caution); } .fill.l-warning { color: var(--warning); } .fill.l-high { color: var(--danger); }

.note { font-size: 12px; color: var(--faint); margin: 14px 0 0; }

.fixed-warn { font-size: 13px; margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; }
.fixed-warn:empty { display: none; }

/* Folds */
.fold > summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 28px; }
.fold > summary .card-title { margin: 0; }
.fold > summary::after { content: ""; width: 8px; height: 8px; border: solid var(--faint); border-width: 0 2px 2px 0; transform: rotate(45deg); margin-inline-start: auto; transition: transform .15s; }
.fold > summary .pill { margin-inline-start: auto; }
.fold > summary .pill + ::after { margin: 0; }
.fold[open] > summary::after { transform: rotate(-135deg); }
.fold[open] > summary { margin-bottom: 12px; }

/* Trading days */
.days { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.days .card-title { margin-bottom: 2px; }
.days-count { font-family: var(--mono); font-size: 24px; font-weight: 600; }
.days-count.done { color: var(--safe); }
.days-actions { display: flex; gap: 8px; }
.btn { height: 44px; padding: 0 16px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; color: var(--muted); width: 100%; margin-top: 16px; }

.foot { text-align: center; color: var(--faint); font-size: 12px; margin-top: 20px; }

/* Sticky dock */
.dock {
  position: fixed; inset-inline: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line); box-shadow: 0 8px 30px rgba(0, 0, 0, .18);
  transform: translateY(140%); transition: transform .2s ease; cursor: pointer; z-index: 10; max-width: 560px; margin: 0 auto;
}
.dock.show { transform: none; }
.dock-lot { font-family: var(--mono); font-weight: 600; font-size: 18px; }
.dock-meta { font-family: var(--mono); font-size: 13px; color: var(--muted); flex: 1; }
@media (min-width: 860px) { .dock { display: none; } }

/* Settings sheet */
dialog { border: 0; padding: 0; background: transparent; color: var(--text); max-width: 560px; width: 100%; margin: auto auto 0; max-height: 92dvh; }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
@media (min-width: 600px) { dialog { margin: auto; } }
.sheet { background: var(--surface); border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 92dvh; overflow: auto; }
@media (min-width: 600px) { .sheet { border-radius: 20px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: -16px; background: var(--surface); padding: 4px 0 8px; z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet .mini-title:first-child { margin-top: 4px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Symbol picker */
.sym-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-bottom: 6px; }
.seg.sym { grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0; }
.seg.sym button { font-size: 13px; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sym-all {
  height: 52px; padding: 0 12px; border-radius: 12px; border: 1px dashed var(--line); background: transparent;
  color: var(--accent); font-weight: 600; font-size: 13px; cursor: pointer;
}
.spec { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 10px; font-size: 12px; color: var(--muted); }
.spec .ltr { color: var(--text); font-weight: 600; }
.rates { margin-top: 10px; }
.rates:empty { display: none; }
.hint.full { grid-column: 1 / -1; margin: 0; }
.fill.l-info { color: var(--accent); }

.search {
  flex: 1; height: 46px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface-2);
  padding: 0 14px; font-size: 16px; outline: none; min-width: 0;
}
.search:focus { border-color: var(--accent); }
.sheet-head:has(.search) { gap: 8px; }
.chips.classes { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chips.classes button { height: 36px; padding: 0 12px; font-family: var(--font); font-size: 13px; white-space: nowrap; flex: none; }
.sym-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sym-list button {
  width: 100%; display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px;
  min-height: 48px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; text-align: start;
}
.sym-list button:hover, .sym-list button.on { background: var(--surface-2); }
.sym-list button.on b { color: var(--accent); }
.sym-list b { font-weight: 600; font-size: 15px; justify-self: start; }
.sym-list span { font-size: 12px; color: var(--muted); }
.sym-list em { font-style: normal; font-size: 12px; color: var(--faint); min-width: 40px; text-align: end; }
#symbolDlg .sheet { min-height: 70dvh; }
