/**
 * UI Enhancement Styles for Comic Studio
 * Additional styles for animations, transitions, and improved UX
 */

/* ============================================
   UTILITY CLASSES
   ============================================ */

:root {
    --komic-bg: #f6fbff;
    --komic-surface: #ffffff;
    --komic-border: #dceaf3;
    --komic-text: #1f2937;
    --komic-muted: #6b7d8d;
    --komic-success: #58cc02;
    --komic-shadow: 0 12px 30px rgba(26, 78, 108, .08);
}

.ui-icon {
    width: 1.25rem;
    height: 1.25rem;
    flex: 0 0 auto;
    display: inline-block;
    vertical-align: -0.2em;
    fill: currentColor;
    color: inherit;
}

.ui-icon-lg { width: 1.5rem; height: 1.5rem; }
.ui-icon-xl { width: 2rem; height: 2rem; }

.komic-app { background: radial-gradient(circle at 12% 0%, #e9f9ff 0, transparent 34%), var(--komic-bg); color: var(--komic-text); }
.komic-app header { background: rgba(255,255,255,.88); border-color: var(--komic-border); }
.komic-app main { animation: komic-enter .35s ease-out both; }
.komic-card { background: var(--komic-surface); border: 1px solid var(--komic-border); border-radius: 16px; box-shadow: var(--komic-shadow); }
.komic-kpi { min-height: 112px; padding: 18px; border-radius: 16px; background: white; border: 1px solid var(--komic-border); }
.komic-progress { height: 9px; border-radius: 999px; background: #e8f1f6; overflow: hidden; }
.komic-progress > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #1cb0f6, #58cc02); }
.komic-focus:focus-visible { outline: 3px solid rgba(28,176,246,.45); outline-offset: 3px; }
@keyframes komic-enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 760px) { .komic-app header nav { gap: 2px; overflow-x: auto; } .komic-app header nav > a { white-space: nowrap; } }
@media (min-width: 1080px) {
    .komic-app > header { position: fixed; inset: 0 auto 0 0; width: 220px; height: 100vh; z-index: 40; border-right: 1px solid var(--komic-border); border-bottom: 0; }
    .komic-app > header > div { max-width: none; height: 100%; padding: 24px 16px; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 28px; }
    .komic-app > header > div > a { padding: 8px; }
    .komic-app > header nav { flex-direction: column; align-items: stretch; gap: 6px; }
    .komic-app > header nav > a, .komic-app > header nav > div { width: 100%; }
    .komic-app > header nav > a { text-align: left; min-height: 44px; display: flex; align-items: center; }
    .komic-app > header nav > div:last-child { margin-top: auto; }
    .komic-app > main { margin-left: 220px; max-width: none; padding-left: clamp(24px, 4vw, 64px); padding-right: clamp(24px, 4vw, 64px); }
}

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

/* Focus visible for better keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--brand-color, #7c3aed);
    outline-offset: 2px;
}

/* Skip to main content link for accessibility */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--brand-color, #7c3aed);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 100;
    border-radius: 0 0 4px 0;
}

.skip-to-main:focus {
    top: 0;
}

/* ============================================
   ANIMATIONS & TRANSITIONS
   ============================================ */

/* Fade in animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}

/* Slide in from right (for toasts) */
@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.slide-in-right {
    animation: slideInRight 0.3s ease-out forwards;
}

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

.animate-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Bounce animation */
@keyframes bounce {
    0%, 100% {
        transform: translateY(-25%);
        animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
    }
    50% {
        transform: translateY(0);
        animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
    }
}

.animate-bounce {
    animation: bounce 1s infinite;
}

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

.animate-spin {
    animation: spin 1s linear infinite;
}

/* Shimmer effect for skeleton loaders */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 0px,
        #f8f8f8 40px,
        #f0f0f0 80px
    );
    background-size: 1000px 100%;
    animation: shimmer 2s infinite;
}

/* ============================================
   LOADING STATES
   ============================================ */

/* Spinner loader */
.spinner {
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-left-color: var(--brand-color, #7c3aed);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}

.spinner-lg {
    width: 48px;
    height: 48px;
    border-width: 4px;
}

/* Skeleton card for story loading */
.skeleton-card {
    position: relative;
    overflow: hidden;
    background: #f0f0f0;
    border-radius: 16px;
}

.skeleton-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.5),
        transparent
    );
    animation: shimmer 2s infinite;
}

