* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Verhindert Zoom bei Input-Focus auf iOS */
    -webkit-text-size-adjust: 100%;
    /* Verbessert Touch-Scrolling */
    -webkit-overflow-scrolling: touch;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background-color: white;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #007bff;
}

h1 {
    color: #007bff;
    font-size: 2.5em;
    margin-bottom: 10px;
}

h2 {
    color: #333;
    margin-bottom: 15px;
    padding: 10px;
    background-color: #f8f9fa;
    border-left: 4px solid #007bff;
}

.form-section {
    margin-bottom: 30px;
    padding: 20px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #fafafa;
}

.form-group {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
}

.form-group.inline {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.form-group.inline label {
    min-width: 120px;
    margin-bottom: 0;
}

label {
    font-weight: bold;
    margin-bottom: 5px;
    color: #555;
}

input, select, textarea {
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px; /* Verhindert Zoom auf iOS */
    transition: border-color 0.3s;
    /* iOS Safari Styling Reset */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    /* Touch-optimiert */
    touch-action: manipulation;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 5px rgba(0,123,255,0.3);
}

.project-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.aufmass-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.list-item {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 15px;
    padding: 12px;
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.list-item:hover {
    background-color: #f8f9fa;
}

.list-item .description {
    font-size: 14px;
    line-height: 1.4;
    color: #333;
}

.list-item input {
    width: 100px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    text-align: right;
    font-size: 16px;
    font-weight: bold;
    /* iOS Safari Styling */
    -webkit-appearance: none;
    touch-action: manipulation;
}

.list-item input:focus {
    border-color: #007bff;
    box-shadow: 0 0 5px rgba(0,123,255,0.3);
    outline: none;
}

.list-item input:valid:not(:placeholder-shown) {
    background-color: #d4edda;
    border-color: #28a745;
}

.category-section {
    margin: 10px 0;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 4px;
    border-left: 3px solid #007bff;
    font-size: 14px;
    line-height: 1.5;
}

.btn {
    padding: 16px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    text-decoration: none;
    display: inline-block;
    transition: all 0.3s ease;
    /* Touch-optimiert */
    touch-action: manipulation;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    /* Mindest-Touch-Größe für mobile Geräte */
    min-height: 44px;
    min-width: 44px;
}

.btn-primary {
    background-color: #007bff;
    color: white;
}

.btn-primary:hover {
    background-color: #0056b3;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
    margin-left: 10px;
}

.btn-secondary:hover {
    background-color: #545b62;
}

.btn-warning {
    background-color: #ffc107;
    color: #212529;
}

.btn-warning:hover {
    background-color: #e0a800;
}

.btn-success {
    background-color: #28a745;
    color: white;
}

.btn-success:hover {
    background-color: #218838;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.aufmass-actions {
    margin-top: 15px;
    display: flex;
    gap: 10px;
}

.manual-textzeile {
    margin-bottom: 15px;
}

.textzeile-content {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 10px;
    align-items: center;
    padding: 12px;
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.textzeile-content:hover {
    background-color: #f8f9fa;
}

.textzeile-text {
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    min-width: 0; /* Für Grid-Verhalten */
    /* iOS Safari Styling */
    -webkit-appearance: none;
    touch-action: manipulation;
}

.textzeile-menge {
    width: 100px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    text-align: right;
    font-size: 16px;
    font-weight: bold;
    /* iOS Safari Styling */
    -webkit-appearance: none;
    touch-action: manipulation;
}

.btn-remove-textzeile {
    background-color: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: background-color 0.2s;
}

.btn-remove-textzeile:hover {
    background-color: #c82333;
}

.textzeile-text:focus,
.textzeile-menge:focus {
    border-color: #007bff;
    box-shadow: 0 0 5px rgba(0,123,255,0.3);
    outline: none;
}

.textzeile-menge:valid:not(:placeholder-shown) {
    background-color: #d4edda;
    border-color: #28a745;
}

.form-actions {
    text-align: center;
    margin: 30px 0;
    padding: 20px;
    background-color: #f8f9fa;
    border-radius: 6px;
}

.saved-data {
    margin-top: 40px;
    padding: 20px;
    background-color: #f8f9fa;
    border-radius: 6px;
}

.aufmass-item {
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    margin-bottom: 10px;
}

.aufmass-header {
    margin-bottom: 15px;
}

.aufmass-item h4 {
    color: #007bff;
    margin-bottom: 10px;
}

/* Fortschrittsanzeige */
.progress-container {
    position: relative;
    background-color: #f8f9fa;
    border-radius: 10px;
    height: 20px;
    margin-top: 8px;
    overflow: hidden;
    border: 1px solid #e9ecef;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #28a745, #20c997);
    border-radius: 10px;
    transition: width 0.3s ease, background-color 0.3s ease;
    position: relative;
}

.progress-bar.incomplete {
    background: linear-gradient(90deg, #dc3545, #fd7e14);
}

.progress-bar.good {
    background: linear-gradient(90deg, #ffc107, #28a745);
}

.progress-bar.complete {
    background: linear-gradient(90deg, #28a745, #20c997);
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    font-weight: 600;
    color: #333;
    text-shadow: 1px 1px 2px rgba(255,255,255,0.8);
    z-index: 2;
}

.aufmass-meta {
    font-size: 12px;
    color: #666;
    margin-bottom: 10px;
}

.position-summary {
    font-size: 14px;
    margin-bottom: 5px;
}

.alert {
    padding: 15px;
    margin-bottom: 20px;
    border: 1px solid transparent;
    border-radius: 4px;
}

.alert-success {
    color: #155724;
    background-color: #d4edda;
    border-color: #c3e6cb;
}

.alert-error {
    color: #721c24;
    background-color: #f8d7da;
    border-color: #f5c6cb;
}

.alert-warning {
    color: #856404;
    background-color: #fff3cd;
    border-color: #ffeaa7;
}

/* iPad Landscape und größere Tablets */
@media (min-width: 768px) and (max-width: 1024px) {
    .container {
        padding: 15px;
    }
    
    .project-info {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .list-item {
        grid-template-columns: 1fr 120px;
    }
    
    .list-item input {
        width: 120px;
    }
}

/* Smartphones und iPad Portrait */
@media (max-width: 768px) {
    .container {
        padding: 12px;
        margin: 0;
    }
    
    h1 {
        font-size: 1.8rem;
        text-align: center;
        margin-bottom: 20px;
    }
    
    h2 {
        font-size: 1.3rem;
        padding: 12px;
        margin-bottom: 12px;
    }
    
    .form-section {
        margin-bottom: 20px;
        padding: 15px;
        border-radius: 12px;
    }
    
    .project-info {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .list-item {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 16px;
        border-radius: 12px;
    }
    
    .list-item .description {
        font-size: 15px;
        line-height: 1.5;
        margin-bottom: 8px;
    }
    
    .list-item input {
        width: 100%;
        padding: 16px;
        font-size: 18px;
        text-align: left;
        border-radius: 10px;
    }
    
    .aufmass-actions {
        flex-direction: column;
        gap: 12px;
    }
    
    .aufmass-actions .btn {
        width: 100%;
        margin-left: 0;
        padding: 18px;
        font-size: 17px;
    }
    
    .progress-container {
        height: 22px;
    }
    
    .progress-text {
        font-size: 12px;
    }
    
    .textzeile-content {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 16px;
        border-radius: 12px;
    }
    
    .textzeile-text,
    .textzeile-menge {
        width: 100%;
        padding: 16px;
        font-size: 16px;
        text-align: left;
        border-radius: 10px;
    }
    
    .btn-remove-textzeile {
        width: 40px;
        height: 40px;
        font-size: 18px;
        align-self: center;
        justify-self: center;
    }
    
    .form-group {
        margin-bottom: 20px;
    }
    
    .form-group.inline {
        flex-direction: column;
        align-items: stretch;
    }
    
    .form-group.inline label {
        min-width: auto;
        margin-bottom: 8px;
    }
    
    .form-actions {
        padding: 20px 0;
        position: sticky;
        bottom: 0;
        background-color: white;
        border-top: 1px solid #ddd;
        margin: 20px -12px 0;
        padding: 20px 12px;
    }
    
    .form-actions .btn {
        margin: 5px;
        width: calc(50% - 10px);
        display: inline-block;
    }
    
    .saved-data {
        margin-top: 20px;
        padding: 15px;
        border-radius: 12px;
    }
    
    .aufmass-item {
        padding: 16px;
        margin-bottom: 15px;
        border-radius: 12px;
    }
    
    .category-section {
        margin: 12px 0;
        padding: 12px;
        border-radius: 8px;
        font-size: 15px;
    }
}

/* Sehr kleine Smartphones */
@media (max-width: 480px) {
    .container {
        padding: 8px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .form-section {
        padding: 12px;
    }
    
    .list-item {
        padding: 12px;
    }
    
    .form-actions .btn {
        width: 100%;
        margin: 5px 0;
    }
    
    .aufmass-actions {
        gap: 8px;
    }
    
    .aufmass-actions .btn {
        padding: 14px;
        font-size: 15px;
    }
    
    .progress-container {
        height: 24px;
        margin-top: 10px;
    }
    
    .progress-text {
        font-size: 11px;
    }
}

/* iOS Safari spezifische Anpassungen */
@supports (-webkit-touch-callout: none) {
    /* iPhone X und höher - Safe Area */
    .container {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        padding-top: max(20px, env(safe-area-inset-top));
    }
    
    /* iOS Safari Vollbild-Modus */
    @media (display-mode: standalone) {
        body {
            padding-top: env(safe-area-inset-top);
        }
        
        .container {
            padding-top: 0;
        }
    }
    
    /* Verbessert Touch-Scrolling */
    .container {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Verhindert Text-Auswahl auf Touch */
    .btn, .list-item .description {
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }
    
    /* iOS Input-Styling */
    input, select, textarea {
        -webkit-appearance: none;
        border-radius: 10px;
    }
    
    select {
        background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        background-size: 16px 12px;
        padding-right: 40px;
    }
}

/* Landscape-Modus auf iPhone */
@media (max-width: 896px) and (orientation: landscape) {
    .container {
        padding: 10px;
    }
    
    h1 {
        font-size: 1.4rem;
        margin-bottom: 15px;
    }
    
    .form-section {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    .list-item {
        padding: 12px;
    }
    
    .form-actions {
        position: relative;
        padding: 15px 0;
        margin: 15px 0 0;
    }
}

/* Touch-Feedback Animation */
@keyframes touchFeedback {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

.btn:active {
    animation: touchFeedback 0.1s ease;
}

/* Focus-Styles für bessere Zugänglichkeit */
input:focus, select:focus, textarea:focus, .btn:focus {
    outline: 3px solid rgba(0, 123, 255, 0.5);
    outline-offset: 2px;
}

/* Hochkontrast-Modus Support */
@media (prefers-contrast: high) {
    .list-item, .manual-textzeile .textzeile-content {
        border: 2px solid #000;
    }
    
    .btn {
        border: 2px solid #000;
    }
}