/* ========================================
   RESET & BASE STYLES
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
    color: #1a1a1a;
    background-attachment: fixed;
    min-height: 100vh;
    min-height: 100dvh;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* ========================================
   CONTAINER & LAYOUT
   ======================================== */
.container {
    max-width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.header {
    background: linear-gradient(135deg, #b30a1c 0%, #8b0715 100%);
    color: white;
    padding: calc(2rem + env(safe-area-inset-top)) 1rem 1.5rem;
    text-align: center;
    box-shadow: 0 4px 12px rgba(179, 10, 28, 0.2);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 100%;
}

.title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 0.95rem;
    opacity: 0.95;
    font-weight: 400;
}

.main-content {
    flex: 1;
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
    max-width: 100%;
}

/* ========================================
   TABS
   ======================================== */
.tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    background: white;
    padding: 0.5rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    position: sticky;
    top: calc(7rem + env(safe-area-inset-top));
    z-index: 99;
}

.tab-btn {
    padding: 0.75rem 0.5rem;
    border: none;
    background: transparent;
    color: #666;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 44px;
}

/* Teilnehmer-Tab visuell ganz rechts anzeigen */
.tab-btn[data-tab="members"] {
    order: 4;
}

.tab-btn.active {
    background: linear-gradient(135deg, #b30a1c 0%, #8b0715 100%);
    color: white;
    box-shadow: 0 2px 6px rgba(179, 10, 28, 0.2);
}

@media (max-width: 480px) {
    .header {
        padding: calc(1.15rem + env(safe-area-inset-top)) 0.875rem 1rem;
    }

    .title {
        font-size: 1.55rem;
    }

    .subtitle {
        font-size: 0.88rem;
    }

    .main-content {
        padding: 0.75rem 0.75rem calc(1rem + env(safe-area-inset-bottom));
    }

    .tabs {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        overflow-x: visible;
        gap: 0.3rem;
        padding: 0.4rem;
        top: calc(5.6rem + env(safe-area-inset-top));
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        font-size: 0.72rem;
        padding: 0.55rem 0.2rem;
        min-width: 0;
        white-space: normal;
        line-height: 1.15;
    }

    .section {
        padding: 1rem;
        border-radius: 10px;
    }

    .input-group {
        grid-template-columns: 1fr;
    }

    .member-item {
        gap: 0.75rem;
        padding: 0.75rem;
    }

    .member-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .member-btn {
        font-size: 0.82rem;
        padding: 0.5rem 0.6rem;
    }

    .action-buttons {
        grid-template-columns: 1fr;
    }
}

/* ========================================
   SECTIONS
   ======================================== */
.section {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.section-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: #1a1a1a;
}

/* ========================================
   FORMS & INPUTS
   ======================================== */
.form-group {
    margin-bottom: 1.25rem;
}

.label {
    display: block;
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: #333;
}

.input-field,
.input-group input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.3s ease;
    background: #f9f9f9;
}

.input-field:focus,
.input-group input:focus {
    outline: none;
    border-color: #b30a1c;
    background: white;
    box-shadow: 0 0 0 3px rgba(179, 10, 28, 0.1);
}

.input-group {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.75rem;
    align-items: flex-end;
}

/* ========================================
   BUTTONS
   ======================================== */
.btn {
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: inherit;
    min-height: 44px;
    touch-action: manipulation;
}

.btn-primary {
    background: linear-gradient(135deg, #b30a1c 0%, #8b0715 100%);
    color: white;
    box-shadow: 0 2px 6px rgba(179, 10, 28, 0.2);
}

.btn-primary:active,
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(179, 10, 28, 0.3);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
    border: 2px solid #e0e0e0;
}

.btn-secondary:active,
.btn-secondary:hover {
    background: #e8e8e8;
    border-color: #b30a1c;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:active,
.btn-danger:hover {
    background: #c82333;
}

/* ========================================
   MEMBERS LIST
   ======================================== */
.members-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.member-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: #f9f9f9;
    border-radius: 8px;
    border: 2px solid #e0e0e0;
    transition: all 0.3s ease;
}

.member-item.has-wine {
    border-color: #c41e3a;
    background: #fff5f5;
}

.member-item.no-wine {
    border-color: #28a745;
    background: #f5fff8;
}

.member-item.not-present {
    border-color: #9e9e9e;
    background: #f3f3f3;
}

.member-item.neutral {
    border-color: #cfd8dc;
    background: #fafafa;
}

.member-checkbox {
    width: 24px;
    height: 24px;
    cursor: pointer;
    accent-color: #b30a1c;
}

.member-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.member-name {
    font-weight: 600;
    color: #1a1a1a;
    font-size: 0.95rem;
}

.member-status {
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    width: fit-content;
}

.member-status.wine {
    background: #ffe0e6;
    color: #c41e3a;
}

.member-status.no-wine {
    background: #e0f7e8;
    color: #28a745;
}

.member-status.not-present {
    background: #eceff1;
    color: #546e7a;
}

.member-status.neutral {
    background: #f1f3f4;
    color: #607d8b;
}

.member-actions {
    display: flex;
    gap: 0.5rem;
}

.member-btn {
    padding: 0.5rem 0.75rem;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
    border: 1px solid #ddd;
    min-height: 40px;
}

.member-btn:active {
    transform: scale(0.95);
}

.member-btn.active {
    color: white;
    border-color: #333;
}

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

