/* ── Reset & tokens ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0B0C0E;
  --bg2:        #15171B;  /* panel */
  --bg3:        #1B1E23;  /* panel-2 */
  --border:     #2A2D33;  /* line */
  --text:       #EDEAE2;
  --text2:      #8B8E96;  /* text-dim */
  --text3:      #6b6e76;
  --green:      #4ADE80;  /* green-glow — bright text/dot/accent green */
  --green-dim:  #1F7A4D;  /* green-dark — gradients, tinted borders */
  --green-mid:  #3FA66B;  /* green-light — secondary positive tone */
  --red:        #ff8f88;  /* bright coral — negative text/icons, high contrast on dark bg */
  --red-solid:  #D8483F;  /* base red — solid fills (hover states, gradients) */
  --red-dim:    #7A2C27;
  --blue:       #5B8DD9;
  --yellow:     #C9A24B;
  --accent:     #C9A24B;  /* gold — primary CTA / brand */
  --accent-h:   #8A7333;  /* gold-dim — secondary gold, gradients, borders */
  --radius:     9px;
  --radius-lg:  14px;
  --shadow:     none;
}

html {
  font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}
html, body { overflow-x: hidden; max-width: 100%; }
:root {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(201,162,75,.07), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.mono, .metric-value, .trade-table td.col-num, .strategy-breakdown-stats {
  font-family: 'IBM Plex Mono', monospace;
  font-variant-numeric: tabular-nums;
}

/* ── Header — matches MGC Process Fortress's header.top/.brand/nav.tabs
      byte-for-byte (same class names, same absolute px values, same
      1100px-centered shell width) so both apps feel like one product
      when a user moves between them. Uses absolute px here (not rem)
      because MGC's header sizes are absolute px, independent of root
      font-size — matching that means bypassing this app's 14px rem base
      for these specific rules. ── */
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 24px 22px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: linear-gradient(155deg, var(--accent), var(--accent-h));
  display: flex; align-items: center; justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 14px;
  color: #151007;
  flex-shrink: 0;
}
.brand-text h1 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: .2px; }
.brand-text p { font-size: 12px; margin: 2px 0 0; color: var(--text2); }
.header-right { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

nav.tabs button, nav.tabs a {
  background: transparent;
  border: none;
  color: var(--text2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .15s, color .15s;
}
nav.tabs button.active { background: var(--bg3); color: var(--text); }
nav.tabs button:hover:not(.active),
nav.tabs a:hover { color: var(--text); }

.sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  color: var(--text2);
  padding: 4px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-right: 4px;
}
.sync-status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text3);
  flex-shrink: 0;
}
.sync-status.syncing .sync-status-dot { background: var(--blue); animation: sync-pulse 1s ease-in-out infinite; }
.sync-status.success .sync-status-dot { background: var(--green); }
.sync-status.error   .sync-status-dot { background: var(--red); }
.sync-status.error   { color: var(--red); border-color: var(--red-dim); }
@keyframes sync-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .3; }
}

/* ── Buttons ── */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 600;
  font-family: inherit;
  transition: filter .12s, transform .12s, border-color .15s, color .15s, background .15s;
  white-space: nowrap;
  touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #151007;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text2);
  font-weight: 500;
}
.btn-ghost:hover { border-color: var(--accent-h); color: var(--accent); }
.btn-ghost.drag-over {
  border-color: var(--blue);
  color: var(--blue);
  background: rgba(91,141,217,.1);
}
.btn-danger {
  background: transparent;
  border-color: var(--border);
  color: var(--text2);
  font-weight: 500;
}
.btn-danger:hover { border-color: var(--red-solid); color: var(--red); background: rgba(216,72,63,.1); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 12px 24px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.filter-group { display: flex; flex-direction: column; gap: 3px; }
.filter-group label { font-size: .75rem; color: var(--text3); text-transform: uppercase; letter-spacing: .05em; }
.filter-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 5px 10px;
  font-size: .85rem;
  min-width: 120px;
}
.filter-input:focus { outline: none; border-color: var(--blue); }
select.filter-input option { background: var(--bg3); }

