:root {
    --primary: #14B8A6;
    --primary-dark: #0D9488;
    --primary-light: #5EEAD4;
    --bg-page: #F8FAFC;
    --bg-card: #FFFFFF;
    --bg-header: #0D9488;
    --text-dark: #1E293B;
    --text-medium: #475569;
    --text-light: #536071; /* Improved from #64748B for WCAG AA 4.5:1 contrast */
    --text-on-primary: #FFFFFF;
    --success: #10B981;
    --error: #EF4444;
    --warning: #F59E0B;
    --border: #E2E8F0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 6px rgba(0,0,0,0.1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;
}

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

/* Screen reader only - accessible hidden text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-dark);
    line-height: 1.5;
    min-height: 100vh;
    /* iOS Safari 100vh fix */
    min-height: -webkit-fill-available;
}

#app {
    min-height: 100vh;
    min-height: -webkit-fill-available; /* iOS Safari fix */
    display: flex;
    display: -webkit-flex; /* Older Safari */
    flex-direction: column;
    -webkit-flex-direction: column;
}

.hidden {
    display: none !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   LOADING STATES & TRANSITIONS
   ═══════════════════════════════════════════════════════════════════════════ */

/* Loading spinner */
.loading-spinner-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    gap: 16px;
}

.loading-spinner-container p {
    color: var(--text-medium);
    font-size: 0.9375rem;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Button loading state */
.btn-loading {
    position: relative;
    color: transparent !important;
}

.btn-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Input disabled state during loading */
input:disabled {
    background-color: var(--bg-page);
    cursor: not-allowed;
    opacity: 0.7;
}

/* Offline Banner */
.offline-banner {
    background: var(--warning);
    color: #000;
    text-align: center;
    padding: 10px 20px;
    font-size: 0.875rem;
    font-weight: 500;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    animation: slideDown 0.3s ease;
}

.offline-banner.hidden {
    display: none !important;
}

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

.header {
    background-color: var(--bg-header);
    color: var(--text-on-primary);
    padding: 12px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-content {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    display: flex;
    align-items: center;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-on-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.credits-badge {
    background: rgba(255,255,255,0.2);
    padding: 6px 12px;
    border-radius: var(--radius-full);
    font-size: 0.875rem;
    font-weight: 500;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-on-primary);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    transition: background 0.2s;
    min-height: 44px;
    min-width: 44px;
}

.btn-text:hover {
    background: rgba(255,255,255,0.1);
}

.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    animation: screenFadeIn 0.25s ease-out;
}

.screen.active {
    display: flex;
}

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

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    margin-bottom: 16px;
    border: 1px solid rgba(0,0,0,0.04);
    transition: box-shadow 0.2s, transform 0.2s;
}

.output-section.card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.06);
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-dark);
}

h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-dark);
}

.subtitle {
    color: var(--text-medium);
    margin-bottom: 20px;
    font-size: 1rem;
}

.screen-login {
    justify-content: center;
    -webkit-justify-content: center; /* Older Safari */
    align-items: center;
    -webkit-align-items: center; /* Older Safari */
    min-height: 100vh;
    min-height: -webkit-fill-available; /* iOS Safari fix */
    background: linear-gradient(135deg, var(--bg-page) 0%, #E2E8F0 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 40px 20px;
    text-align: center;
}

.logo-large {
    margin-bottom: 40px;
}

.logo-icon-large {
    margin-bottom: 16px;
}

.logo-text-large {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.tagline {
    color: var(--text-light);
    font-size: 1.125rem;
}

.login-form {
    background: var(--bg-card);
    padding: 32px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.login-help {
    margin-top: 16px;
    font-size: 0.875rem;
    color: var(--text-light);
    text-align: center;
}

.login-help-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.login-help-link:hover {
    text-decoration: underline;
}

.input-group {
    margin-bottom: 16px;
    text-align: left;
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-medium);
    margin-bottom: 6px;
}

input, select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--bg-card);
    color: var(--text-dark);
}

input:focus, select:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.1);
}

input:focus:not(:focus-visible), select:focus:not(:focus-visible) {
    outline: none;
}

input::placeholder {
    color: var(--text-light);
}

.error-message {
    color: var(--error);
    font-size: 0.875rem;
    margin-bottom: 16px;
    padding: 10px;
    background: #FEF2F2;
    border-radius: var(--radius-md);
}

.btn-primary {
    background: var(--primary);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 1rem;
    border: none;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
    font-family: inherit;
    box-shadow: 0 2px 4px rgba(20, 184, 166, 0.2);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 8px rgba(20, 184, 166, 0.3);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 1px 2px rgba(20, 184, 166, 0.2);
}

