:root {
  --app-bg: #f5f5f7;
  --app-surface: #ffffff;
  --app-text: #111111;
  --app-subtle-text: #555555;
  --app-border: #dddddd;
  --app-accent: #2563eb;
  --app-error: #b91c1c;
  --app-radius: 10px;
  --app-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
  --app-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Phase-P aliases (presentation only) */
  --border: var(--app-border);
  --focus: var(--app-accent);
}

body.dark-theme {
  --app-bg: #020617;
  --app-surface: #020617;
  --app-text: #e5e7eb;
  --app-subtle-text: #9ca3af;
  --app-border: #1f2937;
  --app-accent: #60a5fa;
  --app-error: #fca5a5;
  --app-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);


  /* Phase-P aliases (presentation only) */
  --border: var(--app-border);
  --focus: var(--app-accent);
}

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

html,
body {
  margin: 0;
  padding: 0;
}

/* Enforce HTML hidden attribute reliably */
[hidden] {
  display: none !important;
}


.app-body {
  min-height: 100vh;
  background: var(--app-bg);
  color: var(--app-text);
  font-family: var(--app-font);
  display: flex;
  flex-direction: column;
}

/* Header */

.app-header {
  border-bottom: 1px solid var(--app-border);
  background: var(--app-surface);
}

.app-header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.app-title-block {
  flex: 1;
}

.app-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
}

.app-tagline {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--app-subtle-text);
}

.app-header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}



/* Phase-P: header responsiveness */
.app-header-inner {
  flex-wrap: wrap;
}

.app-header-controls {
  flex-wrap: wrap;
}

@media (max-width: 700px) {
  .app-header-inner {
    align-items: flex-start;
  }

  .app-header-controls {
    width: 100%;
    justify-content: flex-start;
    gap: 10px;
  }

  .app-inline-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }

  .app-inline-label span {
    margin-right: 0;
    white-space: nowrap;
  }
}
.app-inline-label {
  font-size: 0.85rem;
  color: var(--app-subtle-text);
}

.app-inline-label span {
  margin-right: 6px;
}

/* Layout */

.app-main {
  max-width: 1100px;
  margin: 16px auto 24px;
  padding: 0 16px;
  display: grid;
  grid-template-columns: minmax(0, 360px) minmax(0, 1fr);
  gap: 16px;

  padding-bottom: 16px;
}

@media (max-width: 980px) {
  .app-main {
    grid-template-columns: minmax(0, 1fr);
  }
}

.app-panel {
  background: var(--app-surface);
  border-radius: var(--app-radius);
  box-shadow: var(--app-shadow);
  border: 1px solid var(--app-border);
  padding: 16px 16px 20px;
}

.panel-title {
  margin: 0 0 12px;
  font-size: 1.05rem;
  font-weight: 600;
}

/* Form */

.app-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-row label,
.form-label {
  font-size: 0.88rem;
  font-weight: 500;
}

.app-input,
.app-select {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--app-border);
  background: transparent;
  color: var(--app-text);
  font: inherit;
}

.app-input:focus,
.app-select:focus {
  outline: 2px solid var(--app-accent);
  outline-offset: 1px;
}

.form-radio-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.form-radio {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.88rem;
}

.form-row-actions {
  margin-top: 4px;
}

/* Buttons */

.app-button {
  font: inherit;
  border-radius: 999px;
  padding: 6px 14px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;   /* ← FIX */
  text-align: center;        /* ← safety for non-flex cases */
}

.app-button-primary {
  background: var(--app-accent);
  color: #ffffff;
}

.app-button-primary:hover {
  filter: brightness(1.05);
}

.app-button-ghost {
  background: transparent;
  color: var(--app-text);
  border-color: var(--app-border);
}

.app-button-ghost:hover {
  background: rgba(148, 163, 184, 0.08);
}

/* Error box */

.app-error {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(185, 28, 28, 0.06);
  border: 1px solid var(--app-error);
  color: var(--app-error);
  font-size: 0.85rem;
}

/* Output */

.app-panel-output {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.output-block {
  margin-bottom: 16px;
}

.output-title {
  margin: 12px 0 6px;
  font-size: 0.98rem;
  font-weight: 600;
}

/* Tables */

.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  min-width: 520px;
}

.result-table thead {
  background: rgba(148, 163, 184, 0.14);
}

body.dark-theme .result-table thead {
  background: rgba(30, 64, 175, 0.25);
}

.result-table th,
.result-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--app-border);
  text-align: right;
}

.result-table th:first-child,
.result-table td:first-child {
  text-align: left;
}

.result-table tfoot td {
  font-weight: 600;
}

