/* Valere — Business Valuation Workbench
   Aesthetic: precise fintech. Cool neutrals, single blue accent, mono for figures. */

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-alt: #fbfcfd;
  --ink-900: #0f172a;
  --ink-700: #334155;
  --ink-500: #64748b;
  --ink-400: #94a3b8;
  --ink-300: #cbd5e1;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --accent: #2563eb;
  --accent-soft: #eff5ff;
  --accent-ink: #1d4ed8;
  --positive: #059669;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.06);
  --radius: 10px;
  --radius-sm: 6px;
  --sans: 'Satoshi', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink-900); }
body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand-tag { font-size: 12px; color: var(--ink-500); }
.topbar-actions { display: flex; gap: 8px; }

.btn {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-700);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn:hover { background: var(--surface-alt); border-color: var(--ink-300); color: var(--ink-900); }
.btn-primary {
  background: var(--ink-900);
  color: #fff;
  border-color: var(--ink-900);
}
.btn-primary:hover { background: #000; color: #fff; }
.btn-ghost { background: transparent; }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: minmax(360px, 420px) 1fr;
  gap: 20px;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.inputs { padding: 20px; }
.outputs { padding: 24px; }

.panel-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.panel-sub {
  margin: 4px 0 16px;
  font-size: 12px;
  color: var(--ink-500);
}

/* ---------- Input groups ---------- */
.group { padding: 14px 0; border-top: 1px solid var(--line); }
.group:first-of-type { border-top: none; padding-top: 0; }
.group-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-500);
  margin-bottom: 10px;
}
.hint { font-weight: 400; color: var(--ink-400); text-transform: none; letter-spacing: 0; font-size: 11px; margin-left: 4px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 12px; color: var(--ink-700); font-weight: 500; }
.field input, .field select {
  font-family: var(--mono);
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-900);
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
  width: 100%;
}
.field select { font-family: var(--sans); }
.field input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }
.row .field { margin-bottom: 10px; }

.input-suffix { position: relative; }
.input-suffix input { padding-right: 28px; }
.input-suffix span {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-400);
  font-family: var(--mono);
  font-size: 12px;
  pointer-events: none;
}

.weight-status {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-500);
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  border: 1px solid var(--line);
}
.weight-status.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.weight-status.ok { color: var(--positive); }

/* ---------- Outputs headline ---------- */
.headline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
  align-items: end;
}
.eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-500);
  margin-bottom: 8px;
}
.headline-value {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 34px;
  letter-spacing: -0.02em;
  color: var(--ink-900);
  line-height: 1.1;
}
.headline-sub {
  margin-top: 6px;
  font-size: 13px;
  color: var(--ink-500);
  font-family: var(--mono);
}
.range { padding-left: 24px; border-left: 1px solid var(--line); }
.range-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-500);
  margin-bottom: 8px;
}
.range-value {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 500;
  color: var(--ink-700);
  margin-bottom: 12px;
}
.range-bar {
  position: relative;
  height: 6px;
  background: var(--surface-alt);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: visible;
}
.range-fill {
  position: absolute;
  height: 100%;
  background: linear-gradient(90deg, #93c5fd 0%, var(--accent) 50%, #1e40af 100%);
  border-radius: 999px;
}
.range-marker {
  position: absolute;
  top: -4px;
  width: 4px;
  height: 14px;
  background: var(--ink-900);
  border-radius: 2px;
  transform: translateX(-2px);
}

/* ---------- Method cards ---------- */
.methods {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}
.method-card {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-alt);
}
.method-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.method-name { font-size: 12px; font-weight: 600; color: var(--ink-700); }
.method-weight {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent-ink);
  background: var(--accent-soft);
  padding: 2px 6px;
  border-radius: 4px;
}
.method-value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink-900);
  letter-spacing: -0.01em;
}
.method-detail {
  font-size: 11px;
  color: var(--ink-500);
  margin-top: 4px;
}

/* ---------- Sections & tables ---------- */
.section { margin-bottom: 28px; }
.section:last-of-type { margin-bottom: 0; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-head h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.005em;
}
.section-sub { font-size: 11px; color: var(--ink-500); }

.grid-two { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; }

