/* ============================================================
   DRACMA ASSETS MANAGMENT — Visor de Carteras
   Design: editorial finance, B&W dominant, serif accents
   ============================================================ */

:root {
  --bg: #FAFAF8;
  --bg-card: #FFFFFF;
  --bg-sidebar: #0F0F0F;
  --bg-hover: #F3F3F0;
  --bg-accent: #F5F0E8;
  
  --text-primary: #1A1A1A;
  --text-secondary: #6B6B6B;
  --text-tertiary: #9B9B9B;
  --text-inverse: #FAFAF8;
  
  --border: #E8E8E4;
  --border-strong: #D0D0CC;
  
  --accent: #C8A96E;
  --accent-light: #F5EFE0;
  --accent-dark: #8B7340;
  
  --positive: #2D8B4E;
  --negative: #C23B3B;
  --info: #3B6FA0;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --sidebar-width: 220px;
  --transition: 0.2s ease;
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
#sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-inverse);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 100;
  border-right: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand {
  padding: 1.5rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-logo {
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: var(--bg-sidebar);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
}

.brand-text { display: flex; flex-direction: column; }
.brand-name { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; letter-spacing: 0.01em; }
.brand-sub { font-size: 0.65rem; color: rgba(255,255,255,0.4); text-transform: uppercase; letter-spacing: 0.12em; font-weight: 500; }

.sidebar-nav {
  padding: 1rem 0.75rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all var(--transition);
}
.nav-item:hover { color: rgba(255,255,255,0.85); background: rgba(255,255,255,0.06); }
.nav-item.active { color: #fff; background: rgba(255,255,255,0.1); }
.nav-item svg { flex-shrink: 0; }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-date { font-size: 0.7rem; color: rgba(255,255,255,0.3); font-family: var(--font-mono); }

/* ---- Main content ---- */
#main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 2rem 2.5rem;
  max-width: 1280px;
}

/* ---- Views ---- */
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.3s ease; }

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

/* ---- View header ---- */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.75rem;
  gap: 1rem;
}

.view-title {
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.view-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}

.view-controls { display: flex; gap: 0.75rem; align-items: center; }

/* ---- TC Input ---- */
.tc-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
}
.tc-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}
.tc-input {
  width: 120px;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-primary);
  background: var(--bg-card);
}
.tc-input:focus { outline: none; border-color: var(--accent); }
.tc-input.tc-input-manual {
  border-color: #c8a96e;
  background: #faf6ed;
}
.tc-reset {
  padding: 0.42rem 0.8rem;
  font-size: 0.72rem;
}
.tc-status {
  font-size: 0.74rem;
  color: var(--text-secondary);
}
.tc-status.tc-status-manual { color: #8a5a00; }
.tc-status.tc-status-auto { color: var(--text-secondary); }
.tc-status.tc-status-loading { color: var(--accent); }
.tc-status.tc-status-missing { color: var(--negative); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
}
.btn-primary {
  background: var(--text-primary);
  color: var(--text-inverse);
}
.btn-primary:hover { background: #333; }
.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); }

/* ---- Select ---- */
.select-input {
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--text-primary);
  cursor: pointer;
  min-width: 180px;
}
.select-input:focus { outline: none; border-color: var(--accent); }
.select-input:disabled {
  color: var(--text-tertiary);
  background: var(--bg-hover);
  cursor: not-allowed;
}
.cartera-date-select { min-width: 170px; }

/* ---- Search Select ---- */
.search-select { position: relative; min-width: 200px; }
.search-select-input {
  width: 100%;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--text-primary);
}
.search-select-input:focus { outline: none; border-color: var(--accent); }
.search-select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 2px;
  max-height: 250px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.search-select-option {
  padding: 0.5rem 0.85rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}
.search-select-option:hover { background: var(--bg-hover); }
.search-select-option.selected { background: var(--bg-accent); font-weight: 600; }

/* ---- Summary cards ---- */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.card-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  font-weight: 600;
}

.card-value {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.card-value.positive { color: var(--positive); }
.card-value.negative { color: var(--negative); }

/* ---- Fund AUM blocks ---- */
.fund-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  overflow: hidden;
}

.fund-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.25rem;
  background: var(--text-primary);
  color: var(--text-inverse);
  cursor: pointer;
}

