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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100dvh;
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    color: #333;
}

.container {
    max-width: 900px;
    margin: 0 auto;
}

header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
    position: relative;
}

header h1 {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    margin-bottom: 10px;
    line-height: 1.2;
}

header p {
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    opacity: 0.9;
}

.dashboard-link {
    display: inline-block;
    width: fit-content;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    padding: 12px 24px;
    min-height: 44px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: background 0.3s;
    text-align: center;
    white-space: nowrap;
}

.dashboard-link:hover {
    background: rgba(255, 255, 255, 0.3);
}

@media (max-width: 767px) {
    .dashboard-link {
        flex: 1 1 auto;
        min-width: 140px;
        font-size: 14px;
        padding: 10px 16px;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .dashboard-link {
        font-size: 15px;
    }
}

.input-section {
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    margin-bottom: 30px;
}

.input-group {
    margin-bottom: 20px;
}

#product-url {
    width: 100%;
    padding: 16px 18px;
    min-height: 50px;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.3s;
}

#product-url:focus {
    border-color: #667eea;
}

.subid-section {
    margin: 20px 0;
    padding: 20px;
    background: #f9fafb;
    border-radius: 8px;
}

.subid-section h3 {
    font-size: 1rem;
    color: #6b7280;
    margin-bottom: 15px;
}

.subid-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

@media (min-width: 640px) {
    .subid-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
    }
}

.subid-input label {
    display: block;
    font-size: 1rem;
    color: #6b7280;
    margin-bottom: 6px;
    font-weight: 500;
}

.subid-input input {
    width: 100%;
    padding: 14px 12px;
    min-height: 48px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    outline: none;
    transition: border-color 0.3s;
}

.subid-input input:focus {
    border-color: #667eea;
}

#generate-btn {
    width: 100%;
    padding: 16px 30px;
    min-height: 56px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

#generate-btn:hover {
    background: #5568d3;
}

@media (hover: none) {
    #generate-btn:active {
        background: #5568d3;
    }
}

.error-message {
    color: #ef4444;
    margin-top: 15px;
    font-weight: 500;
}

.loading {
    text-align: center;
    color: white;
    padding: 40px;
}

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

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

.results {
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.results h2 {
    color: #667eea;
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.product-card {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 30px;
    padding: 16px;
    background: #f9fafb;
    border-radius: 8px;
}

@media (min-width: 640px) {
    .product-card {
        flex-direction: row;
        gap: 20px;
        padding: 20px;
    }
}

#product-image {
    width: 100%;
    max-width: 200px;
    height: auto;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 8px;
    margin: 0 auto;
}

@media (min-width: 640px) {
    #product-image {
        width: 200px;
        height: 200px;
        margin: 0;
    }
}

.product-details {
    flex: 1;
}

.product-details h3 {
    font-size: clamp(1.1rem, 4vw, 1.3rem);
    margin-bottom: 10px;
    color: #1f2937;
    line-height: 1.3;
}

.price {
    font-size: clamp(1.25rem, 5vw, 1.5rem);
    color: #059669;
    font-weight: 700;
    margin-bottom: 10px;
}

.description {
    color: #6b7280;
    line-height: 1.6;
    font-size: 0.95rem;
}

.caption-section {
    margin-bottom: 30px;
}

.caption-card {
    background: #f9fafb;
    border-radius: 8px;
    padding: 20px;
}

#generated-caption {
    font-size: 1.1rem;
    line-height: 1.8;
    color: #1f2937;
    margin-bottom: 15px;
    white-space: pre-wrap;
}

.copy-btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 14px 24px;
    min-height: 48px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.copy-btn:hover {
    background: #5568d3;
}

@media (hover: none) {
    .copy-btn:active {
        background: #5568d3;
    }
}

.link-section {
    margin-top: 30px;
}

.link-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 10px;
}

@media (min-width: 640px) {
    .link-card {
        flex-direction: row;
        gap: 10px;
    }
}

