:root {
    --apple-gray: #f5f5f7;
    --apple-text: #1d1d1f;
    --apple-blue: #0071e3;
    --apple-blue-hover: #0077ed;
    --card-bg: rgba(255, 255, 255, 0.7);
}

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

button, a, input, select {
    touch-action: manipulation;
}

button {
    user-select: none;
    -webkit-user-select: none;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--apple-gray);
    color: var(--apple-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Navbar */
.navbar {
    position: sticky;
    top: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    z-index: 100;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.nav-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.5px;
    white-space: nowrap;
}

nav a {
    color: var(--apple-text);
    text-decoration: none;
    font-size: 14px;
    margin-left: 24px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

nav a:hover {
    opacity: 1;
}

/* Hero */
.hero {
    text-align: center;
    padding: 80px 24px;
    max-width: 800px;
    margin: 0 auto;
}

.hero h2 {
    font-size: 56px;
    font-weight: 600;
    letter-spacing: -1.5px;
    margin-bottom: 16px;
}

.hero p {
    font-size: 24px;
    color: #86868b;
    font-weight: 300;
}

/* Catalog Grid */
.catalog {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px 80px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 24px;
    margin-bottom: 48px;
}

/* Cards */
.card {
    background: #ffffff;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.04);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.08);
}

.card-image-container {
    width: 100%;
    aspect-ratio: 4/5;
    background: #fbfbfd;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.card:hover .card-image {
    transform: scale(1.03);
}

.upload-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--apple-blue);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    background: rgba(0,0,0,0.02);
}

.upload-placeholder:hover {
    background: rgba(0, 113, 227, 0.05);
}

.file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.card-content {
    padding: 24px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

[contenteditable="true"] {
    outline: none;
    transition: background 0.2s;
    border-radius: 6px;
    padding: 4px;
    margin: -4px;
}

[contenteditable="true"]:hover {
    background: rgba(0,0,0,0.03);
}

[contenteditable="true"]:focus {
    background: rgba(0,0,0,0.05);
}

[contenteditable="true"]:empty:before {
    content: attr(data-placeholder);
    color: #a1a1a6;
    pointer-events: none;
    display: block;
}

.card-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.card-desc {
    font-size: 15px;
    color: #86868b;
    flex-grow: 1;
}

.delete-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    border: none;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    z-index: 10;
}

.card:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    background: rgba(0,0,0,0.4);
}

/* Add Button */
.add-new {
    text-align: center;
}

.apple-btn {
    background: var(--apple-text);
    color: white;
    border: none;
    padding: 16px 32px;
    font-size: 17px;
    border-radius: 980px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s, transform 0.1s;
}

.apple-btn:hover {
    background: #000;
}

.apple-btn:active {
    transform: scale(0.98);
}

/* Tabs Control */
.tabs-control {
    display: flex;
    background: rgba(0,0,0,0.05);
    border-radius: 980px;
    padding: 4px;
    margin: 0 24px;
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 6px 16px;
    border-radius: 980px;
    font-size: 14px;
    font-weight: 500;
    color: var(--apple-text);
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
}

.tab-btn.active {
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.wardrobe-tab {
    background: transparent;
    border: 1px solid rgba(0,0,0,0.1);
    padding: 8px 16px;
    border-radius: 980px;
    font-size: 14px;
    font-weight: 500;
    color: var(--apple-text);
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
    white-space: nowrap;
}

.wardrobe-tab.active {
    background: #000;
    color: #fff;
    border-color: #000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.wardrobes-scroll-container::-webkit-scrollbar {
    display: none;
}

/* Filters */
.filters-section {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px 24px;
}

.filters-container {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.apple-select {
    appearance: none;
    background: #fff url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2214%22%20height%3D%228%22%3E%3Cpath%20fill%3D%22%2386868b%22%20d%3D%22M7%208a.997.997%200%200%201-.707-.293l-6-6A.999.999%200%201%201%201.707.293L7%205.586%2012.293.293a.999.999%200%201%201%201.414%201.414l-6%206A.997.997%200%200%201%207%208z%22%2F%3E%3C%2Fsvg%3E") no-repeat right 12px center;
    background-size: 10px;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 12px;
    padding: 8px 32px 8px 16px;
    font-size: 14px;
    font-family: inherit;
    color: var(--apple-text);
    cursor: pointer;
    transition: border-color 0.2s;
}

.apple-select:hover {
    border-color: rgba(0,0,0,0.2);
}

.apple-select:focus {
    outline: none;
    border-color: var(--apple-blue);
}

.apple-btn-secondary {
    background: transparent;
    color: var(--apple-text);
    border: 1px solid rgba(0,0,0,0.1);
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.apple-btn-secondary:hover {
    background: rgba(0,0,0,0.05);
}

/* Card Tags */
.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.tag-select {
    appearance: none;
    background: rgba(0,0,0,0.04);
    border: none;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    color: #86868b;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.tag-select:hover {
    background: rgba(0,0,0,0.08);
}

.tag-select:focus, .tag-input:focus {
    outline: none;
    background: var(--apple-blue);
    color: #fff;
}

.tag-input {
    appearance: none;
    background: rgba(0,0,0,0.04);
    border: none;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    color: var(--apple-text);
    font-family: inherit;
    width: 80px;
    transition: background 0.2s, color 0.2s;
}

.tag-input::placeholder {
    color: #86868b;
}

.apple-input {
    appearance: none;
    background: #fff;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 12px;
    padding: 8px 16px;
    font-size: 14px;
    font-family: inherit;
    color: var(--apple-text);
    transition: border-color 0.2s;
    width: 120px;
}

.apple-input:focus {
    outline: none;
    border-color: var(--apple-blue);
}

.actions-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 32px;
}

.apple-btn-outline {
    background: transparent;
    color: var(--apple-text);
    border: 2px solid var(--apple-text);
    padding: 14px 28px;
    font-size: 16px;
    border-radius: 980px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s, color 0.2s, transform 0.1s;
}

.apple-btn-outline:hover {
    background: var(--apple-text);
    color: white;
}

.apple-btn-outline:active {
    transform: scale(0.98);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
}

.modal.open {
    display: flex;
}

.modal-content {
    background: #fff;
    width: 90%;
    max-width: 800px;
    height: 80vh;
    border-radius: 24px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 20px;
    font-weight: 600;
}

.modal-close-btn {
    background: rgba(0,0,0,0.05);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 16px;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.2s;
}

.modal-close-btn:hover {
    background: rgba(0,0,0,0.1);
}

.modal-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 24px;
    background: var(--apple-gray);
}

.modal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
}

