/* ============================================
   Social Content Generator - Pico CSS Overrides
   ============================================
   Selective overrides for Pico CSS to match
   the "Digital Studio" aesthetic.

   Design tokens are defined in tokens.css.
   See DESIGN_SYSTEM.md for documentation.
   ============================================ */

/* ============================================
   FONT WEIGHT ALIASES
   ============================================
   Legacy weight variables used in this file.
   ============================================ */

:root {
    --weight-normal: var(--font-weight-normal);
    --weight-medium: var(--font-weight-medium);
    --weight-semibold: var(--font-weight-semibold);
    --weight-bold: var(--font-weight-bold);
}

/* Apply typography to Pico CSS base */
html {
    font-family: var(--font-body);
}

h1, h2, h3, h4, h5, h6,
[role="heading"] {
    font-family: var(--font-display);
    font-weight: var(--weight-semibold);
    letter-spacing: -0.02em;
}

/* Navigation brand text */
nav strong {
    font-family: var(--font-display);
    font-weight: var(--weight-bold);
    letter-spacing: -0.01em;
}

/* Code and pre elements */
code, pre, kbd, samp {
    font-family: var(--font-mono);
}

/* ============================================
   PICO CSS OVERRIDES
   ============================================
   Override Pico CSS variables to use our tokens.
   ============================================ */

:root {
    /* ===== LEGACY COLOR ALIASES ===== */
    /* Used by some components - mapped to new tokens */
    --color-electric: var(--color-primary);
    --color-electric-hover: var(--color-primary-hover);
    --color-electric-muted: var(--color-primary-muted);
    --color-ember: var(--color-warning);
    --color-ember-soft: var(--color-warning-soft);
    --color-mint: var(--color-success);
    --color-mint-soft: var(--color-success-soft);
    --color-crimson: var(--color-error);
    --color-crimson-soft: var(--color-error-soft);
    --surface-ground: var(--color-slate-50);
    --surface-card: var(--surface-base);

    /* ===== PICO CSS OVERRIDES ===== */
    /* Primary buttons - electric blue */
    --pico-primary: var(--color-electric);
    --pico-primary-background: var(--color-electric);
    --pico-primary-border: var(--color-electric);
    --pico-primary-hover: var(--color-electric-hover);
    --pico-primary-hover-background: var(--color-electric-hover);
    --pico-primary-hover-border: var(--color-electric-hover);
    --pico-primary-focus: var(--color-electric);
    --pico-primary-inverse: #ffffff;

    /* Secondary buttons - slate gray */
    --pico-secondary-background: var(--color-slate-200);
    --pico-secondary-border: var(--color-slate-300);
    --pico-secondary-hover-background: var(--color-slate-300);
    --pico-secondary-hover-border: var(--color-slate-400);
    --pico-secondary-inverse: var(--color-ink);

    /* Contrast buttons - dark */
    --pico-contrast-background: var(--color-ink);
    --pico-contrast-border: var(--color-ink);
    --pico-contrast-hover-background: var(--color-ink-soft);
    --pico-contrast-hover-border: var(--color-ink-soft);
    --pico-contrast-inverse: #ffffff;

    /* Text selection */
    --pico-text-selection-color: rgba(59, 109, 240, 0.15);
}

/* Dark mode Pico CSS overrides */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        /* Primary buttons - darker for WCAG AA contrast compliance */
        --pico-primary: #4d7cf4;
        --pico-primary-background: #4d7cf4;
        --pico-primary-border: #4d7cf4;
        --pico-primary-hover: #6b8ef6;
        --pico-primary-hover-background: #6b8ef6;
        --pico-primary-hover-border: #6b8ef6;
        --pico-primary-focus: #4d7cf4;
        --pico-primary-inverse: #ffffff;

        /* Secondary buttons - lighter in dark mode */
        --pico-secondary-background: var(--color-slate-300);
        --pico-secondary-border: var(--color-slate-400);
        --pico-secondary-hover-background: var(--color-slate-400);
        --pico-secondary-hover-border: var(--color-slate-500);
        --pico-secondary-inverse: var(--color-ink);

        /* Contrast buttons - light in dark mode */
        --pico-contrast-background: var(--color-slate-100);
        --pico-contrast-border: var(--color-slate-100);
        --pico-contrast-hover-background: var(--color-slate-200);
        --pico-contrast-hover-border: var(--color-slate-200);
        --pico-contrast-inverse: var(--color-ink);
    }
}

