/* Utilities first to ensure specificity */
.hidden {
    display: none !important;
}

:root {
    --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    --card-bg: rgba(255, 255, 255, 0.95);
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --text-dark: #1e293b;
    --text-medium: #64748b;
    --border: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    /* Remove tap highlight on mobile */
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-dark);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-container {
    max-width: 1000px;
    margin: 40px auto;
    padding: 0 20px;
    flex-grow: 1;
    width: 100%;
}

/* Header & Progress */
header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, var(--primary), #818cf8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.step-indicator {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 1rem;
}

.step-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #cbd5e1;
    transition: 0.3s ease;
}

.step-dot.active {
    background: var(--primary);
    transform: scale(1.2);
}

/* Wizard Cards */
.wizard-step {
    background: var(--card-bg);
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.5);
    animation: fadeIn 0.4s ease-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

h2 {
    margin-top: 0;
    color: var(--text-dark);
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

/* Step 1: Upload */
.drop-zone {
    border: 3px dashed var(--border);
    border-radius: 20px;
    padding: 4rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #f8fafc;
}

.drop-zone:hover {
    border-color: var(--primary);
    background: #eef2ff;
    transform: translateY(-2px);
}

.icon-upload {
    color: var(--primary);
    margin-bottom: 1rem;
    font-size: 3rem;
}

/* Step 2: Edit Items */
.items-list-editor {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 2rem;
    background: white;
    /* Ensure bg is white */
}

.edit-row {
    display: grid;
    grid-template-columns: 2fr 1fr 40px;
    gap: 10px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    align-items: center;
}

.edit-row input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    width: 100%;
    /* Full width in grid cell */
}

.btn-icon {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 10px;
    /* Larger touch target */
}

/* Step 3: People */
.people-input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 2rem;
}

.people-input-group input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    outline: none;
}

.people-input-group input:focus {
    border-color: var(--primary);
}

.params-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.person-chip {
    background: white;
    padding: 8px 16px;
    border-radius: 50px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
}

/* Step 4: Drag & Drop (Matrix) */
.split-workspace {
    display: flex;
    gap: 20px;
    height: 600px;
}

.items-column {
    flex: 1;
    background: #f1f5f9;
    padding: 1rem;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    /* Allow scrolling if list is long */
}

.people-column {
    flex: 2;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 15px;
    overflow-y: auto;
    padding: 5px;
    align-content: start;
}

.person-droppable {
    background: white;
    border-radius: 16px;
    border: 2px solid transparent;
    display: flex;
    flex-direction: column;
    min-height: 150px;
    box-shadow: var(--shadow-sm);
}

.person-droppable.drop-target {
    border-color: var(--primary);
    background: #eef2ff;
}

