/* Final Perps presentation layer. Keep the data and order logic in perps.html. */
:root {
  --chart-bg: #fff;
  --chart-grid: #e8edf0;
  --chart-text: #667782;
  --chart-cross-bg: #e5edf1;
  --chart-up: #168568;
  --chart-down: #d84d55;
  --chart-last: #168568;
}
:root[data-theme="dark"] {
  --chart-bg: #141b25;
  --chart-grid: #263341;
  --chart-text: #9eacbd;
  --chart-cross-bg: #334356;
  --chart-up: #36c49a;
  --chart-down: #f1787e;
  --chart-last: #36c49a;
}
.embedded, .embedded body { overflow-y: hidden; }
.tabnav {
  gap: 8px !important;
  padding: 8px 16px 0 !important;
  margin: 0 !important;
  background: var(--panel);
}
.tabnav button,
.tabnav .tab-link {
  padding: 9px 14px 11px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
}
.embedded .tabnav .tab-link { display: none; }

#marketsView { padding-top: 24px; padding-bottom: 32px; }
#marketsView .mk-head { margin-bottom: 20px; }
#marketsView .mk-head h1 { font-size: clamp(26px, 2.5vw, 34px); letter-spacing: -.035em; }
#marketsView .dash-stats { gap: 10px; margin-bottom: 16px; }
#marketsView .dash-stat,
#marketsView .mv-card,
#marketsView .mk-guide,
#marketsView .mk-table { box-shadow: 0 2px 12px rgba(20, 33, 44, .035); }
#marketsView .dash-stat { padding: 17px 18px; }
#marketsView .mk-table { padding: 18px; }
#marketsView .mk-toolbar { margin-bottom: 16px; }
#marketsView .search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
#marketsView tbody tr { transition: background .15s ease; }
#marketsView th,
#marketsView td { padding-top: 13px; padding-bottom: 13px; }

