/* ============================================================
   Entnahmeplan – lokale Stile (nur echte Eigenheiten)
   ------------------------------------------------------------
   Geteiltes Layout in lib/tokens.css + lib/components/*.
   Hier nur was es in den anderen Rechnern nicht gibt:
     - Anlageart Depot/Zinskonto + Steuermodus vor/nach (Segmented)
     - Vorabpauschale-Toggle innerhalb der Steuerfelder
     - Steuermodell-Erklärung am Seitenende
     - Kombinierte Tabellen-Spalten "Gesamt + Monatlich"
     - Eingabefelder 200px (statt 180px im Sparrechner)
     - Sticky Summary Bar
     - Tabellen-Header-Themes + Tax-Tooltip-Portal
   ============================================================ */

/* Eingabefelder: gleiche Breite wie im Sparrechner (--field-w aus
   tokens.css = 180px). Die Inputs-Spalte selbst bleibt 520px breit. */
#withdrawal-app{
  --w-inputs-max: 520px;
}

/* form-grid + Tabelle sollen die volle Breite der form-card einnehmen,
   damit der Eingabebereich nicht im breiten Container "verloren rechts"
   wirkt. Die Komponente setzt form-grid auf width:fit-content (Inhalts-
   breite), was bei wenigen schmalen Feldern eine sehr schmale Tabelle
   ergibt. Hier mit width:100% in linke Hälfte gezogen, Tabelle 100%,
   Inputs-Spalte nutzt den Rest. */
#withdrawal-app .form-grid{
  width: 100%;
  max-width: 100%;
  margin: 0;
}
#withdrawal-app .w-form-table{
  width: 100%;
}
#withdrawal-app .w-form-table .w-col-inputs{
  width: auto;
}

/* Kleinere Felder für Zinssatz und Laufzeit (Zahlenwert reicht klein) */
#withdrawal-app .w-form-table input#w_rate,
#withdrawal-app .w-form-table input#w_term{
  width:80px;
  max-width:80px;
  flex:0 0 80px;
}

/* Eingabespalte bei aktiver Steuer breiter (für ausgefahrene Steuer-Chips) */
@media (min-width: 900px) and (max-width: 1099px){
  #withdrawal-app:has(#w_taxEnabled:checked){
    --w-inputs-max: 880px;
  }
}
@media (min-width: 1100px){
  #withdrawal-app{
    --w-inputs-max: min(1000px, 100%);
  }
}

/* Steuerfeld-Variante: Entnahmeplan setzt die Tax-Spalten-Breite */
#withdrawal-app{
  --tax-col-min: 110px;
  --tax-col-max: 110px;
}

/* Vorabpauschale-Toggle ist breiter als ein Zahlfeld */
#withdrawal-app .w-tax-fields > .w-tax-field--toggle{
  width: auto;
  min-width: 160px;
  max-width: none;
  display: flex;
  align-items: center;
}

/* "vor/nach Steuern"-Toggle: gedimmt, wenn Steuern aus */
#withdrawal-app:not(:has(#w_taxEnabled:checked)) .w-pmttax-segmented{
  opacity: 0.45;
  pointer-events: none;
}


/* ============================================================
   Anlageart + Steuermodus: Segmented Control
   (Depot/Zinskonto, vor/nach Steuern)
   ============================================================ */
#withdrawal-app .w-assettype-segmented{
  display: inline-flex;
  margin-left: 8px;
  flex-shrink: 0;
  border: 1px solid var(--br);
  border-radius: 8px;
  overflow: hidden;
}
#withdrawal-app .w-assettype-btn{
  padding: 5px 13px;
  min-width: 96px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  background: transparent;
  color: var(--txt);
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
#withdrawal-app .w-assettype-btn + .w-assettype-btn{
  border-left: 1px solid var(--br);
}
#withdrawal-app .w-assettype-btn.is-active{
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
#withdrawal-app .w-assettype-btn:hover:not(.is-active){
  background: rgba(128,128,128,0.12);
}


/* ============================================================
   Sonstige Layout-Anpassungen
   ============================================================ */

/* Szenarien-Button ausblenden (Entnahmeplan hat keinen Szenarien-Dialog) */
#withdrawal-app .addons-scenarios-open{
  display:none;
}

/* Tabellen-Header light theme: weiß statt orange (Default ist im
   Light-Mode hellgrau, hier zur Card-Farbe für klarere Trennung) */