/* Mobile table fit: remove the 3rd column (Year) to avoid horizontal scrolling */
@media (max-width: 560px) {
  .result-table {
    width: 100%;
    table-layout: fixed; /* prevents a long label/value from expanding the table */
    min-width: 0; /* IMPORTANT: overrides min-width:520px so table can shrink */
  }

  .result-table th,
  .result-table td {
    padding: 8px 8px;
    font-size: 14px;
  }

  /* Let labels wrap instead of forcing a wider table */
  .result-table th:first-child,
  .result-table td:first-child {
    white-space: normal;
    word-break: break-word;
    hyphens: auto;
  }

  /* Keep numeric column readable and aligned */
.result-table th:nth-child(2),
.result-table td:nth-child(2) {
  text-align: right;
  white-space: nowrap;
  min-width: 90px;
  max-width: 130px;
  }

  /* Hide Year column on small screens */
  .result-table th:nth-child(3),
  .result-table td:nth-child(3) {
    display: none;
  }
}

@media (max-width: 560px) {
  .result-table th:first-child,
  .result-table td:first-child {
    max-width: 0; /* enables wrapping under fixed layout in some browsers */
    
  }
}


/* Footer */

.app-footer {
  margin-top: 0;
  border-top: 1px solid var(--app-border);
  background: var(--app-surface);
}

.app-footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 16px 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--app-subtle-text);
}

.footer-tools a {
  color: inherit;
  text-decoration: none;
}

.footer-tools a:hover {
  text-decoration: underline;
}

.footer-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Buy Me a Coffee (above footer) */
.bmc-footer {
  margin: auto auto 18px; /* push down, keep tight gap to footer */
  padding: 0 16px;
  text-align: center;
  background: transparent;
  border: 0;
}

.bmc-footer-button {
  display: inline-block;
  padding: 8px 16px;
  font-size: 14px;
  border-radius: 999px;
  background-color: #ffdd00;
  color: #000;
  text-decoration: none;
  font-weight: 500;
}

.bmc-footer-button:hover {
  background-color: #f2cf00;
}

/* Mobile: de-emphasize support button so it does not compete with primary CTA */
@media (max-width: 560px) {
  .bmc-footer-button {
    padding: 6px 14px;
    font-size: 13px;
    opacity: 0.80;
  }

  .bmc-footer-button:hover {
    opacity: 1;
  }
}

/* Remove number input spinners (Chrome, Edge, Safari) */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Remove number input spinners (Firefox) */
input[type=number] {
  -moz-appearance: textfield;
}


/* UI-4 result groups */
.result-group {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 10px;
}

.result-group:first-of-type {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.result-group__summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 4px;
  border-radius: 10px;
}

.result-group__summary::-webkit-details-marker {
  display: none;
}

.result-group__summary::after {
  content: '▸';
  opacity: 0.8;
  transform: rotate(0deg);
  transition: transform 120ms ease;
}

.result-group[open] > .result-group__summary::after {
  transform: rotate(90deg);
}

.result-group__summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.result-group__title {
  font-weight: 700;
  font-size: 0.98rem;
}

.result-group table {
  margin-top: 8px;
}


/* === Phase-P Option A (refined): subtle de-emphasis of Results panel until results exist (CSS-only) ===
   Goal: eliminate “active + empty + equal weight” without blur, copy, or layout shifts.
   Technique: very light contrast reduction on content blocks only (not the panel title),
   plus a slightly calmer panel surface. Automatically reverts once any result row exists.

   Note: uses :has(). In browsers without :has, UI falls back to normal full-weight panel (non-breaking).
*/
.app-panel-output {
  transition: background-color 160ms ease, border-color 160ms ease;
}
.output-block {
  transition: opacity 160ms ease, filter 160ms ease;
}

/* === Phase-P Option A2: quiet the empty results by removing table chrome === */
.app-panel-output:not(:has(.result-table tbody tr)) .result-table thead {
  background: transparent;
}
.app-panel-output:not(:has(.result-table tbody tr)) .result-table th,
.app-panel-output:not(:has(.result-table tbody tr)) .result-table td {
  border-bottom-color: transparent;
}
.app-panel-output:not(:has(.result-table tbody tr)) .result-table {
  opacity: 0.95;           /* affects table only, not title */
}

/* Blend the entire results content area (not the panel title) pre-calc */
.app-panel-output:not(:has(.result-table tbody tr)) .output-block {
  opacity: 0.80;                 /* start at 0.80; adjust 0.75–0.88 */
  filter: contrast(0.92) brightness(0.98) saturate(0.92);
}

/* Footer: keep row-1 on one line (desktop), row-2 centered */
.app-footer-inner{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap: 12px;
  flex-wrap: nowrap;
}

/* Allow wrapping only on small screens */
@media (max-width: 720px){
  .app-footer-inner{ flex-wrap: wrap; }
}

/* Row 2: centered created-by line */
.app-footer-created{
  max-width: 1100px;
  margin: 0 auto;
  padding: 6px 16px 12px;
  text-align: center;
  font-size: 11px;
  color: var(--app-subtle-text);
  line-height: 1.4;
}

.app-footer-created a{
  color: inherit;
  text-decoration: underline;
}
