*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

button { font-family: inherit; font-size: inherit; }

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #252542;
  --border: #2a2a4a;
  --text: #e0e0f0;
  --text-muted: #8888aa;
  --accent: #4BC0C0;
  --danger: #FF6384;
  --success: #4BC0C0;
  --warning: #FFCE56;
  --radius: 12px;
  --shadow: rgba(0,0,0,0.5);
  --input-bg: var(--bg);
  --input-placeholder: #444466;
}

html.light {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface2: #e8ecf1;
  --border: #d0d5dd;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --shadow: rgba(0,0,0,0.08);
  --input-bg: #ffffff;
  --input-placeholder: #9ca3af;
}

body { transition: background 0.3s, color 0.3s; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

.breadcrumb {
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.detail-content {
  flex: 1;
}

/* ===== LOGIN VIEW ===== */
#loginView {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px var(--shadow);
}

.login-header { text-align: center; margin-bottom: 32px; }

.login-header .logo { margin-bottom: 16px; }

.login-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.login-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.field { margin-bottom: 20px; }

.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.field input {
  width: 100%;
  padding: 12px 16px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, background 0.3s;
}

.field input:focus { border-color: var(--accent); }

.field input::placeholder { color: var(--input-placeholder); }

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 20px;
  margin-bottom: 12px;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #0f0f1a;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:hover { opacity: 0.85; }

.btn-outline {
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-sm { padding: 6px 14px; font-size: 0.85rem; }
.btn-xs { padding: 2px 8px; font-size: 0.75rem; }

.login-hint {
  text-align: center;
  margin-top: 20px;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-family: monospace;
}

/* ===== NAVBAR ===== */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1.1rem;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.navbar.admin-active {
  border-bottom: 2px solid #7c3aed;
  box-shadow: inset 0 2px 0 0 rgba(124,58,237,0.15);
}

.admin-badge {
  font-size: 0.8rem;
  color: #c084fc;
  background: rgba(124,58,237,0.15);
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
}

.user-badge {
  background: var(--surface2);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== TAB BAR ===== */
#tabBar {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 100;
  overflow-x: auto;
}

#portfolioTabs {
  display: flex;
  align-items: center;
  gap: 0;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  user-select: none;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
}

.tab.tab-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

#tabWatchlist {
  margin-left: 8px;
}

.tab-sep {
  display: inline-block;
  width: 1px;
  height: 20px;
  background: var(--border);
  align-self: center;
  margin: 0 4px;
}

.tab:hover {
  color: var(--text);
}

.tab.tab-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-dropdown-arrow {
  font-size: 0.6rem;
  margin-left: 2px;
}

.tab-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 200;
  overflow: hidden;
}

.tab-dropdown.open {
  display: block;
}

.tab-dropdown-item {
  padding: 10px 16px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
}

.tab-dropdown-item:last-child {
  border-bottom: none;
}

.tab-dropdown-item:hover {
  background: var(--surface2);
  color: var(--accent);
}

.tab-dropdown-item.active-portfolio {
  color: var(--accent);
  font-weight: 600;
  background: rgba(75,192,192,0.08);
}

/* ===== WATCHLIST ===== */
#watchlistTableWrap {
  overflow-x: auto;
}

#watchlistTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

#watchlistTable th {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
#watchlistTable th:hover { color: var(--text); }
#watchlistTable th .sort-icon { margin-left: 4px; opacity: 0.4; }
#watchlistTable th.active .sort-icon { opacity: 1; color: #4BC0C0; }

#watchlistTable td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
#watchlistTable td:nth-child(-n+7) {
  white-space: nowrap;
  width: 1%;
}
#watchlistTable td.positive { color: #4BC0C0; }
#watchlistTable td.negative { color: #FF6384; }

#watchlistTable .ticker {
  font-weight: 600;
  color: #4BC0C0;
  font-family: monospace;
}

#watchlistTable .wl-precio-cell {
  padding-top: 16px;
  padding-bottom: 2px;
}