:root:not([data-theme="dark"]) #withdrawal-app #yearTable thead,
:root:not([data-theme="dark"]) #withdrawal-app #yearTable thead tr,
:root:not([data-theme="dark"]) #withdrawal-app #yearTable thead th,
:root:not([data-theme="dark"]) #withdrawal-app #yearTable thead th:first-child,
:root:not([data-theme="dark"]) #withdrawal-app #fsSummaryTable thead,
:root:not([data-theme="dark"]) #withdrawal-app #fsSummaryTable thead tr,
:root:not([data-theme="dark"]) #withdrawal-app #fsSummaryTable thead th,
:root:not([data-theme="dark"]) #withdrawal-app #fsSummaryTable thead th:first-child{
  background-color: var(--card);
  background-image: none;
  color: var(--muted);
}


/* ============================================================
   Tabellen: Spaltenbreiten + Header-Umbruch
   ============================================================ */
#withdrawal-app .table-scroll{
  overflow-x: auto;
}
#withdrawal-app #yearTable{
  table-layout: auto;
  width: max-content;
  min-width: 100%;
}
#withdrawal-app #yearTable td,
#fsSummaryTable td{
  white-space: nowrap;
  width: max-content;
}
#withdrawal-app #yearTable th,
#fsSummaryTable th{
  white-space: nowrap;
  width: max-content;
  overflow-wrap: normal;
  word-break: keep-all;
}
#withdrawal-app #yearTable th .w-th-br,
#withdrawal-app #yearTable th br.w-th-br,
#fsSummaryTable th .w-th-br,
#fsSummaryTable th br.w-th-br{
  display: none;
}
@media (max-width: 900px){
  #withdrawal-app #yearTable th,
  #fsSummaryTable th{
    white-space: normal;
    width: auto;
  }
  #withdrawal-app #yearTable th br.w-th-br,
  #fsSummaryTable th br.w-th-br{
    display: block;
    line-height: 0;
  }
}


/* ============================================================
   Kombinierte Spalten (Gesamt + Monatlich nebeneinander)
   Auch im Sticky-Summary-Bar verwendet (per JS in <body> verschoben)
   ============================================================ */
#withdrawal-app .w-td-combined,
#fsStickySummaryBar .w-td-combined{
  white-space: nowrap;
  text-align: right;
}
#withdrawal-app .w-val-main,
#withdrawal-app .w-val-sub,
#fsStickySummaryBar .w-val-main,
#fsStickySummaryBar .w-val-sub{
  display: inline-block;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#withdrawal-app .w-val-sub,
#fsStickySummaryBar .w-val-sub{
  margin-left: 10px;
  opacity: 0.55;
  font-size: 0.875em;
}


/* ============================================================
   Diagramm-Tooltips (chart-tooltip Layout)
   ============================================================ */
#withdrawal-app .chart-tooltip .tt-box,
#withdrawal-app .chart-tooltip .tt-grid{
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
}
#withdrawal-app .chart-tooltip .tt-box .tt-k{ opacity: .88; }
#withdrawal-app .chart-tooltip .tt-box .tt-v,
#withdrawal-app .chart-tooltip .tt-grid .tt-v{
  text-align: right;
  white-space: nowrap;
}
#withdrawal-app .chart-tooltip .tt-grid .tt-kv{ display: contents; }


/* ============================================================
   Steuer-Tooltip (Tabelle): Portal in document.body
   ============================================================ */
#withdrawal-app td.w-tax-col{ white-space: nowrap; }
#withdrawal-app .ep-tax-tip{
  display: inline;
  cursor: help;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  text-decoration-thickness: from-font;
  font-variant-numeric: tabular-nums;
}
#withdrawal-app .ep-tax-tip:focus{
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

:root{ --ep-tax-tooltip-width: 560px; }

.bacap-tip-portal.ep-tooltip{
  box-sizing: border-box;
  position: fixed;
  z-index: 2147483647;
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.35);
  background: var(--card);
  color: var(--txt);
  border: 1px solid var(--br);
  pointer-events: auto;
}

