/* ==========================================================
   EpicTools — Compound Interest Visualizer styles
   Requires css/main.css (design tokens) to be loaded first.
   ========================================================== */

/* ──────────────────────────────────────────────────────────
   VISUALLY HIDDEN (accessible file input)
────────────────────────────────────────────────────────── */
.ci-visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ──────────────────────────────────────────────────────────
   ERROR TOAST
────────────────────────────────────────────────────────── */
.ci-error-toast {
  background: #ef4444;
  color: #fff;
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: var(--sp-4);
  animation: ci-fade-in var(--dur-fast) var(--ease);
}

@keyframes ci-fade-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ──────────────────────────────────────────────────────────
   ACTION BAR
────────────────────────────────────────────────────────── */
.ci-action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  justify-content: flex-end;
  margin-bottom: var(--sp-4);
}

/* ──────────────────────────────────────────────────────────
   BUTTONS
────────────────────────────────────────────────────────── */
.ci-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}
.ci-btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

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

.ci-btn--secondary {
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border-color: var(--color-border-solid);
}
.ci-btn--secondary:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-strong);
}

.ci-btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
  border-color: var(--color-border-solid);
}
.ci-btn--ghost:hover {
  color: var(--color-text);
  background: var(--color-bg-elevated);
}

.ci-btn--lg {
  padding: var(--sp-3) var(--sp-8);
  font-size: 1rem;
}

/* ──────────────────────────────────────────────────────────
   SCENARIO TABS
────────────────────────────────────────────────────────── */
.ci-tabs {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: var(--sp-1);
  border-bottom: 2px solid var(--color-border-solid);
  margin-bottom: 0;
  padding-bottom: 0;
  scrollbar-width: none;
}
.ci-tabs::-webkit-scrollbar { display: none; }

.ci-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid transparent;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius) var(--radius) 0 0;
  background: transparent;
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease);
  margin-bottom: -2px;
}
.ci-tab:hover {
  color: var(--color-text);
  background: var(--color-bg-elevated);
}
.ci-tab:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.ci-tab--active {
  color: var(--color-text-heading);
  background: var(--color-bg-card);
  border-color: var(--color-border-solid) var(--color-border-solid) var(--color-bg-card);
  border-bottom-color: var(--color-bg-card);
}

.ci-tab--add {
  color: var(--color-accent);
  border-style: dashed;
  border-color: var(--color-border-solid);
  margin-left: var(--sp-1);
}
.ci-tab--add:hover {
  color: var(--color-accent-hover);
  background: var(--color-accent-dim);
}

.ci-tab__name { pointer-events: none; }

.ci-tab__dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--color-accent);
  pointer-events: none;
  flex-shrink: 0;
}

.ci-tab__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  font-size: 0.875rem;
  line-height: 1;
  color: var(--color-text-subtle);
  transition: color var(--dur-fast), background var(--dur-fast);
  cursor: pointer;
  flex-shrink: 0;
}
.ci-tab__remove:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
}

/* ──────────────────────────────────────────────────────────
   SCENARIO PANELS
────────────────────────────────────────────────────────── */
.ci-panel {
  display: none;
  padding-top: var(--sp-6);
}
.ci-panel--active { display: block; }

/* ──────────────────────────────────────────────────────────
   FORM LAYOUT
────────────────────────────────────────────────────────── */
.ci-form__name-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

.ci-form__name-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.ci-form__name-input {
  flex: 1;
  max-width: 260px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border-solid);
  border-radius: var(--radius);
  color: var(--color-text-strong);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.ci-form__name-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}

.ci-form-section {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  margin-bottom: var(--sp-4);
}

.ci-form-section__title {
  font-family: var(--font-heading);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: var(--sp-4);
}

.ci-form__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4) var(--sp-5);
}
@media (max-width: 600px) {
  .ci-form__grid { grid-template-columns: 1fr; }
}

.ci-field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.ci-field__label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

.ci-form__btns {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  margin-top: var(--sp-2);
}

/* ──────────────────────────────────────────────────────────
   QUICK YEAR BUTTONS
────────────────────────────────────────────────────────── */
.ci-quick-btns {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.ci-quick-btn {
  padding: var(--sp-1) var(--sp-2);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border-solid);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.ci-quick-btn:hover {
  color: var(--color-text);
  background: var(--color-bg-hover);
}
.ci-quick-btn.active {
  background: var(--color-accent-dim);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* ──────────────────────────────────────────────────────────
   INPUT COMPONENTS
────────────────────────────────────────────────────────── */
.ci-input {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border-solid);
  border-radius: var(--radius);
  color: var(--color-text-strong);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
  -moz-appearance: textfield;
  appearance: textfield;
  box-sizing: border-box;
}
.ci-input::-webkit-inner-spin-button,
.ci-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.ci-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--shadow-focus);
}
.ci-input::placeholder { color: var(--color-text-subtle); }

/* Select keeps the native arrow */
.ci-select {
  cursor: pointer;
  -moz-appearance: auto;
  appearance: auto;
  padding-right: var(--sp-6);
}

