:root {
  --bg: #0b1220; --card: #141e33; --card2: #1a2742; --text: #e8eefc;
  --muted: #8ea0c0; --green: #34d399; --red: #f87171; --accent: #67e8f9;
  --amber: #fbbf24; --line: #22304f; --surface: #101a2c;
}
* { box-sizing: border-box; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 76px;
}
header {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: max(14px, env(safe-area-inset-top)) 16px 10px;
  position: sticky; top: 0; background: rgba(11,18,32,.92);
  backdrop-filter: blur(8px); z-index: 5;
}
header h1 { font-size: 19px; }
main { padding: 0 16px; max-width: 980px; margin: 0 auto; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .8px;
     color: var(--muted); margin: 18px 4px 8px; }
.card {
  background: var(--card); border-radius: 14px; padding: 14px;
  border: 1px solid #22304f; margin-bottom: 10px;
  overflow-wrap: anywhere;
}
.card.reco { border-left: 4px solid var(--accent); }
.card.reco h3 { color: var(--accent); font-size: 14px; margin-bottom: 6px; }
.muted { color: var(--muted); font-size: 12px; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(105px,1fr)); gap: 8px; }
.chip {
  background: var(--card); border: 1px solid #22304f; border-radius: 12px;
  padding: 9px 10px; text-align: center;
}
.chip .n { font-size: 11px; color: var(--muted); white-space: nowrap;
           overflow: hidden; text-overflow: ellipsis; }