.btn-primary:disabled {
    background: var(--border);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.btn-primary:focus-visible, .btn-secondary:focus-visible, .btn-text:focus-visible, .answer-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-secondary {
    background: white;
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s, border-color 0.2s;
    font-family: inherit;
}

.btn-secondary:hover {
    background: rgba(20, 184, 166, 0.05);
    border-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(20, 184, 166, 0.1);
}

.btn-secondary:active {
    transform: translateY(0);
    box-shadow: none;
}

.btn-full {
    width: 100%;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.875rem;
    min-height: 44px;
    min-width: 44px;
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    margin-bottom: 20px;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary);
    background: rgba(20, 184, 166, 0.05);
}

.upload-icon {
    color: var(--text-light);
    margin-bottom: 12px;
}

.upload-zone p {
    color: var(--text-medium);
    margin-bottom: 4px;
}

.upload-formats {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 8px;
}

.text-light {
    color: var(--text-light);
    font-size: 1rem;
}

.preview-container {
    margin-bottom: 20px;
}

.preview-images {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.preview-item {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: grab;
}

.preview-item:active {
    cursor: grabbing;
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-item .remove-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 44px;
    height: 44px;
    background: rgba(0,0,0,0.8);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Touch target meets accessibility requirements */
    padding: 0;
    box-sizing: border-box;
}

.preview-item.main::after {
    content: 'Main';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--primary);
    color: white;
    font-size: 0.75rem;
    padding: 2px;
    text-align: center;
}

.preview-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preview-hint {
    font-size: 0.875rem;
    color: var(--text-medium);
}

.btn-text-small {
    background: none;
    border: none;
    color: var(--error);
    cursor: pointer;
    font-size: 0.875rem;
    padding: 10px 14px;
    min-height: 44px;
    min-width: 44px;
    border-radius: var(--radius-md);
    transition: background 0.2s;
}

.btn-text-small:hover {
    text-decoration: underline;
    background: rgba(239, 68, 68, 0.1);
}

.tip {
    font-size: 1rem;
    color: var(--text-dark);
    margin-bottom: 20px;
    padding: 12px 14px;
    background: #F0FDFA;
    border-radius: var(--radius-md);
    border-left: 3px solid var(--primary);
}

.keyboard-hint {
    font-size: 0.8125rem;
    color: var(--text-light);
    font-style: italic;
}

.description-length {
    font-size: 0.875rem;
    color: var(--text-light);
    margin-top: 8px;
    text-align: right;
}

.back-link {
    color: var(--text-medium) !important;
    margin-bottom: 16px;
    display: inline-flex;
    align-items: center;
    font-size: 1rem;
    min-height: 44px;
    padding: 8px 12px 8px 0;
    border-radius: var(--radius-md);
}

.back-link:hover {
    color: var(--primary) !important;
    background: rgba(20, 184, 166, 0.05);
}

.detected-info {
    text-align: center;
    margin-bottom: 24px;
}

.detected-product {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-dark);
    margin: 16px 0 8px;
    word-break: break-word;
    overflow-wrap: break-word;
}

.detected-category {
    color: var(--text-medium);
    font-size: 1rem;
}

.confirm-buttons {
    display: flex;
    gap: 12px;
}

.confirm-buttons button {
    flex: 1;
}

.manual-entry {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.manual-entry h3 {
    margin-bottom: 16px;
}

.progress-bar {
    height: 4px;
    background: var(--border);
    border-radius: var(--radius-full);
    margin-bottom: 8px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 1rem;
    color: var(--text-medium);
    margin-bottom: 24px;
}

.question-container {
    animation: fadeIn 0.3s ease;
}

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

.question-text {
    font-size: 1.25rem;
    margin-bottom: 20px;
}

.answer-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.answer-btn {
    padding: 14px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-dark);
    font-size: 1rem;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    min-height: 44px;
}

.answer-btn:hover {
    border-color: var(--primary);
    background: rgba(20, 184, 166, 0.05);
}

.answer-btn.selected {
    border-color: var(--primary);
    background: rgba(20, 184, 166, 0.1);
    color: var(--primary-dark);
}

.other-input-container {
    margin-top: 12px;
}

.question-nav {
    margin-top: 24px;
    display: flex;
    justify-content: flex-start;
}

.question-nav .btn-text {
    color: var(--text-medium);
}

.loading-card {
    text-align: center;
    padding: 40px 24px;
}

.loading-progress {
    margin: 24px 0;
}