#watchlistTable .watchlist-chart-btn,
.watchlist-chart-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 8px;
  transition: background 0.2s, border-color 0.2s;
  line-height: 1.4;
  vertical-align: middle;
  margin: 0 0 0 6px;
  color: var(--accent, #4BC0C0);
}
#watchlistTable .watchlist-chart-btn:first-of-type {
  margin-left: 0;
}
#watchlistTable .watchlist-chart-btn:hover {
  background: var(--surface2);
  border-color: #4BC0C0;
}

.wl-price-wrap {
  position: relative;
  height: 30px;
  margin: 4px 0 2px;
  min-width: 100px;
}
.wl-price-bar-wrap {
  position: relative;
  height: 20px;
}
.wl-price-label {
  position: absolute;
  top: -14px;
  width: 90px;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border-radius: 4px;
  padding: 1px 0;
  line-height: 1.2;
  z-index: 2;
  white-space: nowrap;
}
.wl-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 6px;
  height: 6px;
  background: linear-gradient(to right, #FF6384, #FFce56, #4BC0C0);
  border-radius: 3px;
}
.wl-arrow {
  position: absolute;
  top: 0;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--text);
  z-index: 1;
}
.wl-low {
  position: absolute;
  left: 0;
  top: 14px;
  font-size: 0.6rem;
  color: var(--text-muted);
  line-height: 1;
}
.wl-high {
  position: absolute;
  right: 0;
  top: 14px;
  font-size: 0.6rem;
  color: var(--text-muted);
  line-height: 1;
}

.wl-remove-btn {
  cursor: pointer;
  color: var(--danger);
  font-size: 0.8rem;
  opacity: 0.7;
  background: none;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
}

.wl-remove-btn:hover {
  opacity: 1;
  background: rgba(255,99,132,0.1);
}

.cartera-badge {
  display: inline-block;
  padding: 2px 8px;
  margin: 1px 2px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #fff;
  background: #4BC0C0;
  white-space: nowrap;
}

/* ===== CONFIG TABLE ===== */
#configTableWrap {
  overflow-x: auto;
}
#configTableWrap .stock-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
#configTableWrap .stock-table th {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
#configTableWrap .stock-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
#configTableWrap .stock-table tr:hover td {
  background: var(--surface2);
}
.token-mono {
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  word-break: break-all;
}
.token-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.token-badge-free { background: rgba(100,100,100,0.2); color: #999; }
.token-badge-premium { background: rgba(245,200,66,0.2); color: #f5c842; }
.token-badge-admin { background: rgba(124,58,237,0.2); color: #a78bfa; }

/* ===== DASHBOARD ===== */
.dashboard { padding: 24px 32px; max-width: 1400px; margin: 0 auto; }

/* Charts */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px 16px;
  display: flex;
  flex-direction: column;
}

.chart-card h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-muted);
  text-align: center;
}

.chart-card-dist h2 {
  text-align: left;
}

.dist-layout {
  display: flex;
  flex: 1;
  gap: 0;
  min-height: 0;
}

.dist-stats-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding-right: 20px;
  min-width: 140px;
}

.dist-stat-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.dist-stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dist-stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.dist-divider {
  width: 1px;
  background: var(--border);
  margin: 4px 0;
}

.chart-card-dist .chart-container {
  flex: 1;
  min-width: 0;
  min-height: 300px;
  position: relative;
}

#premiumModal { max-width: 560px; width: 90vw; border: 1px solid var(--border); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text); position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); margin: 0; max-height: 90vh; overflow-y: auto; }
#premiumModal::backdrop { background: rgba(0,0,0,0.5); }
#premiumModal .dialog-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
#premiumModal .dialog-header h3 { margin: 0; font-size: 1rem; }
#premiumModal .dialog-body { padding: 20px; line-height: 1.6; font-size: 0.9rem; }
#premiumModal .fund-actions { padding: 0 20px 20px; display: flex; justify-content: center; }
#premiumModalDestino { width: auto; padding: 12px 28px; font-size: 0.9rem; white-space: nowrap; margin: 8px auto 0; border: none; border-radius: 10px; background: #10B981; color: #fff; font-weight: 700; cursor: pointer; transition: background 0.2s, transform 0.15s, box-shadow 0.2s; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 2px 8px rgba(16,185,129,0.3); }
#premiumModalDestino:hover { background: #0E9E6E; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(16,185,129,0.4); }

