/* TradeTracker — Design-Tokens & Layout */

:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --pos: #2a78d6;      /* Serie: Gewinn / Equity (blau) */
  --neg: #e34948;      /* Serie: Verlust / Drawdown (rot) */
  /* Kategorische Serien-Slots (validierte Palette, feste Reihenfolge) */
  --series-1: #2a78d6;
  --series-2: #1baf7a;
  --series-3: #eda100;
  --series-4: #008300;
  --series-5: #4a3aa7;
  --series-6: #e34948;
  --series-7: #e87ba4;
  --series-8: #eb6834;
  --pos-text: #006300; /* Text: positiv */
  --neg-text: #d03b3b; /* Text: negativ */
  --accent: #2a78d6;
  --loader-backdrop: rgba(249, 249, 247, 0.86);
  --wash-opacity: 0.10;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --pos: #3987e5;
    --neg: #e66767;
    --pos-text: #0ca30c;
    --neg-text: #d03b3b;
    --accent: #3987e5;
    --loader-backdrop: rgba(13, 13, 13, 0.86);
    --shadow: none;
    --series-1: #3987e5;
    --series-2: #199e70;
    --series-3: #c98500;
    --series-4: #008300;
    --series-5: #9085e9;
    --series-6: #e66767;
    --series-7: #d55181;
    --series-8: #d95926;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px 48px; }

/* ---------- Public calculator / authentication ---------- */

.public-app {
  width: min(100%, 760px); min-height: 100svh; margin: 0 auto; padding: 0 20px 48px;
}
.public-topbar {
  display: flex; align-items: center; gap: 12px; padding: 18px 0 14px;
  border-bottom: 1px solid var(--grid);
}
.public-topbar h1 {
  flex: 1; margin: 0; font-size: 18px; font-weight: 650; letter-spacing: 0;
}
.public-topbar .dot { color: var(--accent); }
.public-calculator { width: min(100%, 460px); margin: clamp(44px, 11vh, 92px) auto 0; }
.public-calculator h2 { margin: 0 0 22px; font-size: 16px; font-weight: 650; }
.public-calculator .sizing-fields { gap: 22px; }
.login-dialog { max-width: 380px; }
.login-error { min-height: 20px; margin: 8px 0 0; color: var(--neg-text); font-size: 12.5px; }

@media (max-width: 480px) {
  .public-app { padding-inline: 14px; }
  .public-calculator { margin-top: 36px; }
}

/* ---------- Kopfzeile ---------- */

header.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 18px 0 14px;
}
.topbar h1 { font-size: 18px; font-weight: 650; margin: 0; letter-spacing: 0; }
.topbar h1 .dot { color: var(--accent); }
.topbar .spacer { flex: 1; }
#btn-settings { width: 32px; height: 32px; justify-content: center; padding: 0; font-size: 16px; }

button, .btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--ink); font: inherit; font-size: 13px; font-weight: 500;
  padding: 6px 12px; border-radius: 8px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { border-color: var(--baseline); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.06); }
button.danger { color: var(--neg-text); }
button:disabled { opacity: 0.5; cursor: default; }

/* ---------- Loading ---------- */

dialog.app-loader {
  width: 180px; max-width: calc(100vw - 32px); padding: 0; border: 0; outline: 0;
  overflow: visible; color: var(--ink); background: transparent; box-shadow: none;
}
dialog.app-loader[open] { display: grid; place-items: center; }
dialog.app-loader::backdrop {
  background: var(--loader-backdrop);
  backdrop-filter: blur(3px);
}
.loading-status { display: grid; justify-items: center; gap: 12px; min-width: 160px; }
.loading-status p {
  margin: 0; color: var(--ink-2); font-size: 12.5px; font-weight: 600;
  letter-spacing: 0; text-align: center;
}
.loading-candles {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  width: 72px; height: 42px;
}
.loading-candles span {
  position: relative; isolation: isolate; width: 6px; height: 16px;
  border-radius: 2px; color: var(--accent); background: currentColor;
  animation: candle-wave 900ms ease-in-out infinite;
}
.loading-candles span::before {
  content: ''; position: absolute; z-index: -1; left: 50%; top: -7px;
  width: 1px; height: calc(100% + 14px); background: currentColor;
  transform: translateX(-50%); opacity: 0.8;
}
.loading-candles span:nth-child(even) { color: var(--series-2); }
.loading-candles span:nth-child(2) { height: 25px; animation-delay: -720ms; }
.loading-candles span:nth-child(3) { height: 12px; animation-delay: -540ms; }
.loading-candles span:nth-child(4) { height: 29px; animation-delay: -360ms; }
.loading-candles span:nth-child(5) { height: 20px; animation-delay: -180ms; }