:root[data-theme="dark"] {
    /* Primary buttons - darker for WCAG AA contrast compliance */
    --pico-primary: #4d7cf4;
    --pico-primary-background: #4d7cf4;
    --pico-primary-border: #4d7cf4;
    --pico-primary-hover: #6b8ef6;
    --pico-primary-hover-background: #6b8ef6;
    --pico-primary-hover-border: #6b8ef6;
    --pico-primary-focus: #4d7cf4;
    --pico-primary-inverse: #ffffff;

    /* Secondary buttons - lighter in dark mode */
    --pico-secondary-background: var(--color-slate-300);
    --pico-secondary-border: var(--color-slate-400);
    --pico-secondary-hover-background: var(--color-slate-400);
    --pico-secondary-hover-border: var(--color-slate-500);
    --pico-secondary-inverse: var(--color-ink);

    /* Contrast buttons - light in dark mode */
    --pico-contrast-background: var(--color-slate-100);
    --pico-contrast-border: var(--color-slate-100);
    --pico-contrast-hover-background: var(--color-slate-200);
    --pico-contrast-hover-border: var(--color-slate-200);
    --pico-contrast-inverse: var(--color-ink);
}

body {
    background-color: var(--surface-ground);
    color: var(--color-ink);
}

/* ============================================
   3. SPACING & RHYTHM
   ============================================
   Generous spacing creates visual breathing room
   and improves scannability.
   ============================================ */

/* Improved body text line-height for readability */
body {
    line-height: 1.7;
}

/* Card padding increase from 1rem to 2rem */
article {
    padding: var(--space-xl);
    background: var(--surface-card);
    border: 1px solid var(--color-slate-200);
    box-shadow: var(--shadow-sm);
}

/* Ensure article headers and footers have appropriate spacing */
article > header {
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-slate-200);
}

article > footer {
    margin-top: var(--space-lg);
    padding-top: var(--space-md);
    border-top: 1px solid var(--color-slate-200);
}

/* Spacing utility classes */
.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: var(--space-sm) !important; }
.mt-2 { margin-top: var(--space-md) !important; }
.mt-3 { margin-top: var(--space-lg) !important; }
.mt-4 { margin-top: var(--space-xl) !important; }

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: var(--space-sm) !important; }
.mb-2 { margin-bottom: var(--space-md) !important; }
.mb-3 { margin-bottom: var(--space-lg) !important; }
.mb-4 { margin-bottom: var(--space-xl) !important; }

.pt-0 { padding-top: 0 !important; }
.pt-1 { padding-top: var(--space-sm) !important; }
.pt-2 { padding-top: var(--space-md) !important; }
.pt-3 { padding-top: var(--space-lg) !important; }
.pt-4 { padding-top: var(--space-xl) !important; }

.pb-0 { padding-bottom: 0 !important; }
.pb-1 { padding-bottom: var(--space-sm) !important; }
.pb-2 { padding-bottom: var(--space-md) !important; }
.pb-3 { padding-bottom: var(--space-lg) !important; }
.pb-4 { padding-bottom: var(--space-xl) !important; }

/* ============================================
   4. INTERACTIVE ELEMENTS & TRANSITIONS
   ============================================
   Smooth, subtle hover states create a polished feel.
   ============================================ */

/* Base transition for interactive elements - specific properties for better performance */
a, button, [role="button"] {
    transition: color 0.2s ease, background-color 0.2s ease,
                border-color 0.2s ease, transform 0.15s ease;
}

input, select, textarea {
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Article card hover effect - subtle lift */
article {
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

article:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--color-slate-300);
}

