/* CuttingCalculator – Webversion
   Farben aus Styles/Colors.axaml, Maße aus Views/*.axaml, Controls im Stil des Avalonia-FluentTheme.
 */

@font-face {
    font-family: "Libre Franklin";
    src: url("../fonts/libre-franklin-latin-400-normal.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Libre Franklin";
    src: url("../fonts/libre-franklin-latin-700-normal.woff2") format("woff2");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* ---------- Theme-Token ---------- */
:root,
:root[data-theme="light"] {
    --background: #F5F5F5;
    --surface: rgba(221, 220, 220, 0.635);     /* #A2DDDCDC */
    --text: #000000;
    --text-accent: #969595;
    --accent: #eb680b;
    --border: #000000;

    /* BoolToColorConverter: false -> LightGray (hell) / Gray (dunkel) */
    --toggle-off: #D3D3D3;

    /* FluentTheme (Light) */
    --btn-bg: rgba(0, 0, 0, 0.2);
    --btn-bg-hover-solid: #CCCCCC;
    --btn-bg-pressed: rgba(0, 0, 0, 0.4);
    --btn-text: #000000;
    --input-hover: rgba(255, 255, 255, 0.5);
    --input-focus: #FFFFFF;
    --input-disabled-text: rgba(0, 0, 0, 0.36);
    --placeholder: rgba(0, 0, 0, 0.6);
    --popup-bg: #F9F9F9;
    --popup-border: rgba(0, 0, 0, 0.12);
    --item-hover: rgba(0, 0, 0, 0.06);
    --item-selected: rgba(0, 0, 0, 0.1);
    --dialog-bg: #FFFFFF;
    --tabbar-bg: rgba(235, 234, 234, 0.96);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.18);

    color-scheme: light;
}

/* Skalierungseinheit (--scale wird von app.js gesetzt) */
:root {
    --scale: 1;
    --u: calc(1px * var(--scale));
    /* Schriftgrößen: zusätzlich um --text-scale vergrößert gegenüber der Desktop-App */
    --text-scale: 1.2;
    --f: calc(var(--u) * var(--text-scale));
}

:root[data-theme="dark"] {
    --background: #313131;
    --surface: rgba(42, 42, 42, 0.635);        /* #A22A2A2A */
    --text: #FFFFFF;
    --text-accent: #B8B4B4;
    --accent: #eb680b;
    --border: #FFFFFF;

    --toggle-off: #808080;

    --btn-bg: rgba(255, 255, 255, 0.37);
    --btn-bg-hover-solid: #4C4A4A;
    --btn-bg-pressed: rgba(255, 255, 255, 0.4);
    --btn-text: #FFFFFF;
    --input-hover: rgba(255, 255, 255, 0.05);
    --input-focus: #1C1C1C;
    --input-disabled-text: rgba(255, 255, 255, 0.36);
    --placeholder: rgba(255, 255, 255, 0.6);
    --popup-bg: #2C2C2C;
    --popup-border: rgba(255, 255, 255, 0.12);
    --item-hover: rgba(255, 255, 255, 0.08);
    --item-selected: rgba(255, 255, 255, 0.12);
    --dialog-bg: #2B2B2B;
    --tabbar-bg: rgba(38, 36, 36, 0.96);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.5);

    color-scheme: dark;
}

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

html, body {
    margin: 0;
    height: 100%;
}

body {
    background: var(--background);
    color: var(--text);
    font-family: "Franklin Gothic Book", "Libre Franklin", "Franklin Gothic", Arial, sans-serif;
    font-size: calc(14 * var(--f));
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;           /* Desktop: alles passt in den sichtbaren Bereich */
}

[hidden] { display: none !important; }

/* Die Zeile muss auf die Fensterhöhe begrenzt sein (minmax(0, 1fr)); eine auto-Zeile würde auf die
   Inhaltshöhe wachsen und die Seite über den sichtbaren Bereich hinausschieben. */