.loading-bar {
    height: 8px;
    background: var(--border);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-bottom: 8px;
}

.loading-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light), var(--primary));
    background-size: 200% 100%;
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
    width: 0%;
    animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

#loading-percent {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary);
}

.loading-steps {
    text-align: left;
    max-width: 300px;
    margin: 0 auto;
}

.loading-step {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    color: var(--text-light);
}

.loading-step.active {
    color: var(--primary);
}

.loading-step.completed {
    color: var(--success);
}

.loading-step.completed .step-icon {
    color: var(--success);
}

.step-icon {
    font-size: 1rem;
}

.loading-error {
    margin-top: 24px;
    padding: 20px;
    background: #FEF2F2;
    border-radius: var(--radius-md);
    text-align: center;
}

.loading-error p {
    color: var(--error);
    margin-bottom: 16px;
}

.loading-error-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.loading-slow {
    color: var(--warning);
    margin-top: 16px;
    font-size: 0.875rem;
}

.output-section {
    margin-bottom: 16px;
}

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

.btn-copy {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    font-family: inherit;
    min-height: 44px;
    min-width: 44px;
}

.btn-copy:hover {
    background: var(--primary-dark);
}

.btn-copy.copied {
    background: var(--success);
}

.output-title {
    font-size: 1.125rem;
    line-height: 1.4;
    color: var(--text-dark);
    margin-bottom: 16px;
    word-break: break-word;
    padding: 8px 12px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    transition: border-color 0.2s, background 0.2s;
    cursor: text;
    /* Cross-browser user-select for contenteditable */
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

.output-title:hover {
    border-color: var(--border);
    background: var(--bg-page);
}

.output-title:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-color: var(--primary);
    background: var(--bg-card);
}

.output-title:focus:not(:focus-visible) {
    outline: none;
}

.title-controls {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.control-group label {
    font-size: 0.875rem;
    color: var(--text-light);
}

.toggle-group {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.toggle-btn {
    padding: 10px 14px;
    border: none;
    background: var(--bg-card);
    color: var(--text-medium);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    min-height: 44px;
    min-width: 44px;
}

.toggle-btn:not(:last-child) {
    border-right: 1px solid var(--border);
}

.toggle-btn.active {
    background: var(--primary);
    color: white;
}

.title-length {
    font-size: 0.875rem;
    color: var(--text-medium);
}

.title-warning {
    color: var(--error);
    font-weight: 500;
}

.title-length.over-limit {
    color: var(--error);
}

.price-display {
    display: flex;
    align-items: baseline;
    justify-content: center;
    margin-bottom: 8px;
}

.price-currency {
    font-size: 1.5rem;
    color: var(--text-medium);
    margin-right: 4px;
}

.price-value {
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-dark);
}

.price-range {
    text-align: center;
    color: var(--text-medium);
    font-size: 1rem;
    margin-bottom: 20px;
}

.price-slider-container {
    padding: 0 10px;
    margin-bottom: 16px;
}

#price-slider {
    width: 100%;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--border);
    outline: none;
    -webkit-appearance: none;
}

#price-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 44px;
    height: 44px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow);
    margin-top: -18px;
}

#price-slider::-moz-range-thumb {
    width: 44px;
    height: 44px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Edge (legacy) slider thumb */
#price-slider::-ms-thumb {
    width: 44px;
    height: 44px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

#price-slider::-ms-track {
    width: 100%;
    height: 8px;
    background: transparent;
    border-color: transparent;
    color: transparent;
}

#price-slider::-ms-fill-lower {
    background: var(--primary);
    border-radius: var(--radius-full);
}

#price-slider::-ms-fill-upper {
    background: var(--border);
    border-radius: var(--radius-full);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    color: var(--text-medium);
    margin-top: 8px;
}

.price-breakdown {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.breakdown-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 0.875rem;
}

.breakdown-row.total {
    font-weight: 600;
    border-top: 1px solid var(--border);
    margin-top: 8px;
    padding-top: 16px;
}

.breakdown-positive {
    color: var(--success);
}

.breakdown-negative {
    color: var(--error);
}

.category-info {
    margin-bottom: 12px;
}

.category-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.category-id {
    font-family: monospace;
    color: var(--text-light);
}

.category-selector {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

.category-selector select {
    flex: 1;
}

.output-description {
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--text-dark);
    white-space: pre-wrap;
    padding: 12px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    transition: border-color 0.2s, background 0.2s;
    cursor: text;
    min-height: 100px;
    /* Cross-browser user-select for contenteditable */
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

.output-description:hover {
    border-color: var(--border);
    background: var(--bg-page);
}

.output-description:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-color: var(--primary);
    background: var(--bg-card);
}

