* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #0f1115;
  color: #e8eaed;
}

header {
  flex-shrink: 0;
  padding: 16px 20px;
  border-bottom: 1px solid #2a2f3a;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

header p {
  margin: 4px 0 0;
  color: #9aa0a6;
  font-size: 13px;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.header-nav a {
  color: #9aa0a6;
  text-decoration: none;
  font-size: 12px;
}

.header-nav a:hover {
  color: #f6c445;
}

.btn-ghost {
  background: transparent;
  border: 1px solid #2f3542;
  color: #9aa0a6;
}

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel {
  width: 460px;
  flex: 0 0 auto;
  min-width: 280px;
  border-right: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.layout-split {
  flex: 0 0 10px;
  cursor: col-resize;
  background: #1a1e27;
  border-left: 1px solid #2a2f3a;
  border-right: 1px solid #2a2f3a;
  touch-action: none;
}

.layout-split:hover,
.layout-split.dragging {
  background: #3d7cf0;
}

body.layout-dragging {
  cursor: col-resize;
  user-select: none;
}

.panel-header {
  flex-shrink: 0;
  padding: 12px 16px;
  border-bottom: 1px solid #2a2f3a;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

input,
select {
  background: #171a21;
  border: 1px solid #2f3542;
  color: #e8eaed;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
}

.btn {
  background: #2d6cdf;
  border: 1px solid #3d7cf0;
  color: #fff;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: #3d7cf0;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tv-btn {
  background: transparent;
  border: 1px solid #2f3542;
  color: #7eb6ff;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}

.tv-btn:hover {
  background: #1c2a44;
  border-color: #3d7cf0;
}

.table-wrap {
  overflow: auto;
  flex: 1;
  min-height: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

thead th {
  position: sticky;
  top: 0;
  background: #151820;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #2a2f3a;
  color: #9aa0a6;
  font-weight: 500;
}

tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid #1d2230;
  white-space: nowrap;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #171b24;
}

tbody tr.selected {
  background: #1c2a44;
}

.positive {
  color: #4caf84;
}

.negative {
  color: #ef6b6b;
}

.type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.type-stock {
  background: rgba(76, 175, 132, 0.15);
  color: #7fd9a8;
}

.type-option {
  background: rgba(142, 124, 255, 0.15);
  color: #b6a7ff;
}

.type-future {
  background: rgba(246, 196, 69, 0.15);
  color: #f6c445;
}

.col-hold {
  width: 1%;
  white-space: nowrap;
  padding-left: 6px;
  padding-right: 6px;
}

.hold-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
}

.hold-day {
  background: rgba(88, 166, 255, 0.16);
  color: #9cc7ff;
}

.hold-swing {
  background: rgba(255, 159, 107, 0.16);
  color: #ffb088;
}

.hold-empty {
  color: #5c6370;
}

.chart-panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 360px;
  min-height: 0;
  height: 100%;
  overflow: auto;
  padding: 8px 40px 20px;
}

.chart-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-bottom: 1px solid #2a2f3a;
  background: #12151b;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 2;
}

.toolbar-hint {
  margin: 0;
  font-size: 12px;
  color: #9aa0a6;
  flex: 1;
  min-width: 220px;
}

.pane-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #9aa0a6;
}

.pane-btn {
  min-width: 32px;
  padding: 4px 10px;
  line-height: 1;
}

.chart-status,
.chart-error {
  margin: 0;
  padding: 8px 18px 0;
  flex-shrink: 0;
}

.chart-error {
  padding-bottom: 8px;
}

.muted {
  color: #9aa0a6;
  font-size: 14px;
  font-weight: 400;
}

.chart-header {
  padding: 14px 18px;
  border-bottom: 1px solid #2a2f3a;
  flex-shrink: 0;
}

.chart-header h2 {
  margin: 0 0 6px;
  font-size: 16px;
}

.chart-meta {
  color: #9aa0a6;
  font-size: 12px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.fill-rows {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

.fill-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  background: #0f1115;
}

.fill-row .k {
  color: #9aa0a6;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.fill-row .v {
  font-size: 14px;
  font-weight: 600;
  color: #e8eaed;
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 12px;
}

.legend span::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: -1px;
}

.legend .ema9::before {
  background: #f6c445;
}

.legend .ema21::before {
  background: #8e7cff;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #e8eaed;
  user-select: none;
}

.toggle-row input {
  width: 16px;
  height: 16px;
}

.legend .spx::before {
  background: #7dd3fc;
}

.interval-picker {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #9aa0a6;
}

.interval-picker select {
  min-width: 110px;
}

.status.warn {
  color: #f0b45c;
}

.chart-grid {
  flex: 0 0 auto;
  height: 62vh;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  margin: 0 0 12px;
}

.chart-extras {
  flex: 0 0 auto;
}

.grade-panel,
.clip-panel {
  flex: 0 0 auto;
  padding: 10px 18px 8px;
  border-top: 1px solid #2a2f3a;
  background: #10141c;
}

.clip-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.clip-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.clip-fills,
.clip-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.clip-stats {
  position: relative;
}

.clip-lot-note {
  margin: 8px 0 0;
  color: #f0b45c;
  font-size: 12px;
  line-height: 1.45;
  min-height: 0;
}

.trade-type-label {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #e8eaed;
}

.clip-stat {
  flex: 0 0 auto;
  min-width: 120px;
  padding: 8px 10px;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  background: #0f1115;
}

.clip-stat .k {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #9aa0a6;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.clip-info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #9aa0a6;
  font-size: 13px;
  line-height: 1;
  letter-spacing: 0;
  text-transform: none;
  cursor: help;
}

.clip-info:hover,
.clip-info:focus,
.clip-info:focus-visible {
  color: #e8eaed;
  outline: none;
}

.clip-info .clip-tip {
  display: none;
  position: absolute;
  z-index: 30;
  left: 0;
  top: calc(100% + 8px);
  width: min(440px, 100%);
  padding: 10px 12px;
  border: 1px solid #3a4150;
  border-radius: 8px;
  background: #1a1e27;
  color: #e8eaed;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
  line-height: 1.45;
  text-align: left;
  white-space: normal;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.clip-info:hover .clip-tip,
.clip-info:focus .clip-tip,
.clip-info:focus-visible .clip-tip {
  display: block;
}

.clip-stat .v {
  margin-top: 4px;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
}

.clip-regime {
  margin: 8px 0 0;
  color: #c4c7ce;
  font-size: 12px;
  line-height: 1.45;
}

.clip-role {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  font-size: 12px;
  color: #9aa0a6;
}

.clip-role select {
  min-width: 120px;
}

.grade-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-top: 10px;
}

.grade-chip {
  flex: 0 0 auto;
  min-width: 72px;
  height: 64px;
  display: grid;
  place-items: center;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  background: #0f1115;
  font-size: 28px;
  font-weight: 700;
}

.grade-a { color: #4caf84; }
.grade-b { color: #58a6ff; }
.grade-c { color: #f6c445; }
.grade-scratch { color: #9aa0a6; }
.grade-miss { color: #ef6b6b; }
.grade-empty { color: #6b7280; }

.grade-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: flex-end;
  flex: 1;
}

.grade-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: #9aa0a6;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.grade-fields select,
.grade-fields input,
.grade-fields textarea {
  min-width: 120px;
  color: #e8eaed;
  background: #0f1115;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
}

.grade-note-field {
  flex: 1;
  min-width: 220px;
}

.grade-note-field textarea {
  width: 100%;
  resize: vertical;
}

.chart-host {
  flex: 1;
  min-height: 0;
  height: 100%;
  position: relative;
}

.chart-canvas {
  position: absolute;
  inset: 0;
}

.empty-state {
  display: grid;
  place-items: center;
  height: 100%;
  color: #9aa0a6;
  padding: 24px;
  text-align: center;
}

.status {
  font-size: 12px;
  color: #9aa0a6;
}

@media (max-width: 1100px) {
  .layout {
    flex-direction: column;
  }

  .layout-split {
    display: none;
  }

  .chart-panel {
    order: -1;
    min-width: 0;
    width: auto;
  }

  .panel {
    width: 100% !important;
    min-width: 0;
    border-bottom: 1px solid #2a2f3a;
  }

  .chart-grid {
    height: calc(46vh - 48px);
    min-height: 240px;
  }

  .chart-host {
    min-height: 0;
  }
}
