:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: #1f2937;
  --bg-card-hover: #283548;
  --bg-input: #0f172a;
  --border-color: #374151;
  --border-focus: #6366f1;
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  
  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  
  --line-nominal: #06b6d4;
  --line-real: #8b5cf6;
  --line-real-glow: rgba(139, 92, 246, 0.15);
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

[data-theme="light"], .light {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-input: #f8fafc;
  --border-color: #e2e8f0;
  --border-focus: #4f46e5;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --accent-primary: #4f46e5;
  --accent-primary-hover: #4338ca;
  --accent-cyan: #0284c7;
  --accent-emerald: #059669;
  --accent-amber: #d97706;
  --accent-rose: #e11d48;
  
  --line-nominal: #0284c7;
  --line-real: #7c3aed;
  --line-real-glow: rgba(124, 58, 237, 0.1);
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 3rem;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding-bottom: 1.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-cyan));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.brand-icon svg {
  width: 24px;
  height: 24px;
}

.brand-text h1 {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-text p {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

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

.select-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.select-wrapper select {
  appearance: none;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.5rem 2.2rem 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast);
}

.select-wrapper select:focus {
  border-color: var(--border-focus);
}

.select-wrapper .chevron {
  position: absolute;
  right: 0.75rem;
  pointer-events: none;
  color: var(--text-muted);
  width: 14px;
  height: 14px;
}

.theme-toggle-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.theme-toggle-btn:hover {
  background: var(--bg-card-hover);
}

/* Company / Client Scenario Selector Bar */
.company-section {
  margin-bottom: 1.25rem;
}

.company-bar-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.85rem;
  box-shadow: var(--shadow-sm);
}

.company-select-area {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem;
  flex: 1;
}

.company-bar-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.company-tabs-container {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.company-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-full);
  font-size: 0.825rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.company-tab:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-focus);
}

.company-tab.active {
  background: var(--bg-input);
  border-color: var(--company-color, var(--accent-primary));
  box-shadow: 0 0 0 1px var(--company-color, var(--accent-primary)), 0 2px 8px rgba(0, 0, 0, 0.25);
  font-weight: 600;
}

.company-tab-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.company-actions-area {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Quick Calculator Card */
.quick-calc-section {
  margin-bottom: 1.25rem;
}

.card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-title svg {
  color: var(--accent-primary);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-blue {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
}

.badge-purple {
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
}

.badge-green {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto 1.3fr;
  gap: 1rem;
  align-items: center;
}

@media (max-width: 900px) {
  .calc-grid {
    grid-template-columns: 1fr 1fr;
  }
  .calc-arrow-box {
    display: none !important;
  }
  .calc-result-box {
    grid-column: span 2;
  }
}

@media (max-width: 580px) {
  .calc-grid {
    grid-template-columns: 1fr;
  }
  .calc-result-box {
    grid-column: span 1;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: 0.825rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.input-with-prefix {
  position: relative;
  display: flex;
  align-items: center;
}

.input-prefix {
  position: absolute;
  left: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.95rem;
  pointer-events: none;
}

.form-input {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-with-prefix .form-input {
  padding-left: 2rem;
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.calc-arrow-box {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 1.25rem;
  color: var(--text-muted);
}

.calc-result-box {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(6, 182, 212, 0.08));
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.1rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.result-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.result-value-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.result-amount {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--accent-emerald);
  letter-spacing: -0.02em;
}

.result-diff {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-primary);
}

.result-explanation {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.btn-add-quick {
  margin-top: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--accent-primary);
  color: white;
  border: none;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.btn-add-quick:hover {
  background: var(--accent-primary-hover);
  transform: translateY(-1px);
}

/* KPI Summary Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.kpi-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent-primary);
}

.kpi-card.cyan::before { background: var(--accent-cyan); }
.kpi-card.purple::before { background: var(--line-real); }
.kpi-card.emerald::before { background: var(--accent-emerald); }
.kpi-card.amber::before { background: var(--accent-amber); }

.kpi-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 0.35rem;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.kpi-subtext {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.kpi-subtext.positive { color: var(--accent-emerald); }
.kpi-subtext.negative { color: var(--accent-rose); }

/* Chart Section */
.chart-section {
  margin-bottom: 1.25rem;
}

.chart-header-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.chart-mode-toggle {
  display: inline-flex;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.mode-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.35rem 0.75rem;
  border-radius: calc(var(--radius-sm) - 2px);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mode-btn:hover {
  color: var(--text-primary);
}

.mode-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.compare-filter-group {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.5rem;
  padding: 0.35rem 0.65rem;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-size: 0.75rem;
}

.chart-legend-custom {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
  padding: 0.5rem 0.85rem;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

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

@media (max-width: 768px) {
  .chart-wrapper {
    height: 290px;
  }
}

/* Rate History Manager Table */
.table-section {
  margin-bottom: 1.25rem;
}

.table-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.btn-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.825rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  outline: none;
  transition: all var(--transition-fast);
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
}

.btn-secondary {
  background: var(--bg-card);
  border-color: var(--border-color);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
}

.btn-danger {
  background: rgba(244, 63, 94, 0.1);
  color: var(--accent-rose);
  border-color: rgba(244, 63, 94, 0.2);
}

.btn-danger:hover {
  background: rgba(244, 63, 94, 0.2);
}

.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

table.rate-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

table.rate-table th {
  background-color: var(--bg-primary);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

table.rate-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  white-space: nowrap;
}

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

table.rate-table tr:hover td {
  background-color: var(--bg-card-hover);
}

.table-input-year,
.table-input-rate {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  width: 110px;
}

.table-input-rate {
  width: 130px;
}

.table-input-year:focus,
.table-input-rate:focus {
  border-color: var(--border-focus);
}

.real-rate-tag {
  font-weight: 600;
  color: var(--line-real);
}

.growth-positive {
  color: var(--accent-emerald);
  font-weight: 500;
}

.growth-negative {
  color: var(--accent-rose);
  font-weight: 500;
}

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.empty-state h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.empty-state p {
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

/* Footer / Settings note */
.app-footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

/* Modal styles for bulk add or settings */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 520px;
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  transform: translateY(15px);
  transition: transform var(--transition-normal);
}

.modal-overlay.active .modal-dialog {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem;
}

.modal-close:hover {
  color: var(--text-primary);
}

/* Color Picker Row in Modal */
.color-picker-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.color-input-native {
  width: 44px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
}

.color-swatches {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.color-swatch-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.color-swatch-btn:hover {
  transform: scale(1.15);
}

.color-swatch-btn.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px var(--border-focus);
}
