/* ============================================================
   CLP <-> USD Arbitrage Dashboard — styles (per design spec)
   ============================================================ */

/* ---- 1. Design tokens : light (default) ---- */
:root {
  --bg: #eceef3;
  --panel: #ffffff;
  --panel-border: rgba(17,20,32,.07);
  --card: #ffffff;
  --card-border: rgba(17,20,32,.09);
  --text: #14161c;
  --text-dim: #4b515f;
  --text-mute: #878d9b;
  --divider: rgba(17,20,32,.08);
  --input-bg: #ffffff;
  --input-border: rgba(17,20,32,.14);
  --head-bg: rgba(17,20,32,.025);
  --accent: #6d28d9;
  --accent-soft: #f1ebfe;
  --accent-ink: #5b21b6;
  --pos: #0f875a;
  --pos-soft: #e6f5ee;
  --pos-ink: #0b6b45;
  --neg: #c0392b;
  --shadow: 0 1px 2px rgba(16,20,40,.05), 0 12px 34px -18px rgba(16,20,40,.22);

  /* fixed layout tokens */
  --radius: 12px;
  --card-radius: 16px;
  --gap: 22px;
  --card-pad: 22px;
  --table-pad: 15px 18px;
  --stat-size: 30px;

  color-scheme: light;
}

/* ---- Dark theme ---- */
:root[data-theme="dark"] {
  --bg: #080a0f;
  --panel: #0f1218;
  --panel-border: rgba(255,255,255,.07);
  --card: #13161f;
  --card-border: rgba(255,255,255,.08);
  --text: #eceef4;
  --text-dim: #a3a9b8;
  --text-mute: #6a7080;
  --divider: rgba(255,255,255,.07);
  --input-bg: #161922;
  --input-border: rgba(255,255,255,.12);
  --head-bg: rgba(255,255,255,.03);
  --accent: #a78bfa;
  --accent-soft: rgba(139,92,246,.15);
  --accent-ink: #c4b5fd;
  --pos: #34d399;
  --pos-soft: rgba(52,211,153,.13);
  --pos-ink: #6ee7b7;
  --neg: #f87171;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 14px 36px -18px rgba(0,0,0,.75);
  color-scheme: dark;
}

/* ---- Base ---- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* beat author display rules (e.g. exec-confirm) */
html, body { margin: 0; padding: 0; }
body {
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; }
::selection { background: color-mix(in srgb, var(--accent) 26%, transparent); }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.mute { color: var(--text-mute); }

/* ---- 4. Layout ---- */
.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 292px; flex-shrink: 0;
  position: sticky; top: 0; align-self: flex-start;
  height: 100vh; overflow-y: auto;
  padding: 26px 22px 40px;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
}
.main { flex: 1; min-width: 0; padding: 22px 40px 60px; }

/* ---- Toolbar ---- */
.toolbar { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.theme-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--card-border);
  color: var(--text-dim); border-radius: var(--radius);
  padding: 8px 14px; font-size: 13px; font-weight: 500; cursor: pointer;
  font-family: inherit;
}
.theme-toggle:hover { color: var(--text); }
.theme-toggle .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }

/* ---- Title block ---- */
.title-block { display: flex; gap: 16px; align-items: flex-start; margin: 8px 0 20px; }
.title-glyph {
  width: 46px; height: 46px; flex-shrink: 0; border-radius: 13px;
  background: var(--accent-soft); display: flex; align-items: center; justify-content: center;
}
.title-glyph svg { stroke: var(--accent); }
h1 {
  font-size: 29px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 6px;
}
h1 .swap { color: var(--accent); }
.subtitle { color: var(--text-dim); max-width: 820px; margin: 0; font-size: 14px; }

/* ---- Section headings ---- */
h2 { font-size: 19px; font-weight: 600; margin: 30px 0 14px; }
.eyebrow {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-mute);
}

/* ---- Sidebar : Parameters ---- */
.side-head { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.side-head .tile {
  width: 26px; height: 26px; border-radius: 8px; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
}
.side-head .tile svg { stroke: var(--accent); }
.side-head h3 { margin: 0; font-size: 15px; font-weight: 600; }

.field { margin-bottom: 16px; }
.field > label {
  display: block; font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-mute); margin-bottom: 7px;
}

