/* ╔══════════════════════════════════════════════════════════╗
   ║  FINANZAS v7 — Dark Luxury + Light Parchment             ║
   ║  Playfair Display + Inter + JetBrains Mono               ║
   ╚══════════════════════════════════════════════════════════╝ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;1,400&family=Inter:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Tokens dark ──────────────────────────────────────────────────────────── */
:root {
  --nav-w:       220px;
  --radius:      10px;
  --radius-sm:   6px;
  --transition:  .18s cubic-bezier(.4,0,.2,1);
  --shadow:      0 4px 24px rgba(0,0,0,.45);
  --shadow-sm:   0 2px 8px rgba(0,0,0,.3);

  --bg:          #0B0D12;
  --surface:     #111318;
  --surface-2:   #181B22;
  --surface-3:   #1E2129;
  --border:      rgba(255,255,255,.07);
  --border-g:    rgba(201,168,76,.22);

  --text:        #EAE2D4;
  --text-muted:  #8A8278;
  --text-dim:    #55524E;

  --gold:        #C9A84C;
  --gold-2:      #D9B85C;
  --gold-soft:   rgba(201,168,76,.1);
  --gold-soft2:  rgba(201,168,76,.18);

  --green:       #4CAF7D;
  --red:         #E05555;
  --blue:        #5B8DD9;
  --purple:      #9B59B6;
  --orange:      #F7931A;
  --teal:        #20B2AA;
}

/* ── Tokens light ─────────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:          #F2EDE4;
  --surface:     #FAF6F0;
  --surface-2:   #EDE8DF;
  --surface-3:   #E4DDD4;
  --border:      rgba(0,0,0,.08);
  --border-g:    rgba(139,105,48,.25);
  --text:        #1C1810;
  --text-muted:  #6B5F50;
  --text-dim:    #A09080;
  --gold:        #8B6914;
  --gold-2:      #7A5C10;
  --gold-soft:   rgba(139,105,20,.1);
  --gold-soft2:  rgba(139,105,20,.18);
  --shadow:      0 2px 16px rgba(0,0,0,.1);
  --shadow-sm:   0 1px 4px rgba(0,0,0,.08);
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-2); }
button { font-family: 'Inter', sans-serif; }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gold-soft); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(201,168,76,.3); }

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

/* ── Sidebar desktop ──────────────────────────────────────────────────────── */
.sidebar {
  width: var(--nav-w);
  flex-shrink: 0;          /* no encoge */
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;        /* sticky: fluye con el doc, nunca se superpone */
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 1.4rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: .01em;
}
.sidebar-logo-sub {
  font-size: .63rem;
  color: var(--text-dim);
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-top: .2rem;
}

.sidebar-nav {
  flex: 1;
  padding: .6rem 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  width: 100%;
  padding: .58rem 1.25rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: .82rem;
  font-weight: 400;
  text-align: left;
  transition: color var(--transition), background var(--transition);
  position: relative;
  letter-spacing: .01em;
}
.nav-item:hover { color: var(--text); background: var(--gold-soft); }
.nav-item.active {
  color: var(--gold);
  background: var(--gold-soft);
  font-weight: 500;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 22%; bottom: 22%;
  width: 2.5px;
  background: var(--gold);
  border-radius: 0 2px 2px 0;
}
.nav-icon { width: 15px; height: 15px; opacity: .65; flex-shrink: 0; }
.nav-item.active .nav-icon, .nav-item:hover .nav-icon { opacity: 1; }
.nav-sep { height: 1px; background: var(--border); margin: .4rem .75rem; }

.sidebar-bottom {
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.sync-btn, .logout-btn {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .45rem .75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: .78rem;
  transition: all var(--transition);
}
.sync-btn:hover, .logout-btn:hover {
  color: var(--text);
  border-color: var(--gold);
  background: var(--gold-soft);
}
.sidebar-theme {
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* ── Main ─────────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  min-width: 0;  /* evita overflow en flex */
  padding: 2rem 2.5rem 3rem;
  max-width: 100%;
}

/* ── Pages ────────────────────────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; animation: fadeUp .15s ease; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.page-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.01em;
  line-height: 1.2;
}
.page-subtitle {
  font-size: .72rem;
  color: var(--text-dim);
  margin-top: .2rem;
  font-family: 'JetBrains Mono', monospace;
}
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ── Grids ────────────────────────────────────────────────────────────────── */
.kpi-grid  { display: grid; grid-template-columns: repeat(4,1fr); gap: 1rem; margin-bottom: 1.25rem; }
.grid-2    { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.grid-3    { display: grid; grid-template-columns: repeat(3,1fr); gap: 1.25rem; }
.grid-4    { display: grid; grid-template-columns: repeat(4,1fr); gap: 1rem; }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2,1fr); }
  .grid-4   { grid-template-columns: repeat(2,1fr); }
}

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color var(--transition);
}
.card:hover { border-color: rgba(201,168,76,.13); }
.card-title {
  font-size: .66rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: .75rem;
}

