:root {
  --bg-page: #f4f7fb;
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafc;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --primary: #0f5132;
  --primary-hover: #0a3b24;
  --primary-light: #e8f5ee;
  --blue: #1d4ed8;
  --blue-light: #eff6ff;
  --gold: #b45309;
  --gold-light: #fef3c7;
  --danger: #dc2626;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Cairo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Topbar */
.topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  flex-wrap: wrap;
  padding-top: 8px;
  padding-bottom: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #198754);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.25;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.nav-tabs {
  display: flex;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  gap: 4px;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.nav-tab.active {
  background: var(--bg-surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.badge {
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  padding: 1px 8px;
  border-radius: 999px;
  font-weight: 700;
}

/* Toggle Switch */
.toast-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

.toast-toggle input {
  display: none;
}

.toggle-slider {
  width: 36px;
  height: 20px;
  background: #cbd5e1;
  border-radius: 999px;
  position: relative;
  transition: 0.2s;
}

.toggle-slider::after {
  content: '';
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 3px;
  right: 3px;
  transition: 0.2s;
}

.toast-toggle input:checked + .toggle-slider {
  background: var(--primary);
}

.toast-toggle input:checked + .toggle-slider::after {
  transform: translateX(-16px);
}

/* Main Content */
.main-content {
  padding-top: 28px;
  padding-bottom: 56px;
}

.view-section.hidden,
.hidden {
  display: none !important;
}

/* Hero Banner */
.hero-banner {
  background: linear-gradient(135deg, #0b3d26 0%, #14532d 100%);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 26px 30px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-md);
}

.hero-banner h2 {
  font-size: 1.45rem;
  font-weight: 800;
  margin: 8px 0 6px;
}

.hero-banner p {
  color: rgba(255, 255, 255, 0.86);
  font-size: 0.94rem;
  max-width: 680px;
}

.pill-tag {
  display: inline-block;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
}

.pill-tag.pill-blue {
  background: var(--blue-light);
  color: var(--blue);
}

.session-chip {
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.25);
}

/* Cards & Grid */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}

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

.card-header h3 {
  font-size: 1.08rem;
  font-weight: 800;
}

.muted-text {
  color: var(--text-muted);
  font-size: 0.84rem;
}

.calculator-grid {
  display: grid;
  grid-template-columns: 440px 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 980px) {
  .calculator-grid {
    grid-template-columns: 1fr;
  }
}

/* Forms */
.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 520px) {
  .form-row-2 {
    grid-template-columns: 1fr;
  }
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-main);
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper input {
  width: 100%;
  padding: 10px 14px 10px 48px;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  background: var(--bg-subtle);
  transition: border-color 0.2s, background 0.2s;
}

.input-wrapper input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}

.input-suffix {
  position: absolute;
  left: 12px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
}

.range-slider {
  width: 100%;
  margin-top: 8px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Portfolio Cards */
.portfolio-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.portfolio-card {
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--bg-subtle);
}

.portfolio-card input {
  display: none;
}

.portfolio-card:hover {
  border-color: #94a3b8;
}

.portfolio-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.portfolio-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.portfolio-name {
  font-weight: 800;
  font-size: 0.94rem;
}

.portfolio-rate {
  background: #fff;
  color: var(--primary);
  border: 1px solid rgba(15, 81, 50, 0.2);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
}

.portfolio-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Buttons */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px 22px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 6px 18px rgba(15, 81, 50, 0.25);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-calculate {
  width: 100%;
  margin-top: 6px;
  font-size: 1.05rem;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: 0.15s;
}

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

.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.3);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-danger-outline:hover {
  background: #fef2f2;
}

/* Results Column */
.empty-results {
  text-align: center;
  padding: 56px 28px;
}

.empty-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
}

