/* CSS Variables for theming (Premium Dark Mode) */
:root {
  --bg-color: #0b0f19;
  --bg-gradient: radial-gradient(circle at 10% 20%, rgb(18, 25, 43) 0%, rgb(11, 15, 25) 90%);
  --bg-primary: #0b0f19;
  --bg-secondary: #1e293b;
  --bg-card: rgba(30, 41, 59, 0.4);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-primary: #3b82f6;
  --accent-primary-hover: #2563eb;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  
  --positive: #10b981;
  --positive-bg: rgba(16, 185, 129, 0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --negative: #ef4444;
  --negative-bg: rgba(239, 68, 68, 0.1);
  
  --glass-bg: rgba(30, 41, 59, 0.4);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --border-color: rgba(255, 255, 255, 0.08);

  --font-base: 'Inter', system-ui, -apple-system, sans-serif;
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --transition: all 0.2s ease-in-out;
}

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

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

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  letter-spacing: -0.02em;
}

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

/* Layout */
.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

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

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

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

.logo h1 {
  font-size: 1.5rem;
  background: linear-gradient(to right, #60a5fa, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-actions {
  display: flex;
  gap: 1rem;
}

/* Navigation Tabs */
.app-nav {
  display: flex;
  gap: 2.5rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 0.5rem;
  flex-wrap: wrap;
}

.nav-tab {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.1rem;
  font-weight: 500;
  font-family: var(--font-base);
  cursor: pointer;
  padding: 0.5rem 0;
  position: relative;
  transition: var(--transition);
}

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

.nav-tab.active {
  color: var(--accent-primary);
  opacity: 1;
}

.nav-tab.active::after {
  content: '';
  position: absolute;
  bottom: -9px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent-primary);
  border-radius: 2px 2px 0 0;
}

.view-section {
  animation: fadeIn 0.3s ease;
}

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

/* Glassmorphism Classes */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--glass-shadow);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-base);
  font-weight: 500;
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  gap: 0.5rem;
}

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

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

.btn.secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
}

.btn.secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.btn.icon-btn {
  padding: 0.5rem;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
}

.btn.icon-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  transform: rotate(15deg);
}

.btn.small {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

.btn.danger {
  color: var(--negative);
  border-color: var(--negative-bg);
  background: transparent;
}
.btn.danger:hover {
  background: var(--negative-bg);
}

/* Overview Section */
.overview-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
  margin-bottom: 3rem;
}

.stat-card {
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
}

.stat-card h3 {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-badge {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
}

.text-positive { color: var(--positive) !important; }
.text-negative { color: var(--negative) !important; }
.bg-positive { background-color: var(--positive-bg); color: var(--positive); }
.bg-negative { background-color: var(--negative-bg); color: var(--negative); }

/* Tables */
section {
  margin-bottom: 3rem;
}

section h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.table-container {
  overflow-x: auto;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th, td {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--glass-border);
}

th {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

td {
  font-size: 0.95rem;
  white-space: nowrap;
}

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

tbody tr {
  transition: background-color 0.15s ease;
}

tbody tr:hover:not(.empty-state) {
  background-color: rgba(255, 255, 255, 0.02);
}

.empty-state td {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  font-style: italic;
}

.ticker-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.1);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
}

.hidden {
  display: none !important;
}

.modal {
  width: 100%;
  max-width: 450px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: var(--radius-lg);
  padding: 2rem;
  transform: translateY(0) scale(1);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.hidden .modal {
  transform: translateY(20px) scale(0.95);
}

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

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  transition: var(--transition);
}

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

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.form-group input, 
.form-group select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-base);
  font-size: 0.95rem;
  transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.form-group small {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 2rem;
}

/* Utilities */
.text-right { text-align: right; }
.text-center { text-align: center; }

/* Fundamental Analyzer Specific Styles */

