/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #007AFF;
    --primary-dark: #0051D5;
    --background: #F2F2F7;
    --surface: #FFFFFF;
    --text-primary: #000000;
    --text-secondary: #8E8E93;
    --border-color: #C6C6C8;
    --shadow: rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    background-color: var(--surface);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Große Bildschirme - Container mit maximaler Breite für bessere Lesbarkeit */
@media (min-width: 1400px) {
    .container {
        max-width: 1600px;
        margin: 0 auto;
    }
}

/* Header */
header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 20px 16px;
    text-align: center;
    box-shadow: 0 2px 10px var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

/* Table Header */
.table-header {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) auto minmax(120px, 150px) auto minmax(120px, 150px) auto minmax(140px, 180px);
    gap: 0;
    background-color: var(--background);
    padding: 12px 8px;
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    font-size: 14px;
    position: sticky;
    top: 66px;
    z-index: 50;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.table-header > div {
    padding: 4px 8px;
    display: flex;
    align-items: center;
}

.col-name {
    justify-content: center;
    text-align: center;
}

.col-height,
.col-width {
    justify-content: center;
    text-align: center;
    min-width: 0;
}

.col-result {
    justify-content: center;
    text-align: center;
    min-width: 0;
}

.col-divider {
    width: 1px;
    background-color: var(--border-color);
    padding: 0;
    margin: 0 4px;
}

/* Table Body */
.table-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.table-row {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) auto minmax(120px, 150px) auto minmax(120px, 150px) auto minmax(140px, 180px);
    gap: 0;
    padding: 10px 8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    background-color: var(--surface);
    transition: background-color 0.2s;
}

.table-row:focus-within {
    background-color: #F8F8F8;
}

.table-row:nth-child(even) {
    background-color: #FAFAFA;
}

.table-row:nth-child(even):focus-within {
    background-color: #F5F5F5;
}

/* Input Fields */
.input-field {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    background-color: var(--surface);
    color: var(--text-primary);
    transition: all 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.input-field:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

.input-name {
    min-width: 0;
}

.input-number {
    text-align: center;
    width: 100%;
    min-width: 0;
}

.input-number::-webkit-inner-spin-button,
.input-number::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.result-cell {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 8px 10px;
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 500;
    min-height: 36px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-cell:empty::before {
    content: "-";
    color: var(--text-secondary);
}

.delete-btn {
    background: none;
    border: none;
    color: #FF3B30;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    opacity: 0.6;
    transition: opacity 0.2s;
    display: none;
    align-items: center;
    justify-content: center;
}

.table-row:hover .delete-btn,
.table-row:focus-within .delete-btn {
    display: flex;
}

.delete-btn:hover {
    opacity: 1;
}

.delete-btn:active {
    transform: scale(0.95);
}

/* Action Buttons Container */
.action-buttons {
    display: flex;
    gap: 12px;
    margin: 16px;
    flex-wrap: wrap;
}

/* Add Button */
.add-button,
.export-button {
    flex: 1;
    min-width: 150px;
    padding: 14px 20px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.add-button {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

.add-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 122, 255, 0.4);
}

.add-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.export-button {
    background: linear-gradient(135deg, #34C759 0%, #28A745 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(52, 199, 89, 0.3);
}

.export-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(52, 199, 89, 0.4);
}

.export-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(52, 199, 89, 0.3);
}

.button-icon {
    font-size: 20px;
    font-weight: bold;
    line-height: 1;
}

.button-text {
    font-size: 16px;
}

/* Total Row */
.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background-color: var(--background);
    border-top: 2px solid var(--border-color);
    font-weight: 600;
    font-size: 18px;
    margin-top: auto;
}

.total-label {
    color: var(--text-primary);
}

.total-value {
    color: var(--primary-color);
    font-size: 20px;
}

/* Responsive Design - Action Buttons */
@media (max-width: 768px) {
    .action-buttons {
        flex-direction: column;
    }

    .add-button,
    .export-button {
        width: 100%;
    }
}

/* Tablet und mittlere Bildschirme */
@media (max-width: 1024px) and (min-width: 481px) {
    .table-header,
    .table-row {
        grid-template-columns: minmax(120px, 1fr) auto minmax(100px, 130px) auto minmax(100px, 130px) auto minmax(120px, 150px);
    }
}

/* Kleine Bildschirme (Smartphone) */
@media (max-width: 480px) {
    .table-header,
    .table-row {
        grid-template-columns: minmax(100px, 1fr) auto 70px auto 70px auto 90px;
        font-size: 13px;
    }

    .col-height,
    .col-width {
        min-width: 70px;
    }

    .input-number {
        min-width: 70px;
    }

    .col-result,
    .result-cell {
        min-width: 90px;
    }

    header h1 {
        font-size: 20px;
    }

    .input-field {
        font-size: 14px;
        padding: 6px 8px;
    }
}

/* Sehr kleine Bildschirme */
@media (max-width: 360px) {
    .table-header,
    .table-row {
        grid-template-columns: minmax(80px, 1fr) auto 60px auto 60px auto 80px;
        padding: 8px 4px;
        font-size: 12px;
    }

    .col-height,
    .col-width,
    .input-number {
        min-width: 60px;
    }

    .col-result,
    .result-cell {
        min-width: 80px;
    }

    .input-field {
        font-size: 12px;
        padding: 4px 6px;
    }
}

/* Landscape Mode */
@media (orientation: landscape) and (max-height: 500px) {
    header {
        padding: 12px 16px;
    }

    header h1 {
        font-size: 18px;
    }

    .table-header {
        top: 48px;
        padding: 8px;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
    }

    header,
    .add-button,
    .total-row {
        display: none;
    }

    .table-header {
        position: static;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}