.window {
    display: grid;
    grid-template-columns: calc(90 * var(--u)) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-stack {
    display: flex;
    flex-direction: column;
    gap: calc(20 * var(--u));
}

.btn.nav-btn {
    width: calc(75 * var(--u));
    height: calc(75 * var(--u));
    border-radius: 50%;
    padding: calc(5 * var(--u)) calc(8 * var(--u)) calc(6 * var(--u));
}

.nav-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    pointer-events: none;
}

/* ---------- Seiten-Grid (Spalten 45/55, Zeilen 10/85/5) ---------- */
.content {
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.page {
    display: grid;
    grid-template-columns: minmax(0, 45fr) minmax(0, 55fr);
    grid-template-rows: minmax(0, 10fr) minmax(0, 85fr) minmax(0, 5fr);
    height: 100%;
    overflow: hidden;
    background: var(--background);
}

.title-bar {
    grid-column: 1 / span 2;
    grid-row: 1;
    display: flex;
    align-items: center;
    padding-left: calc(70 * var(--u));
    font-size: calc(28 * var(--f));
    font-weight: 700;
    white-space: pre;
    overflow: hidden;
}

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

/* ---------- Karten ---------- */
.input-card,
.output-card {
    grid-row: 2;
    margin: calc(40 * var(--u)) calc(65 * var(--u)) calc(20 * var(--u));
    display: grid;
    row-gap: calc(10 * var(--u));
    grid-template-columns: minmax(0, 1fr);   /* Spalte nie breiter als die Karte (lange Texte) */
    min-width: 0;
    min-height: 0;
}

.input-card {
    grid-column: 1;
    border: 1px solid var(--border);
    border-radius: calc(25 * var(--u));
}

.rows-page1 { grid-template-rows: repeat(6, minmax(0, 2fr)); }
.rows-page2,
.rows-page3 { grid-template-rows: repeat(4, minmax(0, 1fr)) minmax(0, 2fr); }

.card-title {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: calc(30 * var(--u));
    min-height: 0;
    overflow: hidden;
}

.card-title.bordered { border-bottom: 1px solid var(--border); }

.h2 {
    font-size: calc(24 * var(--f));
    font-weight: 700;
}

.sub {
    font-size: calc(20 * var(--f));
    color: var(--text-accent);
}

.field {
    margin: calc(10 * var(--u)) calc(20 * var(--u));
    border: 1px solid var(--border);
    border-radius: calc(25 * var(--u));
    display: flex;
    align-items: center;
    min-height: 0;
}

.field-inner {
    flex: 1;
    margin: 0 calc(10 * var(--u));
    min-width: 0;
}

.label {
    display: block;
    font-size: calc(18 * var(--f));
    margin: 0 calc(10 * var(--u));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.field-box {
    border: 1px solid var(--border);
    border-radius: calc(10 * var(--u));
    overflow: hidden;
}

/* TextBox (Fluent, Background=Transparent, BorderThickness=0) */
.textbox {
    display: block;
    width: 100%;
    min-height: calc(44 * var(--u));
    padding: calc(8 * var(--u)) calc(6 * var(--u)) calc(8 * var(--u)) calc(12 * var(--u));
    border: 0;
    border-radius: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: calc(18 * var(--f));
    font-weight: 700;
}

.textbox::placeholder {
    color: var(--placeholder);
    opacity: 1;
}

.textbox:focus { background: var(--input-focus); }
.textbox:disabled {
    color: var(--input-disabled-text);
    cursor: default;
    -webkit-text-fill-color: var(--input-disabled-text);
}
.textbox:disabled::placeholder { color: var(--input-disabled-text); }

/* Materialform (Rund / Eckig) */
.form-row {
    margin: 0 calc(15 * var(--u));
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
}

.form-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 0;
}

.btn.form-btn {
    border-radius: calc(20 * var(--u));
    margin-top: calc(5 * var(--u));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.form-btn-left { margin-right: 2.5px; }
.form-btn-right { margin-left: 2.5px; }

.shape {
    width: calc(35 * var(--u));
    height: calc(35 * var(--u));
    flex: 0 0 auto;
    background: var(--text-accent);
    margin-right: calc(15 * var(--u));
}

.shape.circle { border-radius: 50%; }

.form-label {
    font-size: calc(20 * var(--f));
    font-weight: 400;
    color: var(--text);
    white-space: nowrap;
}

.button-row {
    margin: calc(10 * var(--u)) calc(20 * var(--u));
    display: flex;
    align-items: center;
    min-height: 0;
}

/* ---------- Buttons (Fluent) ---------- */
.btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 4px;
    background: var(--btn-bg);
    color: var(--btn-text);
    font: inherit;
    padding: calc(5 * var(--u)) calc(8 * var(--u)) calc(6 * var(--u));
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.075s ease-out;
}

.btn:active {
    background: var(--btn-bg-pressed);
    transform: scale(0.98);
}
.btn:focus-visible {
    outline: 2px solid var(--text);
    outline-offset: 1px;
}

.btn.stretch {
    width: 100%;
    height: 100%;
    border-radius: calc(20 * var(--u));
    font-size: calc(20 * var(--f));
}

.btn.bold { font-weight: 700; }
.btn.large { font-size: calc(20 * var(--f)); }

.btn.toggle { background: var(--toggle-off); }
.btn.toggle.active { background: var(--accent); }

.btn.accent {
    background: var(--accent);
    color: #FFFFFF;
}

.calc-btn {
    width: 100%;
    min-height: calc(60 * var(--u));
    border-radius: calc(20 * var(--u));
    font-size: calc(20 * var(--f));
    font-weight: 700;
}

/* Hover nur auf Geräten mit Maus – auf Touchgeräten bliebe der Button sonst grau. */
@media (hover: hover) {
    .btn:hover,
    .btn.toggle:hover,
    .btn.toggle.active:hover,
    .btn.accent:hover {
        background: var(--btn-bg-hover-solid);
        color: var(--btn-text);
    }
    .textbox:hover:not(:disabled):not(:focus),
    .dropdown-toggle:hover { background: var(--input-hover); }
}

/* ---------- Dropdown (ComboBox, Fluent) ---------- */
.dropdown {
    position: relative;
    font-weight: 700;
}

.dropdown-toggle {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: calc(44 * var(--u));
    padding: calc(8 * var(--u)) 0 calc(8 * var(--u)) calc(12 * var(--u));
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: calc(16 * var(--f));
    text-align: left;
    cursor: pointer;
}

.dropdown-toggle:focus-visible { outline: 2px solid var(--text); outline-offset: -2px; }

.dropdown-value {
    flex: 1;
    min-width: 0;                           
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dropdown-value.placeholder { color: var(--placeholder); }

.dropdown-chevron {
    flex: 0 0 calc(32 * var(--u));
    display: flex;
    justify-content: center;
}

.dropdown-chevron svg {
    width: calc(12 * var(--u));
    height: calc(12 * var(--u));
    fill: none;
    stroke: currentColor;
    stroke-width: 1.4;
}

.dropdown-list {
    position: fixed;
    z-index: 100;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    max-height: 320px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--popup-bg);
    border: 1px solid var(--popup-border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    color: var(--text);
    font-family: inherit;
    font-size: calc(16 * var(--f));
    font-weight: 700;
}

.dropdown-item {
    padding: calc(9 * var(--u)) calc(12 * var(--u));
    margin: 2px 4px;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
}

.dropdown-item.focused { background: var(--item-hover); }
.dropdown-item.selected { background: var(--item-selected); }

/* Haftungshinweis unter den Ergebnissen */
.disclaimer {
    margin-top: calc(6 * var(--u));
    font-size: calc(15 * var(--f));
    font-weight: 400;
    line-height: 1.3;
}

/* ---------- Ausgabeseite ---------- */
.output-card {
    grid-column: 2;
    grid-template-rows: repeat(4, minmax(0, 2fr)) minmax(0, 1.7fr) minmax(0, 1.3fr);
}

.tile-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    min-height: 0;
}

.tile {
    margin: calc(10 * var(--u)) calc(20 * var(--u));
    border: 1px solid var(--border);
    border-radius: calc(25 * var(--u));
    padding: calc(5 * var(--u));
    display: grid;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    min-width: 0;
    min-height: 0;
}

.tile-row.first .tile {
    margin-top: 0;
    margin-bottom: 0;
}

.tile.span-2 { grid-column: 1 / span 2; }

.tile-label {
    margin-left: calc(10 * var(--u));
    font-size: calc(18 * var(--f));
    color: var(--text-accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bold-labels .tile-label { font-weight: 700; }

.tile-value {
    text-align: center;
    font-size: calc(22 * var(--f));
    font-weight: 700;
    white-space: pre-line;
    overflow: hidden;
}

.tile-value.copy { cursor: pointer; }

.note {
    margin: calc(-10 * var(--u)) 0 0 calc(30 * var(--u));
    font-size: calc(20 * var(--f));
    font-weight: 700;
    color: var(--text-accent);
    overflow: hidden;
    min-height: 0;
}

.logo-row {
    min-height: 0;
    display: flex;
}

.logo-row img {
    width: 100%;
    height: 100%;
    min-height: 0;
    object-fit: contain;
    object-position: center bottom;
    display: block;
}

/* Fußzeile Seite 3 (Grid.Column/Row außerhalb des Bereichs -> letzte Spalte/Zeile) */
.page-footer {
    grid-column: 2;
    grid-row: 3;
    align-self: end;
    justify-self: center;
    display: flex;
    gap: calc(10 * var(--u));
    font-size: calc(18 * var(--f));
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
}

/* ---------- MessageBox ---------- */
.msgbox {
    padding: 0;
    border: 1px solid var(--popup-border);
    border-radius: 8px;
    background: var(--dialog-bg);
    color: var(--text);
    box-shadow: var(--shadow);
    width: min(420px, calc(100vw - 32px));
    font-family: inherit;
}

.msgbox::backdrop { background: rgba(0, 0, 0, 0.3); }

.msgbox-title {
    padding: 8px 12px;
    font-size: 18px;
    border-bottom: 1px solid var(--popup-border);
}

.msgbox-body {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
}

.msgbox-icon {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
}

.msgbox-text {
    margin: 0;
    font-size: 18px;
    white-space: pre-line;
}

.msgbox-footer {
    display: flex;
    justify-content: flex-end;
    padding: 0 15px 15px;
}

.msgbox-ok {
    min-width: 80px;
    min-height: 32px;
    font-size: 18px;
    border-radius: 4px;
}

/* =====================================================================
   Mobil-Layout (Smartphones hoch oder quer)
   App-artig: Kopfzeile, gestapelte Karten, Tab-Leiste unten.
   ===================================================================== */
@media (max-width: 760px), (max-height: 500px) {
    :root { --u: 1px; --text-scale: 1; }

    body {
        overflow: visible;
        font-size: 14px;
    }

    .window {
        display: block;
        height: auto;
        min-height: 100dvh;
        overflow: visible;
        padding-bottom: calc(72px + env(safe-area-inset-bottom));
    }

    /* Tab-Leiste unten */
    .sidebar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 50;
        background: var(--tabbar-bg);
        border-top: 1px solid var(--popup-border);
        backdrop-filter: blur(8px);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .nav-stack {
        flex-direction: row;
        justify-content: space-around;
        width: 100%;
        max-width: 420px;
        gap: 0;
        padding: 8px 16px;
    }

    .btn.nav-btn {
        width: 56px;
        height: 56px;
        padding: 12px;
        background: transparent;
    }

    .btn.nav-btn.current { background: var(--accent); }
    .nav-btn.current img { filter: brightness(0) invert(1); }

    .content { overflow: visible; }

    .page {
        display: flex;
        flex-direction: column;
        gap: 16px;
        height: auto;
        overflow: visible;
        padding: 0 16px 16px;
    }

    .title-bar {
        position: sticky;
        top: 0;
        z-index: 40;
        margin: 0 -16px;
        padding: 14px 16px 12px;
        padding-top: calc(14px + env(safe-area-inset-top));
        font-size: 20px;
        white-space: normal;
        flex-wrap: wrap;
        background: var(--background);
        border-bottom: 1px solid var(--popup-border);
    }
    .title-bar span { white-space: pre; }

    .input-card,
    .output-card {
        display: flex;
        flex-direction: column;
        gap: 12px;
        margin: 0;
    }

    .input-card {
        border-radius: 20px;
        padding-bottom: 16px;
    }

    .card-title { padding: 14px 20px; }
    .output-card .card-title { padding: 4px 4px 0; }
    .output-card .card-title .sub { display: none; }
    .h2 { font-size: 18px; }
    .sub { font-size: 15px; }

    .field {
        margin: 0 16px;
        border-radius: 18px;
    }
    .field-inner { margin: 10px 12px; }
    .label { font-size: 15px; margin: 0 4px 6px; }

    /* 16px verhindert das automatische Zoomen von iOS beim Fokussieren */
    .textbox,
    .dropdown-toggle {
        min-height: 44px;
        font-size: 16px;
    }
    .textbox { padding: 8px 10px; }
    .dropdown-toggle { padding: 8px 0 8px 12px; }

    .dropdown-list { font-size: 15px; max-height: 60vh; }
    .dropdown-item { padding: 12px 14px; }

    .form-row { margin: 0 16px; }
    .form-row .label { margin: 0 4px 6px; }
    .form-buttons { gap: 8px; }
    .btn.form-btn { min-height: 60px; margin: 0; border-radius: 16px; }
    .form-btn-left,
    .form-btn-right { margin: 0; }
    .shape { width: 28px; height: 28px; margin-right: 12px; }
    .form-label { font-size: 16px; }

    .button-row { margin: 0 16px; }
    .button-row:empty { display: none; }
    .btn.stretch { min-height: 52px; border-radius: 16px; font-size: 15px; }
    .calc-btn { min-height: 56px; border-radius: 16px; font-size: 17px; }

    /* Ergebnisse als kompaktes 2-Spalten-Raster */
    .output-card { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
    .output-card > .card-title,
    .output-card > .note,
    .output-card > .logo-row { grid-column: 1 / -1; }
    .tile-row { display: contents; }
    .tile-row.empty { display: none; }

    .tile,
    .tile-row.first .tile {
        margin: 0;
        min-height: 76px;
        padding: 10px 12px;
        border-radius: 16px;
        grid-template-rows: auto 1fr;
        gap: 6px;
    }
    .tile.span-2 { grid-column: 1 / -1; }
    .tile-label { margin: 0; font-size: 12px; white-space: normal; overflow-wrap: anywhere; }
    .tile-value { font-size: 17px; align-self: center; overflow-wrap: anywhere; }

    .note { margin: 2px 4px 0; font-size: 14px; }
    .disclaimer { font-size: 12px; margin-top: 6px; }
    .logo-row { justify-content: center; padding: 8px 24px 0; }
    .logo-row img { height: auto; max-width: 320px; }

    .page-footer {
        flex-direction: column;
        align-items: center;
        gap: 4px;
        white-space: normal;
        font-size: 13px;
        text-align: center;
    }
}

/* Sehr kleine Displays (z. B. 320 px): Ergebnisse einspaltig */
@media (max-width: 360px) {
    .output-card { grid-template-columns: 1fr; }
    .tile.span-2 { grid-column: 1; }
}

/* Smartphone quer: zwei Spalten nebeneinander, damit weniger gescrollt werden muss */
@media (max-height: 500px) and (min-width: 640px) {
    .page {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }
    .title-bar,
    .page-footer { grid-column: 1 / -1; }
}