/* Progress bar */
.progress-bar {
    position: relative;
    height: 4px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--brand-color, #7c3aed);
    transition: width 0.3s ease;
}

.progress-bar-indeterminate {
    position: absolute;
    height: 100%;
    width: 40%;
    background: var(--brand-color, #7c3aed);
    animation: indeterminate 1.5s infinite;
}

@keyframes indeterminate {
    0% {
        left: -40%;
    }
    100% {
        left: 100%;
    }
}

/* ============================================
   IMPROVED FORM CONTROLS
   ============================================ */

/* Better input focus states */
input:focus,
textarea:focus,
select:focus {
    outline: none;
    ring: 2px;
    ring-color: var(--brand-color, #7c3aed);
    border-color: var(--brand-color, #7c3aed);
}

/* File upload drag & drop area */
.upload-area {
    transition: all 0.3s ease;
}

.upload-area.drag-over {
    background: rgba(124, 58, 237, 0.05);
    border-color: var(--brand-color, #7c3aed);
    border-width: 2px;
    border-style: dashed;
}

/* Custom checkbox */
.custom-checkbox {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid #cbd5e1;
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}

.custom-checkbox:checked {
    background: var(--brand-color, #7c3aed);
    border-color: var(--brand-color, #7c3aed);
}

.custom-checkbox:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    width: 7px;
    height: 12px;
    border-right: 2px solid white;
    border-bottom: 2px solid white;
    transform: translate(-50%, -60%) rotate(45deg);
}

/* ============================================
   IMPROVED BUTTONS
   ============================================ */

/* Button loading state */
.btn-loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

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

/* Button ripple effect */
.btn-ripple {
    position: relative;
    overflow: hidden;
}

.btn-ripple::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn-ripple:active::after {
    width: 300px;
    height: 300px;
}

/* ============================================
   MODAL IMPROVEMENTS
   ============================================ */

/* Modal backdrop */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 40;
    animation: fadeIn 0.2s ease-out;
}

/* Modal content */
.modal-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 50;
    animation: modalSlideIn 0.3s ease-out;
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -45%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

/* ============================================
   CARD HOVER EFFECTS
   ============================================ */

.card-hover {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card-hover:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px -10px rgba(124, 58, 237, 0.2);
}

/* ============================================
   IMAGE ENHANCEMENTS
   ============================================ */

/* Lazy loaded images */
img[data-src] {
    opacity: 0;
    transition: opacity 0.3s;
}

img[data-src].loaded {
    opacity: 1;
}

/* Image placeholder */
.img-placeholder {
    background: linear-gradient(135deg, #f0f0f0 0%, #e0e0e0 100%);
    position: relative;
}

.img-placeholder::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 48px;
    height: 48px;
    background: currentColor;
    color: #64748b;
    -webkit-mask: url('/static/icons.svg#image') center / contain no-repeat;
    mask: url('/static/icons.svg#image') center / contain no-repeat;
    opacity: 0.3;
}

/* ============================================
   TOOLTIP
   ============================================ */

[data-tooltip] {
    position: relative;
}

[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    font-size: 12px;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 100;
}

[data-tooltip]:hover::before {
    opacity: 1;
    transform: translateX(-50%) translateY(-4px);
}

/* ============================================
   RESPONSIVE MOBILE ENHANCEMENTS
   ============================================ */

@media (max-width: 768px) {
    /* Better touch targets */
    button,
    a,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Larger text for readability */
    body {
        font-size: 16px;
    }

    /* Modal fills more screen on mobile */
    .modal-content {
        width: 95%;
        max-width: none;
    }

    /* Stack cards on mobile */
    .grid-cols-4 {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   DARK MODE SUPPORT (Future)
   ============================================ */

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a1a;
        --text-primary: #ffffff;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    /* Hide navigation and non-essential elements */
    nav,
    .no-print,
    button:not(.print-show) {
        display: none !important;
    }

    /* Optimize for print */
    body {
        background: white;
        color: black;
    }

    /* Avoid page breaks inside cards */
    .card,
    .story-card {
        page-break-inside: avoid;
    }
}

/* ============================================
   REDUCED MOTION
   ============================================ */

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