/*!
 * AmortCalc styles — everything is namespaced under .amc-root, so the widget
 * can drop into an existing page without leaking styles either way.
 */

.amc-root {
  color-scheme: light;

  --amc-surface:      #fcfcfb;
  --amc-plane:        #f9f9f7;
  --amc-ink:          #0b0b0b;
  --amc-ink-2:        #52514e;
  --amc-muted:        #898781;
  --amc-line:         #e1e0d9;
  --amc-axis:         #c3c2b7;
  --amc-accent:       #2a78d6;
  --amc-accent-ink:   #ffffff;
  --amc-good:         #006300;
  --amc-warn-bg:      #fff6e6;
  --amc-warn-line:    #fab219;
  --amc-danger:       #d03b3b;
  --amc-ring:         rgba(11, 11, 11, .10);
  --amc-radius:       10px;

  /* Typography follows the host page by default. Override either var on
     .amc-root (or any ancestor) to pin a face or size:
       .amc-root { --amc-font: "Whatever", sans-serif; --amc-font-size: 16px; }
     Use `--amc-font-size: inherit` to take the page's body size as well. */
  --amc-font:         inherit;
  --amc-font-size:    15px;

  font-family: var(--amc-font);
  font-size: var(--amc-font-size);
  color: var(--amc-ink);
  background: var(--amc-surface);
  border: 1px solid var(--amc-ring);
  border-radius: var(--amc-radius);
  padding: 20px;
  line-height: 1.45;
  box-sizing: border-box;
}

/* Explicit, not `inherit`: content slotted into <details> inherits through the
   UA shadow tree, and third-party widget stylesheets on a host page routinely
   ship a global reset that outranks a bare `.amc-root *` rule. Scoped, so it
   can't leak past the widget. */
.amc-root,
.amc-root *,
.amc-root *::before,
.amc-root *::after { box-sizing: border-box !important; }

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .amc-root {
    color-scheme: dark;
    --amc-surface:    #1a1a19;
    --amc-plane:      #0d0d0d;
    --amc-ink:        #ffffff;
    --amc-ink-2:      #c3c2b7;
    --amc-muted:      #898781;
    --amc-line:       #2c2c2a;
    --amc-axis:       #383835;
    --amc-accent:     #3987e5;
    --amc-good:       #0ca30c;
    --amc-warn-bg:    #2a2410;
    --amc-danger:     #e66767;
    --amc-ring:       rgba(255, 255, 255, .12);
  }
}

:root[data-theme="dark"] .amc-root {
  color-scheme: dark;
  --amc-surface:    #1a1a19;
  --amc-plane:      #0d0d0d;
  --amc-ink:        #ffffff;
  --amc-ink-2:      #c3c2b7;
  --amc-muted:      #898781;
  --amc-line:       #2c2c2a;
  --amc-axis:       #383835;
  --amc-accent:     #3987e5;
  --amc-good:       #0ca30c;
  --amc-warn-bg:    #2a2410;
  --amc-danger:     #e66767;
  --amc-ring:       rgba(255, 255, 255, .12);
}

/* ---------------- head ---------------- */

.amc-head { margin: 0 0 16px; }

.amc-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.amc-h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

/* ---------------- form ---------------- */

.amc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 14px 16px;
}

.amc-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.amc-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--amc-ink-2);
}

.amc-hint {
  font-size: 11.5px;
  color: var(--amc-muted);
  line-height: 1.35;
}

.amc-input-wrap { position: relative; display: block; }

.amc-root input[type="text"],
.amc-root input[type="date"],
.amc-root select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: auto;
  margin: 0;
  font: inherit;
  font-size: var(--amc-font-size);
  color: var(--amc-ink);
  background: var(--amc-surface);
  border: 1px solid var(--amc-axis);
  border-radius: 8px;
  padding: 9px 11px;
  appearance: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}

.amc-root select {
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.amc-root input:focus-visible,
.amc-root select:focus-visible,
.amc-root button:focus-visible,
.amc-root summary:focus-visible {
  outline: 2px solid var(--amc-accent);
  outline-offset: 2px;
}

.amc-root .amc-pre input { padding-left: 25px; }
.amc-pre::before {
  content: "$";
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--amc-muted);
  font-size: 14px;
  pointer-events: none;
}

.amc-root .amc-post input { padding-right: 30px; }
.amc-post::after {
  content: "%";
  position: absolute;
  right: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--amc-muted);
  font-size: 14px;
  pointer-events: none;
}
.amc-post-years::after { content: "yrs"; font-size: 12px; }
.amc-root .amc-post-years input { padding-right: 42px; }