/* Prevent hover effects on nested articles or forms */
article article,
article form article {
    transform: none;
    box-shadow: var(--shadow-sm);
}

article article:hover,
article form article:hover {
    transform: none;
    box-shadow: var(--shadow-sm);
    border-color: var(--color-slate-200);
}

/* ============================================
   BUTTON CUSTOMIZATION
   ============================================
   Pico CSS handles colors via variables set in :root.
   We only customize typography, interactions, and transitions.
   No !important needed - we work WITH the framework.
   ============================================ */

/* Typography and spacing */
button, [role="button"], input[type="submit"], input[type="button"] {
    font-family: var(--font-display);
    font-weight: var(--weight-medium);
    letter-spacing: 0;
}

/* Hover enhancement - subtle lift */
button:not(.outline):hover,
[role="button"]:not(.outline):hover,
input[type="submit"]:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

/* Outline button hover */
button.outline:hover,
[role="button"].outline:hover {
    transform: translateY(-1px);
}

/* Active/pressed state - visual feedback */
button:active,
[role="button"]:active,
input[type="submit"]:active {
    transform: translateY(0);
}

/* Focus states for accessibility */
button:focus-visible,
[role="button"]:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--color-electric);
    outline-offset: 2px;
}

/* Disabled state */
button:disabled,
[role="button"][aria-disabled="true"],
input[type="submit"]:disabled,
input[type="button"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    pointer-events: none;
}

/* Button size utilities */
.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
}

/* Link styling */
a {
    color: var(--color-electric);
    text-decoration: none;
}

a:hover {
    color: var(--color-electric-hover);
    text-decoration: underline;
}

/* Navigation links - no underline on hover */
nav a:hover {
    text-decoration: none;
}

/* ============================================
   5. FORM ELEMENTS
   ============================================ */

input, select, textarea {
    background: var(--surface-card);
    border-color: var(--color-slate-300);
}

input:focus, select:focus, textarea:focus {
    border-color: var(--color-electric);
    box-shadow: 0 0 0 3px rgba(59, 109, 240, 0.1);
}

/* Textarea specific styling */
textarea {
    line-height: 1.6;
}

/* ============================================
   6. NAVIGATION
   ============================================ */

nav {
    padding-top: var(--space-md);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-slate-200);
    background: var(--surface-card);
}

nav a {
    color: var(--color-ink);
    font-weight: var(--weight-medium);
}

nav a:hover {
    color: var(--color-electric);
}

/* ============================================
   EXISTING STYLES (Updated/Preserved)
   ============================================ */

/* Center utility */
.center {
    text-align: center;
}

/* Article content styling */
.article-content {
    white-space: pre-wrap;
    line-height: 1.8;
}

.social-content {
    white-space: pre-wrap;
    background: var(--color-slate-100);
    padding: var(--space-md);
    border-radius: var(--pico-border-radius);
}

/* Card header with copy button */
article > header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

article > header button,
article > header form button {
    margin: 0;
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
}

/* Mobile-friendly form inputs */
@media (max-width: 576px) {
    textarea {
        min-height: 120px;
    }

    button[type="submit"]:not(.btn-sm) {
        width: 100%;
        padding: 1rem;
    }
}

/* Footer styling */
footer {
    margin-top: var(--space-xl);
    padding-top: var(--space-md);
    border-top: 1px solid var(--color-slate-200);
}

footer p {
    color: var(--color-slate-500);
    font-size: 0.875rem;
}

/* Empty state */
article.center {
    padding: var(--space-2xl) var(--space-md);
}

/* Progress indicator */
progress {
    width: 100%;
}

/* HTMX loading indicator */
.htmx-indicator {
    display: none;
}

/* When hx-indicator is specified, the indicator element itself gets htmx-request class */
.htmx-indicator.htmx-request {
    display: block;
}

