/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    /* iOS Colors */
    --ios-blue: #007AFF;
    --ios-blue-dark: #0051D5;
    --ios-red: #FF3B30;
    --ios-green: #34C759;
    --ios-orange: #FF9500;
    --ios-gray: #8E8E93;
    --ios-gray-light: #C7C7CC;
    
    /* Background Colors */
    --bg-primary: #F2F2F7;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #F9F9F9;
    
    /* Text Colors */
    --text-primary: #000000;
    --text-secondary: #3C3C43;
    --text-tertiary: #8E8E93;
    
    /* Layout */
    --safe-area-top: env(safe-area-inset-top);
    --safe-area-bottom: env(safe-area-inset-bottom);
    --header-height: 44px;
    --bottom-nav-height: 83px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeOut 0.5s ease 1.5s forwards;
}

@keyframes fadeOut {
    to {
        opacity: 0;
        pointer-events: none;
    }
}

.loading-content {
    text-align: center;
    animation: slideUp 0.8s ease;
}

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

.loading-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: bounce 1s ease infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

.loading-text {
    font-size: 32px;
    font-weight: 700;
    color: white;
    margin-bottom: 20px;
    letter-spacing: -0.5px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Main App */
.main-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Header */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--header-height) + var(--safe-area-top));
    padding-top: var(--safe-area-top);
    background: rgba(242, 242, 247, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 0.5px solid rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.header-title {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.4px;
}

.header-action {
    position: absolute;
    right: 16px;
    background: none;
    border: none;
    color: var(--ios-blue);
    font-size: 17px;
    font-weight: 400;
    cursor: pointer;
    padding: 8px;
}

/* Content */
.app-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: calc(var(--header-height) + var(--safe-area-top) + 16px) 16px calc(var(--bottom-nav-height) + 16px) 16px;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
    padding-bottom: var(--safe-area-bottom);
    background: rgba(249, 249, 249, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 8px;
    z-index: 100;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}

.nav-icon {
    width: 24px;
    height: 24px;
    color: var(--ios-gray);
    transition: all 0.2s ease;
}

.nav-item.active .nav-icon {
    color: var(--ios-blue);
    transform: scale(1.1);
}

.nav-label {
    font-size: 10px;
    color: var(--ios-gray);
    font-weight: 500;
    transition: color 0.2s ease;
}

.nav-item.active .nav-label {
    color: var(--ios-blue);
}

.cart-badge {
    position: absolute;
    top: -2px;
    right: calc(50% - 16px);
    background: var(--ios-red);
    color: white;
    font-size: 10px;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    animation: badgePop 0.3s ease;
}

@keyframes badgePop {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Card Styles */
.card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: all 0.2s ease;
}

.card:active {
    transform: scale(0.98);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Search Bar */
.search-container {
    margin-bottom: 16px;
}

.search-bar {
    width: 100%;
    height: 36px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 10px;
    padding: 0 36px 0 36px;
    font-size: 17px;
    color: var(--text-primary);
    transition: background 0.2s ease;
}

.search-bar:focus {
    outline: none;
    background: white;
    box-shadow: 0 0 0 1px var(--ios-blue);
}

.search-wrapper {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--ios-gray);
}

.clear-search {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--ios-gray-light);
    border: none;
    width: 18px;
    height: 18px;
    border-radius: 9px;
    color: white;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Button Styles */
.btn {
    width: 100%;
    height: 50px;
    border: none;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: var(--ios-blue);
    color: white;
}

.btn-primary:active {
    background: var(--ios-blue-dark);
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--ios-blue);
}

.btn-danger {
    background: var(--ios-red);
    color: white;
}

.btn-success {
    background: var(--ios-green);
    color: white;
}

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

/* Product Card */
.product-card {
    display: flex;
    gap: 12px;
    align-items: center;
}

.product-info {
    flex: 1;
}

