/* InsightStock – Advanced UI (v4) */

:root {
  --primary: #059669;
  --primary-hover: #047857;
  --primary-light: #d1fae5;
  --secondary: #0f172a;
  --accent: #06b6d4;
  --success: #059669;
  --success-bg: #d1fae5;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --info: #0284c7;
  --info-bg: #e0f2fe;
  --light-bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 9999px;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.06);
  --shadow-hover: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.08);
  --navbar-height: 58px;
  --glass-bg: rgba(255,255,255,0.85);
  --glass-border: rgba(255,255,255,0.3);
}

* { box-sizing: border-box; }

/* Mobile: ensure full page visible and scrollable on all screen sizes */
html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  min-height: 100%;
}
html, body {
  min-width: 0;
  max-width: 100vw;
  width: 100%;
}
body {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 100%;
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport – better on mobile browsers (Safari 15.4+) */
}

/* Tighter layout – reduce empty space in corners/edges */
main {
  flex: 1;
  min-height: 0; /* allow flex child to shrink so content can scroll */
  overflow-y: visible;
  overflow-x: hidden;
}
main.container { padding-left: 0.75rem; padding-right: 0.75rem; }
main.container-fluid { padding-left: 0.75rem; padding-right: 0.75rem; }
@media (min-width: 576px) {
  main.container, main.container-fluid { padding-left: 1rem; padding-right: 1rem; }
}

body {
  font-family: 'Plus Jakarta Sans', 'Segoe UI', system-ui, sans-serif;
  background: var(--light-bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Navbar */
.navbar {
  background: linear-gradient(135deg, var(--secondary) 0%, #1e293b 100%) !important;
  box-shadow: var(--shadow);
  min-height: var(--navbar-height);
  padding: 0.45rem 0 !important;
}

.navbar .container { padding-left: 0.75rem; padding-right: 0.75rem; }
@media (min-width: 576px) {
  .navbar .container { padding-left: 1rem; padding-right: 1rem; }
}

.navbar-brand {
  font-weight: 700;
  color: #fff !important;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
  padding-top: 0.3rem;
  padding-bottom: 0.3rem;
  margin-left: -1.25rem;
}

.navbar-brand i {
  margin-right: 0.4rem;
  color: var(--primary);
}

.nav-link {
  color: rgba(255,255,255,0.9) !important;
  transition: all 0.2s;
  padding: 0.45rem 0.85rem !important;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 1rem;
}

.nav-link:hover {
  color: #fff !important;
  background: rgba(255,255,255,0.1);
}

.nav-link.active {
  color: #fff !important;
  background: var(--primary);
}

/* Cards – stronger radius and shadow */
.card {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: box-shadow 0.25s, transform 0.25s;
  overflow: hidden;
}

.card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.card-body { padding: 1.5rem 1.75rem; }

.card-header {
  font-weight: 600;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1rem 1.5rem;
}

/* Buttons – pill style primary */
.btn {
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: all 0.2s;
  letter-spacing: 0.01em;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%) !important;
  border: none !important;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-hover) 0%, #065f46 100%) !important;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(5, 150, 105, 0.4);
}

.btn-lg {
  padding: 0.85rem 1.75rem;
  font-size: 1rem;
}

.btn-outline-primary {
  border-width: 2px;
  font-weight: 600;
}

.btn-outline-primary:hover {
  transform: translateY(-1px);
}

/* Form controls */
.form-control, .form-select {
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  padding: 0.7rem 1rem;
  font-size: 1rem;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-light);
}

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