.lock-overlay {
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.15s;
  margin-left: 4px;
  vertical-align: middle;
}
.lock-overlay:hover {
  transform: scale(1.2);
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.summary-card h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--text-muted);
}

.summary-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.summary-value {
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.index-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.index-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.index-name {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.index-ytd {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

/* Charts */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px 16px;
  display: flex;
  flex-direction: column;
}

.chart-card h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-muted);
  text-align: center;
}

.chart-card-dist h2 {
  text-align: left;
}

.dist-stats {
  display: flex;
  gap: 24px;
  margin-bottom: 12px;
}

.dist-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dist-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dist-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.dist-value.positive { color: #4BC0C0; }
.dist-value.negative { color: #FF6384; }
.positive { color: #4BC0C0; }
.negative { color: #FF6384; }

.chart-container {
  position: relative;
  width: 100%;
  min-height: 350px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.chart-card-ops {
  min-height: 300px;
}
.chart-card-ops .chart-container {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* Table Card */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.table-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
}

.portfolio-name {
  font-weight: 400;
  font-size: 0.75rem;
  color: var(--text-muted);
  opacity: 0.7;
  margin-left: 0.25rem;
}

.table-error {
  background: rgba(255, 99, 132, 0.1);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  color: var(--danger);
  font-size: 0.9rem;
}

/* ===== THEME MOON TOGGLE ===== */
.theme-icon-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  cursor: pointer;
}
.theme-icon-toggle input { display: none; }
.theme-icon-toggle .moon::before {
  content: '🌙';
  font-size: 20px;
  line-height: 1;
  color: #3b82f6;
  opacity: 1;
  text-shadow: 0 0 6px rgba(59, 130, 246, 0.5);
  transition: color 0.2s, opacity 0.2s, text-shadow 0.2s;
}
.theme-icon-toggle input:checked + .moon::before {
  color: #666;
  opacity: 0.3;
  text-shadow: none;
}

/* ===== ADMIN SHIELD TOGGLE ===== */
.admin-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  cursor: pointer;
}
.admin-toggle input { display: none; }
.admin-toggle .shield::before {
  content: '⚙';
  font-size: 20px;
  line-height: 1;
  color: #666;
  opacity: 0.4;
  transition: color 0.2s, opacity 0.2s, text-shadow 0.2s;
}
.admin-toggle input:checked + .shield::before {
  content: '⚙';
  color: #7c3aed;
  opacity: 1;
  text-shadow: 0 0 6px rgba(124, 58, 237, 0.5);
}

/* ===== PREMIUM STAR TOGGLE ===== */
.premium-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  cursor: pointer;
}
.premium-toggle input { display: none; }
.premium-toggle .star::before {
  content: '☆';
  font-size: 22px;
  line-height: 1;
  color: #666;
  transition: color 0.2s, text-shadow 0.2s;
}
.premium-toggle input:checked + .star::before {
  content: '⭐';
  color: #f5c842;
  text-shadow: 0 0 6px rgba(245, 200, 66, 0.5);
}

.login-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 4px;
}

/* ===== DIALOG ===== */
.ops-search-bar {
  padding: 8px 16px 4px;
}
.ops-search-bar input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg, var(--surface));
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}
.ops-search-bar input:focus {
  border-color: #4BC0C0;
}
.ops-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 8px 16px 12px;
  font-size: 0.85rem;
}
.ops-pagination button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.85rem;
}
.ops-pagination .ops-page-info {
  min-width: 80px;
  text-align: center;
}
#opsDialog, #lastOpsDialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}
#opsDialog {
  width: min(800px, 95vw);
  max-height: 80vh;
}
#lastOpsDialog {
  width: min(960px, 95vw);
  max-height: 85vh;
}

