/* F&O OTM Premium Scanner */

:root {
  /* The site's shared palette (/_assets/theme.css) in both themes, the scanner's colours made from it */
  --bg: var(--at-bg);
  --surface: var(--at-surface);
  --surface-head: var(--at-surface-2);
  --border: var(--at-border);
  --border-strong: var(--at-border-strong);
  --text: var(--at-text);
  --text-2: var(--at-text-2);
  --text-3: var(--at-text-3);
  --accent: var(--at-accent);
  --accent-ink: var(--at-accent-ink);
  --accent-soft: var(--at-accent-soft);
  --focus: var(--at-focus);
  --up: var(--at-up);
  --down: var(--at-down);
  --call: color-mix(in srgb, var(--at-up) 8.5%, transparent);
  --put: color-mix(in srgb, var(--at-down) 7.5%, transparent);
  --call-ink: var(--at-up);
  --put-ink: var(--at-down);
  --key-col: var(--at-accent-softer);
  --row-hover: var(--at-accent-softer);
  --error-ink: var(--at-down);
  --error-row: color-mix(in srgb, var(--at-down) 5%, transparent);
  --warn-ink: var(--at-warn);
  --warn-bg: var(--at-warn-soft);
  --warn-border: color-mix(in srgb, var(--at-warn) 35%, transparent);
  --ok: var(--at-up);
  --skeleton: var(--at-surface-3);
  --star: var(--at-gold);
  --star-row: color-mix(in srgb, var(--at-gold) 7%, transparent);
  --star-line: color-mix(in srgb, var(--at-gold) 45%, transparent);
  --badge-bg: var(--at-accent-soft);
  --badge-ink: var(--at-accent-text);
  --shadow: var(--at-shadow);

  --gutter: 16px;
  --head-h: 38px;
  --row-h: 32px;
  --sym-w: 164px;
  --font: var(--at-font);
}


*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Page layout: the table area fills the viewport and scrolls on its own ---------- */

.app {
  display: flex;
  flex: 1;
  flex-direction: column;
  width: 100%;
  max-width: 1440px;
  min-height: 0;
  margin: 0 auto;
  padding: 12px var(--gutter) 10px;
}

.app > * {
  flex: none;
}

/* The site's top bar (site-nav.css): the menu and the scanner's name, the Kotak session on the right */
.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
}

.subtitle {
  margin: 0 0 12px;
  color: var(--text-2);
  font-size: 14px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Kotak session ---------- */

.session {
  display: flex;
  align-items: center;
  min-height: 32px;
}

.session-login {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin: 0;
}

.control-totp {
  width: 104px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  text-align: center;
}

.control-totp::placeholder {
  letter-spacing: 0;
}

.login-error {
  color: var(--error-ink);
  font-size: 13px;
}

.login-error:empty {
  display: none;
}

.session-on {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.session-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent);
}

.link-btn {
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

.link-btn:disabled {
  color: var(--text-3);
  cursor: default;
}

/* ---------- Controls ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin-bottom: 12px;
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.field-label {
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.control,
.btn {
  height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  box-shadow: var(--shadow);
}

select.control {
  padding: 0 28px 0 10px;
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%),
    linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

select.control:disabled {
  color: var(--text-3);
  cursor: default;
}

.control-expiry {
  min-width: 200px;
}

input.control {
  padding: 0 10px;
}

input.control::placeholder {
  color: var(--text-3);
}

input.control:disabled {
  color: var(--text-3);
}

.field-check {
  gap: 7px;
  height: 34px;
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
}

.field-check label {
  cursor: pointer;
  user-select: none;
}

.check {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.check:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Search and the buttons wrap as one unit, so the buttons never end up alone on a row. */
.controls-end {
  display: flex;
  flex: 1 1 380px;
  align-items: center;
  justify-content: flex-end;
  gap: 8px 14px;
  min-width: 0;
}

.field-search {
  flex: 0 1 240px;
  min-width: 120px;
}

.field-search input {
  width: 100%;
}

.control:focus-visible,
.btn:focus-visible,
.link-btn:focus-visible,
.sort:focus-visible,
.tab:focus-visible,
.table-wrap:focus-visible,
.seg-item input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.control:hover:not(:disabled),
.btn:hover:not(:disabled) {
  border-color: var(--text-3);
}

/* Segmented control (All / Stocks / Indices) */

.seg {
  border: 0;
  padding: 0;
  min-width: 0;
}

.seg legend {
  float: left;
  margin-right: 8px;
  padding: 0;
  line-height: 34px;
}

.seg-group {
  display: inline-flex;
  height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.seg-item {
  position: relative;
  display: flex;
}

.seg-item + .seg-item {
  border-left: 1px solid var(--border-strong);
}

.seg-item input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.seg-item span {
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: var(--text-2);
  font-size: 14px;
  user-select: none;
  outline-offset: -2px !important;
}

.seg-item input:checked + span {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.seg-item:hover input:not(:checked) + span {
  color: var(--text);
}

.actions {
  display: flex;
  flex: none;
  gap: 8px;
}

.btn {
  padding: 0 12px;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
}

.btn:disabled {
  color: var(--text-3);
  cursor: default;
  box-shadow: none;
}

.btn:active:not(:disabled) {
  background: var(--surface-head);
}

.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover:not(:disabled) {
  border-color: var(--accent);
  filter: brightness(1.08);
}

.btn-primary:active:not(:disabled) {
  background: var(--accent);
  filter: brightness(0.95);
}

.btn-primary:disabled {
  border-color: var(--border-strong);
  background: var(--surface-head);
}

.btn-small {
  height: 28px;
  padding: 0 10px;
  font-size: 13px;
}

.btn-warn {
  border-color: var(--warn-border);
  background: var(--warn-bg);
  color: var(--warn-ink);
}

.btn-warn:hover:not(:disabled) {
  border-color: var(--warn-ink);
}

.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 0 0 10px;
  padding: 8px 12px;
  border: 1px solid var(--warn-border);
  border-radius: 6px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 14px;
}

/* ---------- Tabs and status ---------- */

.tabbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 4px 16px;
}

.tabs {
  position: relative;
  z-index: 6;
  display: flex;
  gap: 2px;
  margin-bottom: -1px; /* The selected tab covers the panel's top border, so they read as one piece. */
}

.tab {
  position: relative;
  height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  outline-offset: -2px !important;
}

.tab:hover {
  color: var(--text);
}

.tab-note {
  margin-left: 4px;
  color: var(--text-3);
  font-size: 13px;
  font-weight: 500;
}

.tab[aria-selected="true"] {
  height: 39px;
  border-color: var(--border);
  background: linear-gradient(var(--tab-tint, transparent), var(--tab-tint, transparent)), var(--surface);
  color: var(--text);
}

.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset: 0 -1px auto;
  height: 2px;
  border-radius: 8px 8px 0 0;
  background: currentColor;
}