@keyframes candle-wave {
  0%, 100% { opacity: 0.35; transform: translateY(5px) scaleY(0.72); }
  50% { opacity: 1; transform: translateY(-5px) scaleY(1); }
}

@media (prefers-reduced-motion: reduce) {
  .loading-candles span,
  .shot-loader-candles span { animation: none; opacity: 0.85; }
}

/* ---------- Filterzeile ---------- */

.filters {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 4px 0 16px;
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; border-radius: 0; padding: 5px 11px; font-size: 12.5px; color: var(--ink-2); background: transparent; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--accent); color: #fff; }
.filters select, .filters input[type="date"] {
  font: inherit; font-size: 12.5px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px;
  max-width: 100%;
}
.filters .count { color: var(--muted); font-size: 12.5px; margin-left: auto; }

/* ---------- Karten & Raster ---------- */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 16px; box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 2px; font-size: 13px; font-weight: 600; color: var(--ink-2);
}
.card .sub { color: var(--muted); font-size: 12px; margin: 0 0 10px; }

.grid { display: grid; gap: 14px; }
.charts-sm { grid-template-columns: repeat(3, 1fr); margin-top: 14px; }
.analytics-pair { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
@media (max-width: 900px) { .charts-sm { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 14px; }

/* ---------- Statistics ---------- */

.stats-strip {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-bottom: 14px; border-block: 1px solid var(--grid);
}
.stat { min-width: 0; padding: 12px 14px; }
.stat + .stat { border-left: 1px solid var(--grid); }
.stat .label { font-size: 11.5px; color: var(--ink-2); }
.stat .value {
  margin-top: 2px; font-size: 21px; font-weight: 600; letter-spacing: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat .hint { min-height: 17px; margin-top: 1px; color: var(--muted); font-size: 11px; }
.stat .value.pos { color: var(--pos-text); }
.stat .value.neg { color: var(--neg-text); }

@media (max-width: 900px) {
  .stats-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat:nth-child(4) { border-left: 0; }
  .stat:nth-child(n + 4) { border-top: 1px solid var(--grid); }
}
@media (max-width: 540px) {
  .wrap { padding-inline: 12px; }
  .card { padding: 12px; }
  .filters .count { width: 100%; margin-left: 0; }
  .stats-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(odd) { border-left: 0; }
  .stat:nth-child(n + 3) { border-top: 1px solid var(--grid); }
  .stat:nth-child(4) { border-left: 1px solid var(--grid); }
}

/* ---------- Charts ---------- */

.chart { position: relative; }
.chart svg { display: block; width: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.legend .key .swatch { width: 14px; height: 0; border-top: 2.5px solid; border-radius: 2px; }
.chart .empty-hint { color: var(--muted); font-size: 12.5px; padding: 24px 0; text-align: center; }

#tooltip {
  position: fixed; z-index: 50; pointer-events: none; display: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; font-size: 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
  max-width: 260px;
}
#tooltip .tt-title { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
#tooltip .tt-row { display: flex; align-items: center; gap: 7px; }
#tooltip .tt-key { width: 12px; height: 0; border-top: 2.5px solid var(--accent); border-radius: 2px; flex: none; }
#tooltip .tt-val { font-weight: 600; font-variant-numeric: tabular-nums; }
#tooltip .tt-label { color: var(--ink-2); }

/* ---------- Tabelle ---------- */

.table-scroll { overflow-x: auto; }
table.trades { width: 100%; border-collapse: collapse; font-size: 13px; }
table.trades th {
  text-align: left; font-weight: 550; color: var(--muted); font-size: 11.5px;
  padding: 7px 10px; border-bottom: 1px solid var(--grid); cursor: pointer; user-select: none;
  white-space: nowrap;
}
table.trades th.num, table.trades td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.trades td { padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.trades tr:last-child td { border-bottom: 0; }
.no-actions th:last-child, .no-actions td.row-actions { display: none; }
table.trades tr:hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
td .pos { color: var(--pos-text); font-weight: 550; }
td .neg { color: var(--neg-text); font-weight: 550; }
.pill {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px;
  border: 1px solid var(--border); color: var(--ink-2); margin-right: 4px;
}
.dir { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; }
.dir.long { color: var(--pos-text); background: color-mix(in srgb, var(--pos) 12%, transparent); }
.dir.short { color: var(--neg-text); background: color-mix(in srgb, var(--neg) 12%, transparent); }
.row-actions { visibility: visible; }
.row-actions button { padding: 2px 8px; font-size: 12px; }
tr.trade-data-row td { cursor: pointer; }
tr.trade-data-row:hover td,
tr.trade-data-row:focus-visible td {
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}
tr.trade-data-row:focus-visible { outline: none; }
tr.trade-data-row .row-actions { cursor: default; }

/* Aufklappbare Zeitraum-Gruppen in der Trade-Tabelle */
tr.group-row td {
  background: color-mix(in srgb, var(--accent) 4%, transparent);
  cursor: pointer; user-select: none; font-size: 12.5px; padding: 8px 10px;
}
tr.group-row:hover td { background: color-mix(in srgb, var(--accent) 9%, transparent); }
tr.group-row .chev { display: inline-block; width: 16px; color: var(--muted); }
tr.group-row .g-label { font-weight: 600; }
tr.group-row .g-meta { color: var(--muted); margin-left: 8px; }
tr.group-row .g-pnl { font-weight: 600; margin-left: 8px; font-variant-numeric: tabular-nums; }

tr.trade-editor-row td,
tr.trade-editor-row:hover td {
  padding: 0; white-space: normal;
  background: color-mix(in srgb, var(--accent) 4%, var(--surface));
}
.inline-trade-editor { padding: 16px; border-bottom: 1px solid var(--grid); }
.inline-editor-grid {
  display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 12px 14px;
}
.inline-editor-wide { grid-column: span 2; }
.inline-editor-full { grid-column: 1 / -1; }
.inline-editor-media {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px;
}
.inline-editor-media .shots { flex-basis: 100%; margin-bottom: 0; }
.inline-editor-hint { font-size: 12px; }
.inline-editor-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

@media (max-width: 900px) {
  .inline-editor-grid { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
  .inline-editor-wide { grid-column: span 1; }
}
@media (max-width: 600px) {
  .inline-editor-grid { grid-template-columns: 1fr; }
  .inline-editor-wide, .inline-editor-full { grid-column: 1; }
  .inline-trade-editor {
    position: sticky; left: 0; width: calc(100vw - 74px); min-width: 0;
  }
}
/* ---------- Dialoge ---------- */

dialog {
  border: 1px solid var(--border); border-radius: 8px; padding: 0;
  background: var(--surface); color: var(--ink); max-width: 640px; width: calc(100vw - 40px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog .dlg-head { display: flex; align-items: center; padding: 16px 20px 0; }
dialog .dlg-head h2 { margin: 0; font-size: 16px; flex: 1; }
dialog .dlg-body { padding: 14px 20px 20px; }
dialog .dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 0 20px 18px; }

.lightbox-dialog {
  width: min(1120px, calc(100vw - 32px)); max-width: 1120px;
}
.lightbox-dialog .dlg-head { align-items: center; gap: 10px; padding: 12px 14px 0; }
.lightbox-counter { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.lightbox-dialog .dlg-head button,
.lightbox-nav {
  width: 38px; height: 38px; padding: 0; justify-content: center;
  font-size: 20px; line-height: 1;
}
.lightbox-body {
  position: relative; display: grid; grid-template-columns: 38px minmax(0, 1fr) 38px;
  align-items: center; gap: 10px; padding: 12px 14px 16px;
}
.lightbox-stage {
  position: relative; display: grid; place-items: center; min-width: 0; min-height: 180px;
  overflow: hidden; touch-action: pan-y; user-select: none;
}
#lightbox-img {
  display: block; max-width: 100%; max-height: calc(100vh - 112px);
  border-radius: 6px; transition: opacity 120ms ease;
}
.lightbox-stage.is-loading #lightbox-img { opacity: 0.12; }
.lightbox-loader { position: absolute; z-index: 1; inset: 0; display: grid; place-items: center; }
.lightbox-error { color: var(--neg-text); font-size: 12px; }

@media (max-width: 600px) {
  .lightbox-dialog { width: calc(100vw - 16px); }
  .lightbox-dialog .dlg-head { padding-inline: 10px; }
  .lightbox-body { grid-template-columns: minmax(0, 1fr); padding: 10px 8px 12px; }
  .lightbox-nav {
    position: absolute; z-index: 2; top: 50%; transform: translateY(-50%);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
  }
  .lightbox-prev { left: 14px; }
  .lightbox-next { right: 14px; }
  #lightbox-img { max-height: calc(100vh - 102px); }
}

.sizing-dialog { max-width: 460px; }
.sizing-dialog .dlg-body { padding-top: 18px; }
.sizing-fields { display: grid; gap: 18px; }
.sizing-fields label.field { font-size: 13px; }
.sizing-fields label.field input {
  min-height: 48px; margin-top: 7px; padding: 10px 12px;
  border-radius: 8px; font-size: 16px; font-variant-numeric: tabular-nums;
}
.sizing-output {
  display: grid; gap: 10px; padding: 15px 16px;
  border: 1px solid var(--border); border-radius: 8px;
}
.sizing-output-row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.sizing-output-row span { color: var(--ink-2); }
.sizing-output-row strong { font-size: 18px; font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }

@media (max-width: 480px) {
  .sizing-dialog { width: calc(100vw - 24px); }
  .sizing-dialog .dlg-head { padding-inline: 16px; }
  .sizing-dialog .dlg-body { padding-inline: 16px; }
  .sizing-dialog .dlg-foot { padding-inline: 16px; }
  .sizing-output-row { gap: 10px; }
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form-grid .full { grid-column: 1 / -1; }
label.field { display: block; font-size: 12px; color: var(--ink-2); }
label.field input, label.field select, label.field textarea {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 13px;
  color: var(--ink); background: var(--page); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 9px;
}
label.field textarea { resize: vertical; min-height: 56px; }
.form-section {
  font-size: 11.5px; font-weight: 650; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0; border-top: 1px solid var(--grid); padding-top: 10px; margin-top: 4px;
}

.import-report { font-size: 13px; }
.import-report .badge {
  display: inline-block; font-size: 11.5px; font-weight: 600; color: var(--accent);
  border: 1px solid var(--accent); padding: 1px 8px; border-radius: 99px; margin-bottom: 8px;
}
.import-report ul.problems { color: var(--neg-text); font-size: 12px; margin: 6px 0; padding-left: 18px; }
.preview-table { font-size: 12px; width: 100%; border-collapse: collapse; margin-top: 8px; }
.preview-table th, .preview-table td { padding: 4px 8px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
.preview-table th { color: var(--muted); font-weight: 550; }

.drop-zone {
  border: 1.5px dashed var(--baseline); border-radius: 8px; padding: 22px;
  text-align: center; color: var(--ink-2); font-size: 13px; cursor: pointer;
}
.drop-zone.drag { border-color: var(--accent); color: var(--accent); }

/* ---------- Leerer Zustand / Toast ---------- */

.empty-state { text-align: center; padding: 56px 24px; }
.empty-state h2 { font-size: 20px; margin: 0 0 6px; }
.empty-state p { color: var(--ink-2); max-width: 520px; margin: 0 auto 18px; }
.empty-state .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--page); font-size: 13px; font-weight: 500;
  padding: 9px 16px; border-radius: 8px; display: none; z-index: 60;
}

.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- Screenshots ---------- */

.shots { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.shots .shot {
  position: relative; flex: 0 0 114px; width: 114px; height: 64px;
}
.shots img {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: 6px; border: 1px solid var(--border);
  cursor: zoom-in; display: block; transition: opacity 140ms ease;
}
.shots .shot.is-loading img { opacity: 0; pointer-events: none; }
.shots .shot.is-loading button { visibility: hidden; }
.shots .shot button {
  position: absolute; z-index: 2; top: -7px; right: -7px; padding: 0 5px; font-size: 11px;
  border-radius: 99px; background: var(--surface);
}
.shot-loader {
  position: absolute; z-index: 1; inset: 0; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: 6px;
  color: var(--muted); background: color-mix(in srgb, var(--accent) 4%, var(--surface));
}
.shot-loader-candles {
  display: flex; align-items: center; justify-content: center; gap: 5px;
  width: 42px; height: 30px;
}
.shot-loader-candles span {
  position: relative; width: 4px; height: 13px; border-radius: 1px;
  color: var(--accent); background: currentColor;
  animation: shot-candle-wave 760ms ease-in-out infinite;
}
.shot-loader-candles span::before {
  content: ''; position: absolute; left: 50%; top: -4px;
  width: 1px; height: calc(100% + 8px); background: currentColor;
  transform: translateX(-50%); opacity: 0.75;
}
.shot-loader-candles span:nth-child(even) { color: var(--series-2); }
.shot-loader-candles span:nth-child(2) { height: 20px; animation-delay: -570ms; }
.shot-loader-candles span:nth-child(3) { height: 9px; animation-delay: -380ms; }
.shot-loader-candles span:nth-child(4) { height: 17px; animation-delay: -190ms; }
.shot-loader.is-error {
  padding: 8px; color: var(--neg-text); font-size: 11px; line-height: 1.25; text-align: center;
  background: color-mix(in srgb, var(--neg) 5%, var(--surface));
}

@keyframes shot-candle-wave {
  0%, 100% { opacity: 0.3; transform: translateY(3px) scaleY(0.76); }
  50% { opacity: 1; transform: translateY(-3px) scaleY(1); }
}
