:root {
  --bg: #0b0f14;
  --fg: #e6edf3;
  --muted: #9aa4ad;
  --card: #11161d;
  --accent: #7cc7ff;
  --good: #2ecc71;
  --bad: #e74c3c;
  --warn: #f39c12;
  --border: #1e2732;
}
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto;
}
/* Prevent iOS from auto-zooming text; keep base legible */
html {
  -webkit-text-size-adjust: 100%;
}
.hidden {
  display: none !important;
}

/* Generic grid list container with standard spacing */
.grid-list {
  display: grid;
  gap: 12px;
}
.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.brand {
  font-weight: 700;
  letter-spacing: 0.3px;
}
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  color: var(--fg);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    color 0.15s ease, box-shadow 0.15s ease;
}
.icon-btn:hover {
  border-color: var(--accent);
}
/* Reusable button variants (subtle/tinted) */
.icon-btn.btn-primary,
.menu-item.btn-primary {
  color: var(--accent);
  background: rgba(124, 199, 255, 0.1);
  border-color: rgba(124, 199, 255, 0.35);
}
.icon-btn.btn-primary:hover,
.menu-item.btn-primary:hover {
  background: rgba(124, 199, 255, 0.18);
  border-color: rgba(124, 199, 255, 0.55);
}

.icon-btn.btn-success,
.menu-item.btn-success {
  color: var(--good);
  background: rgba(46, 204, 113, 0.1);
  border-color: rgba(46, 204, 113, 0.35);
}
.icon-btn.btn-success:hover,
.menu-item.btn-success:hover {
  background: rgba(46, 204, 113, 0.18);
  border-color: rgba(46, 204, 113, 0.55);
}

.icon-btn.btn-danger,
.menu-item.btn-danger {
  color: var(--bad);
  background: rgba(231, 76, 60, 0.1);
  border-color: rgba(231, 76, 60, 0.35);
}
.icon-btn.btn-danger:hover,
.menu-item.btn-danger:hover {
  background: rgba(231, 76, 60, 0.18);
  border-color: rgba(231, 76, 60, 0.55);
}

.icon-btn.btn-warning,
.menu-item.btn-warning {
  color: var(--warn);
  background: rgba(243, 156, 18, 0.1);
  border-color: rgba(243, 156, 18, 0.35);
}
.icon-btn.btn-warning:hover,
.menu-item.btn-warning:hover {
  background: rgba(243, 156, 18, 0.18);
  border-color: rgba(243, 156, 18, 0.55);
}

.icon-btn.btn-muted,
.menu-item.btn-muted {
  color: var(--muted);
  background: rgba(154, 164, 173, 0.1);
  border-color: rgba(154, 164, 173, 0.35);
}
.icon-btn.btn-muted:hover,
.menu-item.btn-muted:hover {
  background: rgba(154, 164, 173, 0.16);
  border-color: rgba(154, 164, 173, 0.5);
}

/* Focus rings for accessibility */
.icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(124, 199, 255, 0.25);
}
.icon-btn.btn-success:focus-visible {
  box-shadow: 0 0 0 2px rgba(46, 204, 113, 0.25);
}
.icon-btn.btn-danger:focus-visible {
  box-shadow: 0 0 0 2px rgba(231, 76, 60, 0.25);
}
.icon-btn.btn-warning:focus-visible {
  box-shadow: 0 0 0 2px rgba(243, 156, 18, 0.25);
}
.icon-btn.btn-muted:focus-visible {
  box-shadow: 0 0 0 2px rgba(154, 164, 173, 0.25);
}
/* Larger, thicker hamburger */
#hamburger {
  position: relative;
  width: 44px;
  height: 36px;
  padding: 0; /* precise box for bars */
  border-width: 2px;
  font-size: 0; /* hide fallback glyph */
}
#hamburger::before {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: 50%;
  height: 3px; /* bar thickness */
  background: var(--fg);
  transform: translateY(-50%);
  box-shadow: 0 -8px 0 0 var(--fg), /* top bar */ 0 8px 0 0 var(--fg); /* bottom bar */
}

