:root {
    --brand-orange: #D44F16;
    --brand-orange-dark: #B33F10;
    --brand-black: #1A1A1A;
    --bg: #F4F4F2;
    --card-bg: #FFFFFF;
    --border: #E3E1DC;
    --text: #262421;
    --text-muted: #7A756D;
    --radius: 14px;
    --shadow: 0 2px 10px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.app {
    max-width: 560px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg);
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background: var(--brand-black);
    color: #fff;
    padding: 18px 20px 16px;
    border-bottom: 4px solid var(--brand-orange);
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-header .logo-badge {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--brand-orange);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 18px;
    margin: 0;
    font-weight: 700;
}

.app-header p {
    margin: 2px 0 0;
    font-size: 12.5px;
    color: #cfcfcf;
}

/* Content */
.app-content {
    flex: 1;
    padding: 18px 16px 40px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 16px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
}

.card h2 {
    font-size: 15px;
    margin: 0 0 14px;
    color: var(--brand-orange);
    text-transform: uppercase;
    letter-spacing: .04em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.field {
    margin-bottom: 14px;
}

.field label {
    display: block;
    font-size: 12.5px;
    color: var(--text-muted);
    margin-bottom: 5px;
    font-weight: 600;
}

.field input[type="text"],
.field input[type="tel"],
.field input[type="date"],
.field input[type="time"],
.field input[type="number"],
.field input[type="password"],
.field input[type="email"],
.field textarea,
.field select {
    width: 100%;
    padding: 11px 12px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    background: #fff;
    color: var(--text);
    font-family: inherit;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    outline: none;
    border-color: var(--brand-orange);
}

.field textarea {
    min-height: 130px;
    resize: vertical;
    line-height: 1.5;
}

.field textarea.textarea-lg {
    min-height: 240px;
}

.row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 2px;
}

.switch-row .switch-label {
    font-size: 14px;
    font-weight: 600;
}

.switch {
    position: relative;
    width: 46px;
    height: 26px;
    flex-shrink: 0;
}

.switch input { display: none; }

.switch .slider {
    position: absolute;
    inset: 0;
    background: #d8d5cf;
    border-radius: 999px;
    transition: .2s;
    cursor: pointer;
}

.switch .slider::before {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: .2s;
    box-shadow: 0 1px 3px rgba(0,0,0,.3);
}

.switch input:checked + .slider {
    background: var(--brand-orange);
}

.switch input:checked + .slider::before {
    transform: translateX(20px);
}

/* Summary box */
.summary-box {
    background: #FBF3EE;
    border: 1.5px solid #F0D9C9;
    border-radius: 10px;
    padding: 14px;
}

.summary-line {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    padding: 5px 0;
    color: var(--text);
}

.summary-line.total {
    font-weight: 700;
    font-size: 17px;
    color: var(--brand-orange-dark);
    border-top: 1.5px dashed #E3C4A8;
    margin-top: 6px;
    padding-top: 10px;
}

.checkbox-line {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 0;
    font-size: 13.5px;
}

.checkbox-line input {
    margin-top: 3px;
    width: 18px;
    height: 18px;
    accent-color: var(--brand-orange);
}

/* Signature pads */
.sig-wrap {
    border: 1.5px dashed var(--border);
    border-radius: 10px;
    background: #fff;
    position: relative;
}

.sig-wrap canvas {
    width: 100%;
    height: 150px;
    display: block;
    touch-action: none;
}

.sig-clear {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 11.5px;
    padding: 5px 8px;
    color: var(--text-muted);
    cursor: pointer;
}

/* Footer nav */
.btn-save {
    width: 100%;
    margin-top: 6px;
}

.btn {
    flex: 1;
    padding: 14px;
    border-radius: 12px;
    border: none;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
}

.btn-primary {
    background: var(--brand-orange);
    color: #fff;
}

.btn-primary:active { background: var(--brand-orange-dark); }