#affiliate-link {
    flex: 1;
    padding: 14px 12px;
    min-height: 48px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    background: #f9fafb;
    word-break: break-all;
}

.hint {
    color: #6b7280;
    font-size: 0.9rem;
    font-style: italic;
}

input, textarea, select {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

/* Flash Deals Section */
.flash-deals-section {
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    margin-top: 40px;
}

.flash-deals-section h2 {
    color: #1f2937;
    font-size: clamp(1.5rem, 4vw, 2rem);
    margin-bottom: 10px;
}

.filter-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

@media (min-width: 768px) {
    .filter-controls {
        flex-direction: row;
        gap: 12px;
    }
}

.deals-table {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.deals-table th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.5px;
}

.success-message {
    font-weight: 600;
}

/* Mobile-optimized brand search */
.brand-search-container {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

@media (min-width: 768px) {
    .brand-search-container {
        width: auto;
        flex: 0 1 auto;
    }
}

#brand-dropdown li {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 12px 16px !important;
    font-size: 16px;
}

#brand-dropdown li:hover {
    background: #f9fafb;
}

@media (max-width: 768px) {
    #brand-dropdown {
        max-height: 200px !important;
    }

    .brand-search-container {
        width: 100%;
    }

    #brand-clear-btn {
        min-width: 44px;
        padding: 10px 12px;
        font-size: 18px;
        flex-shrink: 0;
    }
}

@media (max-width: 768px) {
    .flash-deals-section {
        padding: 20px;
    }

    /* Hide desktop table on mobile */
    .deals-table thead {
        display: none;
    }

    .deals-table,
    .deals-table tbody,
    .deals-table tr {
        display: block;
        width: 100%;
    }

    .deals-table tr {
        margin-bottom: 16px;
        border: 2px solid #e5e7eb;
        border-radius: 8px;
        padding: 12px;
        background: white;
    }

    .deals-table td {
        display: block;
        text-align: left;
        padding: 8px 0 !important;
        border: none;
    }

    .deals-table td:first-child {
        padding: 0 0 12px 0 !important;
        border-bottom: 1px solid #e5e7eb;
        margin-bottom: 8px;
    }

    /* Add labels for mobile */
    .deals-table td:nth-child(2):before {
        content: "Product: ";
        font-weight: 600;
        color: #6b7280;
        display: block;
        margin-bottom: 4px;
    }

    .deals-table td:nth-child(3):before {
        content: "Tags: ";
        font-weight: 600;
        color: #6b7280;
        display: block;
        margin-bottom: 4px;
    }

    .deals-table td:nth-child(4):before {
        content: "Link: ";
        font-weight: 600;
        color: #6b7280;
        display: block;
        margin-bottom: 4px;
    }
}

.caption-text {
    background: white;
    padding: 15px;
    border-radius: 6px;
    margin: 10px 0;
    color: #1f2937;
    line-height: 1.6;
    white-space: pre-wrap;
}

.caption-text-editable {
    width: 100%;
    background: white;
    padding: 15px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    margin: 10px 0;
    color: #1f2937;
    line-height: 1.6;
    font-family: inherit;
    font-size: 16px;
    min-height: 120px;
    max-height: 500px;
    resize: vertical;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.caption-text-editable[readonly] {
    background: #f9fafb;
    cursor: pointer;
    border: 2px dashed #d1d5db;
}

.caption-text-editable[readonly]:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.caption-text-editable:not([readonly]) {
    background: white;
    border: 2px solid #667eea;
}

.caption-text-editable:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.caption-text-editable:disabled {
    background: #f9fafb;
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-secondary {
    background: #6b7280;
    color: white;
}

.btn-secondary:hover {
    background: #4b5563;
}

.btn-success {
    background: #10b981;
    color: white;
}

.btn-success:hover {
    background: #059669;
}

@media (hover: none) {
    .btn-success:active {
        background: #059669;
    }
}