.product-brand {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.product-name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.product-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.product-badge {
    background: rgba(0, 122, 255, 0.1);
    color: var(--ios-blue);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.product-price {
    font-size: 20px;
    font-weight: 700;
    color: var(--ios-blue);
}

.add-to-cart-btn {
    width: 40px;
    height: 40px;
    border-radius: 20px;
    background: var(--ios-blue);
    border: none;
    color: white;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.add-to-cart-btn:active {
    transform: scale(0.9);
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.empty-icon {
    font-size: 60px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.empty-text {
    font-size: 15px;
    color: var(--text-tertiary);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: flex-end;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: white;
    border-radius: 12px 12px 0 0;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: calc(20px + var(--safe-area-bottom));
    animation: slideUpModal 0.3s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--ios-blue);
    font-size: 17px;
    cursor: pointer;
}

/* Loading Spinner */
.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(0,0,0,0.1);
    border-top-color: var(--ios-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Animations */
.fade-in {
    animation: fadeIn 0.3s ease;
}

.slide-in {
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 0;
    background: transparent;
}

/* Touch feedback */
.touchable {
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.touchable:active {
    opacity: 0.6;
}

/* Group animations */
@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 2000px;
    }
}

@keyframes slideUp {
    from {
        opacity: 1;
        max-height: 2000px;
    }
    to {
        opacity: 0;
        max-height: 0;
    }
}

/* Group card styles */
.group-card {
    transition: all 0.2s ease;
}

.group-header {
    -webkit-tap-highlight-color: transparent;
}

.group-content {
    overflow: hidden;
    transition: all 0.3s ease;
}

/* Full-screen loading overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.3s ease;
}

.loading-content {
    text-align: center;
    color: white;
}

.loading-spinner-large {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    margin: 0 auto 24px;
    animation: spin 1s linear infinite;
}

.loading-text {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
    animation: pulse 1.5s ease infinite;
}

.loading-progress {
    width: 200px;
    height: 4px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
    margin: 0 auto;
    overflow: hidden;
}

.loading-progress-bar {
    height: 100%;
    background: white;
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 2px;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Success overlay */
.success-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    animation: fadeIn 0.3s ease;
}

.success-content {
    text-align: center;
    animation: successPop 0.5s ease;
}

.success-checkmark {
    width: 80px;
    height: 80px;
    background: var(--ios-green);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    color: white;
    margin: 0 auto 16px;
    animation: checkmarkScale 0.5s ease;
}

.success-text {
    font-size: 20px;
    font-weight: 600;
    color: white;
}

@keyframes successPop {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes checkmarkScale {
    0% {
        transform: scale(0) rotate(0deg);
    }
    50% {
        transform: scale(1.2) rotate(180deg);
    }
    100% {
        transform: scale(1) rotate(360deg);
    }
}

/* Desktop adaptations */
@media (min-width: 768px) {
    body {
        background: #f5f5f7;
    }
    
    .main-app {
        max-width: 1200px;
        margin: 0 auto;
        background: var(--bg-primary);
    }
    
    .app-header {
        max-width: 1200px;
        margin: 0 auto;
    }
    
    .app-content {
        max-width: 1200px;
        margin: 0 auto;
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
        gap: 16px;
    }
    
    .bottom-nav {
        max-width: 1200px;
        margin: 0 auto;
    }
    
    .card {
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }
    
    .card:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    
    .group-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
}

@media (min-width: 1024px) {
    .app-content {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Utility classes to reduce inline styles */
.card-section-header {
    font-size: 13px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    margin-bottom: 8px;
    padding: 0 4px;
    font-weight: 500;
}

.info-card {
    padding: 12px;
    background: rgba(0, 122, 255, 0.05);
    border-radius: 8px;
}

.info-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ios-blue);
    margin-bottom: 8px;
}

.info-list {
    margin: 0;
    padding-left: 20px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.stats-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-top: 1px solid var(--ios-gray-light);
}

.stats-value {
    color: var(--text-tertiary);
    font-weight: 500;
}

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
}

.form-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--ios-gray-light);
    border-radius: 8px;
    font-size: 15px;
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #000000;
        --bg-secondary: #1c1c1e;
        --bg-tertiary: #2c2c2e;
        --text-primary: #ffffff;
        --text-secondary: #98989d;
        --text-tertiary: #636366;
        --ios-gray-light: #38383a;
    }
    
    .card {
        background: var(--bg-secondary);
        border: 1px solid var(--ios-gray-light);
    }
    
    .form-input {
        border-color: var(--ios-gray-light);
    }
    
    .modal-content {
        background: var(--bg-secondary);
    }
    
    .group-card {
        background: var(--bg-secondary);
    }
    
    .search-bar {
        background: var(--bg-tertiary);
        border-color: var(--ios-gray-light);
        color: var(--text-primary);
    }
}

/* Offline indicator */
.offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #FF9500;
    color: white;
    padding: 8px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    z-index: 9999;
    display: none;
}

.offline-banner.show {
    display: block;
    animation: slideDown 0.3s ease;
}

/* Favorite button */
.favorite-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    transition: transform 0.2s ease;
}

.favorite-btn:active {
    transform: scale(1.2);
}

/* Quantity selector in catalog */
.qty-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.qty-btn {
    width: 28px;
    height: 28px;
    border-radius: 14px;
    border: none;
    background: var(--ios-blue);
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
}

.qty-btn:active {
    opacity: 0.7;
}

.qty-input {
    width: 45px;
    text-align: center;
    border: 1px solid var(--ios-gray-light);
    border-radius: 6px;
    padding: 4px;
    font-size: 15px;
    font-weight: 600;
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* Analytics table */
.analytics-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.analytics-table thead tr {
    background: var(--bg-secondary);
    text-align: left;
}

.analytics-table th {
    padding: 8px;
    border-bottom: 2px solid var(--ios-gray-light);
    font-weight: 600;
    color: var(--text-secondary);
}

.analytics-table td {
    padding: 12px 8px;
    border-bottom: 1px solid var(--ios-gray-light);
}

.analytics-table tbody tr:last-child td {
    border-bottom: none;
}

/* Smooth transitions for theme */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

button, input, .card {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