#opsDialog::backdrop, #lastOpsDialog::backdrop {
  background: rgba(0,0,0,0.5);
}

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

.dialog-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.dialog-body {
  padding: 16px 24px 24px;
  max-height: calc(80vh - 60px);
  overflow-y: auto;
}

.dialog-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.dialog-body th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.dialog-body td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.dialog-body .empty-ops {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.add-pos-status { text-align: center; font-size: 0.85rem; padding: 8px; border-radius: 6px; }
.add-pos-status.hidden { display: none; }

#addPosDialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(400px, 90vw);
  max-height: 80vh;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

#addPosDialog::backdrop {
  background: rgba(0,0,0,0.5);
}

html.light #addPosDialog { box-shadow: 0 20px 60px rgba(0,0,0,0.1); }

.dialog-body .tipo-compra { color: #4BC0C0; font-weight: 600; }
.dialog-body .tipo-venta { color: #FF6384; font-weight: 600; }

html.light #opsDialog, html.light #lastOpsDialog,
html.light #editHoldingDialog, html.light #editOpDialog { box-shadow: 0 20px 60px rgba(0,0,0,0.1); }

.ops-admin-actions { white-space: nowrap; }
.ops-edit-btn, .ops-delete-btn { cursor: pointer; font-size: 0.85rem; opacity: 0.7; padding: 0 2px; }
.ops-edit-btn:hover, .ops-delete-btn:hover { opacity: 1; }

.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: #4BC0C0; }
th.sort-asc, th.sort-desc { color: #4BC0C0; }

.dialog-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.dialog-form .field-row {
  display: flex;
  gap: 12px;
  margin-bottom: 6px;
}

.dialog-form .field-row .field {
  margin-bottom: 0;
}

.dialog-form h4 {
  margin: 16px 0 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.dialog-form .field {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.dialog-form .field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  min-width: 100px;
  flex-shrink: 0;
}
.dialog-form .field input,
.dialog-form .field select {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
.dialog-form .field input:focus,
.dialog-form .field select:focus {
  border-color: #7c3aed;
}
.dialog-form .btn-primary {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #0f0f1a;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner-lg {
  width: 24px;
  height: 24px;
  border-width: 3px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#editHoldingDialog, #editOpDialog, #paramsDialog, #addPosDialog {
  padding: 0;
  border: none;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  min-width: 380px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  margin: auto;
  position: fixed;
  inset: 0;
}
#editHoldingDialog::backdrop, #editOpDialog::backdrop, #confirmDialog::backdrop, #paramsDialog::backdrop {
  background: rgba(0,0,0,0.5);
}

.confirm-dialog {
  padding: 0;
  border: none;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  min-width: 300px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  margin: auto;
  position: fixed;
  inset: 0;
}

/* ===== DETAIL VIEW ===== */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

#detailSummary {
  overflow: hidden;
}
#detailInfo {
  display: flex;
  flex-direction: column;
}
.detail-summary-text {
  overflow-y: auto;
  max-height: 400px;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--text);
}
.detail-summary-text p {
  margin-bottom: 0.6em;
}

.detail-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1.8fr 1fr;
  gap: 20px;
}

.detail-summary-left {
  display: flex;
  flex-direction: column;
}

.detail-summary-left .detail-name {
  margin-bottom: 8px;
}

.detail-summary-mid {
  text-align: left;
}

.detail-summary-right {
  text-align: right;
}

.detail-summary-right .price-bar-wrap {
  max-width: 280px;
  margin-left: auto;
  padding-top: 8px;
}

.buy-price-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.buy-price-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.wl-buy-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wl-buy-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wl-buy-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.detail-summary-note {
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface2);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  border: 1px dashed var(--border);
}

#detailNews {
  max-height: 50vh;
  overflow-y: auto;
}

.detail-card-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.news-pagination {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.65rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background 0.2s, color 0.2s;
  user-select: none;
}

.page-arrow:hover:not(.disabled) {
  background: var(--surface2);
  color: var(--text);
}

.page-arrow.disabled {
  opacity: 0.3;
  cursor: default;
}