.table-wrap { overflow-x: auto; }
.ftable {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.ftable thead th {
  text-align: right;
  font-weight: 600;
  color: var(--ink-500);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.ftable thead th:first-child { text-align: left; }
.ftable tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12px;
  text-align: right;
  color: var(--ink-700);
}
.ftable tbody td:first-child {
  text-align: left;
  font-family: var(--sans);
  color: var(--ink-900);
  font-weight: 500;
}
.ftable tbody tr:last-child td { border-bottom: none; }
.ftable tbody tr.total td {
  border-top: 1px solid var(--ink-300);
  font-weight: 700;
  color: var(--ink-900);
  background: var(--surface-alt);
}

#ratioTable td:first-child { color: var(--ink-500); font-weight: 500; }
#ratioTable td:last-child { color: var(--ink-900); font-weight: 600; }

.dcf-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 14px;
}
.dcf-summary .stat {
  padding: 10px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.dcf-summary .stat .k { font-size: 11px; color: var(--ink-500); text-transform: uppercase; letter-spacing: 0.05em; }
.dcf-summary .stat .v { font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--ink-900); margin-top: 2px; }

.footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-400);
}

/* ---------- Auth: topbar chip ---------- */
/* The `hidden` HTML attr must win over any display rule. */
[hidden] { display: none !important; }
.auth-slot { display: flex; gap: 8px; margin-left: 8px; padding-left: 12px; border-left: 1px solid var(--line); }
.user-chip { display: inline-flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 12px; }
.user-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--positive); display: inline-block; }
.btn-block { width: 100%; justify-content: center; text-align: center; display: inline-flex; align-items: center; justify-content: center; }

/* ---------- Auth: saved panel ---------- */
.saved-panel {
  border: 1px solid var(--line);
  background: var(--surface-alt);
  border-radius: var(--radius);
  padding: 16px;
}
.saved-empty { display: flex; align-items: center; gap: 14px; }
.saved-lock {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.saved-copy { flex: 1; min-width: 0; }
.saved-title { font-weight: 600; color: var(--ink-900); font-size: 13px; }
.saved-desc { font-size: 12px; color: var(--ink-500); margin-top: 2px; }
.saved-ready { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.saved-badge {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--ink-700);
  padding: 6px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  font-family: var(--mono);
}
.saved-note { font-size: 12px; color: var(--ink-500); flex: 1; min-width: 200px; }
.saved-pill {
  font-family: var(--mono); font-size: 11px;
  padding: 4px 8px; border-radius: 999px;
  background: var(--surface); color: var(--ink-500); border: 1px solid var(--line);
}
.saved-pill.ok { background: #ecfdf5; color: var(--positive); border-color: transparent; }
.saved-pill.err { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ---------- Auth: modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 24px;
  backdrop-filter: blur(4px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface);
  width: 100%; max-width: 400px;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(15,23,42,0.25);
  padding: 24px;
  position: relative;
  animation: modalIn 0.16s ease-out;
}
.modal[hidden] { display: none; }
@keyframes modalIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.modal h3 { margin: 0 0 4px; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.modal-sub { margin: 0 0 16px; font-size: 12px; color: var(--ink-500); }
.modal-close {
  position: absolute; top: 10px; right: 12px;
  background: transparent; border: none;
  font-size: 22px; line-height: 1; color: var(--ink-400);
  cursor: pointer; padding: 4px 8px; border-radius: 4px;
}
.modal-close:hover { background: var(--surface-alt); color: var(--ink-900); }
.modal-form { display: flex; flex-direction: column; gap: 10px; }
.modal-form .field { margin-bottom: 0; }
.modal-form .field input { font-family: var(--sans); font-size: 13px; padding: 9px 11px; }
.modal-form .btn { margin-top: 4px; padding: 10px 14px; }
.modal-form .group-title { margin-bottom: 4px; }
.modal-msg {
  font-size: 12px; color: var(--ink-500); min-height: 16px;
  padding: 6px 0 0;
}
.modal-msg.ok { color: var(--positive); }
.modal-msg.err { color: var(--danger); }
.modal-alt { margin-top: 14px; font-size: 12px; color: var(--ink-500); text-align: center; }
.modal-alt a { color: var(--accent-ink); text-decoration: none; }
.modal-alt a:hover { text-decoration: underline; }
.modal-alt .dot { margin: 0 6px; color: var(--ink-300); }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; padding: 16px; }
  .headline { grid-template-columns: 1fr; }
  .range { padding-left: 0; border-left: none; padding-top: 16px; border-top: 1px solid var(--line); }
  .grid-two { grid-template-columns: 1fr; }
  .methods { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 12px; padding: 14px 16px; }
  .row, .row.three { grid-template-columns: 1fr; }
  .headline-value { font-size: 28px; }
  .dcf-summary { grid-template-columns: 1fr; }
}

/* ---------- Print (Export report) ---------- */
@media print {
  body { background: #fff; }
  .topbar, .inputs, .btn { display: none !important; }
  .app { grid-template-columns: 1fr; padding: 0; }
  .panel { border: none; box-shadow: none; }
}