.btn-secondary {
    background: #EFEDE8;
    color: var(--text);
    flex: 0 0 110px;
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* Success screen */
.success-screen {
    display: none;
    text-align: center;
    padding: 60px 24px;
}

.success-screen.active { display: block; }

.success-icon {
    width: 74px;
    height: 74px;
    border-radius: 50%;
    background: var(--brand-orange);
    color: #fff;
    font-size: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 18px;
}

.success-screen h2 {
    font-size: 19px;
    margin: 0 0 8px;
}

.success-screen p {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0 0 26px;
}

.hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.error-banner {
    background: #FCE9E4;
    border: 1px solid #EFB8A7;
    color: #9B3213;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    margin-bottom: 14px;
    display: none;
}

.error-banner.show { display: block; }

/* Übersicht / liste.php */
.list-item { padding: 14px 16px; }

.list-item-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.list-item-name {
    font-weight: 700;
    font-size: 15px;
}

.list-item-sub {
    font-size: 12.5px;
    color: var(--text-muted);
    margin-top: 2px;
}

.list-item-betrag {
    font-weight: 700;
    font-size: 15px;
    color: var(--brand-orange-dark);
    white-space: nowrap;
}

.list-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.list-item-datum {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: auto;
}

.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 9px;
    border-radius: 999px;
}

.badge-typ {
    background: #EFEDE8;
    color: var(--text-muted);
}

.status-gesendet {
    background: #E5F3E6;
    color: #2E7D32;
}

.status-ausstehend {
    background: #FBF0DD;
    color: #A9660F;
}

.status-fehler {
    background: #FCE9E4;
    color: #9B3213;
}

.list-item-actions {
    margin-top: 10px;
}

.btn-link {
    display: inline-block;
    font-size: 13px;
    font-weight: 700;
    color: var(--brand-orange);
    text-decoration: none;
    border: 1.5px solid var(--brand-orange);
    border-radius: 8px;
    padding: 7px 12px;
}

.btn-link.disabled {
    color: var(--text-muted);
    border-color: var(--border);
}

.header-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.header-link {
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    border: 1.5px solid rgba(255,255,255,.4);
    border-radius: 8px;
    padding: 6px 10px;
    white-space: nowrap;
}

/* Feldgruppen, die auf dem Handy untereinander, auf dem iPad nebeneinander
   stehen sollen (siehe Verwendung von .field-grid in index.php). Auf
   schmalen Bildschirmen wirkt der Wrapper unsichtbar (display:contents),
   die Felder verhalten sich wie normale Blockelemente und stapeln sich. */
.field-grid { display: contents; }

/* --- Tablet / iPad (Hoch- und Querformat) --- */
@media (min-width: 700px) {
    .app { max-width: 760px; }

    .app-header { padding: 22px 28px 20px; }
    .app-content { padding: 24px 28px 40px; }

    .card { padding: 22px 26px; margin-bottom: 16px; }
    .card h2 { font-size: 16px; }

    .field { margin-bottom: 16px; }
    .field label { font-size: 13px; }
    .field input[type="text"],
    .field input[type="tel"],
    .field input[type="date"],
    .field input[type="time"],
    .field input[type="number"],
    .field input[type="password"],
    .field input[type="email"],
    .field textarea,
    .field select {
        font-size: 15.5px;
        padding: 12px 14px;
    }

    .field-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 14px;
        align-items: start;
    }
    .field-grid .field { margin-bottom: 0; }

    .row-2, .row-3 { gap: 14px; }

    /* Mehr Platz zum Unterschreiben mit Finger/Apple Pencil */
    .sig-wrap canvas { height: 210px; }

    .btn { padding: 15px; font-size: 15.5px; }

    .success-screen { padding: 90px 40px; }
}

/* --- Größere iPads / Querformat --- */
@media (min-width: 1024px) {
    .app { max-width: 900px; }
    .app-content { padding: 28px 40px 60px; }
    .card { padding: 26px 30px; }
}

/*
 * --- iPad 11" (Air/Pro) ---
 * Hochformat ≈ 834px, Querformat ≈ 1194px Viewport-Breite.
 * Ab hier stehen die 4 Kacheln als 2x2-Raster nebeneinander statt in
 * einer langen Liste, damit auf dem größeren Bildschirm weniger gescrollt
 * werden muss. .kachel-grid-wrap umschließt in index.php genau die 4
 * .kachel-card-Blöcke (nicht die Fehlermeldung oder den Speichern-Button,
 * die bleiben volle Breite ober-/unterhalb des Rasters).
 */