/* Stepper input */
.stepper {
  display: flex; align-items: stretch;
  background: var(--input-bg); border: 1px solid var(--input-border);
  border-radius: var(--radius); overflow: hidden;
}
.stepper input {
  flex: 1; min-width: 0; border: none; background: transparent; color: var(--text);
  font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums;
  font-size: 14px; padding: 10px 12px; text-align: left;
}
.stepper input:focus { outline: none; }
.stepper button {
  width: 38px; border: none; background: transparent; color: var(--text-dim);
  font-size: 17px; cursor: pointer; border-left: 1px solid var(--divider);
  font-family: inherit;
}
.stepper button:hover { color: var(--text); background: var(--head-bg); }

/* Cards accordion */
.accordion { margin-top: 4px; }
.acc-item {
  border: 1px solid var(--input-border); border-radius: var(--radius);
  background: var(--input-bg); margin-bottom: 10px; overflow: hidden;
}
.acc-head {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 11px 13px; background: transparent; border: none; cursor: pointer;
  color: var(--text); font-family: inherit; font-size: 13.5px; font-weight: 500;
}
.acc-head .brand-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.acc-head .chev { margin-left: auto; color: var(--text-mute); transition: transform .18s; }
.acc-item.open .chev { transform: rotate(90deg); }
.acc-body { display: none; padding: 4px 13px 14px; }
.acc-item.open .acc-body { display: block; }
.acc-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 12.5px; }
.acc-row span:first-child { color: var(--text-mute); }
.acc-row .mini {
  width: 74px; background: var(--card); border: 1px solid var(--input-border);
  border-radius: 8px; color: var(--text); font-family: 'IBM Plex Mono', monospace;
  font-variant-numeric: tabular-nums; font-size: 12.5px; padding: 5px 8px; text-align: right;
}

.refresh-btn {
  width: 100%; margin-top: 12px; display: inline-flex; align-items: center;
  justify-content: center; gap: 9px; background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius); padding: 12px; font-size: 13.5px;
  font-weight: 600; cursor: pointer; font-family: inherit;
}
.refresh-btn:hover { filter: brightness(1.06); }
.refresh-btn:disabled { opacity: .6; cursor: default; }
.refresh-btn svg { transition: transform .6s; }
.refresh-btn.spin svg { transform: rotate(360deg); }

/* ---- Loop-flow strip ---- */
.flow-card {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--card-radius); box-shadow: var(--shadow);
  padding: 18px 22px; margin-bottom: var(--gap);
}
.flow-grid {
  display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; align-items: center; gap: 10px;
}
.flow-node { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; }
.logo-slot {
  width: 54px; height: 54px; border-radius: 12px; border: 1px solid var(--card-border);
  display: flex; align-items: center; justify-content: center; color: var(--text-mute);
  font-size: 10px; background: var(--input-bg); overflow: hidden;
}
.logo-slot img { width: 100%; height: 100%; object-fit: contain; display: block; }
.logo-slot.empty img { display: none; }
.logo-slot.empty::after { content: "logo"; color: var(--text-mute); font-size: 10px; }
.flow-node .brand { font-weight: 600; font-size: 13.5px; }
.flow-node .fig { font-size: 12.5px; color: var(--text-dim); }
.cards-list { display: flex; flex-direction: column; gap: 16px; align-items: center; }
.card-item { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.card-item .brand-dot { display: none; }  /* shown only on mobile */
.flow-arrow { color: var(--accent); display: flex; justify-content: center; }

/* ---- Rate cards ---- */
.rate-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
.rate-card {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--card-radius); box-shadow: var(--shadow); padding: var(--card-pad);
}
.rate-card .eyebrow { display: flex; align-items: center; gap: 8px; }
.rate-card .figure { font-size: 33px; font-weight: 600; margin: 12px 0 2px; }
.rate-card .unit { font-size: 12.5px; color: var(--text-mute); }
.live { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; color: var(--pos); font-weight: 600; font-size: 11px; }
.live .pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--pos); animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.82); opacity: .35; } }

/* ---- Profitable banner ---- */
.banner {
  display: flex; align-items: center; gap: 14px; margin: var(--gap) 0;
  padding: 16px 20px; border-radius: var(--card-radius);
}
.banner.good { background: var(--pos-soft); border: 1px solid color-mix(in srgb, var(--pos) 30%, transparent); }
.banner.bad  { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent); }
.banner .badge {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.banner.good .badge { background: var(--pos); }
.banner.bad .badge { background: var(--accent); }
.banner .badge svg { stroke: #fff; }
.banner .msg { font-weight: 600; }
.banner.good .msg { color: var(--pos-ink); }
.banner.bad .msg { color: var(--accent-ink); }

/* ---- Tables ---- */
.table-wrap {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--card-radius); box-shadow: var(--shadow); overflow: hidden;
}
.table-wrap.scroll-x { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--head-bg); text-align: left; padding: var(--table-pad);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-mute); border-bottom: 1px solid var(--divider); white-space: nowrap;
}
tbody td { padding: var(--table-pad); border-bottom: 1px solid var(--divider); font-size: 13.5px; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; }
tr.net-row td { background: var(--accent-soft); }
tr.net-row td.num { color: var(--accent-ink); font-weight: 700; font-size: 15px; }
tr.net-row td:first-child { color: var(--accent-ink); font-weight: 600; }

