/* ============================================================
   Börsen-App – Shared Design System
   Font: Plus Jakarta Sans (Google Fonts)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  /* Accent */
  --accent:        #6366f1;
  --accent-hover:  #4f46e5;
  --accent-subtle: rgba(99, 102, 241, 0.1);

  /* Semantic */
  --green:         #10b981;
  --green-subtle:  rgba(16, 185, 129, 0.1);
  --red:           #ef4444;
  --red-subtle:    rgba(239, 68, 68, 0.1);
  --amber:         #f59e0b;
  --amber-subtle:  rgba(245, 158, 11, 0.1);

  /* Typography */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

  /* Sizing */
  --radius-sm:  6px;
  --radius:     10px;
  --radius-lg:  14px;
  --nav-h:      56px;
}

/* Dark Theme (default) */
:root,
[data-theme="dark"] {
  --bg:           #09090b;
  --bg-card:      #18181b;
  --bg-hover:     #27272a;
  --border:       #27272a;
  --border-focus: #6366f1;
  --text:         #fafafa;
  --text-muted:   #71717a;
  --text-subtle:  #3f3f46;
  --shadow:       0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md:    0 4px 12px rgba(0,0,0,0.5);
}

/* Light Theme */
[data-theme="light"] {
  --bg:           #f4f4f5;
  --bg-card:      #ffffff;
  --bg-hover:     #f4f4f5;
  --border:       #e4e4e7;
  --border-focus: #6366f1;
  --text:         #09090b;
  --text-muted:   #71717a;
  --text-subtle:  #d4d4d8;
  --shadow:       0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:    0 4px 12px rgba(0,0,0,0.1);
}

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

html { font-size: 16px; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}

/* ── Top Navigation ────────────────────────────────────────── */
.app-nav {
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--nav-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 32px;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}

.nav-logo-icon {
  width: 30px;
  height: 30px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}

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

.nav-link.active {
  color: var(--text);
  background: var(--bg-hover);
}

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

.nav-link { position: relative; }

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Theme Toggle */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-muted);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.theme-toggle:hover {
  color: var(--text);
  background: var(--bg-hover);
}

/* Mobile Nav */
.nav-hamburger {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.nav-hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-muted);
  border-radius: 2px;
  transition: all 0.2s;
}

@media (max-width: 640px) {
  .nav-hamburger { display: flex; }
  .nav-links {
    display: none;
    position: absolute;
    top: var(--nav-h);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 8px;
    gap: 2px;
    box-shadow: var(--shadow-md);
  }
  .nav-links.open { display: flex; }
  .nav-link { width: 100%; }
}

/* ── Layout ─────────────────────────────────────────────────── */
.page-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 24px;
}

.page-container-sm {
  max-width: 860px;
  margin: 0 auto;
  padding: 28px 24px;
}

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Stat Tiles ─────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.stat-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.2;
}

.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  line-height: 1;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

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

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

.btn-secondary:hover:not(:disabled) {
  border-color: var(--text-muted);
}

.btn-danger {
  background: var(--red-subtle);
  color: var(--red);
  border-color: var(--red);
}

.btn-success {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.btn-success:hover:not(:disabled) {
  background: #059669;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-lg {
  padding: 11px 22px;
  font-size: 15px;
}

.btn-full { width: 100%; justify-content: center; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
}

.badge-buy    { background: var(--green-subtle); color: var(--green); }
.badge-sell   { background: var(--red-subtle);   color: var(--red);   }
.badge-hold   { background: var(--bg-hover);     color: var(--text-muted); }
.badge-info   { background: var(--accent-subtle); color: var(--accent); }
.badge-warn   { background: var(--amber-subtle);  color: var(--amber); }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

tbody tr:hover { background: var(--bg-hover); }

/* ── Form Elements ──────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.form-input,
.form-select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  transition: border-color 0.15s;
  outline: none;
  appearance: none;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.form-hint {
  display: block;
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Toggle Switch ──────────────────────────────────────────── */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.2s, border-color 0.2s;
}

.toggle-track::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle-switch input:checked + .toggle-track {
  background: var(--green);
  border-color: var(--green);
}

