/* ============================================================
   INVERSIONES APP — Stylesheet
   Dark fintech dashboard · JetBrains Mono + Sora
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=Sora:wght@300;400;500;600;700&display=swap');

/* ---- Custom Properties ------------------------------------ */
:root {
  --bg-base:        #080c14;
  --bg-surface:     #0d1220;
  --bg-card:        #111827;
  --bg-card-hover:  #141f30;
  --bg-input:       #0d1220;
  --border:         rgba(255,255,255,.07);
  --border-strong:  rgba(255,255,255,.13);

  --green:          #00e5a0;
  --green-dim:      rgba(0,229,160,.12);
  --red:            #ff4d6d;
  --red-dim:        rgba(255,77,109,.12);
  --neutral:        #3d4a5e;
  --neutral-dim:    rgba(61,74,94,.25);

  --accent:         #4f8ef7;
  --accent-glow:    rgba(79,142,247,.2);

  --text-primary:   #e8f0fe;
  --text-secondary: #7a8caa;
  --text-muted:     #3d4a5e;

  --font-mono:      'JetBrains Mono', monospace;
  --font-ui:        'Sora', sans-serif;

  --radius-sm:      8px;
  --radius-md:      14px;
  --radius-lg:      20px;
  --radius-xl:      28px;

  --shadow-card:    0 2px 20px rgba(0,0,0,.45);
  --shadow-glow:    0 0 30px rgba(79,142,247,.15);

  --transition:     .2s cubic-bezier(.4,0,.2,1);

  --sidebar-w:      240px;
  --header-h:       60px;
}

/* ---- Reset ------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font-ui);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---- Scrollbar ------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* ---- Layout ---------------------------------------------- */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  min-height: 100vh;
}

/* ---- Header ---------------------------------------------- */
.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(12px);
}

.header-brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  text-decoration: none;
}
.header-brand .brand-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--green));
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 16px;
}

.header-right { display: flex; align-items: center; gap: 12px; }

.btn-icon {
  width: 36px; height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  cursor: pointer; color: var(--text-secondary);
  transition: var(--transition);
  font-size: 16px;
}
.btn-icon:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.mobile-menu-btn { display: none; }

/* ---- Sidebar --------------------------------------------- */
.app-sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto;
}

.nav-section {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 16px 12px 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: .88rem;
  font-weight: 500;
  transition: var(--transition);
  border: none; background: none;
  width: 100%; text-align: left;
  text-decoration: none;
}
.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(79,142,247,.2);
}
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: .78rem;
  color: var(--text-muted);
  text-align: center;
}

/* ---- Main content ---------------------------------------- */
.app-main {
  overflow-y: auto;
  padding: 28px 24px;
}

/* ---- Page sections --------------------------------------- */
.page-section { display: none; }
.page-section.active { display: block; }

/* ---- Page header ----------------------------------------- */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap; gap: 16px;
}
.page-title {
  font-size: 1.5rem; font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
}
.page-subtitle { font-size: .85rem; color: var(--text-secondary); margin-top: 3px; }

/* ---- Buttons --------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #6fa3ff; transform: translateY(-1px); }
.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.btn-danger { background: var(--red-dim); color: var(--red); border: 1px solid var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: .8rem; }

/* ---- Cards ----------------------------------------------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: var(--transition);
}
.card:hover { border-color: var(--border-strong); }

/* ---- Stats grid ------------------------------------------ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
}
.stat-card.positive::before { background: var(--green); }
.stat-card.negative::before { background: var(--red); }
.stat-card.neutral::before  { background: var(--accent); }

.stat-label {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}
.stat-value.pos { color: var(--green); }
.stat-value.neg { color: var(--red); }
.stat-sub {
  font-size: .75rem;
  color: var(--text-secondary);
  margin-top: 5px;
}

/* ---- Charts grid ----------------------------------------- */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
}
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
}
.chart-title {
  font-size: .82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.chart-canvas-wrap { position: relative; height: 220px; }

/* ---- Calendar -------------------------------------------- */
.calendar-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap; gap: 12px;
}
.calendar-month {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 700;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.calendar-dow {
  text-align: center;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  padding: 6px 0;
}
.calendar-day {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  min-height: 54px;
  padding: 4px;
  gap: 2px;
}
.calendar-day:hover { border-color: var(--accent); transform: scale(1.04); z-index: 1; }
.calendar-day.empty { background: transparent; border-color: transparent; cursor: default; }
.calendar-day.today { border-color: var(--accent); }
.calendar-day.today .day-num { color: var(--accent); }

.calendar-day.ganancia {
  background: var(--green-dim);
  border-color: rgba(0,229,160,.3);
}
.calendar-day.perdida {
  background: var(--red-dim);
  border-color: rgba(255,77,109,.3);
}

.day-num {
  font-family: var(--font-mono);
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-primary);
}
.day-amount {
  font-family: var(--font-mono);
  font-size: .65rem;
  font-weight: 700;
  line-height: 1;
}
.calendar-day.ganancia .day-amount { color: var(--green); }
.calendar-day.perdida  .day-amount { color: var(--red); }