.modal-item {
    background: #fff;
    border-radius: 12px;
    padding: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s, transform 0.2s;
    text-align: center;
}

.modal-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.modal-item.selected {
    border-color: var(--apple-blue);
    background: rgba(0, 113, 227, 0.05);
}

.modal-item img {
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 8px;
    background: var(--apple-gray);
}

.modal-item p {
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid rgba(0,0,0,0.05);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Outfit Linked Items */
.outfit-items-section {
    margin-top: auto;
    padding-top: 16px;
}

.outfit-items-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: thin;
}

.outfit-items-list::-webkit-scrollbar {
    height: 4px;
}

.outfit-items-list::-webkit-scrollbar-track {
    background: transparent;
}

.outfit-items-list::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
}

.mini-thumbnail {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.05);
    background: #f5f5f7;
}

.mini-thumbnail-placeholder {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    flex-shrink: 0;
    background: rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: #86868b;
    border: 1px solid rgba(0,0,0,0.05);
}

/* Detail Modal Specifics */
.detail-modal-content {
    background: #fbfbfd;
    max-width: 600px;
    height: 90vh;
}

.detail-modal-body {
    padding: 0;
    display: flex;
    flex-direction: column;
}

.detail-modal-body .card-image-container {
    width: 100%;
    aspect-ratio: 4/5;
    background: #f0f0f5;
    position: relative;
}

.detail-modal-body .card-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.detail-modal-body .card-content {
    padding: 24px;
    background: #fff;
    flex-grow: 1;
}

/* Dynamic Collage */
.collage-container {
    width: 100%;
    height: 100%;
    display: grid;
    gap: 2px;
    background: #fff;
}
.collage-container[data-count="0"] {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #86868b;
    background: rgba(0,0,0,0.02);
    font-size: 14px;
}
.collage-container[data-count="1"] {
    grid-template-columns: 1fr;
}
.collage-container[data-count="2"] {
    grid-template-columns: 1fr 1fr;
}
.collage-container[data-count="3"] {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}
.collage-container[data-count="3"] img:first-child {
    grid-row: span 2;
}
.collage-container[data-count="4"],
.collage-container[data-count="5"],
.collage-container[data-count="6"],
.collage-container[data-count="7"],
.collage-container[data-count="8"],
.collage-container[data-count="9"],
.collage-container[data-count="10"] {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}
.collage-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* --- iPhone Safari Optimizations --- */

/* Safe area insets for notched iPhones */
.navbar {
    padding-top: env(safe-area-inset-top, 0px);
}
.nav-content {
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
}
.catalog {
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
    padding-bottom: max(80px, env(safe-area-inset-bottom));
}

@media (max-width: 768px) {
    /* Responsive Grid: 3 columns on mobile */
    .grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .hero {
        padding: 24px 16px;
    }
    
    .hero h2 {
        font-size: 28px;
    }
    
    .hero p {
        font-size: 16px;
    }
    
    /* Make card fonts smaller and reduce padding for 3-column layout */
    .card-content {
        padding: 10px;
    }
    
    .card-title {
        font-size: 12px;
        margin-bottom: 4px;
        line-height: 1.2;
    }
    
    .card-desc {
        font-size: 10px;
        line-height: 1.3;
    }
    
    /* Hide tags on mobile as requested */
    .card-tags {
        display: none !important;
    }

    /* Prevent Safari auto-zoom on focus by enforcing 16px font-size ONLY on inputs, not on editable text to respect user's small font request */
    .tag-select,
    .tag-input,
    .apple-select,
    .apple-input {
        font-size: 16px !important;
    }

    /* Horizontal scrolling for filters on mobile */
    .filters-container {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 12px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
    }
    .filters-container::-webkit-scrollbar {
        display: none; /* Safari */
    }
    
    .apple-select, .apple-input {
        flex-shrink: 0;
    }

    /* Increase touch target size for delete button, but make it fit small cards */
    .delete-btn {
        width: 24px;
        height: 24px;
        top: 6px;
        right: 6px;
        font-size: 14px;
        opacity: 1; /* Always visible on mobile, no hover */
        background: rgba(0,0,0,0.3);
    }
    
    /* Horizontal scrolling for outfit items */
    .outfit-items-list {
        -webkit-overflow-scrolling: touch;
    }

    .tabs-control {
        margin: 0;
    }
    
    .modal-content {
        width: 95%;
        height: 90dvh; /* Use dynamic viewport height for Safari */
    }
    
    .modal-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .actions-container {
        flex-direction: column;
        width: 100%;
    }
    
    .actions-container button {
        width: 100%;
        justify-content: center;
    }
}

.filters-master-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@media (min-width: 768px) {
    .filters-master-container {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }
    
    .filters-container {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        scrollbar-width: none;
    }
}