.toggle-switch input:checked + .toggle-track::before {
  transform: translateX(20px) translateY(-50%);
  background: #fff;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.toggle-info h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}

.toggle-info p {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Confidence Bar ─────────────────────────────────────────── */
.conf-bar {
  width: 64px;
  height: 5px;
  background: var(--bg-hover);
  border-radius: 999px;
  overflow: hidden;
}

.conf-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s;
}

.conf-high   { background: var(--green); }
.conf-medium { background: var(--amber); }
.conf-low    { background: var(--red); }

/* ── Loading / Spinner ──────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px;
  color: var(--text-muted);
  font-size: 14px;
}

.loading-state .spinner {
  width: 32px;
  height: 32px;
}

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

/* ── Empty State ────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 36px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

/* ── Toast ──────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toast-in 0.25s ease;
  max-width: 340px;
}

.toast.toast-success { border-color: var(--green); }
.toast.toast-error   { border-color: var(--red);   }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open,
.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 800px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  animation: modal-in 0.2s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

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

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 18px;
  transition: all 0.15s;
}

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

.modal-body { padding: 24px; }

.ai-analysis h4 { font-size: .9rem; font-weight: 600; margin: 1.25rem 0 .4rem; color: var(--text); }
.ai-analysis h4:first-child { margin-top: 0; }
.ai-analysis p { margin: 0 0 .5rem; font-size: .88rem; color: var(--gray-600); }

/* ── Disclaimer Banner ──────────────────────────────────────── */
.disclaimer-bar {
  background: var(--amber-subtle);
  border-bottom: 1px solid var(--amber);
  color: var(--amber);
  padding: 8px 24px;
  font-size: 13px;
  text-align: center;
}

[data-theme="light"] .disclaimer-bar {
  background: #fffbeb;
  color: #92400e;
  border-color: #f59e0b;
}

/* ── Progress Bar ───────────────────────────────────────────── */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-hover);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* ── Section Header ─────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
}

.section-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Info Box ───────────────────────────────────────────────── */
.info-box {
  background: var(--accent-subtle);
  border: 1px solid rgba(99,102,241,0.25);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.info-box p { font-size: 13px; line-height: 1.6; color: var(--text); }
.info-box p + p { margin-top: 6px; }

/* ── Login Card ─────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}

.login-logo {
  width: 44px;
  height: 44px;
  background: var(--accent);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin-bottom: 24px;
}

.login-card h1 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-card p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

/* ── Alert / Message ────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
  border: 1px solid;
}

.alert-success { background: var(--green-subtle); border-color: var(--green); color: var(--green); }
.alert-error   { background: var(--red-subtle);   border-color: var(--red);   color: var(--red); }
.alert-warn    { background: var(--amber-subtle);  border-color: var(--amber); color: var(--amber); }

/* ── Risk Profile Buttons ───────────────────────────────────── */
.risk-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.risk-btn {
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: grid;
  grid-template-columns: 14px 1fr;
  grid-template-rows: auto auto;
  column-gap: 8px;
  align-items: center;
}
.risk-btn svg {
  grid-row: 1;
  grid-column: 1;
  flex-shrink: 0;
}
.risk-btn small {
  grid-row: 2;
  grid-column: 2;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

.risk-btn:hover { border-color: var(--text-muted); color: var(--text); }

.risk-btn.active {
  border-color: var(--accent);
  background: var(--accent-subtle);
  color: var(--text);
}

.risk-btn.active.konservativ { border-color: var(--green); background: var(--green-subtle); }
.risk-btn.active.risikofreudig { border-color: var(--red);   background: var(--red-subtle); }

/* ── Lucide Icons ───────────────────────────────────────────── */
[data-lucide] {
  display: inline-block;
  vertical-align: middle;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  flex-shrink: 0;
}

/* ── Utility ────────────────────────────────────────────────── */
.text-muted    { color: var(--text-muted); }
.text-green    { color: var(--green); }
.text-red      { color: var(--red); }
.text-accent   { color: var(--accent); }
.text-sm       { font-size: 13px; }
.text-xs       { font-size: 11px; }
.font-mono     { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }
.positive      { color: var(--green); }
.negative      { color: var(--red); }
.mt-1  { margin-top: 4px; }
.mt-2  { margin-top: 8px; }
.mt-4  { margin-top: 16px; }
.mt-6  { margin-top: 24px; }
.mb-4  { margin-bottom: 16px; }
.mb-6  { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.flex  { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* ── Page-in Animation ──────────────────────────────────────── */
.page-fade {
  animation: page-in 0.25s ease;
}

@keyframes page-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Theme Init Script (inline helper) ─────────────────────── */
/* Call initTheme() early to avoid flash of wrong theme */