.tab-call[aria-selected="true"] {
  --tab-tint: var(--call);
  color: var(--call-ink);
}

.tab-put[aria-selected="true"] {
  --tab-tint: var(--put);
  color: var(--put-ink);
}

.tab[aria-selected="true"] .tab-note {
  color: var(--text-2);
}

.status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 4px 12px;
  min-height: 32px;
  margin-bottom: 3px;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

.status-main {
  display: flex;
  flex-wrap: wrap;
  gap: 0 6px;
  margin: 0;
}

.status-main > span:not(:first-child):not(:empty)::before {
  content: "\00b7";
  margin-right: 6px;
  color: var(--text-3);
}

.status-side {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-muted {
  color: var(--text-2);
}

.status-margin {
  color: var(--text);
}

.progress {
  position: relative;
  z-index: 5;
  height: 3px;
  margin-bottom: -3px;
  overflow: hidden;
  /* A full-width track, so the bar reads as progress, not as a tab's underline */
  background: var(--accent-soft);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.progress.is-active {
  opacity: 1;
  transition: none;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.3s ease;
}

.progress-bar.is-reset {
  transition: none;
}

/* ---------- Table ---------- */

.panels {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 260px;
}

.table-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 0 8px 8px 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.grid {
  width: 100%;
  min-width: 1054px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.w-sym { width: var(--sym-w); }
.w-spot { width: 172px; }
.w-lot { width: 84px; }
.w-strike { width: 104px; }
.w-pct { width: 92px; }
.w-prem { width: 104px; }
.w-rs { width: 104px; }
.w-margin { width: 120px; }
.w-ret { width: 106px; }

.grid th,
.grid td {
  padding: 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.grid .num {
  text-align: right;
}

/* Header */

.grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: var(--head-h);
  padding: 0;
  border-bottom: 1px solid var(--border-strong);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
}

.grid-call thead th {
  background: linear-gradient(var(--call), var(--call)), var(--surface-head);
}

.grid-put thead th {
  background: linear-gradient(var(--put), var(--put)), var(--surface-head);
}

.grid thead th.c-sym {
  left: 0;
  z-index: 3;
}

.sort {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 3px;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: inherit;
  white-space: nowrap;
  cursor: pointer;
  outline-offset: -2px !important;
}

.num .sort {
  justify-content: flex-end;
}

.sort:hover {
  color: var(--text);
}

/* Sort arrow: space is always reserved so labels never shift. On numeric columns it sits left of the label. */
.sort::after,
.num .sort::before {
  content: "\2193";
  flex: none;
  width: 10px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  visibility: hidden;
}

.num .sort::after {
  content: none;
}

th[aria-sort] .sort {
  color: var(--text);
}

th[aria-sort] .sort::after,
th[aria-sort] .sort::before {
  visibility: visible;
  color: var(--accent);
}

th[aria-sort="ascending"] .sort::after,
th[aria-sort="ascending"] .sort::before {
  content: "\2191";
}

/* Body */

/* Cell backgrounds stack a row tint (starred, hover, error) over a column tint (Return %), always opaque for sticky cells. */
.grid tbody td {
  height: var(--row-h);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(var(--row-tint, transparent), var(--row-tint, transparent)),
    linear-gradient(var(--col-tint, transparent), var(--col-tint, transparent)), var(--surface);
}

.grid tbody td.c-ret {
  --col-tint: var(--key-col);
}

.grid tbody tr.row-starred {
  --row-tint: var(--star-row);
}

.grid tbody tr:hover {
  --row-tint: var(--row-hover);
}

.grid tbody tr.row-starred:hover {
  --row-tint: color-mix(in srgb, var(--star-row), var(--row-hover));
}

.grid tbody tr.star-end td {
  box-shadow: inset 0 -1px 0 var(--star-line);
}

.grid tbody tr:last-child td {
  border-bottom-color: transparent;
}

.grid .gs {
  border-left: 1px solid var(--border);
}

.grid thead .gs {
  border-left-color: var(--border-strong);
}

.grid .c-sym {
  position: sticky;
  left: 0;
  z-index: 1;
  border-right: 1px solid var(--border);
}

.grid thead .c-sym {
  border-right-color: var(--border-strong);
}

.sym {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

/* Star toggle: fixed box, so the symbol text never moves when it changes. */
.star {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin: 0 -2px 0 -5px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
}

.star svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linejoin: round;
}

.star:hover {
  color: var(--text-2);
}

.star[aria-pressed="true"] {
  color: var(--star);
}

.star[aria-pressed="true"] svg {
  fill: currentColor;
}

.star:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 0;
}

.sym-name {
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}

.badge {
  flex: none;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--badge-bg);
  color: var(--badge-ink);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.3;
}

.c-spot .chg {
  display: inline-block;
  min-width: 56px;
  margin-left: 6px;
  color: var(--text-3);
  font-size: 12.5px;
}

.c-spot .chg.up {
  color: var(--up);
}

.c-spot .chg.down {
  color: var(--down);
}

.c-prem {
  font-weight: 600;
}

.grid td.c-ret {
  color: var(--text);
  font-weight: 650;
}

.grid td.na {
  color: var(--text-3);
  font-weight: 400;
}

.grid td.c-flag {
  color: var(--warn-ink);
  font-weight: 700;
  cursor: help;
}

/* Pending rows: placeholders with the exact row height so filling in never moves anything. */

.sk {
  display: inline-block;
  width: 70%;
  max-width: 56px;
  height: 8px;
  border-radius: 4px;
  background: var(--skeleton);
  vertical-align: middle;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

.row-stale td:not(.c-sym),
.row-stale td.c-ret,
.row-stale .chg.up,
.row-stale .chg.down {
  color: var(--text-3);
}

/* Error rows */

.grid tbody tr.row-error,
.grid tbody tr.row-error:hover {
  --row-tint: var(--error-row);
}

.row-error .c-error {
  color: var(--error-ink);
  font-size: 13.5px;
}

/* The message stays in view next to the sticky Symbol column when the table is scrolled sideways. */
.grid td.c-error {
  overflow: visible;
}

.err-msg {
  position: sticky;
  left: calc(var(--sym-w) + 8px);
  display: inline-block;
  max-width: calc(100vw - 2 * var(--gutter) - var(--sym-w) - 28px);
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.row-error .sym-name {
  color: var(--error-ink);
}

.grid .row-empty td {
  height: 120px;
  color: var(--text-2);
  text-align: center;
}

/* ---------- Footer ---------- */

.footer {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2px 16px;
  padding-top: 8px;
  color: var(--text-2);
  font-size: 13px;
}

.footer p {
  margin: 0;
}

.noscript {
  margin: 16px;
  color: var(--error-ink);
}

/* ---------- Small screens ---------- */

@media (max-width: 720px) {
  :root {
    --gutter: 12px;
  }

  .app {
    padding-top: 12px;
  }

  .masthead {
    padding-inline: 12px;
  }

  .subtitle {
    font-size: 13.5px;
  }

  .controls {
    gap: 10px 12px;
  }

  /* OTM % and Expiry share one row on phones, with their labels above. */
  .field-stack {
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
  }

  .field-stack .field-label {
    font-size: 12px;
  }

  .field-stack:has(.control-expiry) {
    flex: 1 1 auto;
  }

  .control-expiry {
    min-width: 0;
  }

  .controls-end {
    flex-basis: 100%;
    gap: 8px;
  }

  .field-search {
    flex: 1 1 auto;
  }

  .tabbar {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .status {
    justify-content: space-between;
  }

  .tab {
    padding: 0 12px;
  }

  .status-main {
    gap: 0 10px;
  }

  .status-main > span:not(:first-child):not(:empty)::before {
    content: none;
  }

  /* On phones the page scrolls normally and the table gets (almost) the whole screen once scrolled to. */
  .app {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .panels {
    flex: none;
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
    min-height: 320px;
  }

  .table-wrap {
    overscroll-behavior: auto;
  }
}

@media (max-height: 560px) {
  .app {
    height: auto;
  }

  .panels {
    flex: none;
    height: 80vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sk {
    animation: none;
  }

  .progress,
  .progress-bar {
    transition: none;
  }
}


/* The scanner's toolbar holds only its name (and, for the admin, the Kotak session), so
   the name stays at every width instead of leaving an empty bar on phones. */
.masthead .at-bar-title {
  display: block;
}