/* Optional: keep hamburger fixed at top-right across scroll */
.btn-float-top-right {
  position: fixed !important;
  top: 12px;
  right: 12px;
  z-index: 1000;
}
/* Optional: use for the dropdown menu when button is floating */
.menu-float-below {
  position: fixed !important;
  top: 56px;
  right: 12px;
  z-index: 999;
}
.menu {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0; /* full height drawer with scroll */
  height: auto;
  max-height: 100vh; /* fallback */
  max-height: 100dvh; /* modern mobile viewport */
  width: min(92vw, 440px); /* fallback */
  width: min(92svw, 440px);
  min-width: 300px;
  background: var(--card);
  border-left: 1px solid var(--border);
  border-top: none;
  border-right: none;
  border-bottom: none;
  border-radius: 12px 0 0 12px;
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.35);
  display: grid;
  align-content: start;
  grid-auto-rows: min-content;
  gap: 8px; /* compact, consistent spacing */
  padding: 12px;
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  overflow-y: auto; /* nothing gets cut off */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  z-index: 1000;
  font-size: 18px; /* larger, legible menu */
}
.menu-item {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--fg);
  text-align: left;
  cursor: pointer;
  width: 100%;
  font-size: 18px; /* match container */
}
.menu-item:hover {
  border-color: var(--accent);
}

/* Mobile: make the slideout cover more width, keep clean spacing */
@media (max-width: 480px) {
  .menu {
    width: min(94vw, 480px); /* fallback */
    width: min(94svw, 480px);
    font-size: 18px;
    padding: 14px;
    gap: 8px;
  }
  .menu-item {
    font-size: 18px;
    padding: 12px 14px;
  }
}
.panes {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 12px;
}
.pane {
  display: grid;
  gap: 12px;
}
.card {
  background-color: rgba(50, 100, 200, 0.04);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}

/* Wider variant for data-heavy cards */
.card-wide {
  width: 100%;
  max-width: 1600px;
  margin-left: auto;
  margin-right: auto;
}

