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

/* =============================================================================
   Skip Link (Accessibility)
   ============================================================================= */

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #667eea;
    color: white;
    padding: 8px 16px;
    z-index: 1001;
    text-decoration: none;
    font-weight: 600;
}

.skip-link:focus {
    top: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

h1 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 28px;
}

.subtitle {
    color: #6b7280;
    margin-bottom: 30px;
    font-size: 16px;
}

.step {
    display: none;
    will-change: opacity, transform;
}

.step.active {
    display: block;
    animation: fadeIn 0.3s;
}

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

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

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #2c3e50;
}

input[type="text"],
textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 16px;
    transition: border-color 0.3s;
}

input[type="text"]:focus,
textarea:focus {
    outline: none;
    border-color: #667eea;
}

textarea {
    min-height: 300px;
    resize: vertical;
    font-family: inherit;
}

.btn {
    background: #667eea;
    color: white;
    padding: 12px 30px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s, transform 0.1s;
}

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

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

.btn:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

.btn-secondary {
    background: #95a5a6;
    margin-left: 10px;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.btn-copy {
    background: #27ae60;
    margin-left: 10px;
}

.btn-copy:hover {
    background: #229954;
}

.info-box {
    background: #f8f9fa;
    border-left: 4px solid #667eea;
    padding: 20px;
    margin: 20px 0;
    border-radius: 4px;
}

.info-box h3 {
    margin-bottom: 10px;
    color: #2c3e50;
}

.info-box p {
    margin: 5px 0;
    color: #555;
}

.loading {
    display: none;
    text-align: center;
    padding: 20px;
}

.loading.active {
    display: block;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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

.error {
    background: #fee;
    border-left: 4px solid #e74c3c;
    padding: 15px;
    margin: 20px 0;
    border-radius: 4px;
    color: #c0392b;
}

.success {
    background: #d4edda;
    border-left: 4px solid #27ae60;
    padding: 15px;
    margin: 20px 0;
    border-radius: 4px;
    color: #155724;
}

.help-text {
    font-size: 14px;
    color: #7f8c8d;
    margin-top: 5px;
    transition: color 0.2s, font-weight 0.2s;
}

.help-text.hint-active {
    color: #667eea;
    font-weight: 600;
}

.step-indicator {
    display: flex;
    justify-content: space-between;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.step-item {
    flex: 1;
    text-align: center;
    position: relative;
    color: #6c757d; /* Changed from #bdc3c7 for WCAG AA contrast (5.7:1) */
    font-size: 14px;
    font-weight: 600;
}

.step-item.active {
    color: #667eea;
}

.step-item.active::before {
    content: "\25B6 "; /* Right-pointing triangle */
}

.step-item.completed {
    color: #27ae60;
}

.step-item.completed::before {
    content: "\2713 "; /* Checkmark */
}

.autocomplete-container {
    position: relative;
}

.autocomplete-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid #e0e0e0;
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    will-change: opacity;
}

.autocomplete-suggestions.active {
    display: block;
}

.autocomplete-item {
    padding: 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background-color: #f8f9fa;
}

.autocomplete-item.selected {
    background-color: #e8eaf6;
}

.autocomplete-item:focus,
.autocomplete-item:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: -2px;
    background-color: #e8eaf6;
}

.autocomplete-item strong {
    color: #2c3e50;
}

.autocomplete-item small {
    display: block;
    color: #7f8c8d;
    font-size: 13px;
    margin-top: 3px;
}

.autocomplete-loading {
    padding: 12px;
    text-align: center;
    color: #7f8c8d;
    font-size: 14px;
}

.autocomplete-error {
    padding: 12px;
    text-align: center;
    color: #c0392b;
    font-size: 14px;
}

.topic-selection {
    margin: 20px 0;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 6px;
    border: none;
}

.topic-selection legend {
    padding: 0;
    margin-bottom: 0;
}

.topic-selection h3 {
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 18px;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.radio-option {
    display: flex;
    align-items: center;
    padding: 12px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
}

.radio-option:hover {
    border-color: #667eea;
    background: #f8f9ff;
}

.radio-option input[type="radio"] {
    margin-right: 12px;
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.radio-option label {
    cursor: pointer;
    margin: 0;
    flex: 1;
}

.radio-option input[type="radio"]:checked + label {
    font-weight: 600;
    color: #667eea;
}

.radio-option:has(input[type="radio"]:checked) {
    border-color: #667eea;
    background: #f8f9ff;
}

/* =============================================================================
   Offline Banner
   ============================================================================= */

.offline-banner {
    background: #fff3cd;
    color: #856404;
    padding: 12px 20px;
    text-align: center;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.offline-banner[hidden] {
    display: none;
}

.offline-icon {
    font-size: 18px;
}

/* =============================================================================
   Location Button
   ============================================================================= */

.btn-location {
    background: transparent;
    color: #667eea;
    border: 2px solid #667eea;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 10px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-location:hover {
    background: #667eea;
    color: white;
}

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

.location-icon {
    font-size: 16px;
}

.spinner-small {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* =============================================================================
   Topic Description
   ============================================================================= */

.topic-description {
    background: #e8f4fd;
    border-left: 4px solid #667eea;
    padding: 12px 15px;
    margin-top: 15px;
    border-radius: 0 4px 4px 0;
    font-size: 14px;
    color: #2c3e50;
    line-height: 1.5;
}

/* =============================================================================
   Retry Button
   ============================================================================= */

.btn-retry {
    background: #667eea;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-left: 15px;
    transition: background 0.3s;
}

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

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

/* =============================================================================
   Recent Searches / History
   ============================================================================= */

.recent-searches {
    margin: 20px 0;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
}

.recent-searches-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.recent-searches-header h4 {
    margin: 0;
    color: #2c3e50;
    font-size: 14px;
}

.btn-link {
    background: none;
    border: none;
    color: #667eea;
    font-size: 12px;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
}

.btn-link:hover {
    color: #5568d3;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    display: flex;
    flex-direction: column;
    padding: 10px 12px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    width: 100%;
}

.history-item:hover {
    border-color: #667eea;
    background: #f8f9ff;
}

.history-address {
    font-weight: 600;
    color: #2c3e50;
    font-size: 14px;
}

.history-mla {
    color: #7f8c8d;
    font-size: 12px;
    margin-top: 2px;
}

/* =============================================================================
   Restore Prompt
   ============================================================================= */

.restore-prompt {
    background: #e8f4fd;
    border: 2px solid #667eea;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.restore-prompt-content p {
    margin: 0 0 10px 0;
    color: #2c3e50;
}

.restore-details {
    font-size: 14px;
    color: #7f8c8d !important;
}

.restore-buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.btn-small {
    padding: 8px 16px;
    font-size: 14px;
}

/* =============================================================================
   Email Customization Section
   ============================================================================= */

.customization-section {
    margin: 20px 0;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 6px;
}

.customization-section h3 {
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 18px;
}

.customization-section textarea {
    min-height: 100px;
    resize: vertical;
}

.mla-email-display {
    margin: 15px 0;
    padding: 15px;
    background: white;
    border: 2px solid #667eea;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.mla-email-display .email-text {
    flex: 1;
    font-weight: 600;
    color: #2c3e50;
    font-size: 16px;
    word-break: break-all;
}

.btn-copy-email {
    background: #27ae60;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s, transform 0.1s;
    white-space: nowrap;
}

.btn-copy-email:hover {
    background: #229954;
}

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

.btn-mailto {
    background: #667eea;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s, transform 0.1s;
    white-space: nowrap;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.btn-mailto:hover {
    background: #5568d3;
    color: white;
}

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

/* =============================================================================
   Mobile Responsive Styles
   ============================================================================= */

@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    .container {
        padding: 20px;
        border-radius: 8px;
    }

    h1 {
        font-size: 24px;
    }

    .subtitle {
        font-size: 14px;
        margin-bottom: 20px;
    }

    .step-indicator {
        flex-direction: column;
        gap: 8px;
        margin-bottom: 20px;
        padding-bottom: 15px;
    }

    .step-item {
        padding: 8px;
        border-radius: 4px;
        background: #f8f9fa;
    }

    .step-item.active {
        background: #e8eaf6;
    }

    .step-item.completed {
        background: #d4edda;
    }

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

    input[type="text"],
    textarea {
        padding: 10px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    textarea {
        min-height: 200px;
    }

    .btn {
        display: block;
        width: 100%;
        padding: 14px 20px;
        margin-bottom: 10px;
    }

    .btn-secondary {
        margin-left: 0;
    }

    .btn-copy {
        margin-left: 0;
    }

    .info-box {
        padding: 15px;
        margin: 15px 0;
    }

    .mla-email-display {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .btn-copy-email {
        width: 100%;
        padding: 12px;
    }

    .btn-mailto {
        width: 100%;
        padding: 12px;
        justify-content: center;
    }

    .topic-selection {
        padding: 15px;
        margin: 15px 0;
    }

    /* Ensure minimum 44x44px touch targets for accessibility */
    .radio-option {
        min-height: 44px;
        padding: 12px;
    }

    .autocomplete-suggestions {
        max-height: 200px;
    }

    .autocomplete-item {
        min-height: 44px;
        padding: 12px;
    }

    /* New elements - mobile styles */
    .btn-location {
        width: 100%;
        justify-content: center;
    }

    .btn-retry {
        width: 100%;
        margin-left: 0;
        margin-top: 10px;
    }

    .error {
        flex-direction: column;
        align-items: stretch;
    }

    .restore-buttons {
        flex-direction: column;
    }

    .restore-buttons .btn {
        margin-bottom: 0;
    }

    .customization-section {
        padding: 15px;
        margin: 15px 0;
    }

    .customization-section textarea {
        min-height: 80px;
    }

    .offline-banner {
        padding: 10px 15px;
        font-size: 14px;
    }
}

@media (max-width: 400px) {
    .container {
        padding: 15px;
    }

    h1 {
        font-size: 20px;
    }

    .btn {
        font-size: 14px;
        padding: 12px 16px;
    }
}

/* =============================================================================
   Email Warning Styles
   ============================================================================= */

.email-warning {
    color: #856404;
}

/* =============================================================================
   Character Counter Styles
   ============================================================================= */

.char-counter {
    font-size: 12px;
    color: #7f8c8d;
    display: block;
    text-align: right;
    margin-top: 4px;
}

.char-counter.warning {
    color: #e74c3c;
}

/* =============================================================================
   Focus Indicators (Accessibility)
   ============================================================================= */

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible,
.btn:focus-visible,
.history-item:focus-visible,
.radio-option:focus-visible {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}