/* ── KPI ──────────────────────────────────────────────────────────────────── */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.25rem;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.kpi::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--gold), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}
.kpi:hover::after { opacity: 1; }
.kpi-label {
  font-size: .67rem;
  text-transform: uppercase;
  letter-spacing: .11em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: .4rem;
}
.kpi-value {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -.02em;
}
.kpi-sub {
  font-size: .73rem;
  color: var(--text-muted);
  margin-top: .3rem;
  line-height: 1.4;
}

/* ── Distribution bars ────────────────────────────────────────────────────── */
.dist-bar-wrap { margin-bottom: .65rem; }
.dist-bar-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .78rem;
  margin-bottom: .28rem;
}
.dist-bar-track { height: 4px; background: var(--surface-3); border-radius: 2px; overflow: hidden; }
.dist-bar-fill  { height: 100%; border-radius: 2px; transition: width .5s ease; }

/* ── Block headers (posiciones) ───────────────────────────────────────────── */
.block-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem 0 .3rem;
  margin-top: .75rem;
}
.block-dot   { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.block-title {
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .1em;
}
.block-total {
  margin-left: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: .82rem;
  color: var(--gold);
}

/* ── Table ────────────────────────────────────────────────────────────────── */
.positions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .83rem;
  line-height: 1.5;
}
.positions-table th {
  text-align: left;
  padding: .45rem .65rem;
  font-size: .64rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-dim);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.positions-table td {
  padding: .52rem .65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.positions-table tbody tr:hover td { background: var(--gold-soft); }
.positions-table tbody tr:last-child td { border-bottom: none; }

/* ── Editable field ───────────────────────────────────────────────────────── */
.editable-field {
  background: var(--surface-2);
  border: 1px solid var(--border-g);
  border-radius: 5px;
  padding: .22rem .45rem;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: .79rem;
  outline: none;
  transition: border-color var(--transition);
  width: 90px;
}
.editable-field:focus { border-color: var(--gold); }

/* ── Badges & text utils ──────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .1rem .4rem;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: .69rem;
  font-weight: 500;
}
.badge-green { background: rgba(76,175,125,.14); color: var(--green); }
.badge-red   { background: rgba(224,85,85,.14);  color: var(--red); }
.badge-gold  { background: var(--gold-soft);      color: var(--gold); }

.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-gold   { color: var(--gold); }
.text-blue   { color: var(--blue); }
.text-muted  { color: var(--text-muted); }
.text-dim    { color: var(--text-dim); }
.mono        { font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .5rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1;
}
.btn-primary {
  background: var(--gold);
  color: #0B0D12;
}
.btn-primary:hover { background: var(--gold-2); box-shadow: 0 2px 12px rgba(201,168,76,.3); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--gold); background: var(--gold-soft); }
.btn-danger {
  background: rgba(224,85,85,.1);
  color: var(--red);
  border: 1px solid rgba(224,85,85,.2);
}
.btn-danger:hover { background: rgba(224,85,85,.2); }
.btn-sm { padding: .3rem .7rem; font-size: .76rem; }
.btn-icon {
  padding: .38rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { color: var(--gold); border-color: var(--gold); background: var(--gold-soft); }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block;
  font-size: .72rem;
  color: var(--text-muted);
  margin-bottom: .3rem;
  font-weight: 500;
}
.form-input, .form-select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem .75rem;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: .85rem;
  outline: none;
  transition: border-color var(--transition);
}
.form-input:focus, .form-select:focus { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold-soft); }
.form-input::placeholder { color: var(--text-dim); }
.form-select { cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

/* ── Alert ────────────────────────────────────────────────────────────────── */
.alert-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem .7rem;
  border-radius: var(--radius-sm);
  font-size: .79rem;
  margin-bottom: .35rem;
  border-left: 2.5px solid;
}
.alert-info    { background: rgba(91,141,217,.09);  border-color: var(--blue);   color: var(--blue); }
.alert-warn    { background: var(--gold-soft);       border-color: var(--gold);   color: var(--gold); }
.alert-danger  { background: rgba(224,85,85,.09);   border-color: var(--red);    color: var(--red); }
.alert-success { background: rgba(76,175,125,.09);  border-color: var(--green);  color: var(--green); }