/* ── Metrics ── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  padding: 20px 24px 8px;
}
.metric-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  transition: border-color .2s;
}
.metric-card:hover { border-color: var(--accent-h); }
.metric-label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text3);
  margin-bottom: 6px;
}
.metric-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.metric-sub { font-size: .78rem; color: var(--text2); margin-top: 2px; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.neutral  { color: var(--text); }

/* ── Charts ── */
.charts-row {
  display: flex;
  gap: 12px;
  padding: 12px 24px;
}
.chart-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chart-main  { flex: 3; min-width: 0; }
.chart-side  { flex: 1; min-width: 200px; }
.chart-full  { flex: 1; }
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chart-header h3 { font-size: .85rem; font-weight: 600; color: var(--text2); }
.chart-legend { display: flex; align-items: center; gap: 8px; font-size: .75rem; color: var(--text3); }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.legend-dot.green { background: var(--green); }
.legend-dot.red   { background: var(--red); }

.chart-svg { width: 100%; height: 200px; overflow: visible; }
.chart-donut { width: 120px; height: 120px; margin: 0 auto; display: block; }
.chart-xaxis {
  display: flex;
  justify-content: space-between;
  font-size: .68rem;
  color: var(--text3);
  padding: 0 4px;
}
.bar-chart-wrap { display: flex; flex-direction: column; }

.strategy-breakdown { display: flex; flex-direction: column; gap: 10px; }
.strategy-breakdown-empty { color: var(--text3); font-size: .8rem; padding: 8px 0; }
.strategy-breakdown-row {
  display: grid;
  grid-template-columns: 110px 1fr 130px;
  align-items: center;
  gap: 10px;
}
.strategy-breakdown-name {
  font-size: .8rem;
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.strategy-breakdown-bar-wrap {
  background: var(--bg3);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}
.strategy-breakdown-bar { height: 100%; border-radius: 999px; transition: width .4s ease; }
.strategy-breakdown-bar.positive { background: linear-gradient(90deg, var(--green-dim), var(--green)); }
.strategy-breakdown-bar.negative { background: linear-gradient(90deg, var(--red-dim), var(--red-solid)); }
.strategy-breakdown-bar.neutral  { background: var(--text3); }
.strategy-breakdown-stats {
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
  color: var(--text2);
  text-align: right;
}
.strategy-breakdown-count { color: var(--text3); }

.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0;
  font-size: .8rem;
  align-items: center;
}
.donut-row { display: flex; align-items: center; gap: 6px; }
.donut-dot { width: 10px; height: 10px; border-radius: 2px; }