.person-header {
    background: #f8fafc;
    padding: 12px;
    text-align: center;
    border-radius: 14px 14px 0 0;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.drop-list {
    flex: 1;
    padding: 10px;
    min-height: 80px;
}

/* Draggable Items */
.draggable-item {
    background: white;
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 12px;
    border: 1px solid var(--border);
    cursor: grab;
    box-shadow: var(--shadow-sm);
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    touch-action: none;
    /* Prevent scroll while dragging */
}

.draggable-item .price {
    font-weight: 700;
    color: var(--primary);
    background: #eef2ff;
    padding: 4px 8px;
    border-radius: 8px;
}

/* Buttons */
.btn-primary,
.btn-secondary {
    padding: 14px 24px;
    /* Larger touch targets */
    border-radius: 12px;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-bottom: 10px;
    /* Stack spacing on mobile */
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 6px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background: #f1f5f9;
    color: var(--text-dark);
}

.btn-row {
    display: flex;
    gap: 15px;
    margin-top: 1.5rem;
}

.btn-row button {
    margin-bottom: 0;
    /* Reset */
    flex: 1;
}

/* Tip Section */
.tip-section {
    margin-top: 2rem;
    background: #f8fafc;
    padding: 1.5rem;
    border-radius: 16px;
    border: 1px solid var(--border);
}

.tip-section h3 {
    margin-top: 0;
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

.tip-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
}

.tip-options {
    display: flex;
    gap: 8px;
}

.btn-tip {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-tip:hover,
.btn-tip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.tip-custom {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tip-custom input {
    width: 100px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

/* Sticky Footer Totals */
.total-summary {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    color: var(--text-dark);
    padding: 15px 20px;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    transform: translateY(0);
    transition: transform 0.3s ease;
}

/* Eliminated .total-summary.hidden override to prevent click blocking */

.summary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.total-display {
    display: flex;
    flex-direction: column;
}

.total-display .label {
    font-size: 0.8rem;
    color: var(--text-medium);
}

.total-display .amount {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
}

.summary-header .btn-primary {
    width: auto;
    margin-bottom: 0;
    padding: 10px 20px;
    font-size: 1rem;
}

.summary-details {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.95rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
}

.btn-toggle-details {
    background: none;
    border: none;
    color: var(--text-medium);
    font-size: 0.8rem;
    margin: 0 auto;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* --- MOBILE RESPONSIVENESS --- */
@media (max-width: 768px) {
    .app-container {
        margin: 10px auto;
        padding: 0 15px;
    }

    .wizard-step {
        padding: 1.5rem;
        border-radius: 20px;
    }

    header h1 {
        font-size: 2rem;
    }

    /* Step 2: Edit Items */
    .edit-row {
        grid-template-columns: 1fr 80px 40px;
        /* Name takes less space, Price fixed, Delete fixed */
        gap: 8px;
        font-size: 0.9rem;
    }

    /* Step 4: Split Workspace */
    .split-workspace {
        flex-direction: column;
        height: auto;
    }

    .items-column {
        max-height: 250px;
        /* Limit height of pool */
        min-height: 150px;
    }

    .people-column {
        grid-template-columns: 1fr;
        /* 1 column of people on very small screens? No, 2 is better usually */
        grid-template-columns: repeat(2, 1fr);
    }

    .person-droppable {
        min-height: 120px;
    }

    /* Adjust totals for mobile */
    .total-summary {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .people-column {
        grid-template-columns: 1fr;
        /* Single column for people on very narrow phones */
    }
}

/* Share Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal-content {
    width: 90%;
    max-width: 380px;
    max-height: 85vh;
    /* Limit height to viewport */
    /* Transparent/No BG for content wrapper to let receipt shine */
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.receipt-scroll-wrapper {
    overflow-y: auto;
    width: 100%;
    flex: 1;
    /* Take available space */
    border-radius: 5px;
    /* Optional, for scrollbar corner */
    display: flex;
    /* Centers the paper if needed */
    flex-direction: column;
    align-items: center;
}

.receipt-paper {
    background: #fffcf5;
    /* Slightly warm paper color */
    width: 100%;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    font-family: 'Courier New', Courier, monospace;
    /* Receipt font */
    color: #333;
    position: relative;
    /* Zigzag edge simulation via gradient could act here, but keeping simple for now */
    border-top: 5px solid var(--primary);
    margin: auto;
    /* Center in scroll area */
}

.receipt-header {
    text-align: center;
    margin-bottom: 10px;
}

.receipt-header h3 {
    margin: 0;
    font-size: 1.2rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.receipt-divider {
    text-align: center;
    overflow: hidden;
    white-space: nowrap;
    color: #999;
    margin: 5px 0;
    font-size: 0.8rem;
}

.receipt-body {
    font-size: 0.9rem;
    line-height: 1.4;
}

.receipt-item-row {
    display: flex;
    justify-content: space-between;
}

.receipt-total-row {
    display: flex;
    justify-content: space-between;
    font-weight: bold;
    margin-top: 5px;
    font-size: 1rem;
}

.btn-row button {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

/* Mobile Assignment Bottom Sheet */
.bottom-sheet-content {
    background: white;
    width: 100%;
    max-width: 600px;
    /* On desktop, don't be full width */
    border-radius: 20px 20px 0 0;
    padding: 25px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
    animation: slideUp 0.3s ease-out;
}

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

    to {
        transform: translateY(0);
    }
}

.assign-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
    margin-top: 15px;
    max-height: 40vh;
    overflow-y: auto;
}

.assign-btn {
    background: #f1f5f9;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-dark);
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.assign-btn:hover {
    background: #eef2ff;
    border-color: var(--primary);
    color: var(--primary);
}

.assign-btn i {
    font-size: 1.2rem;
    margin-bottom: 2px;
}

/* Make draggable items clickable looking */
.draggable-item {
    cursor: pointer;
    /* Change from grab to pointer to imply clickability */
}