.calendar-day.future { opacity: .35; pointer-events: none; }

/* ---- Modal ----------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(8,12,20,.85);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: none;
  place-items: center;
  padding: 20px;
}
.modal-overlay.open { display: grid; animation: fadeIn .2s ease; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp .25s ease;
  box-shadow: 0 24px 80px rgba(0,0,0,.7);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--bg-card);
  z-index: 10;
}
.modal-title {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
}
.modal-close {
  width: 32px; height: 32px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  display: grid; place-items: center;
  font-size: 18px; line-height: 1;
  transition: var(--transition);
}
.modal-close:hover { background: var(--red-dim); color: var(--red); border-color: var(--red); }
.modal-body { padding: 24px; }
.modal-footer {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}

/* ---- Forms ----------------------------------------------- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-secondary);
  margin-bottom: 7px;
}
.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: .88rem;
  transition: var(--transition);
  outline: none;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-control option { background: var(--bg-card); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

textarea.form-control { resize: vertical; min-height: 80px; }

/* ---- Tipo selector ---------------------------------------- */
.tipo-pills {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.tipo-pill {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.tipo-pill:hover { border-color: var(--border-strong); color: var(--text-primary); }
.tipo-pill.selected { color: #fff; border-color: transparent; }

/* ---- Result toggle --------------------------------------- */
.result-toggle {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.result-btn {
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 600;
  font-size: .85rem;
  transition: var(--transition);
  text-align: center;
}
.result-btn:hover { border-color: var(--border-strong); }
.result-btn.ganancia.active {
  background: var(--green-dim);
  border-color: var(--green);
  color: var(--green);
}
.result-btn.perdida.active {
  background: var(--red-dim);
  border-color: var(--red);
  color: var(--red);
}

/* ---- Activos table --------------------------------------- */
.activos-table {
  width: 100%; border-collapse: collapse;
}
.activos-table th {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.activos-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  font-size: .87rem;
  vertical-align: middle;
}
.activos-table tr:hover td { background: var(--bg-card-hover); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: .72rem;
  font-weight: 700;
}
.amount-cell {
  font-family: var(--font-mono);
  font-weight: 600;
}
.amount-cell.pos { color: var(--green); }
.amount-cell.neg { color: var(--red); }

/* ---- Top activos bar ------------------------------------- */
.top-activo-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.top-activo-row:last-child { border-bottom: none; }
.top-activo-bar-wrap { flex: 1; height: 4px; background: var(--bg-surface); border-radius: 2px; overflow: hidden; }
.top-activo-bar { height: 100%; border-radius: 2px; transition: width .5s ease; }

/* ---- Toast ----------------------------------------------- */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  font-size: .85rem;
  font-weight: 500;
  display: flex; align-items: center; gap: 8px;
  animation: slideUp .25s ease;
  box-shadow: var(--shadow-card);
}
.toast.success { border-color: rgba(0,229,160,.4); color: var(--green); }
.toast.error   { border-color: rgba(255,77,109,.4); color: var(--red); }
.toast.info    { border-color: rgba(79,142,247,.4); color: var(--accent); }

/* ---- Loading --------------------------------------------- */
.loading-overlay {
  position: absolute; inset: 0;
  background: var(--bg-card);
  display: grid; place-items: center;
  border-radius: inherit;
  z-index: 5;
}
.spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Filters --------------------------------------------- */
.filters-bar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
}
.select-sm {
  padding: 7px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: .83rem;
  cursor: pointer;
  outline: none;
  transition: var(--transition);
}
.select-sm:focus { border-color: var(--accent); }
.select-sm option { background: var(--bg-card); }

/* ---- Empty state ----------------------------------------- */
.empty-state {
  text-align: center; padding: 50px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; opacity: .5; }
.empty-state p { font-size: .9rem; }

/* ---- Mobile nav overlay ---------------------------------- */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 150;
}

/* ---- Responsive ------------------------------------------ */
@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr;
  }

  .app-sidebar {
    position: fixed;
    left: -260px; top: 0; bottom: 0;
    width: 240px;
    z-index: 200;
    transition: left var(--transition);
    box-shadow: 4px 0 30px rgba(0,0,0,.5);
  }
  .app-sidebar.open { left: 0; }
  .sidebar-overlay.open { display: block; }

  .mobile-menu-btn { display: grid; }

  .app-main { padding: 20px 16px; }

  .calendar-grid { gap: 4px; }
  .calendar-day { min-height: 44px; }
  .day-num { font-size: .75rem; }
  .day-amount { font-size: .58rem; }

  .stats-grid { grid-template-columns: 1fr 1fr; }

  .form-row, .form-row-3 { grid-template-columns: 1fr; }

  .modal { border-radius: var(--radius-md); }
}

@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr; }
  .calendar-day .day-amount { display: none; }
}