.member-btn.remove {
    background: #ffebee;
    color: #c41e3a;
    border-color: #c41e3a;
}

.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: #999;
}

.empty-state-text {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.empty-state-hint {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* ========================================
   INFO BOXES
   ======================================== */
.info-box {
    background: #e3f2fd;
    border-left: 4px solid #2196f3;
    padding: 1rem;
    border-radius: 6px;
    margin-top: 1rem;
}

.info-text {
    font-size: 0.9rem;
    color: #1565c0;
    margin-bottom: 0.5rem;
}

.info-text:last-child {
    margin-bottom: 0;
}

/* ========================================
   RESULTS
   ======================================== */
.result-container {
    min-height: 300px;
}

.placeholder-box {
    text-align: center;
    padding: 3rem 1rem;
    color: #999;
    font-size: 0.95rem;
}

.result-card {
    background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
    padding: 1.25rem;
    border-radius: 10px;
    margin-bottom: 1rem;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid #e0e0e0;
}

.result-row:last-child {
    border-bottom: none;
}

.result-label {
    font-weight: 500;
    color: #666;
    font-size: 0.95rem;
}

.result-value {
    font-weight: 700;
    color: #b30a1c;
    font-size: 1.1rem;
}

.group-title {
    font-weight: 600;
    font-size: 1rem;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: #1a1a1a;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.group-title:first-child {
    margin-top: 0;
}

.person-item {
    padding: 0.75rem;
    background: white;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #e0e0e0;
}

.person-name {
    font-weight: 500;
    color: #333;
}

.person-amount {
    font-weight: 700;
    color: #b30a1c;
    font-size: 0.95rem;
}

.summary-total {
    background: linear-gradient(135deg, #b30a1c 0%, #8b0715 100%);
    color: white;
    padding: 1.5rem;
    border-radius: 10px;
    margin-top: 1rem;
    text-align: center;
}

.summary-total-label {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-bottom: 0.5rem;
}

.summary-total-amount {
    font-size: 1.8rem;
    font-weight: 700;
}

.action-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.action-buttons .btn {
    width: 100%;
    white-space: normal;
}

/* ========================================
   MODAL
   ======================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: flex-end;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    width: 100%;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    padding: 1.5rem;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
    position: relative;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.modal-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #999;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.export-preview {
    background: #f9f9f9;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
}

/* ========================================
   TAB CONTENT
   ======================================== */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

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

/* ========================================
   UTILITIES
   ======================================== */
.text-center {
    text-align: center;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

/* ========================================
   RESPONSIVE - TABLET
   ======================================== */
@media (min-width: 768px) {
    .main-content {
        max-width: 600px;
        margin: 0 auto;
    }

    .tabs {
        gap: 0.75rem;
    }

    .tab-btn {
        font-size: 1rem;
        padding: 0.85rem 1rem;
    }

    .title {
        font-size: 2.25rem;
    }
}

/* ========================================
   RESPONSIVE - DESKTOP
   ======================================== */
@media (min-width: 1024px) {
    .main-content {
        max-width: 700px;
    }

    .section {
        padding: 2rem;
    }

    .header {
        padding: 2.5rem 1rem 2rem;
    }

    .title {
        font-size: 2.5rem;
    }
}

@media (hover: none) and (pointer: coarse) {
    .btn-primary:hover,
    .btn-secondary:hover,
    .btn-danger:hover {
        transform: none;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
    body {
        background: white;
    }

    .header,
    .tabs,
    .modal-close,
    .btn:not(.no-print) {
        display: none;
    }

    .export-preview {
        background: white;
        border: none;
    }

    .modal-content {
        max-height: none;
        border-radius: 0;
    }
}

/* ========================================
   DARK MODE
   ======================================== */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #1a1a1a 0%, #242424 100%);
        color: #e0e0e0;
    }

    .section,
    .modal-content {
        background: #2d2d2d;
        color: #e0e0e0;
    }

    .section-title {
        color: #e0e0e0;
    }

    .input-field,
    .input-group input {
        background: #3a3a3a;
        color: #e0e0e0;
        border-color: #444;
    }

    .input-field:focus,
    .input-group input:focus {
        background: #2d2d2d;
        border-color: #b30a1c;
    }

    .label,
    .member-name {
        color: #e0e0e0;
    }

    .member-item {
        background: #3a3a3a;
        border-color: #444;
    }

    .member-item.has-wine {
        background: #4a2a2a;
        border-color: #c41e3a;
    }

    .member-item.no-wine {
        background: #2a4a38;
        border-color: #28a745;
    }

    .member-item.not-present {
        background: #343434;
        border-color: #666;
    }

    .member-item.neutral {
        background: #303030;
        border-color: #555;
    }

    .result-card {
        background: #3a3a3a;
    }

    .result-row {
        border-color: #444;
    }

    .person-item {
        background: #3a3a3a;
        border-color: #444;
    }

    .member-status.not-present {
        background: #455a64;
        color: #eceff1;
    }

    .member-status.neutral {
        background: #424242;
        color: #cfd8dc;
    }

    .info-box {
        background: #1a3a4a;
        border-left-color: #4a9eff;
    }

    .info-text {
        color: #7ab8ff;
    }

    .tabs {
        background: #2d2d2d;
    }

    .tab-btn {
        color: #999;
    }

    .export-preview {
        background: #3a3a3a;
        border-color: #444;
    }

    .empty-state,
    .empty-state-text,
    .empty-state-hint {
        color: #888;
    }
}