/* Alerts / flash */
.alert {
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-warning { background: var(--warning-bg); color: #92400e; }
.alert-info { background: var(--info-bg); color: var(--info); }

/* Hero section (home page) */
.hero-section {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

.hero-section .display-4, .hero-section h1 {
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #fff !important;
}
.hero-section .text-primary { color: #fff !important; }
.hero-section .btn-outline-primary {
  border-color: rgba(255,255,255,0.8);
  color: #fff;
}
.hero-section .btn-outline-primary:hover {
  background: rgba(255,255,255,0.15);
  border-color: #fff;
  color: #fff;
}

.hero-section .lead { opacity: 0.95; font-size: 1.15rem; }

.hero-buttons .btn { min-width: 160px; }

/* Sentiment */
.sentiment-positive { background: var(--success-bg); color: var(--success); }
.sentiment-negative { background: var(--danger-bg); color: var(--danger); }
.sentiment-neutral { background: var(--info-bg); color: var(--info); }

.sentiment-indicator {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  text-align: center;
  font-weight: 600;
}

/* Stock search */
.stock-search { max-width: 640px; margin: 2rem auto; }
.search-input {
  border-radius: var(--radius-pill);
  padding: 1rem 1.5rem;
  font-size: 1.05rem;
  border: 2px solid var(--border);
}
.search-input:focus { border-color: var(--primary); }

.search-results {
  position: absolute;
  z-index: 100;
  width: 100%;
  max-height: 280px;
  overflow-y: auto;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hover);
  border: 1px solid var(--border);
}
.search-container { position: relative; }

/* Key factors */
.key-factors {
  background: linear-gradient(135deg, var(--primary-light) 0%, #ecfdf5 100%);
  border-radius: var(--radius);
  padding: 1.5rem;
  border: 1px solid rgba(5, 150, 105, 0.2);
}
.key-factor-item {
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--primary);
  margin: 0.5rem 0;
  background: var(--card-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-weight: 500;
}

/* News cards */
.news-card {
  border-left: 4px solid var(--primary);
  margin: 0.5rem 0;
  transition: all 0.2s;
}
.news-card:hover { border-left-color: var(--primary-hover); box-shadow: var(--shadow); }

/* Main content */
main { flex: 1; padding-top: 0.75rem; padding-bottom: 2.5rem; }

.container { max-width: 1140px; }

/* Footer */
footer.bg-dark {
  background: linear-gradient(135deg, var(--secondary) 0%, #1e293b 100%) !important;
  margin-top: auto;
  padding: 1.75rem 0 !important;
  border-top: 1px solid rgba(255,255,255,0.08);
}

/* Error page */
.error-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: 2rem;
}
.error-card {
  text-align: center;
  max-width: 440px;
}
.error-code {
  font-size: 4.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}
.error-title { font-size: 1.4rem; margin: 1rem 0 0.5rem; font-weight: 600; }
.error-text { color: var(--text-muted); margin-bottom: 1.5rem; }

/* Progress */
.progress {
  background: var(--light-bg);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-bar { border-radius: var(--radius-pill); transition: width 0.4s ease; }

.bx-spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Login / auth cards */
.card.shadow-lg {
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
}

/* Utilities */
.text-primary { color: var(--primary) !important; }
.bg-primary { background: var(--primary) !important; }

/* Dashboard strip (logged-in) */
.dashboard-strip {
  background: linear-gradient(90deg, rgba(5, 150, 105, 0.12) 0%, rgba(6, 182, 212, 0.08) 100%);
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.dashboard-stat {
  color: var(--text);
  font-weight: 500;
}
.dashboard-stat.dashboard-cost { color: var(--primary); font-weight: 600; }

/* Footer */
footer.bg-dark {
  padding-top: 0.75rem !important;
  padding-bottom: 0.75rem !important;
  margin-top: 1.25rem !important;
}
footer .container { padding-left: 0.5rem; padding-right: 0.5rem; }
footer .row > .col-md-6:first-child { padding-left: 0.25rem; margin-left: -0.5rem; }
footer .fw-semibold, footer .text-white-50 { font-size: 0.95rem; }

/* Toasts */
.toast-container {
  position: fixed;
  top: calc(var(--navbar-height) + 12px);
  right: 16px;
  z-index: 9998;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast-item {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hover);
  background: var(--card-bg);
  border-left: 4px solid var(--primary);
  animation: toastIn 0.3s ease;
}
.toast-item.toast-success { border-left-color: var(--success); }
.toast-item.toast-danger { border-left-color: var(--danger); }
.toast-item.toast-warning { border-left-color: var(--warning); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Skeleton loaders */
.skeleton {
  background: linear-gradient(90deg, var(--light-bg) 25%, var(--border) 50%, var(--light-bg) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.2s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton {
  to { background-position: 200% 0; }
}
.skeleton-text { height: 1em; margin-bottom: 0.5rem; }
.skeleton-title { height: 1.5rem; width: 60%; margin-bottom: 1rem; }
.skeleton-card { height: 120px; }
.skeleton-list .skeleton-text { width: 100%; }
.skeleton-list .skeleton-text:last-child { width: 70%; }

/* Task filters (tabs) */
.task-filters {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.task-filters .btn {
  border-radius: var(--radius-pill);
  font-weight: 500;
}
.task-filters .btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Task card status border */
.task-card.task-status-started { border-left: 4px solid var(--info); }
.task-card.task-status-completed { border-left: 4px solid var(--success); }
.task-card.task-status-failed,
.task-card.task-status-cancelled { border-left: 4px solid var(--danger); }
.task-card { border-left: 4px solid var(--border); }

/* Glass card (optional) */
.card.card-glass {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
}

/* Form step indicator */
.form-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.form-steps .step {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  color: var(--text-muted);
}
.form-steps .step-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--light-bg);
  border: 2px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}
.form-steps .step.active .step-num,
.form-steps .step.done .step-num {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.form-steps .step.active { color: var(--primary); }
.form-steps .step.done { color: var(--text); }
.form-steps .step-connector {
  width: 24px;
  height: 2px;
  background: var(--border);
}
.form-steps .step.done + .step-connector,
.step-connector + .step.done .step-num { background: var(--primary); }

/* Result page: transaction card & Q&A bar */
.result-transaction-card {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.result-qa-bar .form-control {
  border-radius: var(--radius-pill);
  padding: 0.75rem 1.25rem;
}
.result-qa-bar .btn { border-radius: var(--radius-pill); }

/* Focus visible (a11y) */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
/* Login page */
.login-page-wrap {
  background: linear-gradient(160deg, var(--light-bg) 0%, var(--primary-light) 50%, #e0f2fe 100%);
  min-height: calc(100vh - var(--navbar-height) - 120px);
  margin: 0 -0.5rem;
  padding: 0 0.5rem;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Market News – reading layout */
.market-news-page .hero-section .display-5 { color: #fff !important; }
.market-news-report {
  max-width: 100%;
  margin: 0;
  text-align: left;
  font-size: 1.05rem;
  line-height: 1.7;
}
.market-news-report h1,
.market-news-report h2,
.market-news-report h3 {
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
  color: var(--text);
}
.market-news-report h2 { font-size: 1.35rem; border-bottom: 1px solid var(--border); padding-bottom: 0.35rem; }
.market-news-report h3 { font-size: 1.15rem; }
.market-news-report p { margin-bottom: 1rem; }
.market-news-report ul, .market-news-report ol { margin-bottom: 1rem; padding-left: 1.5rem; }
.market-news-report li { margin-bottom: 0.35rem; }
.market-news-report strong { font-weight: 600; color: var(--text); }
.market-news-report a { color: var(--primary); text-decoration: none; }
.market-news-report a:hover { text-decoration: underline; }
.market-news-report code { background: var(--light-bg); padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.9em; }
.market-news-report pre { background: var(--light-bg); padding: 1rem; border-radius: var(--radius-sm); overflow-x: auto; margin-bottom: 1rem; }
.market-news-report blockquote { border-left: 4px solid var(--primary); margin: 1rem 0; padding-left: 1rem; color: var(--text-muted); }
.market-news-report .market-news-h2 { font-size: 1.2rem; margin-top: 1.5rem; margin-bottom: 0.5rem; }
.market-news-report .market-news-h2.market-news-section-accent,
.market-news-section-accent.market-news-h3 {
  background: linear-gradient(135deg, var(--primary-light) 0%, #ecfdf5 100%);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}
#citationsSection .market-news-section-accent { margin-top: 0; }
.market-news-report .market-news-list { margin-bottom: 1rem; }
.market-news-report .market-news-item { margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border); }
.market-news-report .market-news-item:last-child { border-bottom: none; }
.market-news-report .market-news-item-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-start; }
.market-news-report .market-news-item-left { flex: 1 1 200px; }
.market-news-report .market-news-item-preview { flex: 1 1 220px; font-size: 0.9rem; color: var(--text-muted); line-height: 1.6; padding: 0.25rem 0 0.25rem 1rem; border-left: 2px solid var(--border); }
@media (max-width: 600px) {
  .market-news-report .market-news-item-row { flex-direction: column; }
  .market-news-report .market-news-item-preview { border-left: none; border-top: 1px solid var(--border); padding-left: 0; padding-top: 0.75rem; margin-top: 0.25rem; }
}

@media (max-width: 768px) {
  .card-body { padding: 1.25rem; }
  .error-code { font-size: 3.5rem; }
  .hero-section { padding: 1.5rem 1rem; }
  .toast-container { left: 16px; right: 16px; max-width: none; }
  .dashboard-strip .d-flex { flex-direction: column; align-items: flex-start !important; }
  .market-news-report { font-size: 1rem; }
}

/* Mobile compatibility: tables, containers, safe areas */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  -webkit-tap-highlight-color: transparent;
  margin-left: 0;
  margin-right: 0;
  max-width: 100%;
  width: 100%;
}
@media (max-width: 576px) {
  .table-responsive {
    margin-left: -0.5rem;
    margin-right: -0.5rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    width: calc(100% + 1rem);
    max-width: calc(100% + 1rem);
  }
}
@media (max-width: 576px) {
  .container, .container-fluid { padding-left: 0.75rem; padding-right: 0.75rem; max-width: 100%; width: 100%; }
  main.container, main.container-fluid { padding-left: 0.75rem; padding-right: 0.75rem; width: 100%; }
  .card, .card-body { overflow: visible; }
  .d-flex { flex-wrap: wrap; }
  .d-flex.justify-content-between { flex-wrap: wrap; gap: 0.75rem; }
  /* Safe area for notched phones */
  body {
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  /* Full-width modals on small screens */
  .modal-dialog { margin: 0.5rem; max-width: calc(100vw - 1rem); width: calc(100% - 1rem); }
  /* Ensure result page header stacks and fits */
  .stock-header, .header-actions { width: 100%; }
  .header-actions { align-self: stretch; }
  .header-actions .btn { width: 100%; justify-content: center; }
}

/* Very small screens (320px–375px) */
@media (max-width: 375px) {
  .container, .container-fluid, main.container, main.container-fluid { padding-left: 0.5rem; padding-right: 0.5rem; }
  .hero-section .display-5 { font-size: 1.5rem; }
  .hero-section .lead { font-size: 0.95rem; }
  .hero-buttons .btn { min-width: 0; width: 100%; }
}
/* Prevent long text/URLs from overflowing on small screens */
.market-news-report, .card-body, .table, .news-content { word-wrap: break-word; overflow-wrap: break-word; }