/* SVG chart helpers (applied in JS) */
.chart-area-path { fill-opacity: .15; }
.chart-line      { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-zero      { stroke: var(--border); stroke-width: 1; stroke-dasharray: 4 4; }
.chart-gridline  { stroke: var(--bg3); stroke-width: 1; }
.chart-bar       { rx: 3; }

/* ── Trade Table ── */
.table-section {
  margin: 0 24px 40px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.table-header h3 { font-size: .9rem; font-weight: 600; }
.trade-count { font-size: .8rem; color: var(--text3); }
.table-wrap { overflow-x: auto; }

/* ── Top scroll mirror ── */
.table-scroll-top {
  overflow-x: auto;
  overflow-y: hidden;
  height: 8px;
  margin-bottom: 2px;
}
.table-scroll-top::-webkit-scrollbar { height: 6px; }
.table-scroll-top::-webkit-scrollbar-track { background: var(--bg); }
.table-scroll-top::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.table-scroll-top::-webkit-scrollbar-thumb:hover { background: var(--text3); }
.table-scroll-top-inner { height: 1px; }
.trade-table { width: 100%; border-collapse: collapse; font-size: .83rem; }
.trade-table thead tr { border-bottom: 1px solid var(--border); }
.trade-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 500;
  color: var(--text2);
  white-space: nowrap;
  user-select: none;
}
.trade-table th[data-sort] { cursor: pointer; }
.trade-table th[data-sort]:hover { color: var(--text); }
.trade-table th.sorted { color: var(--blue); }
.sort-icon { opacity: .4; font-size: .75em; }
.trade-table tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
.trade-table tbody tr:last-child { border-bottom: none; }
.trade-table tbody tr:hover { background: var(--bg3); }
.trade-table td { padding: 9px 12px; color: var(--text); white-space: nowrap; }
.trade-table .empty-row td {
  text-align: center;
  padding: 40px;
  color: var(--text3);
}

.badge {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 7px;
  font-size: .72rem;
  font-weight: 600;
}
.badge-long, .badge-win, .badge-plan-yes { background: rgba(31,122,77,.22); color: var(--green); }
.badge-short, .badge-loss, .badge-plan-no { background: rgba(216,72,63,.18); color: var(--red); }

.row-actions { display: flex; gap: 6px; opacity: 0; transition: opacity .15s; }
.trade-table tbody tr:hover .row-actions,
.trade-table tbody tr.row-selected .row-actions { opacity: 1; }

.col-check { width: 36px; padding: 6px 8px; }
.col-check input[type="checkbox"] { cursor: pointer; width: 14px; height: 14px; accent-color: var(--blue); }
.trade-table tbody tr.row-selected td { background: rgba(91,141,217,.07); }

.bulk-toolbar {
  display: none;
  align-items: center;
  gap: .75rem;
  padding: .5rem 1rem;
  background: rgba(91,141,217,.06);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.bulk-toolbar.active { display: flex; }
.bulk-count { font-size: .82rem; color: var(--blue); font-weight: 600; white-space: nowrap; }
.bulk-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.bulk-field-select { width: auto; min-width: 140px; }
.bulk-value-input { width: 160px; }
.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text2);
  cursor: pointer;
  padding: 2px 7px;
  font-size: .8rem;
}
.btn-icon:hover { border-color: var(--text2); color: var(--text); }
.btn-icon.danger:hover { border-color: var(--red); color: var(--red); }

/* ── Column drag-to-reorder ── */
.trade-table th[draggable="true"] { cursor: grab; }
.trade-table th[draggable="true"]:active { cursor: grabbing; }
.trade-table th.dragging { opacity: .35; }
.trade-table th.drag-over { box-shadow: inset 3px 0 0 var(--blue); }

/* ── New column cell types ── */
.col-num { width: 32px; text-align: center; color: var(--text3); font-size: .78rem; }
.col-day { color: var(--text2); font-size: .82rem; }
.col-outcome { text-align: center; }
.col-text { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.outcome-check { font-size: 1.1rem; font-weight: 700; }
.outcome-check.win  { color: var(--green); }
.outcome-check.loss { color: var(--red);   }
.outcome-dim { color: var(--text3); }
.time-dim { color: var(--text3); font-size: .75rem; display: block; margin-top: 1px; }

/* ── Charts cell button ── */
.btn-img-cell {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text3);
  cursor: pointer;
  padding: 2px 7px;
  font-size: .78rem;
  white-space: nowrap;
}
.btn-img-cell:hover { border-color: var(--text2); color: var(--text); }
.btn-img-cell.has-imgs { color: var(--blue); border-color: rgba(91,141,217,.4); }

/* ── Charts modal ── */
.charts-modal { max-width: 860px; width: 95vw; }
.modal-subtitle { font-size: .8rem; font-weight: 400; color: var(--text2); margin-left: 6px; }
.chart-slots {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  padding: 16px 20px 20px;
}
.chart-slot {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.chart-slot-label {
  padding: 7px 12px;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.optional-tag {
  font-size: .68rem;
  font-weight: 400;
  color: var(--text3);
  background: var(--bg2);
  padding: 1px 6px;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.chart-slot-img {
  flex: 1;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
  cursor: pointer;
  outline: none;
  transition: box-shadow .15s;
}
.chart-slot-img:focus,
.chart-slot-img:focus-within {
  box-shadow: inset 0 0 0 2px var(--blue);
}
.chart-slot-img img.chart-thumb-large {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  cursor: zoom-in;
  display: block;
}
.chart-slot-empty { color: var(--text3); font-size: .8rem; }
.chart-slot-actions {
  padding: 8px 12px;
  display: flex;
  gap: 8px;
  border-top: 1px solid var(--border);
}
.chart-upload-btn { cursor: pointer; }
.chart-paste-hint {
  padding: 8px 16px 4px;
  font-size: .7rem;
  color: var(--text3);
  text-align: center;
}
.chart-paste-hint kbd {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 4px;
  font-size: .65rem;
  font-family: inherit;
}

/* ── Lightbox ── */
.chart-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.9);
  z-index: 400;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.chart-lightbox.open { display: flex; }
.chart-lightbox img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 4px;
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: var(--bg3); }

form { padding: 18px 22px; display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; flex: 1; }
.form-group.full-width { flex: 1 0 100%; }
.form-group label { font-size: .78rem; color: var(--text2); }
.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 10px;
  font-size: .88rem;
  font-family: inherit;
  width: 100%;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: var(--blue); }