#tradeView .tk-strip { background: var(--panel); }
#tradeView .tk-item { min-height: 42px; }
#tradeView .tk-item.on { background: var(--accent-bg) !important; }
#tradeView .back { margin: 16px 16px 0; font-size: 13px; font-weight: 600; }
#tradeView .tk-bar {
  margin: 12px 16px 14px;
  padding: 16px 18px;
  gap: 12px 24px;
  box-shadow: 0 2px 12px rgba(20, 33, 44, .035);
}
#tradeView .tk-bar .trade-head { gap: 18px; }
#tradeView #marketBtn { min-width: 198px; }
#tradeView .price-row .mark { font-size: 27px; font-weight: 700; letter-spacing: -.03em; }
#tradeView .tk-bar .stats { gap: 10px 22px; }
#tradeView .tk-bar .stats > div { min-width: 72px; }
#tradeView .tk-bar .stats > div[hidden] { display: none !important; }
#tradeView .tk-bar .stats span { font-size: 11px !important; }
#tradeView .tk-bar .stats b { font-size: 13px !important; }
#tradeView .trade { margin: 0 16px !important; }
#tradeView .trade { gap: 18px !important; }
#tradeView .trade-left > .panel:first-child,
#tradeView .op,
#tradeView .trade-left > .discover {
  box-shadow: 0 2px 12px rgba(20, 33, 44, .035);
}
#tradeView .trade-left > .panel:first-child {
  background: var(--panel) !important;
  border: 1px solid var(--line) !important;
  border-radius: 12px !important;
  padding: 16px !important;
  overflow: hidden;
}
#tradeView .trade-left > .panel:first-child .chart-head h2,
#tradeView .trade-left > .panel:first-child .chart-head .title {
  color: var(--ink) !important;
  font-size: 15px;
}
#tradeView .trade-left > .panel:first-child .chart-head .source { color: var(--muted); }
#tradeView .trade-left > .panel:first-child .ranges {
  background: var(--chip);
  border-color: var(--line);
  border-radius: 8px;
}
#tradeView .trade-left > .panel:first-child .ranges button { color: var(--muted); }
#tradeView .trade-left > .panel:first-child .ranges button.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(20, 33, 44, .12);
}
#tradeView .trade-left > .panel:first-child #chart {
  background: var(--chart-bg) !important;
  border: 1px solid var(--line) !important;
  border-radius: 8px !important;
  height: 640px !important;
  min-height: 640px !important;
}
#tradeView .trade-left > .panel:first-child .chart-foot { color: var(--muted); }
#tradeView .trade-left > .panel:first-child .chart-foot a { color: var(--muted); }
#tradeView .op { border-radius: 12px !important; }
#tradeView .op-head { margin-bottom: 2px; }
#tradeView .op-input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
#tradeView .op-sum > div { align-items: baseline; }
#tradeView .op-sum dt { line-height: 1.35; }
#tradeView .op-sum dd { white-space: nowrap; }
#tradeView .op-submit { border-radius: 9px; }
#tradeView #submitOrder[hidden],
#confirmBackdrop[hidden],
#confirmBox[hidden] { display: none !important; }
#confirmBackdrop {
  position: fixed;
  inset: 0;
  z-index: 180;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(8, 16, 24, .58);
}
#confirmBox {
  width: min(560px, 100%);
  max-height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .28);
}
.order-confirm-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex: none; }
.order-confirm-head h2 { margin: 0; font-size: 22px; line-height: 1.25; letter-spacing: -.02em; }
.order-confirm-close { width: 32px; height: 32px; flex: none; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; }
.order-confirm-close:hover { color: var(--ink); }
.order-review-grid { margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.order-review-grid > div { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.order-review-grid > div:last-child { border-bottom: 0; }
.order-review-grid > div:nth-child(even) { background: var(--bg); }
.order-review-grid dt { color: var(--muted); flex: 0 0 auto; }
.order-review-grid dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.order-confirm-note { margin: 12px 0 14px; color: var(--muted); font-size: 12px; line-height: 1.45; flex: none; }
#confirmStatus[hidden] { display: none !important; }
.order-confirm-status { margin: 0 0 14px; padding: 10px 12px; max-height: 110px; overflow: auto; flex: none; border: 1px solid var(--line); border-radius: 8px; background: var(--accent-bg); color: var(--ink); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.order-confirm-status.error { border-color: var(--down); background: color-mix(in srgb, var(--down) 10%, var(--panel)); color: var(--down); }
#confirmBox .confirm-actions { gap: 10px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); flex: none; }
#confirmBox .confirm-actions button { min-width: 0; height: 46px; border-radius: 9px; font-size: 14px; }
#confirmBox .confirm-actions .ghost { background: var(--bg); }
#confirmBox button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#tradeView .op-note { margin-top: 2px; }
#tradeView .trade-left > .panel:first-child .pl-bar { margin: 6px 0 10px; }
#tradeView .trade-left > .panel:first-child .pl-bar button:focus-visible,
#tradeView button:focus-visible,
#marketsView button:focus-visible,
.tabnav button:focus-visible {
  outline: 2px solid var(--accent) !important;
  outline-offset: 2px;
}
#tradeView .trade-left > .discover { border-radius: 12px !important; border: 1px solid var(--line) !important; }
#tradeView .pf-tabs { max-width: 100%; overflow-x: auto; white-space: nowrap; flex-wrap: nowrap; }
#tradeView .pf-tabs button { flex: none; }

@media (max-width: 1100px) {
  #tradeView .tk-bar .trade-head { justify-content: flex-start; }
  #tradeView .tk-bar .stats { flex-basis: 100%; }
  #tradeView .trade { margin: 0 16px !important; }
  #tradeView .trade-left > .panel:first-child #chart { height: 500px !important; min-height: 500px !important; }
}
@media (max-width: 700px) {
  #confirmBackdrop { padding: 12px; }
  #confirmBox { padding: 16px; border-radius: 12px; }
  .order-review-grid > div { padding: 7px 9px; font-size: 12px; }
  .order-review-grid dt { flex: 0 1 auto; }
  .tabnav { padding-left: 12px !important; }
  #marketsView { padding: 20px 12px 28px; }
  #marketsView .mk-head h1 { font-size: 27px; }
  #marketsView .dash-stats { gap: 8px; }
  #marketsView .dash-stat { padding: 13px; }
  #marketsView .dash-stat b { font-size: 19px; }
  #marketsView .mk-table { padding: 14px 10px; }
  #tradeView .back { margin-left: 12px; }
  #tradeView .tk-bar { margin: 10px 12px 12px; padding: 14px; }
  #tradeView .tk-bar .trade-head { gap: 12px; }
  #tradeView #marketBtn { min-width: 0; width: 100%; }
  #tradeView .tk-bar .trade-head .th-right { width: 100%; }
  #tradeView .price-row { width: 100%; justify-content: space-between; }
  #tradeView .tk-bar .stats { gap: 12px 8px; }
  #tradeView .trade { margin: 0 12px !important; }
  #tradeView .op { padding: 16px !important; }
  #tradeView .trade-left > .panel:first-child { padding: 12px !important; }
  #tradeView .trade-left > .panel:first-child #chart { height: 350px !important; min-height: 350px !important; }
}