.fund-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.search-container {
    display: flex;
    gap: 0.5rem;
    width: 100%;
    max-width: 400px;
    position: relative;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 100px; /* leaves room for the button */
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-top: 0.5rem;
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: var(--glass-shadow);
    display: none;
}

.autocomplete-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

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

.autocomplete-item:hover {
    background: var(--bg-card);
}

.autocomplete-symbol {
    font-weight: 600;
    color: var(--accent);
}

.autocomplete-name {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.search-container input[type="text"] {
    flex: 1;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-size: 1rem;
    transition: var(--transition);
}

.search-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}
.search-btn:hover {
    background: var(--accent-hover);
}

/* Loader */
.loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Dashboard Headers */
.ticker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.price-tag {
    text-align: right;
}

.price-label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

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

/* Valuation Cards */
.valuation-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2.5rem;
}

.val-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    backdrop-filter: blur(10px);
}

.val-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.val-val {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Sub-tabs inside Fundamental view */
.fund-tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.fund-tab-btn {
    background: transparent;
    color: var(--text-secondary);
    padding: 1rem 0;
    border-radius: 0;
    margin-right: 1.5rem;
    position: relative;
    border: none;
    font-size: 1rem;
    cursor: pointer;
}

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

.fund-tab-btn.active {
    color: var(--accent);
}

.fund-tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--accent);
}

.fund-tab-content {
    display: none;
    animation: fadeIn 0.4s ease;
}

.fund-tab-content.active { display: block; }

/* Grid / Tables for Fundamental */
.metrics-grid {
    display: grid;
    gap: 2rem;
}

.metrics-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    overflow-x: auto;
}

.metrics-section table {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.metrics-section th:first-child, .metrics-section td:first-child {
    text-align: left;
}

.row-label {
    font-weight: 500;
    color: var(--text-primary);
}

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

/* Statements Tab */
.statement-selector {
    margin-bottom: 1.5rem;
}

.statement-selector select {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    cursor: pointer;
    outline: none;
    max-width: 300px;
}

/* Valuation Models & Sub-Tabs */
.sub-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    background: rgba(15, 23, 42, 0.5);
    padding: 0.25rem;
    border-radius: var(--radius-md);
    width: fit-content;
}

.sub-tab-content {
    display: none;
    animation: fadeIn 0.4s ease;
}

.sub-tab-content.active {
    display: block;
}

.sub-tab-btn {
    background: transparent;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    transition: var(--transition);
    border: none;
    cursor: pointer;
}

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

.sub-tab-btn.active {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.model-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.model-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
    margin-top: 1rem;
}

.model-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.model-input-group label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.model-input-group input {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    font-size: 1.1rem;
    font-weight: 600;
}

.model-input-group input.readonly-field {
    opacity: 0.7;
    cursor: default;
}

.model-results {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
}

.result-box {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.result-box span {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.result-box strong {
    font-size: 1.8rem;
    color: var(--text-primary);
}

/* Export & Template Tab */
.export-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.export-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
}

.export-section p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    max-width: 800px;
}

.file-input {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem;
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    cursor: pointer;
}

.file-input::file-selector-button {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-right: 1rem;
    transition: var(--transition);
}

.upload-status.success {
    color: var(--positive);
}

.upload-status.error {
    color: var(--negative);
}

/* Responsive */
@media (max-width: 768px) {
  .app-container {
    padding: 1rem;
  }
  
  .app-nav, .fund-tabs, .sub-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem;
  }
  
  .fund-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }
  
  .search-container {
    max-width: 100%;
  }

  .overview-cards {
    grid-template-columns: 1fr;
  }
  
  .valuation-cards {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  }
  
  .model-grid, .model-results {
    grid-template-columns: 1fr;
  }
  
  .table-container {
    -webkit-overflow-scrolling: touch;
  }
  
  .modal {
    padding: 1.5rem;
    width: 100%;
    max-width: 100%;
    margin: 1rem;
  }
}