/* ---------------- advanced ---------------- */

.amc-adv {
  margin-top: 16px;
  border: 1px solid var(--amc-line);
  border-radius: 8px;
  background: var(--amc-plane);
}

.amc-adv > summary {
  cursor: pointer;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--amc-ink-2);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.amc-adv > summary::-webkit-details-marker { display: none; }

.amc-adv > summary::before {
  content: "";
  width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform .15s ease;
}

.amc-adv[open] > summary::before { transform: rotate(90deg); }

.amc-adv > .amc-grid {
  padding: 4px 14px 16px;
}

/* ---------------- actions ---------------- */

.amc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.amc-btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--amc-ink);
  background: var(--amc-surface);
  border: 1px solid var(--amc-axis);
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}

.amc-btn:hover { border-color: var(--amc-muted); }

.amc-btn-primary {
  background: var(--amc-accent);
  border-color: var(--amc-accent);
  color: var(--amc-accent-ink);
}

.amc-btn-primary:hover { filter: brightness(1.06); }

.amc-btn-sm { font-size: 12.5px; padding: 6px 11px; }

/* ---------------- error ---------------- */

.amc-error {
  margin-top: 16px;
  padding: 11px 14px;
  border-radius: 8px;
  border: 1px solid var(--amc-danger);
  color: var(--amc-danger);
  font-size: 14px;
  background: transparent;
}

/* ---------------- summary ---------------- */

.amc-results { margin-top: 24px; }

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

.amc-stat {
  background: var(--amc-surface);
  border: 1px solid var(--amc-line);
  border-radius: 10px;
  padding: 13px 15px;
}

.amc-stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--amc-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.amc-stat-value {
  margin-top: 4px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--amc-ink);
}

.amc-stat-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--amc-ink-2);
}

.amc-stat--good .amc-stat-value { color: var(--amc-good); }
.amc-stat--warn { background: var(--amc-warn-bg); border-color: var(--amc-warn-line); }

/* ---------------- charts ---------------- */

.amc-charts {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 20px;
  margin-top: 24px;
}

@media (max-width: 720px) {
  .amc-charts { grid-template-columns: minmax(0, 1fr); }
}

.amc-chart {
  margin: 0;
  min-width: 0;
  border: 1px solid var(--amc-line);
  border-radius: 10px;
  padding: 14px 14px 10px;
  background: var(--amc-surface);
}

.amc-figcap {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}

.amc-figtitle { font-size: 14px; font-weight: 600; }
.amc-figsub { font-size: 12px; color: var(--amc-muted); }

.amc-canvas-wrap { position: relative; height: 260px; }

.amc-note { font-size: 13px; color: var(--amc-ink-2); margin: 0; }

/* ---------------- schedule ---------------- */

.amc-sched { margin-top: 24px; }

.amc-sched-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.amc-sched-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.amc-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--amc-ink-2);
  font-weight: 600;
}

.amc-inline select { width: auto; font-size: 13px; padding: 6px 30px 6px 10px; }

.amc-table-wrap {
  max-height: 480px;
  overflow: auto;
  border: 1px solid var(--amc-line);
  border-radius: 10px;
}

.amc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

.amc-table th,
.amc-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--amc-line);
  white-space: nowrap;
}

.amc-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--amc-plane);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--amc-muted);
}

.amc-table tbody th { font-weight: 500; color: var(--amc-muted); }
.amc-table tbody tr:hover td,
.amc-table tbody tr:hover th { background: var(--amc-plane); }

.amc-table .amc-num { text-align: right; }

.amc-table tfoot th,
.amc-table tfoot td {
  position: sticky;
  bottom: 0;
  background: var(--amc-plane);
  font-weight: 600;
  border-top: 1px solid var(--amc-axis);
  border-bottom: none;
}

.amc-row-extra td,
.amc-row-extra th { background: color-mix(in srgb, var(--amc-accent) 7%, transparent); }

.amc-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--amc-accent);
  border: 1px solid color-mix(in srgb, var(--amc-accent) 40%, transparent);
}

.amc-more { margin-top: 10px; }

/* ---------------- print ---------------- */

@media print {
  .amc-root {
    border: none;
    padding: 0;
    font-size: 11px;
    background: #fff;
    color: #000;
  }
  .amc-adv,
  .amc-actions,
  .amc-sched-tools,
  .amc-more { display: none !important; }
  .amc-table-wrap { max-height: none; overflow: visible; border: none; }
  .amc-table thead th { position: static; }
  .amc-table tfoot th, .amc-table tfoot td { position: static; }
  .amc-charts { break-inside: avoid; }
  .amc-summary { break-inside: avoid; }
}