/* Tool-specific layout on top of site.css (light system) */

.tool-page {
  padding-bottom: 1rem;
  max-width: 100%;
  min-width: 0;
  overflow-x: clip;
  box-sizing: border-box;
}
.tool-hero { padding: 1.5rem 0 0.85rem; }
.tool-hero h1 {
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}
.tool-hero .lede {
  font-size: 0.98rem;
  max-width: 52ch;
  overflow-wrap: break-word;
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 0.85rem;
  align-items: start;
  max-width: 100%;
  min-width: 0;
}
.tool-grid > * {
  min-width: 0;
  max-width: 100%;
}
@media (max-width: 900px) {
  .tool-grid { grid-template-columns: minmax(0, 1fr); }
}

.stack {
  display: grid;
  gap: 0.75rem;
  min-width: 0;
  max-width: 100%;
}

/* Compact assumptions form */
#model-form.panel {
  padding: 1rem 1.05rem 1.1rem;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}
#model-form h2 { font-size: 1rem; margin-bottom: 0.55rem; }

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0 0 0.55rem;
  padding: 0.5rem 0.6rem 0.55rem;
  background: var(--bg-2);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.35rem 0.55rem;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
fieldset label {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 550;
  margin-bottom: 0; /* override site.css label margin */
  min-width: 0;
  max-width: 100%;
}
fieldset input {
  font: inherit;
  font-size: 0.88rem;
  color: var(--text);
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
legend {
  padding: 0 0.3rem;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 650;
  grid-column: 1 / -1;
}

.actions { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.25rem; }
.actions .btn { padding: 0.5rem 0.9rem; font-size: 0.88rem; }
.hint { color: var(--warn); font-size: 0.82rem; margin: 0.45rem 0 0; }
.fine { color: var(--muted); font-size: 0.78rem; margin: 0.5rem 0 0; }
.ok { color: var(--accent); font-size: 0.85rem; font-weight: 600; margin: 0.4rem 0 0; }

/* —— Results (compact) —— */
.results.panel {
  padding: 0.9rem 1rem 1rem;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}
.results h2 {
  font-size: 1rem;
  margin: 0 0 0.55rem;
}
.results-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem 0.75rem;
  margin-bottom: 0.45rem;
}
.results-head h2 { margin: 0; min-width: 0; }
.lock-note {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 550;
  flex: 1 1 auto;
  text-align: right;
  min-width: 0;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.4rem;
  margin-bottom: 0.55rem;
  max-width: 100%;
}
/* Half-width results column: 4 KPIs spill — drop to 2 early */
@media (max-width: 1100px) {
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 420px) {
  .kpi-row { grid-template-columns: minmax(0, 1fr); }
}
.kpi {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.5rem 0.5rem;
  min-width: 0;
  overflow: hidden;
}
.kpi span {
  display: block;
  color: var(--muted);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.2;
  padding-right: 2.4rem; /* room for lock badge */
  overflow-wrap: anywhere;
}
.kpi strong {
  display: block;
  font-size: clamp(0.78rem, 1.6vw, 0.95rem);
  color: var(--text);
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
  padding-right: 0.15rem;
}
.kpi-soft strong {
  font-size: clamp(0.78rem, 1.5vw, 0.88rem);
  font-weight: 650;
  color: var(--text-2);
}
.kpi-lock {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  font-size: 0.55rem;
  font-style: normal;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  opacity: 0.8;
  line-height: 1;
  max-width: 40%;
  text-align: right;
}

.chart-wrap {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem;
  margin-bottom: 0.55rem;
  overflow: hidden;
  max-width: 100%;
  min-width: 0;
}
.chart-wrap canvas {
  width: 100% !important;
  max-width: 100%;
  height: 168px;
  display: block;
}

/* Gated table */
.table-shell {
  position: relative;
  margin-bottom: 0.15rem;
  max-width: 100%;
  min-width: 0;
}
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 11.5rem;
  overflow-y: auto;
  max-width: 100%;
}
.results.is-locked .table-wrap {
  max-height: 7.5rem;
  filter: blur(3.5px);
  user-select: none;
  pointer-events: none;
  opacity: 0.72;
}
.table-veil {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1;
  padding: 0.5rem;
  box-sizing: border-box;
}
.results.is-locked .table-veil {
  display: flex;
}
.table-veil span {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 650;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  text-align: center;
  max-width: min(100%, 16rem);
  line-height: 1.3;
}

