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

:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --border: #e8eaed;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --gold: #d97706;
  --gold-light: #fef3c7;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition: 0.2s ease;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* === Upload Screen === */
.upload-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: linear-gradient(135deg, #f0f4ff 0%, #f8f9fb 50%, #f0fdf4 100%);
}

.upload-box {
  text-align: center;
  max-width: 440px;
  width: 100%;
}

.upload-icon {
  color: var(--primary);
  margin-bottom: 16px;
}

.upload-box h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.upload-subtitle {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 15px;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 32px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: var(--transition);
  border: none;
}

.upload-btn:hover { background: #1d4ed8; transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.upload-btn input { display: none; }

.drop-zone {
  margin-top: 24px;
  padding: 32px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  transition: var(--transition);
}

.drop-zone.dragover { border-color: var(--primary); background: var(--primary-light); }
.drop-zone p { color: var(--text-secondary); font-size: 14px; }

.upload-note {
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.7;
}

/* === Dashboard Layout === */
.dashboard { min-height: 100vh; padding-bottom: 80px; }
.hidden { display: none !important; }

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-bar-left { display: flex; align-items: center; gap: 12px; }
.top-bar-right { display: flex; align-items: center; gap: 8px; }

.logo {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--primary);
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.btn-icon:hover { background: var(--bg); color: var(--text); }

/* Slider Navigation */
.slider-nav {
  display: flex;
  gap: 4px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.slider-nav::-webkit-scrollbar { display: none; }

.slider-btn {
  flex-shrink: 0;
  padding: 8px 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.slider-btn:hover { border-color: var(--primary); color: var(--primary); }
.slider-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Tab Navigation */
.tab-nav {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tab-nav::-webkit-scrollbar { display: none; }

.tab-separator {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

.tab-btn {
  flex-shrink: 0;
  padding: 14px 20px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

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

/* Content */
.content {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

/* === Cards === */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

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

.card:hover { box-shadow: var(--shadow); }

.card-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.card-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.card-sub {
  font-size: 13px;
  color: var(--text-secondary);
}

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

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.card-row:last-child { border-bottom: none; }

.card-row-label { font-size: 13px; color: var(--text-secondary); }
.card-row-value { font-size: 14px; font-weight: 600; }

/* Chart containers */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

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

.chart-card h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

.chart-wrapper {
  position: relative;
  width: 100%;
  height: 300px;
}

.chart-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
}

.chart-wrapper-sm { height: 250px; }
.chart-wrapper-lg { height: 400px; }

.full-width {
  grid-column: 1 / -1;
}

/* === Tables === */
.data-table-wrapper {
  overflow-x: auto;
  margin-bottom: 24px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

.data-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}

.data-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

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

.data-table .positive { color: var(--success); }
.data-table .negative { color: var(--danger); }

.data-table .row-total {
  font-weight: 700;
  background: var(--bg);
}

.data-table .row-category {
  font-weight: 700;
  background: var(--primary-light);
  color: var(--primary);
}

/* Section titles */
.section-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
  margin-top: 32px;
  letter-spacing: -0.3px;
}

.section-title:first-child { margin-top: 0; }

.section-subtitle {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  margin-top: 24px;
}

/* === Country badges === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
}

.badge-eur { background: var(--primary-light); color: var(--primary); }
.badge-chf { background: var(--danger-light); color: var(--danger); }
.badge-equities { background: var(--success-light); color: var(--success); }
.badge-defence { background: var(--primary-light); color: var(--primary); }
.badge-gold { background: var(--gold-light); color: var(--gold); }

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 900px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.editor-content { max-width: 95vw; max-height: 90vh; }

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

.modal-header h3 { font-size: 16px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* Editor */
.editor-tabs {
  display: flex;
  gap: 0;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.editor-tab {
  padding: 12px 20px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.editor-tab:hover { color: var(--text); }
.editor-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.editor-body {
  overflow: auto;
  flex: 1;
  padding: 16px;
}

.editor-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.editor-table th,
.editor-table td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  min-width: 80px;
}

.editor-table th {
  background: var(--bg);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

.editor-table td input {
  width: 100%;
  border: none;
  background: none;
  font-size: 12px;
  font-family: var(--font);
  padding: 2px;
  outline: none;
}

.editor-table td input:focus {
  background: var(--primary-light);
  border-radius: 2px;
}

.editor-table td.row-header {
  font-weight: 600;
  background: var(--bg);
  position: sticky;
  left: 0;
  z-index: 1;
}

/* Buttons */
.btn {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

/* Bottom Navigation (mobile) */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 0;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 100;
}

.bottom-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 10px;
  font-weight: 500;
}

.bottom-btn.active { color: var(--primary); }

/* Year selector for mobile */
.year-selector-mobile {
  display: none;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.year-selector-mobile select {
  width: 100%;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  background: var(--bg);
  appearance: auto;
}

/* Loading spinner */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Country filter inside views */
.country-filter {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}

.country-filter-btn {
  padding: 6px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.country-filter-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Responsive */
@media (max-width: 768px) {
  .menu-toggle { display: block; }
  .tab-nav { display: none; }
  .bottom-nav { display: flex; }
  .dashboard { padding-bottom: 100px; }
  .content { padding: 16px; }
  .top-bar { padding: 12px 16px; }
  .slider-nav { padding: 8px 16px; gap: 6px; }
  .slider-btn { padding: 6px 14px; font-size: 12px; }

  .card-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { padding: 14px; }
  .card-value { font-size: 18px; }
  .card-label { font-size: 10px; }

  .chart-grid { grid-template-columns: 1fr; gap: 12px; }
  .chart-wrapper { height: 250px; }
  .chart-card { padding: 14px; }

  .section-title { font-size: 16px; margin-top: 24px; }

  .modal { padding: 0; }
  .modal-content { max-width: 100%; max-height: 100vh; border-radius: 0; height: 100%; }
  .editor-content { max-width: 100%; max-height: 100%; }

  .year-selector-mobile { display: block; }
}

@media (max-width: 480px) {
  .card-grid { grid-template-columns: 1fr; }
}

/* Utility classes */
.mt-0 { margin-top: 0; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* Dual currency display */
.dual-currency {
  display: flex;
  gap: 16px;
  align-items: baseline;
}

.dual-currency .amount { font-size: 20px; font-weight: 700; }
.dual-currency .currency-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }

/* Scroll indicator */
.scroll-indicator {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 24px;
  background: linear-gradient(to right, transparent, var(--surface));
  pointer-events: none;
}