.fund-block-header h3 {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.fund-block-aum {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
}

.fund-block-body { padding: 0; }

.fund-clases-table {
  width: 100%;
  border-collapse: collapse;
}

.fund-clases-table th,
.fund-clases-table td {
  padding: 0.6rem 1.25rem;
  text-align: left;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
}

.fund-clases-table th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.fund-clases-table td:last-child,
.fund-clases-table th:last-child { text-align: right; }

.fund-clases-table tr:last-child td { border-bottom: none; }

/* ---- Cartera layout ---- */
.cartera-layout { display: flex; flex-direction: column; gap: 1.5rem; }

.cartera-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem;
  color: var(--text-tertiary);
  gap: 1rem;
  font-size: 0.9rem;
}

.cartera-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.cartera-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.section-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.section-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
}

.section-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: var(--bg-accent);
  color: var(--accent-dark);
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-weight: 500;
}

.btn-toggle {
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-toggle:hover { color: var(--text-primary); border-color: var(--border-strong); }
.btn-toggle.active { background: var(--text-primary); color: var(--text-inverse); border-color: var(--text-primary); }

.section-body { padding: 1.25rem; }

/* ---- Balance table ---- */
.balance-table {
  width: 100%;
  border-collapse: collapse;
}

.balance-table td {
  padding: 0.45rem 0;
  font-size: 0.82rem;
  border-bottom: 1px solid var(--border);
}

.balance-table td:first-child {
  color: var(--text-secondary);
  font-weight: 500;
}

.balance-table td:nth-child(2) {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.balance-table td:nth-child(3) {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  width: 60px;
}

.balance-table tr:last-child td { border-bottom: none; }
.balance-table tr.row-highlight td { font-weight: 600; color: var(--text-primary); }

/* ---- Composicion chart area ---- */
.chart-container {
  position: relative;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
}

/* ---- Investment detail tables ---- */
.inv-type-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: var(--bg-hover);
  cursor: pointer;
  user-select: none;
}

.inv-type-header h4 {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.inv-type-total {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.inv-table {
  width: 100%;
  border-collapse: collapse;
}

.inv-table th {
  padding: 0.5rem 0.75rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  font-weight: 600;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.inv-table td {
  padding: 0.5rem 0.75rem;
  font-size: 0.78rem;
  border-bottom: 1px solid var(--border);
}

.inv-table .num {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.74rem;
}

.inv-table tr:last-child td { border-bottom: none; }
.inv-table tr:hover { background: var(--bg-hover); }

.var-positive { color: var(--positive); }
.var-negative { color: var(--negative); }

/* ---- Cuotapartes ---- */
.cuotapartes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.cp-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
}

.cp-card-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.cp-card-value {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
}

.cp-card-vars {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.cp-var {
  font-size: 0.7rem;
  font-family: var(--font-mono);
}

.cp-var-label {
  color: var(--text-tertiary);
  font-size: 0.62rem;
  display: block;
}

/* ---- Indicadores ---- */
.indicadores-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.indicador-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.15rem;
}

.indicador-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  font-weight: 600;
}

.indicador-value {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  margin-top: 0.35rem;
}

/* ---- Upload ---- */
.upload-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 3rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-card);
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.upload-icon { margin-bottom: 1rem; color: var(--text-tertiary); }
.upload-text { font-size: 0.9rem; color: var(--text-secondary); font-weight: 500; }
.upload-hint { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 0.4rem; }

.upload-progress { margin-top: 1.5rem; }
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  width: 0%;
  transition: width 0.5s ease;
}
.progress-text { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.5rem; }

.upload-result {
  margin-top: 1rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
}
.upload-result.success { background: #EAF5ED; color: var(--positive); border: 1px solid #C3E3CB; }
.upload-result.error { background: #FDEDED; color: var(--negative); border: 1px solid #F5C6C6; }

/* ---- Utility ---- */
.hidden { display: none !important; }

.text-right { text-align: right; }
.text-mono { font-family: var(--font-mono); }

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-tertiary);
  font-size: 0.85rem;
}

/* ---- Responsive ---- */
@media (max-width: 1100px) {
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
  .cartera-top { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  :root { --sidebar-width: 60px; }
  .brand-text, .nav-item span, .sidebar-date { display: none; }
  .sidebar-brand { justify-content: center; padding: 1rem; }
  .nav-item { justify-content: center; padding: 0.7rem; }
  #main-content { padding: 1.5rem 1rem; }
  .summary-cards { grid-template-columns: 1fr 1fr; }
  .view-header { flex-direction: column; }
  .view-controls { width: 100%; flex-direction: column; align-items: stretch; }
  .search-select, .cartera-date-select { width: 100%; }
}