.ci-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.ci-input-wrap--prefix .ci-input--prefix { padding-left: 2.1rem; }
.ci-input-wrap--suffix .ci-input--suffix { padding-right: 3.8rem; }
.ci-input--prefix.ci-input--suffix       { padding-left: 2.1rem; padding-right: 3.8rem; }

.ci-input-prefix,
.ci-input-suffix {
  position: absolute;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  pointer-events: none;
  user-select: none;
}
.ci-input-prefix { left: var(--sp-3); }
.ci-input-suffix { right: var(--sp-3); }

/* ──────────────────────────────────────────────────────────
   SUMMARY CARDS
────────────────────────────────────────────────────────── */
.ci-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-4);
}

.ci-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.ci-card--highlight {
  border-color: var(--color-accent);
  background: var(--color-accent-dim);
}

.ci-card--accent {
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.07);
}

.ci-card--full {
  grid-column: 1 / -1;
}

.ci-card__label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
}

.ci-card__value {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text-heading);
  line-height: 1.2;
}

.ci-card--highlight .ci-card__value { color: var(--color-accent); }
.ci-card--accent    .ci-card__value { color: #fbbf24; }

.ci-card__note {
  font-size: 0.75rem;
  color: var(--color-text-subtle);
}

/* ──────────────────────────────────────────────────────────
   CHART
────────────────────────────────────────────────────────── */
.ci-chart-section {
  padding: var(--sp-5);
}

.ci-chart-wrap {
  position: relative;
  width: 100%;
  height: 340px;
  margin-top: var(--sp-4);
}

.ci-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ──────────────────────────────────────────────────────────
   YEAR-BY-YEAR SCHEDULE TABLE
────────────────────────────────────────────────────────── */
.ci-schedule {
  margin-top: var(--sp-6);
}

.ci-schedule__title {
  font-family: var(--font-heading);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-text-heading);
  margin-bottom: var(--sp-4);
}

.ci-schedule__scroll {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.ci-schedule__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  white-space: nowrap;
}

.ci-schedule__table thead th {
  background: var(--color-bg-elevated);
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--sp-3) var(--sp-4);
  text-align: right;
  border-bottom: 1px solid var(--color-border-solid);
}
.ci-schedule__table thead th:first-child { text-align: left; }

.ci-schedule__table tbody td {
  padding: var(--sp-3) var(--sp-4);
  color: var(--color-text);
  text-align: right;
  border-bottom: 1px solid var(--color-border);
}
.ci-schedule__table tbody tr:last-child td { border-bottom: none; }
.ci-schedule__table tbody tr:hover td { background: var(--color-bg-elevated); }

.ci-schedule__year {
  text-align: left !important;
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.8125rem;
}

.ci-schedule__balance {
  font-weight: 700;
  color: var(--color-text-strong);
}

.ci-schedule__interest {
  color: var(--color-accent);
  font-weight: 600;
}

/* ──────────────────────────────────────────────────────────
   COMPARISON TABLE
────────────────────────────────────────────────────────── */
.ci-comparison {
  margin-top: var(--sp-8);
  padding-top: var(--sp-8);
  border-top: 1px solid var(--color-border);
}

.ci-comparison--hidden { display: none; }

.ci-comparison__title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text-heading);
  margin-bottom: var(--sp-5);
}

.ci-comparison__scroll {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--sp-3);
}

.ci-comparison__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  white-space: nowrap;
}

.ci-comparison__table thead th {
  background: var(--color-bg-elevated);
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--sp-3) var(--sp-5);
  text-align: right;
  border-bottom: 1px solid var(--color-border-solid);
}
.ci-comparison__table thead th:first-child { text-align: left; }

.ci-comparison__table tbody th {
  padding: var(--sp-3) var(--sp-5);
  text-align: left;
  font-weight: 500;
  color: var(--color-text-muted);
  font-size: 0.8125rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg-card);
}

.ci-comparison__table tbody td {
  padding: var(--sp-3) var(--sp-5);
  text-align: right;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}
.ci-comparison__table tbody tr:last-child th,
.ci-comparison__table tbody tr:last-child td { border-bottom: none; }

.ci-comparison__row--bold td {
  font-weight: 700;
  color: var(--color-text-strong);
}

.ci-comparison__cell--best {
  color: var(--color-accent) !important;
  font-weight: 700 !important;
  position: relative;
}
.ci-comparison__cell--best::after {
  content: ' ★';
  font-size: 0.7em;
  opacity: 0.8;
}

.ci-comparison__note {
  font-size: 0.8125rem;
  color: var(--color-text-subtle);
}

/* ──────────────────────────────────────────────────────────
   RESULTS SECTION SPACING
────────────────────────────────────────────────────────── */
.ci-results {
  margin-top: var(--sp-6);
  padding-top: var(--sp-6);
  border-top: 1px solid var(--color-border);
}

/* ──────────────────────────────────────────────────────────
   RESPONSIVE
────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .ci-cards {
    grid-template-columns: 1fr 1fr;
  }

  .ci-card__value {
    font-size: 1.25rem;
  }

  .ci-chart-wrap {
    height: 260px;
  }

  .ci-action-bar {
    justify-content: flex-start;
  }
}

@media (max-width: 420px) {
  .ci-cards {
    grid-template-columns: 1fr;
  }
}
