/* ============================================================
   NEPSE ANALYZER - Main Stylesheet
   Themes: Dark (default) + Light
   Font: IBM Plex Mono + IBM Plex Sans
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap');

/* ---- CSS Variables ---- */
:root {
  --font-mono: 'IBM Plex Mono', monospace;
  --font-sans: 'IBM Plex Sans', sans-serif;
  --radius: 8px;
  --radius-sm: 4px;
  --transition: 0.2s ease;
  --sidebar-width: 220px;
}

[data-theme="dark"] {
  --bg: #0d0f14;
  --bg-panel: #13161e;
  --bg-card: #1a1e2a;
  --bg-hover: #1f2535;
  --border: #252c3e;
  --border-hover: #3a4460;
  --text: #e2e8f7;
  --text-secondary: #7b8aab;
  --text-muted: #4a5568;
  --accent: #3d7eff;
  --accent-hover: #5591ff;
  --accent-glow: rgba(61, 126, 255, 0.15);
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #38bdf8;
  --chart-up: #22c55e;
  --chart-down: #ef4444;
  --chart-grid: #1a1e2a;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
}

[data-theme="light"] {
  --bg: #f0f2f8;
  --bg-panel: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f7f9ff;
  --border: #e1e7f5;
  --border-hover: #c7d2ed;
  --text: #1a2035;
  --text-secondary: #4a5580;
  --text-muted: #8a96bb;
  --accent: #1d5fcc;
  --accent-hover: #1a50b8;
  --accent-glow: rgba(29, 95, 204, 0.1);
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0284c7;
  --chart-up: #16a34a;
  --chart-down: #dc2626;
  --chart-grid: #f0f4ff;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
}

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

html { font-size: 14px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* ---- Layout ---- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---- Sidebar ---- */
.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.sidebar-logo span {
  display: block;
  font-size: 0.65rem;
  color: var(--text-secondary);
  font-weight: 400;
  margin-top: 2px;
  letter-spacing: 0.5px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition);
  margin-bottom: 2px;
  border: 1px solid transparent;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border);
}

.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: var(--accent);
  border-opacity: 0.3;
}

.nav-item .nav-icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

/* ---- Topbar ---- */
.topbar {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* ---- Page Content ---- */
.page { padding: 24px; display: none; }
.page.active { display: block; }

/* ---- Cards ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 12px;
  background: var(--accent);
  border-radius: 2px;
}

/* ---- Grid ---- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }

/* ---- Stat Cards ---- */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color var(--transition);
}
.stat-card:hover { border-color: var(--border-hover); }
.stat-label {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 6px;
}
.stat-value {
  font-size: 1.3rem;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text);
}
.stat-change {
  font-size: 0.75rem;
  margin-top: 4px;
  font-family: var(--font-mono);
}
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

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

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

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: rgba(239,68,68,0.1); }

.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-icon {
  padding: 7px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1rem;
  transition: all var(--transition);
}
.btn-icon:hover { color: var(--text); border-color: var(--border-hover); }

/* ---- Inputs ---- */
.input, select.input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 12px;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  width: 100%;
  transition: border-color var(--transition);
  outline: none;
}
.input:focus, select.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-muted); }

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