.chip .v { font-weight: 600; font-size: 14px; }
.chip .c { font-size: 12px; font-weight: 600; }
.up { color: var(--green); } .down { color: var(--red); } .flat { color: var(--muted); }
.pending {
  background: #2a2416; border: 1px solid var(--amber); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 10px;
}
.pending b { color: var(--amber); }
nav {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex;
  background: #0e1729; border-top: 1px solid #22304f;
  padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
nav button {
  flex: 1; background: none; border: none; color: var(--muted);
  font-size: 20px; padding: 8px 0 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
nav button span { font-size: 10px; }
nav button.active { color: var(--accent); }
.hidden { display: none !important; }
.row { margin: 10px 0; }
select, input {
  width: 100%; background: var(--card2); color: var(--text);
  border: 1px solid #2c3d63; border-radius: 10px; padding: 10px 12px; font-size: 15px;
}
button#tokenSave {
  width: 100%; margin-top: 10px; background: var(--accent); color: #04101f;
  border: none; border-radius: 10px; padding: 11px; font-weight: 700; font-size: 15px;
}
.gate {
  position: fixed; inset: 0; background: var(--bg); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.gate-card { width: 100%; max-width: 340px; text-align: center; }
.gate-card h1 { margin-bottom: 6px; }
.gate-card p { color: var(--muted); margin-bottom: 14px; }
.err { color: var(--red); margin-top: 10px; font-size: 13px; }
.md h1 { font-size: 18px; margin: 10px 0 8px; }
.md h2 { font-size: 15px; color: var(--accent); text-transform: none;
         letter-spacing: 0; margin: 16px 0 6px; }
.md p, .md ul { margin-bottom: 8px; }
.md ul { padding-left: 20px; }
.md table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0;
            display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid #2c3d63; padding: 5px 8px; text-align: left; }
.md th { background: var(--card2); }
.md hr { border: none; border-top: 1px solid #2c3d63; margin: 12px 0; }
.md em { color: var(--muted); }
.pos { display: flex; justify-content: space-between; align-items: center;
       background: var(--card); border: 1px solid #22304f;
       border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; }
.skeleton { height: 60px; border-radius: 8px;
  background: linear-gradient(90deg, #1a2742 25%, #22304f 50%, #1a2742 75%);
  background-size: 200% 100%; animation: sh 1.2s infinite; }
@keyframes sh { to { background-position: -200% 0; } }
.kv { display: flex; justify-content: space-between; padding: 3px 0; }
.kv span:first-child { color: var(--muted); }
.flowbar { display: flex; align-items: flex-end; gap: 3px; height: 46px; margin-top: 6px; }
.flowbar div { flex: 1; border-radius: 2px 2px 0 0; min-height: 2px; }
.flowbar div.pos-f { background: var(--green); } .flowbar div.neg-f { background: var(--red); }
.btnrow { display: flex; gap: 8px; margin-top: 10px; }
.btnrow button { flex: 1; border: none; border-radius: 10px; padding: 10px;
                 font-weight: 700; font-size: 14px; cursor: pointer; }
.btn-ok { background: var(--green); color: #04240f; }
.btn-no { background: #3a2530; color: var(--red); border: 1px solid var(--red) !important; }

/* ---------- cartera multibroker ---------- */
.portfolio-toolbar {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 20px;
  padding: 22px 2px 18px; border-bottom: 1px solid var(--line);
}
.eyebrow {
  display: block; color: var(--accent); font-size: 10px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 5px;
}
h2.portfolio-title {
  margin: 0; color: var(--text); font-size: clamp(20px, 4vw, 34px);
  line-height: 1.08; letter-spacing: -.035em; text-transform: none;
}
.quiet-button {
  flex: 0 0 auto; border: 1px solid #314362; background: transparent;
  color: var(--text); border-radius: 999px; padding: 8px 13px; cursor: pointer;
  font-weight: 650; transition: border-color .18s ease, color .18s ease, transform .18s ease;
}
.quiet-button:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.quiet-button:disabled { opacity: .55; cursor: wait; transform: none; }
.portfolio-summary {
  display: grid; grid-template-columns: minmax(230px, 1.25fr) repeat(3, minmax(120px, .75fr));
  gap: 0; min-height: 146px; border-bottom: 1px solid var(--line);
  animation: portfolio-enter .42s ease both;
}
.portfolio-skeleton { grid-column: 1 / -1; margin: 28px 0; height: 76px; }
.portfolio-total, .portfolio-metric {
  display: flex; flex-direction: column; justify-content: center; min-width: 0;
  padding: 24px 22px; border-right: 1px solid var(--line);
}
.portfolio-summary > :last-child { border-right: 0; }
.portfolio-total { padding-left: 2px; }
.portfolio-total .label, .portfolio-metric .label {
  color: var(--muted); font-size: 11px; letter-spacing: .045em; text-transform: uppercase;
}
.portfolio-total strong {
  font-size: clamp(34px, 6vw, 54px); line-height: 1; letter-spacing: -.055em;
  margin: 8px 0 7px; font-variant-numeric: tabular-nums;
}
.portfolio-total small, .portfolio-metric small { color: var(--muted); font-size: 11px; }
.portfolio-metric strong {
  font-size: clamp(18px, 3vw, 25px); margin: 8px 0 5px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.portfolio-filters { display: flex; align-items: center; gap: 4px; padding: 14px 0 8px; }
.portfolio-filters button {
  border: 0; background: transparent; color: var(--muted); border-radius: 7px;
  padding: 7px 11px; font-size: 12px; font-weight: 750; cursor: pointer;
  transition: background .18s ease, color .18s ease;
}
.portfolio-filters button.active { color: #05222a; background: var(--accent); }
.venue-breakdown {
  display: flex; overflow-x: auto; gap: 0; border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}
.venue-item {
  min-width: 165px; padding: 13px 18px 13px 0; margin-right: 18px;
  animation: portfolio-enter .36s ease both;
}
.venue-item .venue-name { display: flex; align-items: center; gap: 7px; font-weight: 750; }
.venue-item strong { display: block; margin-top: 5px; font-size: 17px; font-variant-numeric: tabular-nums; }
.venue-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.venue-dot.degraded { background: var(--amber); }
.venue-dot.off { background: var(--red); }
.status-tag {
  display: inline-flex; align-items: center; border: 1px solid #334664; border-radius: 999px;
  color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .06em;
  text-transform: uppercase; padding: 2px 6px;
}
.portfolio-warnings { margin: 12px 0 2px; }
.portfolio-warning {
  display: grid; grid-template-columns: 16px 1fr; gap: 8px; padding: 8px 0;
  color: #d8c998; border-bottom: 1px solid rgba(251,191,36,.14); font-size: 12px;
}
.portfolio-warning:last-child { border-bottom: 0; }
.section-line { display: flex; align-items: baseline; justify-content: space-between; }
.section-line h2 { margin-left: 0; }
.position-list { border-top: 1px solid var(--line); transition: opacity .18s ease; }
.position-list.is-changing { opacity: .28; }
.holding { border-bottom: 1px solid var(--line); animation: holding-enter .34s ease both; }
.holding summary {
  list-style: none; display: grid;
  grid-template-columns: minmax(180px, 1.3fr) minmax(105px, .7fr) minmax(105px, .75fr) 24px;
  align-items: center; gap: 16px; padding: 17px 2px; cursor: pointer;
  transition: background .16s ease, padding .16s ease;
}
.holding summary::-webkit-details-marker { display: none; }
.holding summary:hover { background: rgba(103,232,249,.035); padding-left: 8px; padding-right: 8px; }
.holding-title { min-width: 0; }
.holding-title b { font-size: 15px; }
.holding-subtitle {
  display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin-top: 3px;
  color: var(--muted); font-size: 11px;
}
.holding-number { text-align: right; font-variant-numeric: tabular-nums; }
.holding-number b { display: block; font-size: 15px; }
.holding-number span { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }
.holding-pnl { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.holding-pnl small { display: block; font-size: 10px; margin-top: 2px; color: currentColor; opacity: .75; }
.holding-chevron {
  color: var(--muted); transform: rotate(0); transition: transform .2s ease; font-size: 18px;
}
.holding[open] .holding-chevron { transform: rotate(45deg); color: var(--accent); }
.holding-details {
  display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 0;
  padding: 2px 0 18px; animation: detail-open .2s ease both;
}
.detail-block { padding: 12px 16px 12px 0; border-top: 1px solid rgba(49,67,98,.72); }
.detail-block.wide { grid-column: span 2; }
.detail-block span { color: var(--muted); display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .055em; }
.detail-block b { display: block; margin-top: 5px; font-size: 13px; font-variant-numeric: tabular-nums; }
.detail-block p { color: var(--muted); font-size: 11px; margin-top: 5px; max-width: 52ch; }
.quality-good { color: var(--green) !important; }
.quality-warn { color: var(--amber) !important; }
.operational-strip {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 13px 0;
}
.operational-strip .btnrow { margin: 0; min-width: 180px; }
.operational-copy { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.trade-list { margin-bottom: 18px; }
.trade-list .kv { border-bottom: 1px solid var(--line); padding: 9px 0; }
.empty-state { color: var(--muted); padding: 28px 0; border-bottom: 1px solid var(--line); }

@keyframes portfolio-enter { from { opacity: 0; transform: translateY(7px); } }
@keyframes holding-enter { from { opacity: 0; transform: translateY(5px); } }
@keyframes detail-open { from { opacity: 0; transform: translateY(-4px); } }

@media (max-width: 720px) {
  main { padding: 0 12px; }
  .portfolio-toolbar { align-items: center; padding-top: 15px; }
  .portfolio-summary { grid-template-columns: 1fr 1fr; }
  .portfolio-total { grid-column: 1 / -1; border-right: 0; border-bottom: 1px solid var(--line); padding: 22px 0; }
  .portfolio-metric { padding: 16px 10px 16px 0; }
  .portfolio-metric:nth-child(3) { border-right: 0; padding-left: 12px; }
  .portfolio-metric:nth-child(4) { grid-column: 1 / -1; border-right: 0; border-top: 1px solid var(--line); }
  .holding summary { grid-template-columns: 1fr auto 20px; gap: 10px; }
  .holding-number { grid-column: 1; grid-row: 2; text-align: left; margin-top: -7px; }
  .holding-number b, .holding-number span { display: inline; font-size: 10px; color: var(--muted); }
  .holding-number b::after { content: " · "; }
  .holding-pnl { grid-column: 2; grid-row: 1 / span 2; }
  .holding-chevron { grid-column: 3; grid-row: 1 / span 2; }
  .holding-details { grid-template-columns: 1fr 1fr; }
  .detail-block.wide { grid-column: 1 / -1; }
  .operational-strip { align-items: flex-start; flex-direction: column; }
  .operational-strip .btnrow { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
