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

:root {
  --bg:         #f0f2f7;
  --surface:    #ffffff;
  --surface-2:  #f7f8fc;
  --border:     #e2e6ef;
  --border-2:   #c8cedc;
  --navy:       #0d1b2a;
  --navy-2:     #1a3a5c;
  --accent:     #2563eb;
  --accent-2:   #1d4ed8;
  --accent-bg:  #eff6ff;
  --text:       #1e293b;
  --text-2:     #334155;
  --text-3:     #8492b6;
  --green:      #059669;
  --green-bg:   #ecfdf5;
  --red:        #dc2626;
  --red-bg:     #fef2f2;
  --warn:       #d97706;
  --warn-bg:    #fffbeb;
  --highlight:  #dbeafe;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow:     0 8px 24px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.06);
  --radius:     10px;
  --radius-sm:  6px;
  --font:       'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:  'Consolas', 'Cascadia Code', monospace;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ────────────────────────────────────────────────────── */
.app-header {
  background: var(--navy);
  border-bottom: 1px solid var(--navy-2);
  padding: 0 24px;
  height: 56px;
  flex-shrink: 0;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ── Brand (replaces old .logo / .logo-text) ───────────────────── */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-right: auto;   /* pushes currency + button to the right */
}

.brand-logo {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.brand-name {
  font-size: 18px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-subtitle {
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.2;
  white-space: nowrap;
}

/* keep .header-sub as a spacer (margin-right: auto moves currency to the right) */
.header-sub {
  display: none;   /* replaced by brand-subtitle inside the brand block */
  font-size: 12px;
  color: #64748b;
  margin-left: 4px;
  margin-right: auto;
}

/* ── Currency Switcher ─────────────────────────────────────────── */
.currency-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 6px;
  padding: 4px 10px;
}

.currency-label {
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .5px;
  white-space: nowrap;
}

.currency-select {
  background: transparent;
  border: none;
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  padding: 0 2px;
  font-family: var(--font);
}

.currency-select option { background: var(--navy); color: #e2e8f0; }

/* ── Main ──────────────────────────────────────────────────────── */
.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 20px 40px;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.card-note {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 10px;
  line-height: 1.5;
}

.card-note-inline {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 400;
  margin-left: 4px;
}

/* ── Form Grid ─────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  background: var(--surface-2);
}

.form-section legend {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--accent);
  padding: 0 4px;
}

/* ── Field Row (grid layout, no truncation) ────────────────────── */
.field-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 150px;
  gap: 10px 16px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.field-row:last-child { border-bottom: none; }

/* ── Field Main (left column) ──────────────────────────────────── */
.field-main { min-width: 0; }

.field-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.field-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  line-height: 1.3;
  max-width: none;
}

.field-helper {
  margin-top: 4px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text-3);
  white-space: normal;
  overflow: visible;
}

/* ── Field Badges ──────────────────────────────────────────────── */
.field-badge {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  line-height: 1.6;
  flex-shrink: 0;
}

.badge-market   { background: #dbeafe; color: #1d4ed8; }
.badge-actual   { background: #d1fae5; color: #065f46; }
.badge-forward  { background: #fef3c7; color: #92400e; }
.badge-normal   { background: #e0e7ff; color: #3730a3; }
.badge-bs       { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.badge-longterm { background: #fae8ff; color: #7e22ce; }

/* ── Help Icon (?) ─────────────────────────────────────────────── */
.help-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid #93c5fd;
  background: #eff6ff;
  color: #2563eb;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, color .15s, border-color .15s;
  padding: 0;
  line-height: 1;
}

.help-icon:hover,
.help-icon.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Input / Select (right column) ────────────────────────────── */
.field-row input,
.field-row select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--text);
  background: var(--surface);
  text-align: right;
  outline: none;
  transition: border-color .15s;
}

.field-row input:focus,
.field-row select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px #2563eb22;
}

.field-row select { text-align: left; font-family: var(--font); }

/* ── Forward-revenue checkbox ──────────────────────────────────── */
.field-row-check {
  grid-column: 1 / -1;
  padding: 4px 0 6px;
  border-bottom: 1px solid var(--border);
}

.check-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--warn);
  font-weight: 500;
  cursor: pointer;
}

.check-label input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--warn);
  flex-shrink: 0;
  cursor: pointer;
}

/* ── Buttons ───────────────────────────────────────────────────── */
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.btn {
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}

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

.btn-secondary { background: var(--surface); color: var(--accent); border-color: var(--accent); }
.btn-secondary:hover { background: var(--accent-bg); }
.btn-secondary:disabled { opacity: .4; cursor: not-allowed; }

.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border-2); }
.btn-ghost:hover { background: var(--surface-2); }

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

/* ── Warnings ──────────────────────────────────────────────────── */
.warnings-card { border-color: #fde68a; background: var(--warn-bg); }
.warn-title { color: var(--warn); margin-bottom: 10px; }

#warningsList { list-style: none; display: flex; flex-direction: column; gap: 5px; }

#warningsList li {
  font-size: 13px;
  color: #92400e;
  padding: 6px 10px 6px 26px;
  background: #fff;
  border-left: 3px solid var(--warn);
  border-radius: 3px;
  position: relative;
  line-height: 1.45;
}

#warningsList li::before {
  content: '!';
  position: absolute;
  left: 9px;
  font-weight: 700;
  color: var(--warn);
}

/* ── Results ───────────────────────────────────────────────────── */
#resultsSection { display: flex; flex-direction: column; gap: 16px; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.metric.highlight { background: var(--highlight); border-color: #bfdbfe; }

