/* DCA Entry Planner — helles, schlichtes Dashboard, System-Fonts, keine externen Ressourcen. */

:root {
    --bg: #f4f6fa;
    --card-bg: #ffffff;
    --border: #e2e6ee;
    --border-strong: #cbd3e1;
    --text: #1b2230;
    --text-muted: #6b7688;
    --text-faint: #9aa4b5;
    --accent: #2f6df6;
    --accent-dark: #1f56d3;
    --accent-soft: #eaf1ff;
    --row-start-bg: #f7f8fb;
    --green: #1a7f47;
    --green-bg: #e6f5ec;
    --orange: #a35a06;
    --orange-bg: #fdf0dd;
    --red: #b3261e;
    --red-bg: #fceceb;
    --radius: 14px;
    --radius-sm: 8px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

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

body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

.page {
    max-width: 1220px;
    margin: 0 auto;
    padding: 28px 20px 48px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Header ---------- */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.brand h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.version {
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-size: 0.75rem;
    font-weight: 600;
}

.lead {
    margin: 10px 0 24px;
    max-width: 68ch;
    color: var(--text-muted);
}

/* ---------- Karten ---------- */

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgba(23, 33, 54, 0.04);
    padding: 20px 22px 22px;
    margin-bottom: 20px;
}

.card h2 {
    margin: 0 0 16px;
    font-size: 1rem;
    font-weight: 650;
    letter-spacing: 0.01em;
}

/* ---------- Buttons ---------- */

.btn {
    appearance: none;
    border: 1px solid var(--border-strong);
    background: #fff;
    color: var(--text);
    font: inherit;
    font-weight: 550;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color 0.12s ease, border-color 0.12s ease;
}

.btn:hover {
    background: #f2f4f8;
}

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

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

.btn:focus-visible,
.num-input:focus-visible,
.text-input:focus-visible,
.btn-delete:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-delete {
    appearance: none;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-faint);
    font-size: 1.1rem;
    line-height: 1;
    padding: 4px 9px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.btn-delete:hover {
    background: var(--red-bg);
    color: var(--red);
}

/* ---------- Eingabefelder ---------- */

.num-input {
    width: 100%;
    font-family: var(--font-mono);
    font-size: 0.95rem;
    text-align: right;
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
}

.text-input {
    width: 100%;
    font: inherit;
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
}

.num-input::placeholder,
.text-input::placeholder {
    color: var(--text-faint);
}

.num-input.is-invalid {
    border-color: var(--red);
    background: var(--red-bg);
}

.start-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    align-items: end;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field label,
.derived-label {
    font-size: 0.8rem;
    font-weight: 550;
    color: var(--text-muted);
}

.derived {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: var(--row-start-bg);
    border: 1px solid var(--border);
}

.derived-value {
    font-family: var(--font-mono);
    font-size: 0.95rem;
    text-align: right;
}

.hint {
    margin: 14px 0 0;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    background: var(--orange-bg);
    color: var(--orange);
    font-size: 0.85rem;
}

/* ---------- Tabelle ---------- */

.table-wrap {
    overflow-x: auto;
    margin: 0 -6px 16px;
    padding: 0 6px;
}

table.stages {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

table.stages th,
table.stages td {
    padding: 9px 10px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.stages thead th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-strong);
}

table.stages .col-stage {
    text-align: left;
    font-weight: 600;
    width: 1%;
}

table.stages .col-action {
    width: 1%;
    padding-left: 2px;
    padding-right: 2px;
}

table.stages .col-input {
    width: 13%;
    min-width: 120px;
}

.num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

tr.row-start {
    background: var(--row-start-bg);
    color: var(--text-muted);
}

tr.row-start .col-stage {
    color: var(--text-muted);
}

tr.is-incomplete .col-num {
    color: var(--text-faint);
}

tbody tr:last-child th,
tbody tr:last-child td {
    border-bottom: none;
}

/* Break-Even-Ampel: Farbe ist Zusatzinformation, der Wert steht immer im Klartext. */
.be-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 6px;
    font-weight: 600;
}

.be-low {
    color: var(--green);
    background: var(--green-bg);
}

.be-mid {
    color: var(--orange);
    background: var(--orange-bg);
}

.be-high {
    color: var(--red);
    background: var(--red-bg);
}

/* ---------- Zusammenfassung ---------- */

.summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin: 0;
}

.summary-item {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--row-start-bg);
}

.summary dt {
    font-size: 0.78rem;
    font-weight: 550;
    color: var(--text-muted);
}

.summary dd {
    margin: 4px 0 0;
    font-size: 1.02rem;
    font-weight: 600;
}

/* ---------- Footer ---------- */

.app-footer {
    margin-top: 8px;
    color: var(--text-faint);
    font-size: 0.8rem;
    text-align: center;
}

/* ---------- Schmale Viewports: Tabelle als Karten je Stufe ---------- */

@media (max-width: 760px) {
    .page {
        padding: 20px 14px 40px;
    }

    .table-wrap {
        overflow-x: visible;
    }

    table.stages thead {
        display: none;
    }

    table.stages,
    table.stages tbody,
    table.stages tr,
    table.stages th,
    table.stages td {
        display: block;
        width: auto;
    }

    table.stages tr {
        position: relative;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        padding: 10px 12px;
        margin-bottom: 12px;
    }

    table.stages th,
    table.stages td {
        border-bottom: none;
        padding: 4px 0;
        white-space: normal;
    }

    table.stages .col-stage {
        font-size: 0.78rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted);
        margin-bottom: 4px;
    }

    table.stages tbody td[data-label] {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
    }

    table.stages tbody td[data-label]::before {
        content: attr(data-label);
        font-family: var(--font);
        font-size: 0.8rem;
        font-weight: 550;
        color: var(--text-muted);
    }

    /* Prozentbreiten des Desktop-Layouts überschreiben — sie sind
       spezifischer als das width:auto der Block-Darstellung oben. */
    table.stages .col-stage,
    table.stages .col-input,
    table.stages .col-action {
        width: auto;
        min-width: 0;
    }

    table.stages .num-input {
        flex: 0 0 55%;
        width: 55%;
    }

    table.stages .col-action {
        position: absolute;
        top: 6px;
        right: 6px;
        padding: 0;
    }

    tr.row-start .col-action {
        display: none;
    }
}