/* ---- Search ---- */
.search-wrapper {
  position: relative;
  width: 100%;
}
.search-wrapper .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-wrapper .input { padding-left: 30px; }
.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 220px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: var(--shadow);
  display: none;
}
.search-dropdown.open { display: block; }
.search-option {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background var(--transition);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.search-option:hover { background: var(--bg-hover); }
.search-option .symbol { font-family: var(--font-mono); font-weight: 600; }
.search-option .date { font-size: 0.75rem; color: var(--text-secondary); }

/* ---- Chart Container ---- */
.chart-container {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.chart-wrapper {
  height: 420px;
  position: relative;
}
.period-btn {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  font-family: var(--font-mono);
  transition: all var(--transition);
}
.period-btn:hover, .period-btn.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: var(--accent);
}
.indicator-toggle {
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  font-family: var(--font-mono);
  transition: all var(--transition);
}
.indicator-toggle.on {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

/* ---- AI Prediction Card ---- */
.prediction-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--bg-card);
  position: relative;
  overflow: hidden;
}
.prediction-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.prediction-card.up::before { background: linear-gradient(90deg, var(--success), #16a34a); }
.prediction-card.down::before { background: linear-gradient(90deg, var(--danger), #991b1b); }
.prediction-card.neutral::before { background: linear-gradient(90deg, var(--warning), #b45309); }

.trend-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 1px;
}
.trend-badge.up { background: rgba(34,197,94,0.12); color: var(--success); }
.trend-badge.down { background: rgba(239,68,68,0.12); color: var(--danger); }
.trend-badge.neutral { background: rgba(245,158,11,0.12); color: var(--warning); }

.confidence-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}
.confidence-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--info));
  transition: width 0.6s ease;
}

/* ---- Stats Grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}
.stats-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.stats-item-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.stats-item-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.95rem;
  margin-top: 2px;
}

/* ---- Upload Zone ---- */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-card);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.upload-zone-icon { font-size: 2.5rem; margin-bottom: 12px; }
.upload-zone-title {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.upload-zone-sub { font-size: 0.85rem; color: var(--text-secondary); }

/* ---- Progress ---- */
.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--info));
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* ---- Table ---- */
.table-wrapper { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
thead th {
  text-align: left;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
tbody tr:hover td { background: var(--bg-hover); }
tbody tr:last-child td { border-bottom: none; }

.td-up { color: var(--success); }
.td-down { color: var(--danger); }

/* ---- Watchlist ---- */
.watchlist-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  transition: all var(--transition);
  cursor: pointer;
}
.watchlist-item:hover { border-color: var(--border-hover); background: var(--bg-hover); }
.watchlist-symbol { font-family: var(--font-mono); font-weight: 600; }
.watchlist-price { font-family: var(--font-mono); font-size: 0.85rem; color: var(--text-secondary); }

/* ---- Login page ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.login-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.login-title {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 6px;
}
.login-sub { color: var(--text-secondary); font-size: 0.875rem; margin-bottom: 28px; }

/* ---- Toasts ---- */
#toastContainer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.875rem;
  box-shadow: var(--shadow);
  transform: translateX(120%);
  transition: transform 0.3s ease;
  min-width: 250px;
  max-width: 380px;
}
.toast.toast-show { transform: translateX(0); }
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--info); }
.toast-icon { font-weight: 700; flex-shrink: 0; }
.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--danger); }
.toast-info .toast-icon { color: var(--info); }

/* ---- Loader ---- */
.loader {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: var(--radius);
}

/* ---- Badge ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: var(--font-mono);
}
.badge-success { background: rgba(34,197,94,0.12); color: var(--success); }
.badge-danger { background: rgba(239,68,68,0.12); color: var(--danger); }
.badge-info { background: rgba(56,189,248,0.12); color: var(--info); }
.badge-warning { background: rgba(245,158,11,0.12); color: var(--warning); }

/* ---- Tabs ---- */
.tab-list {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  margin-bottom: 20px;
}
.tab-btn {
  flex: 1;
  padding: 7px 14px;
  border: none;
  background: transparent;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  transition: all var(--transition);
}
.tab-btn.active {
  background: var(--accent);
  color: #fff;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- Correlation Matrix ---- */
.correlation-matrix {
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.75rem;
}
.correlation-matrix table td, .correlation-matrix table th {
  padding: 6px 10px;
  text-align: center;
}
.corr-high { background: rgba(34,197,94,0.3); }
.corr-mid { background: rgba(245,158,11,0.2); }
.corr-low { background: rgba(239,68,68,0.2); }

/* ---- Sections ---- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-title {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
}

/* ---- Divider ---- */
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .grid-auto { grid-template-columns: 1fr 1fr; }
  .chart-wrapper { height: 280px; }
  .page { padding: 16px; }
}

/* ---- Utility ---- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.text-mono { font-family: var(--font-mono); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-accent { color: var(--accent); }
.font-600 { font-weight: 600; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
