:root {
  --font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-muted: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e1e5ed;
  --strong-border: #cbd2dd;
  --primary: #0f62fe;
  --primary-strong: #0b4fd9;
  --accent: #0ea5e9;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow-sm: 0 6px 12px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 14px 26px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 18px 34px rgba(15, 23, 42, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 14px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 44px;
  --max-width: 1200px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  line-height: 1.5;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 120ms ease;
}
a:hover {
  color: var(--primary-strong);
}

img {
  max-width: 100%;
  height: auto;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* NAVBAR */
.navbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}
.navbar-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-2) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0f62fe, #2dd4bf);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 900;
  font-size: 16px;
  box-shadow: var(--shadow-sm);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.nav-link {
  color: var(--text);
  font-weight: 600;
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-sm);
  transition: background 120ms ease, color 120ms ease;
}
.nav-link:hover,
.nav-link:focus-visible {
  background: #eef2f7;
  color: var(--primary);
  outline: none;
}
.nav-dropdown {
  position: relative;
  padding-bottom: 4px;
}
.nav-dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid transparent;
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--text);
  cursor: pointer;
  transition: color 120ms ease;
}
.nav-dropdown-toggle:hover,
.nav-dropdown-toggle:focus-visible {
  color: var(--primary);
  outline: none;
}
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
  display: block;
}
.nav-dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  left: auto;
  min-width: 200px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 8px;
  display: none;
  z-index: 15;
}
.nav-dropdown.open .nav-dropdown-menu {
  display: block;
}
.nav-dropdown-menu .nav-link {
  display: block;
  width: 100%;
  border-radius: var(--radius-sm);
}
.nav-toggle {
  display: none;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  font-weight: 700;
}

/* LAYOUT */
.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-6);
  width: 100%;
}
.page-header {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: var(--space-3);
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  color: var(--muted);
}
.page-title {
  margin: 4px 0;
  font-size: 30px;
  letter-spacing: -0.02em;
}
.page-subtitle {
  margin: 0;
  color: var(--muted);
}
.grid {
  display: grid;
  gap: var(--space-3);
}
.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

/* CARDS */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.card.tight {
  padding: var(--space-3);
}
.card-hero {
  background: linear-gradient(135deg, #f7f9fc, #ffffff);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}
.card-header {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-3);
}
.card-title {
  margin: 0;
  font-size: 18px;
}
.card-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease, border 120ms ease;
  text-decoration: none;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #fff;
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.btn-secondary {
  background: #eef2f7;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.2);
  outline-offset: 2px;
}

/* FORMS */
label {
  font-weight: 600;
  color: var(--text);
  display: block;
  margin-bottom: 6px;
}
.input,
select,
textarea {
  width: 100%;
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  font-size: 14px;
  transition: border 120ms ease, box-shadow 120ms ease;
}
.input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(37, 99, 235, 0.2);
  border-color: var(--primary);
}
.form-grid {
  display: grid;
  gap: var(--space-3);
}
.muted {
  color: var(--muted);
}
.helper {
  font-size: 14px;
  color: var(--muted);
}

/* TABLES */
.table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}
.table th,
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.table th {
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
}
.table tbody tr:hover {
  background: #f8fafc;
}
.table.striped tbody tr:nth-child(odd) {
  background: #fbfdff;
}
.table-sticky thead th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

/* BADGES & PILLS */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e0f2fe;
  color: #0369a1;
  font-weight: 700;
  font-size: 12px;
}
.badge.success {
  background: #ecfdf3;
  color: #15803d;
}
.badge.danger {
  background: #fef2f2;
  color: #b91c1c;
}
.badge.muted {
  background: #f1f5f9;
  color: #475569;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #f8fafc;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 700;
}

/* ALERTS */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--text);
}
.alert.success {
  background: #ecfdf3;
  border-color: #bbf7d0;
  color: #166534;
}
.alert.info {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
}
.alert.warning {
  background: #fffbeb;
  border-color: #fcd34d;
  color: #92400e;
}
.alert.danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

/* LISTS / TILES */
.tile-list {
  display: grid;
  gap: var(--space-3);
}
.tile {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-decoration: none;
  color: var(--text);
  transition: transform 120ms ease, box-shadow 120ms ease, border 120ms ease, background 120ms ease;
}
.tile:hover {
  transform: translateY(-1px);
  border-color: var(--strong-border);
  box-shadow: var(--shadow-sm);
  background: #f9fbff;
}