.form-group textarea { resize: vertical; }
select option { background: var(--bg2); }

.form-preview {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: .83rem;
  color: var(--text2);
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.form-preview:empty { display: none; }
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: .85rem;
  color: var(--text);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 300;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Import modal drop zone ── */
.import-modal { width: 460px; }
.import-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }

.import-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 40px 30px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  text-align: center;
}
.import-drop-zone:hover,
.import-drop-zone.drag-over {
  border-color: var(--blue);
  background: rgba(91,141,217,.06);
}
.import-drop-icon {
  font-size: 2.2rem;
  color: var(--text3);
  line-height: 1;
  transition: color .15s;
}
.import-drop-zone.drag-over .import-drop-icon,
.import-drop-zone:hover .import-drop-icon { color: var(--blue); }
.import-drop-label {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text2);
}
.import-drop-sub { font-size: .8rem; color: var(--text3); }

.import-hint {
  font-size: .75rem;
  color: var(--text3);
  line-height: 1.5;
}
.import-hint code {
  font-family: monospace;
  color: var(--text2);
  font-size: .72rem;
}

/* ── AI Review button ── */
.btn-ai {
  background: linear-gradient(135deg, rgba(201,162,75,.16), rgba(138,115,51,.1));
  border: 1px solid var(--accent-h);
  color: var(--accent);
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .85rem;
  font-weight: 600;
  font-family: inherit;
  transition: filter .12s, border-color .15s;
  white-space: nowrap;
  touch-action: manipulation;
}
.btn-ai:active { transform: scale(.97); }
.btn-ai:hover {
  filter: brightness(1.15);
  border-color: var(--accent);
}
.btn-icon-only {
  padding: 6px 10px;
  font-size: 1rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.btn-icon-only:hover { border-color: var(--text2); color: var(--text); }

/* ── Settings hint ── */
.settings-hint {
  font-size: .75rem;
  color: var(--text3);
  margin-top: 5px;
  line-height: 1.4;
}

.settings-danger-zone {
  margin: 20px 24px 0;
  padding: 14px 16px;
  border: 1px solid var(--red-dim);
  border-radius: var(--radius);
}
.settings-danger-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--red);
  margin-bottom: 4px;
}
.settings-danger-zone .btn-danger { margin-top: 10px; }

/* ── AI Panel (slide-in drawer) ── */
.ai-panel-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 150;
}
.ai-panel-backdrop.open { display: block; }

.ai-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 480px;
  max-width: 100vw;
  height: 100vh;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  z-index: 160;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}
.ai-panel.open { transform: translateX(0); }

.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .95rem;
  font-weight: 600;
}
.ai-panel-icon { color: var(--accent); font-size: 1.1rem; }

.ai-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* Idle state */
.ai-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  text-align: center;
  padding: 40px 20px;
}
.ai-idle-icon {
  font-size: 2.5rem;
  color: var(--accent);
  opacity: .4;
}
.ai-idle-text {
  color: var(--text2);
  font-size: .88rem;
  line-height: 1.6;
  max-width: 320px;
}

/* Loading state */
.ai-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 100%;
  color: var(--text2);
  font-size: .88rem;
}
.ai-spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Streaming content */
.ai-content {
  font-size: .88rem;
  line-height: 1.7;
  color: var(--text);
}
.ai-content h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  margin: 20px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.ai-content h3 {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  margin: 14px 0 6px;
}
.ai-content p { margin: 0 0 10px; }
.ai-content ul { margin: 0 0 10px; padding-left: 18px; }
.ai-content li { margin-bottom: 4px; }
.ai-content strong { color: var(--text); font-weight: 600; }
.ai-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}
.ai-content .pos { color: var(--green); }
.ai-content .neg { color: var(--red); }