@media (min-width: 820px) {
    .app { max-width: 1040px; }
    .app-header { padding: 24px 32px 22px; }
    .app-content { padding: 26px 32px 50px; }

    .kachel-grid-wrap {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 18px;
        align-items: start;
    }
    .kachel-card { margin-bottom: 0; }

    /* Innerhalb der schmaleren Kachel-Spalte reichen 3 statt 4 Foto-Spalten */
    .foto-grid { grid-template-columns: repeat(3, 1fr); }

    .btn-save { max-width: 420px; margin-left: auto; margin-right: auto; }
}

@media (min-width: 1180px) {
    .app { max-width: 1180px; }
    .app-content { padding: 30px 40px 60px; }
    .kachel-grid-wrap { gap: 22px; }
    .kachel-card { padding: 26px 28px; }
    .foto-grid { grid-template-columns: repeat(4, 1fr); }
    .sig-wrap canvas { height: 230px; }
}

/* --- Verbrauchtes Material --- */
.material-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.material-row:first-child { padding-top: 0; }
.material-row:last-of-type { border-bottom: none; }

.material-row-fields { flex: 1; }
.material-row-fields .field { margin-bottom: 10px; }
.material-row-fields .field:last-child { margin-bottom: 0; }
.material-row-fields .field-grid { gap: 10px; }

.material-remove {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 1.5px solid var(--border);
    background: #fff;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    margin-top: 22px;
}

.material-remove:active {
    background: #FCE9E4;
    border-color: #EFB8A7;
    color: #9B3213;
}

.material-empty-hint {
    font-size: 12.5px;
    color: var(--text-muted);
    padding: 4px 0 10px;
}

.btn-add {
    width: 100%;
    padding: 11px;
    border-radius: 10px;
    border: 1.5px dashed var(--brand-orange);
    background: #FBF3EE;
    color: var(--brand-orange-dark);
    font-weight: 700;
    font-size: 13.5px;
    cursor: pointer;
}

.btn-add:active {
    background: #F5E4D9;
}

/* --- Kacheln: direkt sichtbare Formularblöcke (keine Navigation) --- */
.kachel-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 16px;
    margin-bottom: 14px;
}

.kachel-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.kachel-card-header .kachel-icon {
    font-size: 22px;
    line-height: 1;
}

.kachel-card-header h2 {
    margin: 0;
    font-size: 15px;
    color: var(--brand-orange);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.field-label-row {
    font-size: 12.5px;
    color: var(--text-muted);
    font-weight: 600;
    margin: 4px 0 8px;
}

/* --- Fotoupload --- */
.foto-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.foto-grid:empty { margin-bottom: 0; }

.foto-item {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.foto-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.foto-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.55);
    color: #fff;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.foto-add-label {
    display: block;
    text-align: center;
    cursor: pointer;
}

@media (min-width: 700px) {
    .kachel-card { padding: 22px 24px; }
    .kachel-card-header .kachel-icon { font-size: 26px; }
    .kachel-card-header h2 { font-size: 16px; }
    .foto-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Entwurf / Offline-Hinweise */
.info-banner { display:none; background:#E8F4EA; color:#1F5E2E; border:1px solid #B9DCC0; border-radius:10px; padding:10px 14px; margin-bottom:12px; font-size:14px; }
.info-banner.show { display:block; }
.info-banner.warn { background:#FFF4E0; color:#7A4B00; border-color:#F0D29A; }
.link-btn { background:none; border:0; color:inherit; text-decoration:underline; font-weight:700; cursor:pointer; padding:0 0 0 6px; font-size:inherit; }

/* Sitzungs-Popup */
.modal-overlay { display:none; position:fixed; inset:0; background:rgba(0,0,0,.55); z-index:1000; align-items:center; justify-content:center; padding:20px; }
.modal-overlay.show { display:flex; }
.modal-box { background:#fff; border-radius:14px; padding:22px; max-width:420px; width:100%; box-shadow:0 10px 40px rgba(0,0,0,.35); }
.modal-box h2 { margin:0 0 10px; font-size:20px; }
.modal-box p { margin:0 0 16px; color:#444; line-height:1.4; }
.modal-box .btn { width:100%; }