.page-indicator {
  font-size: 0.7rem;
  color: var(--text-muted);
  min-width: 30px;
  text-align: center;
}

.detail-symbol {
  font-size: 1.5rem;
  font-weight: 700;
  color: #4BC0C0;
  font-family: monospace;
}

.detail-name {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.detail-price {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}

.price-bar-wrap {
  margin-bottom: 12px;
}

.price-bar {
  position: relative;
  height: 30px;
  margin: 4px 0 2px;
  min-width: 100px;
}

.price-bar-track {
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  height: 6px;
  border-radius: 3px;
}

.price-bar-arrow {
  position: absolute;
  top: 0;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--text);
  transform: translateX(-50%);
}

.price-bar-label {
  position: absolute;
  width: auto;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface2);
  border-radius: 4px;
  padding: 1px 6px;
  line-height: 1.2;
  z-index: 2;
}

.price-bar-low, .price-bar-high {
  position: absolute;
  top: 14px;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.price-bar-low { left: 0; }
.price-bar-high { right: 0; }

.detail-buy-price {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.news-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.news-item:last-child {
  border-bottom: none;
}

.news-date {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  min-width: 70px;
}

.news-title {
  flex: 1;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.news-title:hover {
  text-decoration: underline;
}

.news-source {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: right;
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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



/* ===== FUNDAMENTALS DIALOG ===== */
#fundDialog {
  padding: 0; border: none; border-radius: 12px; background: var(--surface); color: var(--text);
  min-width: 1000px; max-width: 1200px; width: 95vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  margin: auto; position: fixed; inset: 0;
}
#fundDialog::backdrop { background: rgba(0,0,0,0.5); }

.fund-divider { height: 1px; background: var(--border); margin: 16px 0; }
.fund-row2-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.fund-col { min-width: 0; overflow-wrap: break-word; }
.fund-row2-grid > .fund-col + .fund-col { border-left: 1px solid var(--border); padding-left: 20px; }
.fund-display-item { padding: 3px 0; font-size: 0.8rem; color: var(--text); line-height: 1.5; }
.fund-kpis-stacked { display: flex; flex-direction: column; gap: 4px; }
.fund-kpi-display-row { display: flex; align-items: center; gap: 6px; }
.fund-kpi-display-label { font-size: 0.75rem; color: var(--text-muted); flex: 0 0 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display:flex;align-items:center;gap:4px; }
.fund-kpi-info { cursor: help; flex-shrink:0; display:inline-flex;align-items:center; transition:transform 0.15s, filter 0.15s; }
.fund-kpi-info:hover { transform: scale(1.2); filter: brightness(1.3); }
.fund-kpi-info svg circle { transition: fill 0.15s, stroke 0.15s; }
.fund-kpi-info:hover svg circle { fill: var(--accent); stroke: var(--accent); }
.fund-kpi-info:hover svg text { fill: #fff; }
.fund-kpi-display-stars { display: flex; gap: 1px; }
.fund-star-static { font-size: 1rem; color: var(--border); }
.fund-star-static.active { color: #FFCE56; }
.fund-kpi-display-val { font-size: 0.7rem; color: var(--text-muted); min-width: 20px; text-align: right; }
.fund-badge { font-size: 0.7rem; background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; padding: 1px 10px; color: var(--text); font-weight: 600; text-transform: none; letter-spacing: 0; }
.fund-grid { display: grid; grid-template-columns: 1fr 1.2fr 1fr 1.4fr; gap: 16px; max-height: 70vh; overflow-y: auto; align-items: start; }
.fund-col .field { margin-bottom: 0; }
.fund-actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; padding-top: 8px; border-top: 1px solid var(--border); }
.fund-list { display: flex; flex-wrap: wrap; gap: 4px; min-height: 28px; }
.fund-item { display: inline-flex; align-items: center; gap: 4px; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; font-size: 0.8rem; overflow-wrap: break-word; max-width: 100%; }
.fund-item-remove { cursor: pointer; color: #FF6384; font-weight: 700; font-size: 0.75rem; margin-left: 2px; }
.fund-item-remove:hover { color: #ff3040; }
.fund-input { flex: 1; min-width: 120px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-size: 0.8rem; outline: none; }
.fund-input:focus { border-color: #4BC0C0; }
.fund-kpi-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.fund-kpi-label { flex: 0 0 140px; font-size: 0.8rem; color: var(--text); }
.fund-stars { display: flex; gap: 2px; }
.fund-star { cursor: pointer; font-size: 1.1rem; color: var(--text-muted); transition: color 0.15s; user-select: none; }
.fund-star.active { color: #FFCE56; }
.fund-star:hover { color: #FFCE56; }
.fund-star-val { font-size: 0.75rem; color: var(--text-muted); min-width: 20px; text-align: center; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .charts-row { grid-template-columns: 1fr; }
  .dashboard { padding: 16px; }
  .navbar { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
  .navbar .nav-brand span { font-size: 0.95rem; }
  .nav-actions { gap: 8px; flex-wrap: wrap; }
  .login-card { padding: 24px; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-summary-grid { grid-template-columns: 1fr; gap: 12px; }
  .detail-summary-right { text-align: left; }
  .detail-summary-right .price-bar-wrap { max-width: 100%; margin-left: 0; }
  .dist-layout { flex-direction: column; gap: 16px; }
  .dist-stats-panel { flex-direction: row; flex-wrap: wrap; gap: 10px; padding-right: 0; min-width: 0; }
  .dist-stat-item { min-width: 80px; }
  .dist-divider { width: auto; height: 1px; margin: 0; }
  .chart-card-dist .chart-container { min-height: 250px; }
  .chart-container { min-height: 250px; }
  .index-stats { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .table-card { padding: 16px; overflow-x: auto; }
  #tabBar { padding: 0 12px; overflow-x: auto; }
  .tab { padding: 10px 12px; font-size: 0.8rem; }
  #fundDialog { min-width: unset; max-width: 95vw; width: 95vw; }
  .fund-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  #watchlistTable { font-size: 0.75rem; }
  #watchlistTable td, #watchlistTable th { padding: 6px 8px; }
  .wl-buy-row { flex-wrap: wrap; }
  .dialog-body { padding: 12px 16px 16px; }
  .dialog-header { padding: 12px 16px; }
  .dialog-form .field { flex-direction: column; align-items: stretch; }
  .dialog-form .field-row { flex-direction: column; gap: 8px; }
  .nav-brand svg { width: 22px; height: 22px; }
  .admin-badge { font-size: 0.7rem; padding: 2px 8px; }
  .user-badge { padding: 4px 10px; font-size: 0.75rem; }
  #logoutBtn { padding: 4px 10px; font-size: 0.75rem; }
  .detail-symbol { font-size: 1.2rem; }
  .detail-price { font-size: 1.3rem; }
  .summary-value { font-size: 1.2rem; }
  .breadcrumb { font-size: 0.75rem; }
  .chart-card { padding: 14px 16px 12px; }
  .chart-card h2 { font-size: 0.85rem; }
}

@media (max-width: 480px) {
  .dashboard { padding: 8px; }
  .navbar { padding: 8px 10px; }
  .navbar .nav-brand span { display: none; }
  .nav-actions { gap: 4px; }
  .tab { padding: 8px 10px; font-size: 0.75rem; }
  .table-card { padding: 10px; }
  .fund-grid { grid-template-columns: 1fr; }
  .detail-card { padding: 14px; }
  .detail-summary-grid { gap: 8px; }
  .index-stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .chart-container { min-height: 200px; }
  .chart-card-dist .chart-container { min-height: 200px; }
  #fundDialog { width: 100vw; max-width: 100vw; border-radius: 0; min-height: 100dvh; max-height: 100dvh; }
  .fund-grid { max-height: none; }
  #watchlistTable { font-size: 0.7rem; }
  #watchlistTable td, #watchlistTable th { padding: 4px 6px; }
  .nav-actions .premium-toggle, .nav-actions .admin-toggle { display: none; }
}