/* ---- Loop totals ---- */
.totals { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--gap); margin-top: 8px; }
.total-cell .lbl { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-mute); margin-bottom: 8px; }
.total-cell .val { font-size: var(--stat-size); font-weight: 600; font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; }
.total-cell .val.accent { color: var(--accent); }
.roi-pill {
  display: inline-block; margin-top: 8px; padding: 3px 10px; border-radius: 999px;
  background: var(--pos-soft); color: var(--pos-ink); font-family: 'IBM Plex Mono', monospace;
  font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 600;
}

/* ---- Footnotes ---- */
.footnote { font-size: 12.5px; color: var(--text-mute); margin-top: 12px; }
.footnote .mono { font-size: 12.5px; }

/* ---- Executed button (under the income breakdown) ---- */
.exec-row { display: flex; align-items: center; gap: 12px; margin-top: 16px; min-height: 40px; }
.exec-btn {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  padding: 10px 22px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.exec-btn:hover { filter: brightness(1.06); }
.exec-btn:disabled { opacity: .55; cursor: default; filter: none; }
.exec-confirm { display: inline-flex; align-items: center; gap: 10px; }
.exec-q { font-size: 13.5px; font-weight: 600; color: var(--text); }
.exec-yes, .exec-no {
  border-radius: var(--radius); padding: 9px 18px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.exec-yes { background: var(--pos); color: #fff; border: none; }
.exec-no { background: var(--input-bg); color: var(--text-dim); border: 1px solid var(--input-border); }
.exec-yes:hover { filter: brightness(1.06); }
.exec-no:hover { color: var(--text); }
.exec-msg { font-size: 13px; font-weight: 600; }
.exec-msg.ok { color: var(--pos); }
.exec-msg.err { color: var(--neg); }

/* ---- Executed-profit bar charts ---- */
.sec-charts { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.chart-card {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--card-radius); box-shadow: var(--shadow); padding: var(--card-pad);
}
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.chart-head h2 { margin: 0; font-size: 16px; }
.chart-sub { font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600; color: var(--pos); }
.chart-sub.neg { color: var(--neg); }

.chart { --plot-h: 180px; }
.chart-grid { display: flex; align-items: flex-start; gap: 8px; }
.chart-yaxis { position: relative; width: 46px; flex-shrink: 0; height: var(--plot-h); }
.chart-ytick {
  position: absolute; right: 0; transform: translateY(50%); line-height: 1;
  font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums;
  font-size: 10px; color: var(--text-mute); white-space: nowrap;
}
.chart-body { flex: 1; min-width: 0; }
.chart-plot { position: relative; height: var(--plot-h); }
.chart-gline {
  position: absolute; left: 0; right: 0; height: 0;
  border-top: 1px dashed var(--divider); pointer-events: none;
}
.chart-gline.zero { border-top-style: solid; border-top-color: var(--card-border); }
.chart-cols { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 3px; }
.chart-col { flex: 1 1 0; position: relative; height: 100%; min-width: 0; }
.chart-bar {
  position: absolute; left: 14%; right: 14%; border-radius: 3px 3px 0 0;
  background: var(--pos); transition: height .25s ease, bottom .25s ease;
}
.chart-bar.neg { background: var(--neg); border-radius: 0 0 3px 3px; }
.chart-xaxis { display: flex; gap: 3px; margin-top: 6px; padding-left: 54px; }
.chart-xlbl {
  flex: 1 1 0; text-align: center; font-size: 9.5px; color: var(--text-mute);
  font-family: 'IBM Plex Mono', monospace; white-space: nowrap; overflow: hidden;
}
.chart-empty { color: var(--text-mute); font-size: 13px; text-align: center; padding: 60px 0; }

/* ---- Mobile header (hidden on desktop) ---- */
.m-header { display: none; }
.m-glyph {
  width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.m-glyph svg { stroke: var(--accent); }
.m-titles { line-height: 1.16; }
.m-title { font-size: 15.5px; font-weight: 700; letter-spacing: -.01em; }
.m-title .swap { color: var(--accent); }
.m-sub { font-size: 11px; color: var(--text-mute); }
.m-actions { margin-left: auto; display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 11px; background: var(--input-bg);
  border: 1px solid var(--input-border); color: var(--text-dim); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--text); }

/* node-text wrapper (keeps eyebrow+brand grouped; identical on desktop) */
.node-text { display: flex; flex-direction: column; gap: 6px; text-align: center; }

/* ============================================================
   MOBILE  (< 900px) — desktop spec applies unchanged >= 900px
   ============================================================ */
@media (max-width: 899px) {
  .app { display: block; }

  /* sticky header replaces the toolbar + title block */
  .m-header {
    display: flex; align-items: center; gap: 11px;
    position: sticky; top: 0; z-index: 30;
    background: var(--panel); border-bottom: 1px solid var(--panel-border);
    padding: 11px 16px;
  }
  .toolbar, .title-block { display: none; }

  /* sidebar becomes a collapsible parameters sheet */
  .sidebar {
    position: static; width: auto; height: auto; overflow: visible;
    border-right: none; display: none;
    margin: 14px 16px 0; padding: 18px;
    background: var(--card); border: 1px solid var(--card-border); border-radius: 18px;
  }
  .app.params-open .sidebar { display: block; }

  /* main = ordered, gapped column; result-first ordering */
  .main { display: flex; flex-direction: column; gap: 18px; padding: 16px 16px 90px; }
  .sec h2 { margin: 0 0 12px; font-size: 17px; }
  .sec .footnote { margin-top: 10px; }
  .sec-banner { order: 1; }
  .sec-loop   { order: 2; }
  .sec-rates  { order: 3; }
  .sec-income { order: 5; }
  .sec-totals { order: 6; }
  .sec-charts { order: 7; grid-template-columns: 1fr; }
  .banner { margin: 0; }

  /* rate cards: label left / figure right */
  .rate-grid { grid-template-columns: 1fr; gap: 12px; }
  .rate-card {
    display: grid; grid-template-columns: 1fr auto;
    grid-template-areas: "eb fig" "unit fig"; align-items: center; column-gap: 12px;
  }
  .rate-card .eyebrow { grid-area: eb; }
  .rate-card .figure { grid-area: fig; margin: 0; font-size: 26px; }
  .rate-card .unit { grid-area: unit; }

  /* loop: vertical with down-arrows */
  .flow-card { padding: 14px; }
  .flow-grid { grid-template-columns: 1fr; gap: 0; }
  .flow-arrow { transform: rotate(90deg); margin: 8px 0; }
  .flow-node {
    background: var(--input-bg); border: 1px solid var(--card-border);
    border-radius: 14px; padding: 12px 14px; width: 100%;
  }
  .flow-node--single { flex-direction: row; align-items: center; gap: 12px; }
  .flow-node--single .node-text { text-align: left; flex: 1; gap: 2px; }
  .flow-node--single .logo-slot { width: 42px; height: 42px; flex-shrink: 0; }
  .flow-node--single .fig { margin-left: auto; font-size: 13px; white-space: nowrap; }
  .flow-node--cards { align-items: stretch; }
  .flow-node--cards .eyebrow { text-align: left; }
  .cards-list { gap: 0; align-items: stretch; }
  .card-item {
    flex-direction: row; align-items: center; gap: 12px; text-align: left;
    padding: 12px 0; border-bottom: 1px solid var(--divider);
  }
  .card-item:first-child { padding-top: 2px; }
  .card-item:last-child { border-bottom: none; }
  .card-item .logo-slot { width: 42px; height: 42px; flex-shrink: 0; }
  .card-item .fig { margin-left: auto; white-space: nowrap; }
  .card-item .brand-dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; }

  /* totals: 2x2 tiles + full-width accent net-profit card */
  .totals { grid-template-columns: 1fr 1fr; gap: 12px; }
  .total-cell {
    background: var(--card); border: 1px solid var(--card-border);
    border-radius: 14px; padding: 14px;
  }
  .total-cell .lbl { margin-bottom: 6px; }
  .total-cell .val { font-size: 19px; }
  .total-cell:last-child { grid-column: 1 / -1; background: var(--accent); border-color: transparent; }
  .total-cell:last-child .lbl { color: rgba(255,255,255,.82); }
  .total-cell:last-child .val { color: #fff; font-size: 28px; }
  .total-cell:last-child .roi-pill { background: rgba(255,255,255,.2); color: #fff; margin-top: 10px; }
}