/* Disable form elements during HTMX request */
.htmx-request button[type="submit"] {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.htmx-request input,
.htmx-request textarea,
.htmx-request select {
    opacity: 0.7;
    pointer-events: none;
}

/* Profile Tabs */
.profile-tabs {
    margin-bottom: var(--space-xl);
    padding: 0;
}

.profile-tabs ul {
    display: flex;
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
    border-bottom: 2px solid var(--color-slate-200);
}

.profile-tabs li {
    margin: 0;
}

.profile-tabs a {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0.75rem 1.25rem;
    text-decoration: none;
    color: var(--color-slate-500);
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
}

.profile-tabs a:hover {
    color: var(--color-electric);
    text-decoration: none;
}

.profile-tabs a.active {
    color: var(--color-electric);
    border-bottom-color: var(--color-electric);
    font-weight: var(--weight-medium);
}

.tab-icon {
    font-size: 1.1em;
}

/* Mobile: show only icons */
@media (max-width: 576px) {
    .profile-tabs a {
        padding: var(--space-sm) 0.75rem;
    }

    .profile-tabs .tab-label {
        display: none;
    }

    .tab-icon {
        font-size: 1.3em;
    }
}

/* YouTube Cookie Modal */
.youtube-modal-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    backdrop-filter: blur(4px);
}

.youtube-modal-content {
    background: var(--surface-card);
    border-radius: var(--pico-border-radius);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.youtube-modal-content article {
    margin: 0;
}

.youtube-modal-content article:hover {
    transform: none;
    box-shadow: none;
}

.youtube-modal-content article header {
    border-bottom: 1px solid var(--color-slate-200);
    padding-bottom: var(--space-sm);
    margin-bottom: var(--space-md);
}

.youtube-modal-content article footer {
    border-top: 1px solid var(--color-slate-200);
    padding-top: var(--space-md);
    margin-top: var(--space-md);
}

/* Animation for modal */
.youtube-modal-backdrop[style*="flex"] .youtube-modal-content {
    animation: modal-slide-in 0.25s ease-out;
}

@keyframes modal-slide-in {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================
   Progress Panel (SSE-powered generation steps)
   ============================================ */

.progress-panel {
    background: var(--surface-card);
    border-radius: var(--pico-border-radius);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
    border: 1px solid var(--color-slate-200);
    box-shadow: var(--shadow-sm);
}

.progress-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--color-slate-200);
}

.progress-step:last-child {
    border-bottom: none;
}

.step-icon {
    width: 1.5rem;
    height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.step-icon.waiting {
    color: var(--color-slate-400);
}

.step-icon.pending {
    color: var(--color-electric);
    animation: spin 1s linear infinite;
}

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

.step-icon.failed {
    color: var(--color-crimson);
}

.step-label {
    font-weight: var(--weight-medium);
    min-width: 140px;
}

.step-message {
    color: var(--color-slate-500);
    font-size: 0.9rem;
}

.step-message.loading-dots {
    animation: pulse 1s ease-in-out infinite;
}

/* Spin animation for pending state */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Pulse animation for loading text */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Success/error result styling */
.progress-result {
    margin-top: var(--space-md);
}

.progress-result.success header {
    color: var(--color-mint);
}

.progress-result.error header {
    color: var(--color-crimson);
}

/* Step status transitions */
.progress-step.success .step-label {
    color: var(--color-mint);
}

.progress-step.failed .step-label {
    color: var(--color-crimson);
}

.progress-step.pending .step-label {
    color: var(--color-electric);
}

/* Sub-step styling for nested progress indicators */
.progress-step.sub-step {
    padding-left: var(--space-xl);
    border-bottom: none;
    padding: 0.3rem 0 0.3rem var(--space-xl);
}

.sub-steps {
    margin-left: var(--space-md);
    border-left: 2px solid var(--color-slate-200);
    padding-left: var(--space-sm);
}

.step-group {
    margin-bottom: var(--space-sm);
}

/* Email log page styles */
#email-log-section article {
    margin-bottom: var(--space-md);
}

#email-log-section header {
    margin-bottom: var(--space-md);
}

#email-log-list article {
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

#email-log-list article:hover {
    border-color: var(--color-electric);
}

/* ============================================
   Button Utility Classes
   ============================================ */