#ep-tax-tooltip-portal.ep-tax-tooltip{
  box-sizing: border-box;
  position: fixed;
  z-index: 2147483647;
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.35);
  background: var(--card);
  color: var(--txt);
  border: 1px solid var(--br);
  pointer-events: auto;
  width: var(--ep-tax-tooltip-width, 560px);
  max-width: min(var(--ep-tax-tooltip-width, 560px), calc(100vw - 24px));
  max-height: min(78vh, calc(100vh - 24px));
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 900px){
  #ep-tax-tooltip-portal.ep-tax-tooltip{
    max-width: min(var(--ep-tax-tooltip-width, 560px), calc(100vw - 40px));
    max-height: none;
    overflow: visible;
  }
}

.bacap-tip-portal{ z-index: 2147483647; }
.bacap-tip-portal.w-tax-pop{ z-index: 2147483647; }

.chart-tooltip.tt-overlay{
  position: fixed;
  z-index: 9999;
  pointer-events: auto;
  max-height: min(70vh, 520px);
  overflow: auto;
}

/* Steuer-Tooltip-Inhalt */
.ep-tax-tipbox{ display:block; }
.ep-tax-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.ep-tax-title{ font-weight: 800; line-height: 1.15; }
.ep-tax-total{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap: 2px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ep-tax-total span{ font-size: 12px; opacity: .75; }
.ep-tax-total b{ font-size: 14px; }

.ep-tax-meta{
  display:flex;
  flex-wrap:wrap;
  gap: 8px;
  margin: 6px 0 10px 0;
}
.ep-tax-chip{
  display:inline-flex;
  gap: 6px;
  align-items:baseline;
  padding: 6px 8px;
  border: 1px solid var(--br);
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  font-size: 12px;
  line-height: 1.1;
}
.ep-tax-chip b{ font-variant-numeric: tabular-nums; }

.ep-tax-section{
  border: 1px solid var(--br);
  border-radius: 12px;
  background: rgba(255,255,255,0.05);
  padding: 10px;
  margin: 10px 0;
}
.ep-tax-section-h{
  font-weight: 800;
  font-size: 12px;
  opacity: .85;
  margin: 0 0 8px 0;
  letter-spacing: .02em;
}

.ep-tax-grid{ display:block; }
.ep-tax-row{
  display:grid;
  grid-template-columns: minmax(130px, 1.25fr) repeat(3, minmax(90px, 1fr));
  gap: 8px;
  align-items: start;
  padding: 6px 0;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.ep-tax-row:first-child{ border-top: none; padding-top: 0; }
.ep-tax-row--h{
  font-size: 12px;
  opacity: .8;
  font-weight: 700;
}
.ep-tax-row--sum{ font-weight: 800; }
.ep-tax-num{ text-align: right; font-variant-numeric: tabular-nums; }
.ep-tax-num--ded{ opacity: .9; }

@media (max-width: 520px){
  .ep-tax-row{ grid-template-columns: 1fr; gap: 4px; }
  .ep-tax-row--h{ display:none; }
  .ep-tax-num{ text-align: left; }
}

.ep-tax-note{
  margin-top: 8px;
  font-size: 12px;
  opacity: .85;
  line-height: 1.25;
}
.ep-tax-foot{
  margin-top: 8px;
  font-size: 12px;
  opacity: .85;
}


/* ============================================================
   Steuer-Erklärungs-Sektion am Seitenende
   ============================================================ */
#w_tax_explain{
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--br);
  border-radius: 14px;
  background: var(--card);
  color: var(--txt);
}
#w_tax_explain.is-hidden{ display:none; }
#w_tax_explain h3{ margin: 0 0 8px 0; font-size: 16px; }
#w_tax_explain p{ margin: 8px 0; line-height: 1.35; }
#w_tax_explain ul{ margin: 8px 0 8px 18px; padding: 0; }
#w_tax_explain li{ margin: 6px 0; }
#w_tax_explain .w-tax-explain-hint{ opacity: .9; }


/* ============================================================
   Mobile-Anpassungen (Entnahmeplan-spezifisch)
   Das normale Stack-Layout kommt aus form-table.css;
   hier nur Entnahmeplan-eigene Felder.
   ============================================================ */
@media (max-width: 760px){
  #withdrawal-app .w-assettype-segmented,
  #withdrawal-app .w-decay-toggle{
    margin-left: 0;
    margin-top: 6px;
    flex: 1 1 100%;
    width: 100%;
  }
  #withdrawal-app .w-assettype-btn{
    flex: 1 1 0;
    text-align: center;
  }
}