/* HOME */
.home-hero {
  margin-bottom: var(--space-3);
  padding: var(--space-5);
}
.home-categories {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-3);
  align-items: stretch;
}
.home-card {
  padding: var(--space-4);
  min-height: 140px;
}

/* AUTH */
.auth-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-4);
  background: var(--bg);
}
.auth-card {
  width: min(480px, 100%);
  background: #fff;
  border-radius: 20px;
  border: 1px solid var(--border);
  padding: var(--space-5);
  box-shadow: var(--shadow-md);
}

/* UTILITIES */
.flex {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.justify-between {
  justify-content: space-between;
}
.wrap {
  flex-wrap: wrap;
}
.center {
  justify-content: center;
}
.mt-2 {
  margin-top: var(--space-2);
}
.mt-3 {
  margin-top: var(--space-3);
}
.mt-4 {
  margin-top: var(--space-4);
}
.mb-2 {
  margin-bottom: var(--space-2);
}
.mb-3 {
  margin-bottom: var(--space-3);
}
.mb-4 {
  margin-bottom: var(--space-4);
}
.text-center {
  text-align: center;
}
.text-right {
  text-align: right;
}
.shadow {
  box-shadow: var(--shadow-md);
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 12px;
  background: #f1f5f9;
  color: var(--text);
  font-weight: 700;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  background: #f8fafc;
  font-weight: 700;
}

.chart-host {
  min-height: 280px;
  height: 320px;
  width: 100%;
  min-width: 0;
  display: block;
  position: relative;
}

.chart-host #price-chart,
.chart-host .plotly-graph-div,
.chart-host .js-plotly-plot {
  width: 100% !important;
  height: 100% !important;
  min-width: 100% !important;
}

.goals-chart-wrap {
  width: 100%;
  height: 100%;
  min-height: 360px;
  min-width: 0;
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  flex: 1 1 auto;
}

.goals-chart-wrap #plpulse-goals-chart {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: block;
}

.goals-chart-wrap #plpulse-goals-chart,
.goals-chart-wrap .plotly-graph-div,
.goals-chart-wrap .js-plotly-plot {
  width: 100% !important;
  height: 100% !important;
}

.goals-chart-wrap #plpulse-goals-chart > div {
  width: 100% !important;
  height: 100% !important;
}

.goals-chart-wrap #plpulse-goals-chart,
.goals-chart-wrap #plpulse-goals-chart .plot-container,
.goals-chart-wrap #plpulse-goals-chart .svg-container,
.goals-chart-wrap #plpulse-goals-chart .main-svg {
  width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
}

.goals-card .goals-card-body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: stretch;
  flex: 1 1 auto;
  min-height: 360px;
}

.goals-card {
  display: flex;
  flex-direction: column;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-weight: 700;
}
.chip.positive {
  border-color: rgba(22, 163, 74, 0.3);
  color: #15803d;
  background: rgba(22, 163, 74, 0.08);
}
.chip.negative {
  border-color: rgba(220, 38, 38, 0.3);
  color: #b91c1c;
  background: rgba(220, 38, 38, 0.08);
}

/* CHAT */
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 4px;
}
.bubble {
  max-width: 86%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #f8fafc;
}
.bubble .meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.bubble.me {
  align-self: flex-end;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #0b1726;
  border-color: rgba(34, 197, 94, 0.3);
}
.bubble.me .meta {
  color: rgba(11, 23, 38, 0.7);
}
.bubble.other {
  align-self: flex-start;
}
.attachment-box {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: #fff;
}
.attachment-box img {
  max-width: 220px;
  border-radius: 10px;
  display: block;
}

/* FOOTER */
.footer {
  margin-top: auto;
  padding: var(--space-4) var(--space-4) var(--space-5);
  background: #fff;
  border-top: 1px solid var(--border);
}
.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
  color: var(--muted);
  font-size: 14px;
}

/* MEDIA */
@media (max-width: 768px) {
  .navbar-inner {
    flex-wrap: wrap;
  }
  .nav-links {
    display: none;
    width: 100%;
  }
  .nav-links.open {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }
  .nav-toggle {
    display: inline-flex;
  }
  .page {
    padding: var(--space-4);
  }
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
}