/* Key-value grid: stable, responsive columns for summary/detail rows */
.kv-grid {
  display: grid;
  gap: 10px;
  align-items: start;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.kv-grid.tight {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.kv-grid .cell .value { text-align: left; }

/* Form controls: ensure >=16px to avoid iOS zoom on focus */
input,
select,
textarea {
  font-size: 16px;
  line-height: 1.3;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(124, 199, 255, 0.25);
  border-color: rgba(124, 199, 255, 0.55);
}
/* Make controls naturally fill available space in cells */
.cell input,
.cell select,
.cell textarea {
  width: 100%;
  max-width: 100%;
  text-align: left;
}
.row {
  display: grid;
  gap: 8px;
  align-items: center;
  grid-template-columns: 1fr auto;
}
.row-actions {
  grid-template-columns: auto auto 1fr;
  display: inline-block;
}
.status {
  justify-self: end;
  text-align: right;
  min-width: 160px;
}
.row-positions {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.orders-row {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

/* Make list rows (positions/orders) look like distinct cards */
.row-positions,
.orders-row {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.03),
    rgba(255, 255, 255, 0)
  );
  transition: border-color 0.15s ease, background-color 0.15s ease,
    box-shadow 0.15s ease;
}
.row-positions[role="button"],
.orders-row[role="button"] {
  cursor: pointer;
}
.row-positions[role="button"]:hover,
.orders-row[role="button"]:hover {
  border-color: var(--accent);
  background: rgba(124, 199, 255, 0.06);
}
.row-positions[role="button"]:focus-visible,
.orders-row[role="button"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(124, 199, 255, 0.2) inset;
}
.big-checkbox {
  width: 22px;
  height: 22px;
}
.error-text {
  color: var(--bad);
}
.error-field {
  outline: 2px solid var(--bad);
  background: rgba(231, 76, 60, 0.07);
}
@media (max-width: 480px) {
  .row-positions {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
  .orders-row {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
}
.badge {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 12px;
  color: var(--muted);
}
.price-up {
  color: var(--good);
}
.price-down {
  color: var(--bad);
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
/* key-value cell with label left and value right */
.cell {
  display: grid;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.cell .label {
  color: var(--muted);
  font-size: 12px;
  flex: 0 1 45%;
  min-width: 80px;
}
.cell .value {
  text-align: right;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

/* Utilities */
.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wrap {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.muted {
  color: var(--muted);
}

/* Detail sections and legs list */
.detail-section {
  display: grid;
  gap: 8px;
}
.detail-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.detail-main {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.detail-legs {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}
.legs-list {
  display: grid;
  gap: 8px;
}
/* Individual legs as card-like rows */
.legs-list .row {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--border);
}
.legs-list .row:hover {
  border-color: var(--accent);
}

/* prevent horizontal overflow globally */
html,
body {
  overflow-x: hidden;
}

/* Readability: add padding and subtle zebra backgrounds to list rows */
#positions-list .row,
#orders-list .row {
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}
#positions-list .row:nth-child(odd),
#orders-list .row:nth-child(odd) {
  background: rgba(255, 255, 255, 0.04);
}
/* Make summary row slightly distinct */
#positions-list .summary-row {
  background: rgba(124, 199, 255, 0.06);
}

/* Create Order: let typed fields participate in parent grid layout */
#order-form #of-typed-fields {
  display: contents;
}
/* On small screens, prefer a single-column form layout for comfortable inputs */
@media (max-width: 480px) {
  #order-form {
    grid-template-columns: 1fr !important;
  }
}

/* Detail view container within cards */
.detail {
  display: grid;
  gap: 10px;
}
.detail .detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.detail .detail-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.detail .detail-body > .detail-section {
  grid-column: 1 / -1;
}
.detail .close-btn {
  border-radius: 10px;
  font-size: 18px;
  font-weight: 700;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border-width: 2px;
}
.detail .close-btn:hover {
  border-color: var(--accent);
  background: rgba(124, 199, 255, 0.08);
}
@media (max-width: 480px) {
  .detail .close-btn {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
}

/* Detail action buttons: even spacing, wrap when needed */
.detail-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

/* Modal overlay + container */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: grid;
  place-items: center;
  z-index: 2000;
}
.modal-overlay.hidden {
  display: none;
}
.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: clamp(280px, 90vw, 560px);
  max-height: 90vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-weight: 600;
}
.modal-body {
  padding: 10px 12px;
  display: grid;
  gap: 10px;
  overflow: auto;
}
.modal-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
.modal-close {
  border-radius: 10px;
}

@media (max-width: 480px) {
  .modal {
    width: 96vw;
    border-radius: 10px;
  }
  .modal-body {
    padding: 8px;
  }
  .modal-header,
  .modal-actions {
    padding: 8px;
  }
}
/* Summary: App styling and layout.
   - Dark theme variables, layout grids, cards, rows, and responsive controls.
   - Topbar, menu/drawer, detail panes, lists, and badges.
   - Form elements, buttons (variants), and focus rings.
   - Modal overlay and container styles; price up/down color cues.
*/

/* Simple grid-table for historical preview */
.grid-table {
  display: grid;
  gap: 6px;
  max-width: 100%;
  overflow-x: auto; /* ensure table never widens the page */
}
.grid-table .header,
.grid-table .row {
  display: grid;
  /* Let columns shrink within container without forcing body overflow */
  grid-template-columns: minmax(0, 2fr) repeat(5, minmax(0, 1fr));
  gap: 8px;
  align-items: baseline;
}
.grid-table .cell {
  padding: 4px 6px;
}
.grid-table .header .cell {
  color: var(--muted);
  border-bottom-color: rgba(255,255,255,0.08);
}
/* Give each data row a subtle card-like separation for readability */
.grid-table .row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.02);
}
.grid-table .row + .row { margin-top: 6px; }
/* Details block under summary row */
.details-row { margin-top: 10px; overflow-anchor: none; }

/* Simple responsive chart container */
.chart-container {
  width: 100%;
  height: 260px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
  padding: 6px;
  position: relative;
}
.grid-list .row {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.02);
  min-height: 64px;
}

/* Strategy create form grid */
.grid-form {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
}
.form-field input,
.form-field select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f141c;
  color: var(--fg);
}
.chart-canvas { width: 100%; height: 100%; display: block; }
/* Overlay label inside chart (top-right) */
.chart-overlay {
  position: absolute;
  top: 6px;
  right: 8px;
  background: rgba(124,199,255,0.08);
  border-color: rgba(124,199,255,0.35);
}
@media (max-width: 900px) {
  .grid-table .header,
  .grid-table .row {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
}