.empty-results h3 {
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.empty-results p {
  color: var(--text-muted);
  max-width: 440px;
  margin: 0 auto;
}

.results-wrapper {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.kpi-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

@media (max-width: 760px) {
  .kpi-grid-3 {
    grid-template-columns: 1fr;
  }
}

.kpi-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-box.highlight {
  background: linear-gradient(135deg, #f0fdf4 0%, #ffffff 100%);
  border-color: #bbf7d0;
}

.kpi-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 700;
}

.kpi-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-main);
}

.kpi-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.accent-green { color: var(--primary); }
.accent-blue { color: var(--blue); }
.accent-gold { color: var(--gold); }

/* Readiness */
.readiness-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.readiness-score {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
}

.progress-track {
  height: 12px;
  background: var(--bg-subtle);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #198754, var(--primary));
  border-radius: 999px;
  transition: width 0.5s ease;
}

/* Charts */
.chart-legend {
  display: flex;
  gap: 14px;
  font-size: 0.8rem;
  font-weight: 700;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dot-total { background: var(--primary); }
.dot-principal { background: #94a3b8; }

.svg-chart-box {
  width: 100%;
  min-height: 240px;
}

.svg-chart-box svg {
  width: 100%;
  height: auto;
  display: block;
}

/* Analytics View */
.analytics-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.analytics-header-bar h2 {
  font-size: 1.45rem;
  font-weight: 800;
  margin-top: 6px;
}

.analytics-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.kpi-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

@media (max-width: 900px) {
  .kpi-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  .kpi-grid-4 {
    grid-template-columns: 1fr;
  }
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-muted);
}

.stat-num {
  font-size: 1.65rem;
  font-weight: 800;
}

.stat-foot {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.stat-foot code {
  background: var(--bg-subtle);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.74rem;
}

.analytics-charts-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

@media (max-width: 900px) {
  .analytics-charts-grid {
    grid-template-columns: 1fr;
  }
}

.segmented-control {
  display: inline-flex;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  padding: 4px 12px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
}

.seg-btn.active {
  background: #fff;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.donut-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 220px;
  flex-wrap: wrap;
}

/* Funnel */
.funnel-card {
  margin-bottom: 20px;
}

.funnel-steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

@media (max-width: 820px) {
  .funnel-steps {
    grid-template-columns: 1fr 1fr;
  }
}

.funnel-step {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
}

.funnel-step-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.funnel-count {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 8px;
}

.funnel-bar-bg {
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.funnel-bar-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 999px;
}

/* Table */
.filter-group select {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--bg-subtle);
}

.table-responsive {
  overflow-x: auto;
}

.events-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.events-table th,
.events-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
  text-align: right;
  white-space: nowrap;
}

.events-table th {
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-weight: 800;
}

.event-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  font-family: monospace;
}

.ev-calc { background: var(--primary-light); color: var(--primary); }
.ev-view { background: var(--blue-light); color: var(--blue); }
.ev-input { background: var(--gold-light); color: var(--gold); }
.ev-analytics { background: #f3e8ff; color: #7e22ce; }

.btn-inspect {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

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

.empty-table-cell {
  text-align: center !important;
  color: var(--text-muted);
  padding: 28px !important;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
}

.modal-box {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  padding: 22px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

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

.icon-close {
  background: none;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  color: var(--text-muted);
}

.json-viewer {
  background: #0f172a;
  color: #38bdf8;
  padding: 16px;
  border-radius: var(--radius-md);
  font-family: monospace;
  font-size: 0.84rem;
  direction: ltr;
  text-align: left;
  max-height: 360px;
  overflow: auto;
  margin-bottom: 16px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 90;
  max-width: 340px;
}

.toast-item {
  background: #0f172a;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.22);
  border-right: 4px solid #4ade80;
  font-size: 0.84rem;
  animation: slideIn 0.25s ease;
}

.toast-title {
  font-weight: 800;
  color: #4ade80;
  display: block;
  margin-bottom: 2px;
  font-family: monospace;
}

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