/* Small button variant - consistent sizing */
.btn-sm {
    padding: 0.25rem 0.75rem !important;
    font-size: 0.875rem !important;
}

/* Button row - ensures consistent alignment */
.btn-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* Make form wrapper invisible to flex layout */
.btn-row > form {
    display: contents;
}

/* Reset margin and ensure alignment for all buttons in btn-row */
.btn-row > button,
.btn-row > a[role="button"],
.btn-row > form > button {
    margin: 0;
    align-self: center;
}

/* ============================================
   Checkbox Styling - Ensure Checked State Visibility
   ============================================ */

/* Force checkboxes to be visible and show checked state */
input[type="checkbox"] {
    opacity: 1 !important;
    visibility: visible !important;
    position: relative !important;
    width: auto !important;
    height: auto !important;
    appearance: auto !important;
    -webkit-appearance: checkbox !important;
    -moz-appearance: checkbox !important;
}

/* Ensure checkbox checked state is visible */
input[type="checkbox"]:checked {
    opacity: 1 !important;
    visibility: visible !important;
    background-color: var(--color-electric) !important;
    border-color: var(--color-electric) !important;
}

/* Pico CSS override - ensure checkmark is visible */
input[type="checkbox"]:checked::before,
input[type="checkbox"]:checked::after {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Draft checkbox specific styling */
.draft-checkbox {
    cursor: pointer !important;
    margin-right: 1rem !important;
}

/* ============================================
   Checkbox List Alignment
   ============================================ */

.checkbox-list-header {
    display: flex;
    align-items: center;
    padding-left: 0.75rem;
    margin-bottom: 0.75rem;
}

.checkbox-list-header label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin: 0;
    cursor: pointer;
    user-select: none;
    font-weight: var(--weight-medium);
}

.checkbox-list-header input[type="checkbox"] {
    margin: 0;
    margin-right: var(--space-sm);
}

/* ============================================
   Status Badges
   ============================================ */

/* Edited badge styling */
.badge-edited {
    background: var(--color-ember);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: var(--weight-medium);
}

/* Success badge */
.badge-success {
    background: var(--color-mint);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: var(--weight-medium);
}

/* Error badge */
.badge-error {
    background: var(--color-crimson);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: var(--weight-medium);
}

/* Posted badge (alias for success with link styling) */
.badge-posted {
    background: var(--color-mint);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: var(--weight-medium);
    text-decoration: none;
    margin-left: 0.5rem;
}

.badge-posted:hover {
    background: #0d9668;
    color: white;
    text-decoration: none;
}

/* Failed badge */
.badge-failed {
    background: var(--color-crimson);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: var(--weight-medium);
    margin-left: 0.5rem;
}

/* Badge with margin (for inline use) */
.badge-ml {
    margin-left: 0.5rem;
}

/* Verification score badge */
.badge-verification {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75em;
    margin-left: 0.5rem;
    font-weight: 600;
}
.badge-verification-green {
    color: var(--pico-ins-color, #2e7d32);
    background: rgba(46, 125, 50, 0.1);
}
.badge-verification-yellow {
    color: var(--pico-color-amber-500, #f59e0b);
    background: rgba(245, 158, 11, 0.1);
}
.badge-verification-red {
    color: var(--pico-del-color, #dc2626);
    background: rgba(220, 38, 38, 0.1);
}

/* ============================================
   Responsive Adjustments
   ============================================ */

@media (max-width: 768px) {
    article {
        padding: var(--space-lg);
    }

    article:hover {
        transform: none; /* Disable lift on touch devices */
    }
}

@media (max-width: 576px) {
    article {
        padding: var(--space-md);
    }
}

/* ============================================
   Motion Accessibility (WCAG 2.1 Level AA)
   ============================================
   Respects user preference for reduced motion
   to prevent discomfort for users with
   vestibular disorders.
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    article:hover {
        transform: none;
    }

    .progress-step.pending .step-icon {
        animation: none;
    }

    button:hover,
    [role="button"]:hover {
        transform: none;
    }
}