.metric-label {
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
}

.metric-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
  font-family: var(--font-mono);
}

/* ── Signal Chip ───────────────────────────────────────────────── */
.signal-chip { font-size: 13px; }
.signal-chip.undervalued { color: var(--green); }
.signal-chip.overvalued  { color: var(--red); }
.signal-chip.fair        { color: var(--warn); }

/* ── Tables ────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 560px;
}

.data-table th {
  background: var(--navy);
  color: #cbd5e1;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 9px 12px;
  text-align: right;
  white-space: nowrap;
}

.data-table th:first-child { text-align: left; }

.data-table td {
  padding: 8px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  color: var(--text);
}

.data-table td:first-child {
  text-align: left;
  font-family: var(--font);
  font-weight: 600;
  color: var(--navy);
}

.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table td.neg { color: var(--red); }
.data-table td.pos { color: var(--green); }

.multiples-table { min-width: 480px; }
.multiples-table td:last-child { font-family: var(--font); text-align: left; color: var(--text-2); font-size: 12px; }
.multiples-table td.primary-multiple { font-weight: 700; color: var(--accent); }

/* ── Industry Guidance ─────────────────────────────────────────── */
.industry-guidance {
  background: var(--accent-bg);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 12.5px;
  color: var(--navy-2);
  margin-bottom: 12px;
  line-height: 1.5;
}

/* ── Comparison ────────────────────────────────────────────────── */
.comp-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.comp-header .card-title { margin-bottom: 0; }
.comp-table { min-width: 780px; }
.comp-table .signal-chip { font-size: 12px; font-family: var(--font); }
.comp-table td.upside-pos { color: var(--green); font-weight: 700; }
.comp-table td.upside-neg { color: var(--red); font-weight: 700; }

.comp-del-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  font-size: 15px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color .15s;
}
.comp-del-btn:hover { color: var(--red); }

/* ── Methodology card ──────────────────────────────────────────── */
.methodology-card { padding: 0; overflow: hidden; }

.method-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.method-summary::-webkit-details-marker { display: none; }
.method-title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; color: var(--navy); }
.method-arrow { font-size: 11px; color: var(--text-3); transition: transform .2s; }
details[open] .method-arrow { transform: rotate(180deg); }
.method-summary:hover { background: var(--surface-2); }

.method-content { border-top: 1px solid var(--border); padding: 16px 20px 20px; }

.method-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.method-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.method-block h4 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--accent);
  margin-bottom: 7px;
}

.method-block pre {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--navy);
  background: #eef2ff;
  padding: 8px 10px;
  border-radius: 4px;
  white-space: pre-wrap;
  line-height: 1.6;
  margin-bottom: 6px;
}

.method-note { font-size: 11px; color: var(--text-3); line-height: 1.45; }

/* ── Footer ────────────────────────────────────────────────────── */
.app-footer {
  text-align: center;
  padding: 16px;
  font-size: 12px;
  color: var(--text-3);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ── Utility ───────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════════
   HELP MODAL — centered fixed overlay, always in viewport
   ═══════════════════════════════════════════════════════════════ */

/* Backdrop: covers the full screen, dims + blurs the page */
.help-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: backdropIn .18s ease;
}

@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }

/* Modal card: centered, never overflows viewport */
.help-modal {
  width: min(560px, 100%);
  max-height: min(720px, calc(100vh - 48px));
  overflow: hidden;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
  display: flex;
  flex-direction: column;
  animation: modalIn .18s ease;
}

@keyframes modalIn { from { opacity: 0; transform: scale(.97) translateY(6px); } to { opacity: 1; transform: none; } }

/* Sticky header */
.help-modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
  padding: 18px 22px 14px;
  border-bottom: 1px solid #e5eaf3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}

.help-modal-title {
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.3;
  margin-bottom: 6px;
}

.pop-badge { align-self: flex-start; }

.help-modal-close {
  border: none;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
  padding: 0;
  margin-top: 2px;
  transition: color .15s;
}

.help-modal-close:hover { color: #dc2626; }

/* Scrollable body */
.help-modal-body {
  padding: 18px 22px 22px;
  overflow-y: auto;
  flex: 1;
}

/* Sections inside the modal */
.help-section {
  margin-bottom: 18px;
}

.help-section:last-child { margin-bottom: 0; }

.help-section-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #64748b;
  margin-bottom: 6px;
}

.help-section p {
  font-size: 14px;
  line-height: 1.6;
  color: #334155;
  margin: 0;
  white-space: pre-wrap;
}

/* Formula block */
.help-formula {
  margin-top: 4px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  font-family: ui-monospace, 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  color: #0f172a;
  white-space: pre-wrap;
  overflow-x: auto;
}

/* Source hint */
.help-source {
  font-size: 13px;
  color: #2563eb;
  font-family: ui-monospace, 'Cascadia Code', 'Consolas', monospace;
  background: #f0f9ff;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #bae6fd;
  margin: 0;
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-main { padding: 12px 12px 32px; gap: 12px; }
  .card { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .header-sub { display: none; }
  .form-actions { gap: 8px; }

  /* stack label above input */
  .field-row { grid-template-columns: 1fr; gap: 6px; }
  .field-row input,
  .field-row select { width: 100%; text-align: left; }

  /* bottom sheet modal on mobile */
  .help-modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .help-modal {
    width: 100%;
    max-height: 85vh;
    border-radius: 18px 18px 0 0;
  }
}

@media (max-width: 480px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .btn { padding: 7px 14px; font-size: 12px; }
  .method-grid { grid-template-columns: 1fr; }
}