/* ── Charts ───────────────────────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 220px; }
.chart-wrap canvas { position: absolute; inset: 0; }
#chart-evolucion-wrap { height: 240px; position: relative; }
#chart-evolucion-wrap canvas { position: absolute; inset: 0; }

/* ── Hipoteca bars ────────────────────────────────────────────────────────── */
.hip-bar-wrap { margin-bottom: 1rem; }
.hip-bar-label { display: flex; justify-content: space-between; font-size: .78rem; margin-bottom: .35rem; }
.hip-bar-track { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.hip-bar-fill  { height: 100%; border-radius: 3px; background: var(--teal); transition: width .6s ease; }

/* ── Upload zone ──────────────────────────────────────────────────────────── */
.upload-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  color: var(--text-muted);
  font-size: .82rem;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--gold);
  background: var(--gold-soft);
}
.upload-zone input[type="file"] { display: none; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border-g);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: modalIn .2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-title  { font-family: 'Playfair Display', serif; font-size: 1.1rem; }
.modal-body   { padding: 1.2rem 1.5rem; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toastWrap {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .65rem 1rem;
  font-size: .82rem;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toastIn .2s ease;
  min-width: 180px;
  pointer-events: auto;
}
.toast.success { border-color: rgba(76,175,125,.4);  color: var(--green); }
.toast.error   { border-color: rgba(224,85,85,.4);   color: var(--red); }
.toast.warn    { border-color: rgba(201,168,76,.35);  color: var(--gold); }
.toast.info    { border-color: rgba(91,141,217,.35);  color: var(--blue); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Theme toggle ─────────────────────────────────────────────────────────── */
.theme-toggle {
  width: 36px; height: 20px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  transition: background var(--transition);
  flex-shrink: 0;
}
.theme-toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: var(--gold);
  border-radius: 50%;
  transition: transform var(--transition);
}
[data-theme="light"] .theme-toggle::after { transform: translateX(16px); }

/* ── Range buttons ────────────────────────────────────────────────────────── */
.range-btn {
  padding: .2rem .55rem;
  font-size: .67rem;
  font-family: 'Inter', sans-serif;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.range-btn:hover { color: var(--text); border-color: var(--gold); }
.range-btn.active {
  background: var(--gold-soft2);
  color: var(--gold);
  border-color: var(--border-g);
  font-weight: 600;
}

/* ── Misc utils ───────────────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.label { font-size: .66rem; text-transform: uppercase; letter-spacing: .1em; color: var(--text-muted); font-weight: 600; display: block; margin-bottom: .5rem; }
.mb-1 { margin-bottom: .35rem; } .mb-2 { margin-bottom: .75rem; } .mb-3 { margin-bottom: 1.25rem; }
.mt-1 { margin-top: .35rem; }   .mt-2 { margin-top: .75rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-gap     { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.text-center  { text-align: center; }
.text-right   { text-align: right; }

/* ── Nominas ──────────────────────────────────────────────────────────────── */
.nomina-parsed-card {
  background: var(--surface-2);
  border: 1px solid var(--border-g);
  border-radius: 8px;
  padding: .85rem 1rem;
  margin-bottom: .5rem;
  font-size: .8rem;
}
.nomina-parsed-card .nom-mes { font-weight: 600; color: var(--gold); margin-bottom: .35rem; }

/* ── Bottom nav (mobile only) ─────────────────────────────────────────────── */
.mobile-header { display: none; }
.bottom-nav    { display: none; }

@media (max-width: 768px) {
  /* Ocultar sidebar en móvil */
  .sidebar { display: none; }

  /* Mobile header fijo */
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .65rem 1rem .5rem;
    padding-top: calc(.65rem + env(safe-area-inset-top, 0px));
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
  }
  .mobile-header-title {
    font-family: 'Playfair Display', serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--gold);
  }

  /* Main sin sidebar */
  .main {
    padding: 1rem 1rem calc(72px + env(safe-area-inset-bottom, 0px) + 1rem);
  }

  /* KPI grid 2 columnas */
  .kpi-grid { grid-template-columns: repeat(2,1fr); gap: .75rem; }
  .kpi-value { font-size: 1.5rem; }
  .page-title { font-size: 1.4rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  /* Ocultar columnas secundarias en tablas */
  /* Posiciones móvil: ocultar NAV (4) y P.Medio (6) */
  .positions-table th:nth-child(4),
  .positions-table td:nth-child(4),
  .positions-table th:nth-child(6),
  .positions-table td:nth-child(6) { display: none; }

  .form-row { grid-template-columns: 1fr; }
  #toastWrap { bottom: 5rem; right: 1rem; left: 1rem; }

  /* Bottom nav */
  .bottom-nav {
    display: block;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: rgba(11,13,18,.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    z-index: 200;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  [data-theme="light"] .bottom-nav { background: rgba(242,237,228,.95); }
  .bottom-nav-inner {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 56px;
  }
  .bn-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .18rem;
    padding: .3rem .4rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-dim);
    font-size: .57rem;
    font-family: 'Inter', sans-serif;
    transition: color var(--transition);
    min-width: 48px;
  }
  .bn-item:hover, .bn-item.active { color: var(--gold); }
  .bn-icon { width: 20px; height: 20px; }

  /* More sheet */
  .more-sheet {
    position: fixed;
    bottom: -100%;
    left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border-g);
    border-radius: 16px 16px 0 0;
    z-index: 300;
    transition: bottom .3s cubic-bezier(.4,0,.2,1);
    padding: 0 0 calc(1.5rem + env(safe-area-inset-bottom, 0px));
    max-height: 70vh;
    overflow-y: auto;
  }
  .more-sheet.open { bottom: 0; }
  .more-sheet-handle {
    width: 36px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: .75rem auto .5rem;
  }
  .more-sheet-grid {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: .5rem;
    padding: .5rem 1.25rem;
  }
  .more-sheet-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .35rem;
    padding: .75rem .5rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: .72rem;
    font-family: 'Inter', sans-serif;
    text-align: center;
    transition: all var(--transition);
  }
  .more-sheet-item:hover, .more-sheet-item.active {
    color: var(--gold);
    border-color: var(--gold);
    background: var(--gold-soft);
  }
  .more-sheet-icon { width: 22px; height: 22px; }
  .more-sheet-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 250;
    background: rgba(0,0,0,.4);
  }
  .more-sheet-overlay.open { display: block; }

  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { max-width: 100%; border-radius: 16px 16px 0 0; }
}