.output-description:focus:not(:focus-visible) {
    outline: none;
}

.item-specifics {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.specific-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

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

.specific-label {
    font-weight: 500;
    color: var(--text-medium);
}

.specific-value-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.specific-value {
    color: var(--text-dark);
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
    margin-bottom: 40px;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
    animation: modalFadeIn 0.2s ease;
    backdrop-filter: blur(2px);
}

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

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.25s ease;
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
    will-change: transform, opacity;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.75rem;
    cursor: pointer;
    color: var(--text-medium);
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: background 0.2s;
}

.modal-close:hover {
    background: var(--border);
}

.history-list {
    overflow-y: auto;
    padding: 16px 20px;
}

.history-item {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.history-item:hover {
    border-color: var(--primary);
}

.history-item-title {
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-meta {
    font-size: 0.875rem;
    color: var(--text-medium);
}

.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--text-dark);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    transition: opacity 0.3s ease, transform 0.3s ease;
    will-change: transform, opacity;
}

.toast.fade-out {
    opacity: 0;
    transform: translateX(100%);
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--error);
}

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

@media (max-width: 480px) {
    .header-content {
        padding: 0;
        gap: 8px;
    }

    .header-right {
        gap: 4px;
    }

    .header-right .btn-text {
        padding: 10px 8px;
        font-size: 0.8125rem;
    }

    .credits-badge {
        padding: 6px 8px;
        font-size: 0.75rem;
    }

    .logo-text {
        display: none;
    }

    .container {
        padding: 16px;
    }

    .card {
        padding: 16px;
    }

    .login-form {
        padding: 20px;
    }

    .logo-text-large {
        font-size: 2rem;
    }

    /* Larger inputs on mobile for easier tapping */
    input, select {
        padding: 14px 16px;
        font-size: 16px; /* Prevents iOS zoom on focus */
        min-height: 48px;
    }

    /* Login help link touch target */
    .login-help-link {
        display: inline-block;
        padding: 10px 4px;
        min-height: 44px;
    }

    .preview-item {
        width: 80px;
        height: 80px;
    }

    .title-controls {
        flex-direction: column;
        gap: 16px;
    }

    .price-value {
        font-size: 2.5rem;
    }

    /* Stack category rows vertically on mobile */
    .category-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .category-row .btn-copy {
        align-self: flex-end;
    }

    /* Stack specific rows on mobile */
    .specific-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .specific-value-container {
        width: 100%;
        justify-content: space-between;
    }

    /* Make action buttons more spaced */
    .action-buttons {
        margin-bottom: 100px;
        gap: 10px;
    }

    .action-buttons button {
        font-size: 0.9375rem;
        padding: 14px 16px;
    }

    /* Full-height modals on mobile */
    .modal {
        padding: 0;
        align-items: flex-end;
    }

    .modal-content {
        max-width: 100%;
        max-height: 90vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    .history-list {
        -webkit-overflow-scrolling: touch;
    }

    /* Better section headers on mobile */
    .section-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .section-header h3 {
        flex: 1;
        min-width: 0;
    }

    .toast-container {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }

    .toast {
        text-align: center;
    }

    /* Better question buttons on mobile */
    .answer-btn {
        padding: 16px 20px;
    }

    /* Ensure upload zone is easy to tap */
    .upload-zone {
        padding: 48px 20px;
    }
}

@media (min-width: 768px) {
    .container {
        padding: 32px 20px;
    }

    .action-buttons {
        flex-direction: row;
    }

    .action-buttons button {
        flex: 1;
    }
}

/* Professional Footer */
.app-footer {
    background: var(--text-dark);
    color: rgba(255,255,255,0.8);
    padding: 24px 20px;
    margin-top: auto;
}

.footer-content {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
}

.footer-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.footer-logo {
    font-weight: 600;
    color: var(--primary-light);
    font-size: 1rem;
}

.footer-tagline {
    font-size: 0.875rem;
    color: rgba(255,255,255,0.6);
}

.footer-links {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.footer-link {
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 0.875rem;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    transition: color 0.2s, background 0.2s;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

.footer-link:hover {
    color: white;
    background: rgba(255,255,255,0.1);
}

.footer-divider {
    color: rgba(255,255,255,0.3);
    font-size: 0.75rem;
}

.footer-copyright {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.5);
}

.footer-version {
    margin-left: 8px;
    opacity: 0.7;
}

@media (max-width: 480px) {
    .footer-brand {
        flex-direction: column;
        gap: 4px;
    }

    .footer-links {
        flex-direction: column;
        gap: 8px;
    }

    .footer-divider {
        display: none;
    }
}

/* Extra small screens (320px) */
@media (max-width: 350px) {
    .container {
        padding: 12px;
    }

    .card {
        padding: 12px;
    }

    .login-form {
        padding: 16px;
    }

    .logo-text-large {
        font-size: 1.75rem;
    }

    .tagline {
        font-size: 1rem;
    }

    h2 {
        font-size: 1.25rem;
    }

    .price-value {
        font-size: 2rem;
    }

    .preview-item {
        width: 70px;
        height: 70px;
    }

    .btn-primary, .btn-secondary {
        padding: 10px 16px;
        font-size: 0.9375rem;
    }

    .header-right .btn-text {
        padding: 8px 6px;
        font-size: 0.75rem;
    }

    .credits-badge {
        padding: 4px 6px;
        font-size: 0.6875rem;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   ACCESSIBILITY ENHANCEMENTS
   ═══════════════════════════════════════════════════════════════════════════ */

/* Skip Link for keyboard users */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary);
    color: white;
    padding: 12px 20px;
    z-index: 1001;
    font-weight: 500;
    text-decoration: none;
    border-radius: 0 0 var(--radius-md) 0;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
    outline: 2px solid white;
    outline-offset: 2px;
}

/* Reduced Motion Preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .loading-fill {
        animation: none;
    }

    .loading-spinner {
        animation: none;
    }

    .screen {
        animation: none;
    }

    .toast {
        animation: none;
    }

    .modal {
        animation: none;
    }

    .modal-content {
        animation: none;
    }

    .question-container {
        animation: none;
    }

    .btn-loading::after {
        animation: none;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: more) {
    :root {
        --border: #333333;
        --text-light: #333333;
    }

    .btn-primary {
        border: 2px solid var(--text-dark);
    }

    .btn-secondary {
        border-width: 2px;
    }
}

/* Focus visible for all interactive elements */
a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible,
[contenteditable]:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Upload zone focus */
.upload-zone:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-color: var(--primary);
}

/* Toggle button focus */
.toggle-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    position: relative;
    z-index: 1;
}