/* Streaming cursor */
.ai-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink .7s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Re-analyze button row */
.ai-actions {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Table context cells ── */
.note-cell    { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.context-cell { max-width: 90px; overflow: hidden; text-overflow: ellipsis; font-size: .78rem; color: var(--text2); }

/* ── Trade Context collapsible form section ── */
.form-context {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.form-context-toggle {
  cursor: pointer;
  padding: 8px 12px;
  font-size: .8rem;
  color: var(--text3);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.form-context-toggle:hover { color: var(--text2); }
.form-context-toggle::marker,
.form-context-toggle::-webkit-details-marker { display: none; }
.form-context-toggle::before { content: '▶'; font-size: .65rem; transition: transform .15s; }
details[open] .form-context-toggle::before { transform: rotate(90deg); }
.form-context-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-top: 1px solid var(--border);
}

/* ── Inline form screenshots ── */
.form-screenshots {
  margin-top: 4px;
}
.form-screenshots-label {
  font-size: .7rem;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
}
.form-screenshots-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.form-ss-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.form-ss-label {
  font-size: .7rem;
  color: var(--text3);
}
.form-ss-preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--bg3);
  border: 1px dashed var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s;
}
.form-ss-preview:hover,
.form-ss-preview:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 2px rgba(91,141,217,.25); }
.form-ss-empty {
  font-size: 1.6rem;
  color: var(--text3);
  line-height: 1;
  user-select: none;
}
.form-ss-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.form-ss-del {
  background: none;
  border: none;
  color: var(--text3);
  font-size: .7rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color .15s;
}
.form-ss-del:hover { color: var(--red); }
.form-ss-hint {
  margin-top: 6px;
  font-size: .7rem;
  color: var(--text3);
  text-align: center;
}
.form-ss-hint kbd {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 4px;
  font-size: .65rem;
  font-family: inherit;
}

/* ── Custom field dropdown ── */
.field-dropdown {
  position: fixed;
  z-index: 2000;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
  display: none;
}
.field-dropdown.open { display: block; }
.field-dropdown-list { padding: 4px 0; }
.dd-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 6px 12px;
  cursor: pointer;
  gap: 8px;
}
.dd-item:hover, .dd-item:focus { background: var(--bg3); outline: none; }
.dd-label { flex: 1; font-size: .875rem; }
.dd-item-x {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  opacity: 0;
  transition: opacity .15s, color .15s;
  flex-shrink: 0;
}
.dd-item:hover .dd-item-x,
.dd-item:focus .dd-item-x { opacity: 1; }
.dd-item-x:hover { color: var(--red); }
.dd-empty {
  padding: 8px 12px;
  font-size: .8rem;
  color: var(--text3);
}

/* ── Form inline screenshots (reuses .cp-slot grid styles) ── */
.form-ss-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.form-ss-section-label {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 8px;
}