@media (min-width: 769px) {
  .more-sheet, .more-sheet-overlay { display: none !important; }
  /* Asegurar que el sidebar nunca se superpone */
  .app-layout { align-items: flex-start; }
  .editable-field { width: 70px !important; font-size: .72rem !important; padding: .2rem .3rem !important; }
  .positions-table { font-size: .75rem; }
  .positions-table th, .positions-table td { padding: .4rem .3rem; }
}

/* ── Columnas ocultas en mobile ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .hide-sm { display: none !important; }
}

/* ── Selector posiciones gráfica ─────────────────────────────────────────────── */
#pos-chart-selector {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  max-width: 100%;
}
#pos-chart-selector .range-btn {
  font-size: .63rem;
  padding: .18rem .48rem;
  white-space: nowrap;
  transition: all var(--transition);
}
#pos-chart-selector .range-btn.active {
  font-weight: 600;
}

/* ── snap-pos-fields grid compacto ───────────────────────────────────────────── */
#snap-pos-fields input {
  padding: .25rem .45rem;
  font-size: .76rem;
}
#snap-pos-fields span {
  font-size: .72rem;
}

/* ── Historial: overflow en móvil ────────────────────────────────────────────── */
#historial-table { overflow-x: auto; }
#historial-table table { min-width: 440px; }

/* ── Snap row seleccionada ───────────────────────────────────────────────────── */
tr.snap-selected td { background: var(--gold-soft) !important; }
tr[data-snapday]:hover td { cursor: pointer; }

/* ── Revisión guiada: tabla compacta ─────────────────────────────────────────── */
#revModalBody table { font-size: .8rem; }
#revModalBody .editable-field { width: 90px; padding: .2rem .4rem; }

.chart-wrap-tall { position: relative; height: 220px; }
.chart-wrap-tall canvas { position: absolute; inset: 0; }

/* ── Posiciones mobile: inputs más cómodos ──────────────────────────────── */
@media (max-width: 768px) {
  .editable-field {
    width: 78px;
    font-size: .75rem;
    padding: .2rem .35rem;
  }
  .positions-table td { padding: .4rem .4rem; font-size: .78rem; }
  .positions-table th { font-size: .62rem; padding: .35rem .4rem; }
  /* Ocultar columnas menos importantes en posiciones */
  .positions-table .hide-xs { display: none !important; }
}
/* Historial tabla: alinear todas las celdas numéricas */
#historial-table table { table-layout: fixed; width: 100%; }