#month-table {
  width: 100%;
  min-width: 28rem; /* scroll inside .table-wrap instead of page spill */
  border-collapse: collapse;
  font-size: 0.78rem;
}
#month-table th,
#month-table td {
  padding: 0.32rem 0.45rem;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
  color: var(--text);
}
#month-table th:first-child,
#month-table td:first-child { text-align: left; }
#month-table th {
  color: var(--muted);
  font-weight: 600;
  background: var(--bg-2);
  position: sticky;
  top: 0;
  z-index: 1;
}
#month-table tbody tr:last-child td { border-bottom: 0; }
#month-table tbody tr:nth-child(even) td { background: var(--panel-2); }
.masked-row td:not(:first-child) {
  letter-spacing: 0.08em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.suggestions {
  margin: 0.55rem 0 0;
  padding-left: 1rem;
  color: var(--muted);
  font-size: 0.82rem;
}
.suggestions li { margin-bottom: 0.25rem; }
.suggestions li strong { color: var(--warn); }

/* Compact gate */
.gate.panel {
  padding: 0.85rem 1rem 0.95rem;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}
.gate h2 { font-size: 0.95rem; margin: 0 0 0.35rem; overflow-wrap: anywhere; }
.gate > .muted {
  margin: 0 0 0.55rem;
  font-size: 0.82rem;
  line-height: 1.4;
  overflow-wrap: break-word;
}
.gate.is-unlocked h2 { margin-bottom: 0.45rem; }
.gate label {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 550;
  margin-bottom: 0.4rem;
  min-width: 0;
  max-width: 100%;
}
.gate input[type="email"],
.gate input[type="text"] {
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.gate .check {
  flex-direction: row;
  align-items: flex-start;
  gap: 0.45rem;
  font-size: 0.78rem;
  line-height: 1.35;
}
.gate .check input {
  margin-top: 0.15rem;
  flex-shrink: 0;
}
.gate .btn {
  margin-top: 0.15rem;
  padding: 0.5rem 0.9rem;
  font-size: 0.88rem;
  max-width: 100%;
}

.about.panel {
  padding: 0.9rem 1rem;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.about h2 { font-size: 1rem; }
.about p {
  margin: 0 0 0.55rem;
  font-size: 0.88rem;
  overflow-wrap: break-word;
}

/* —— Tablet + phone: no iOS focus-zoom, real tap targets —— */
@media (max-width: 900px) {
  fieldset input {
    font-size: 16px;
    min-height: 44px;
  }
  .actions .btn,
  .gate .btn {
    min-height: 44px;
  }
  .gate input[type="email"],
  .gate input[type="text"] {
    font-size: 16px;
    min-height: 44px;
  }
}

/* —— Mobile —— */
@media (max-width: 640px) {
  .tool-hero { padding: 1.15rem 0 0.65rem; }
  .tool-hero .lede { font-size: 0.94rem; max-width: none; }

  fieldset {
    grid-template-columns: minmax(0, 1fr);
    padding: 0.55rem 0.65rem 0.6rem;
  }
  fieldset input {
    font-size: 16px;
    min-height: 44px;
    padding: 0.5rem 0.55rem;
  }

  .actions {
    flex-direction: column;
  }
  .actions .btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .results-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
  }
  .lock-note {
    font-size: 0.7rem;
    text-align: left;
  }

  .kpi-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.35rem;
  }

  .chart-wrap canvas {
    height: 150px;
  }

  .table-veil span {
    font-size: 0.72rem;
    padding: 0.35rem 0.6rem;
  }

  /* Wide month table stays inside shell — never page-level spill */
  .table-shell,
  .table-wrap {
    max-width: 100%;
    min-width: 0;
  }
  #month-table {
    min-width: 26rem;
  }

  .gate input[type="email"],
  .gate input[type="text"] {
    font-size: 16px;
    min-height: 44px;
  }
  .gate .btn {
    width: 100%;
    min-height: 44px;
  }
}

@media (max-width: 380px) {
  .kpi-row { grid-template-columns: minmax(0, 1fr); }
  #month-table {
    min-width: 24rem;
    font-size: 0.74rem;
  }
}