/* ── Multi-tag input ── */
.multi-tags-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 8px;
  min-height: 36px;
  cursor: text;
  transition: border-color .15s;
}
.multi-tags-wrap:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(91,141,217,.15);
}
.multi-tags-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--blue);
  color: #fff;
  border-radius: 12px;
  padding: 1px 8px 1px 10px;
  font-size: .75rem;
  font-weight: 500;
  white-space: nowrap;
}
.tag-chip-x {
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  cursor: pointer;
  font-size: .9rem;
  line-height: 1;
  padding: 0;
  margin-left: 1px;
  transition: color .1s;
}
.tag-chip-x:hover { color: #fff; }
.multi-tags-search {
  flex: 1;
  min-width: 80px;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: .875rem;
  padding: 2px 0;
}
.multi-tags-search::placeholder { color: var(--text3); }
.dd-item-selected .dd-label { opacity: .45; }
.dd-item-selected::before {
  content: '✓';
  color: var(--blue);
  font-size: .75rem;
  margin-right: 6px;
}

/* ── Chart popover ── */
.chart-popover {
  position: fixed;
  z-index: 2100;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 320px;
  padding: 10px;
  user-select: none;
}
.chart-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.chart-popover-title {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart-popover-close {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: .95rem;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
  transition: color .15s;
}
.chart-popover-close:hover { color: var(--text); }
.chart-popover-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.cp-slot {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.cp-slot-label {
  font-size: .68rem;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.cp-slot-img {
  aspect-ratio: 16/9;
  background: var(--bg3);
  border: 1px dashed var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  outline: none;
  position: relative;
  transition: border-color .15s;
}
.cp-slot-img:focus {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px var(--blue);
}
.cp-slot-img:hover { border-color: var(--text3); }
.cp-slot-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  pointer-events: none;
  text-align: center;
}
.cp-empty-line1 {
  font-size: .7rem;
  color: var(--text3);
  font-weight: 500;
}
.cp-empty-line2 {
  font-size: .62rem;
  color: var(--text3);
  opacity: .7;
}
.cp-slot-img img.cp-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}
/* Overlay remove button — appears on hover over the slot */
.cp-img-overlay-del {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,.65);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: .7rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s, background .15s;
  z-index: 2;
}
.cp-slot-img:hover .cp-img-overlay-del { opacity: 1; }
.cp-img-overlay-del:hover { background: var(--red-solid) !important; opacity: 1 !important; }
.cp-slot-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.cp-upload-btn {
  font-size: .68rem;
  color: var(--text3);
  cursor: pointer;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 6px;
  line-height: 1.6;
  transition: color .15s, border-color .15s;
  flex: 1;
  text-align: center;
}
.cp-upload-btn:hover { color: var(--text); border-color: var(--text3); }
.cp-del-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--text3);
  font-size: .75rem;
  cursor: pointer;
  padding: 1px 5px;
  line-height: 1.6;
  transition: color .15s, border-color .15s;
}
.cp-del-btn:hover { color: var(--red); border-color: var(--red); }
.cp-hint {
  margin-top: 8px;
  font-size: .67rem;
  color: var(--text3);
  text-align: center;
}
.cp-hint kbd {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 3px;
  font-size: .63rem;
  font-family: inherit;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── Responsive: tablet (≤700px) ── */
@media (max-width: 700px) {
  .charts-row { flex-direction: column; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { flex-direction: column; }
}

/* ── Responsive: phone (≤480px, e.g. iPhone 13 @ 390px logical width) ── */
@media (max-width: 480px) {
  .header { padding: 10px 14px 14px; gap: 6px 8px; }
  .brand-text h1 { font-size: 15px; }
  .brand-text p { display: none; }
  .header-right { gap: 6px; }
  nav.tabs button, nav.tabs a { padding: 7px 10px; font-size: 12px; }
  .filter-bar { padding: 12px 14px; }
  .charts-row { padding: 10px 14px; }
  .table-section { margin: 0 14px 24px; }
  .table-header { padding: 12px 14px; }
  .metrics-grid { grid-template-columns: 1fr; padding: 14px 14px 6px; gap: 10px; }

  /* Buttons: smaller footprint but still ≥40px tall for comfortable tapping */
  .btn { padding: 9px 12px; font-size: .82rem; }
  .btn-icon-only { min-width: 40px; min-height: 40px; }
  .btn-sm { padding: 7px 10px; }

  /* Sync badge: show just the dot + a short label, full detail moves to the
     title attribute (tap-and-hold / hover) so it never forces the header wide. */
  .sync-status { padding: 4px 8px; }
  .sync-status-text { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .filter-bar { gap: 8px; }
  .filter-input { min-width: 0; width: 100%; }
  .filter-group { flex: 1 1 calc(50% - 4px); min-width: 130px; }

  .strategy-breakdown-row { grid-template-columns: 78px 1fr 92px; gap: 6px; }
  .strategy-breakdown-stats { font-size: .72rem; }

  .modal-header { padding: 14px 16px 12px; }
  form { padding: 14px 16px; }
  .settings-danger-zone { margin: 16px 16px 0; }

  .ai-panel { width: 100vw; }

  /* Table: let it scroll horizontally within its own box rather than the page */
  .table-wrap { -webkit-overflow-scrolling: touch; }
}