/* History item focus for keyboard navigation */
.history-item:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Range slider focus */
#price-slider:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 4px;
}

/* Modal close button focus */
.modal-close:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Footer link focus */
.footer-link:focus-visible {
    outline: 2px solid var(--primary-light);
    outline-offset: 2px;
}

/* Ensure text selection is visible */
::selection {
    background: var(--primary);
    color: white;
}

/* Live region styling (for screen readers) */
[aria-live] {
    position: relative;
}

/* Visually hidden but accessible to screen readers */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   CROSS-BROWSER COMPATIBILITY
   ═══════════════════════════════════════════════════════════════════════════ */

/* Flexbox gap fallback for Safari < 14.1 using @supports */
@supports not (gap: 10px) {
    .header-content > * + * {
        margin-left: 16px;
    }

    .header-right > * + * {
        margin-left: 16px;
    }

    .logo > * + * {
        margin-left: 10px;
    }

    .preview-images > * {
        margin: 6px;
    }

    .action-buttons > * + * {
        margin-top: 12px;
    }

    .answer-options > * + * {
        margin-top: 10px;
    }

    .confirm-buttons > * + * {
        margin-left: 12px;
    }

    .footer-links > * + * {
        margin-left: 8px;
    }
}

/* Firefox-specific fixes */
@-moz-document url-prefix() {
    /* Firefox scrollbar styling */
    * {
        scrollbar-width: thin;
        scrollbar-color: var(--border) transparent;
    }
}

/* Safari-specific fixes */
@supports (-webkit-touch-callout: none) {
    /* Fix Safari button appearance */
    button {
        -webkit-appearance: none;
    }

    /* Fix Safari input appearance */
    input[type="text"],
    input[type="range"] {
        -webkit-appearance: none;
    }

    /* Safari momentum scrolling */
    .history-list,
    .modal-content {
        -webkit-overflow-scrolling: touch;
    }
}

/* Webkit scrollbar styling (Chrome, Safari, Edge) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}

/* Print styles - hide non-essential elements */
@media print {
    .header,
    .app-footer,
    .toast-container,
    .modal,
    .btn-copy,
    .action-buttons {
        display: none !important;
    }

    .screen {
        display: block !important;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ccc;
        page-break-inside: avoid;
    }
}
