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

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

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

.animate-in {
    animation: fadeInUp 400ms ease;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

.pulse {
    animation: pulse 2s ease infinite;
}

/* ==================== Mobile Header - Hidden on Desktop ==================== */
.mobile-header {
    display: none;
}

.mobile-overlay {
    display: none;
}

/* ==================== Responsive ==================== */
@media (max-width: 1024px) {
    .hero {
        grid-template-columns: 1fr;
    }

    .hero-visual {
        display: none;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .sidebar {
        width: 260px;
    }
}

@media (max-width: 768px) {
    /* ===== ULTRA-SLEEK MOBILE LAYOUT ===== */

    /* Base adjustments */
    html {
        font-size: 14px;
    }

    body {
        background: var(--color-bg);
        background-attachment: scroll;
    }

    /* App layout - stack vertically */
    .app-layout {
        flex-direction: column;
        position: relative;
    }

    /* Mobile Header Bar */
    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 16px;
        background: var(--color-surface);
        border-bottom: 1px solid var(--color-border);
        position: sticky;
        top: 0;
        z-index: 200;
    }

    .mobile-header-brand {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .mobile-header-brand img {
        width: 36px;
        height: 36px;
    }

    .mobile-header-brand span {
        font-family: var(--font-head);
        font-size: 1.1rem;
        font-weight: 700;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }

    /* Hamburger Menu Button */
    .mobile-menu-toggle {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        width: 28px;
        height: 24px;
        background: transparent;
        border: none;
        cursor: pointer;
        padding: 0;
        z-index: 201;
    }

    .mobile-menu-toggle span {
        width: 28px;
        height: 3px;
        background: var(--color-brand);
        border-radius: 10px;
        transition: all 0.3s ease;
        transform-origin: center;
    }

    .mobile-menu-toggle.active span:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }

    .mobile-menu-toggle.active span:nth-child(2) {
        opacity: 0;
    }

    .mobile-menu-toggle.active span:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    /* Mobile Sidebar - Full Screen Overlay */
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 85%;
        max-width: 320px;
        height: 100vh;
        background: var(--color-surface);
        border-right: 1px solid var(--color-border);
        z-index: 150;
        transition: left 0.3s ease;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        box-shadow: 2px 0 20px rgba(0, 0, 0, 0.3);
    }

    .sidebar.mobile-open {
        left: 0;
    }

    /* Mobile Overlay */
    .mobile-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: rgba(0, 0, 0, 0.6);
        z-index: 140;
        backdrop-filter: blur(2px);
    }

    .mobile-overlay.active {
        display: block;
    }

    /* Show logo in sidebar */
    .sidebar-logo {
        padding: 20px 16px !important;
        display: flex !important;
        border-bottom: 1px solid var(--color-border);
    }

    .sidebar-logo img {
        width: 40px !important;
        height: 40px !important;
    }

    .sidebar-logo span {
        font-size: 1.2rem !important;
    }

    /* Show profile in sidebar - ultra-compact centered layout */
    .sidebar-profile {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 10px 12px !important;
        text-align: center;
        border-bottom: 1px solid var(--color-border);
        gap: 3px;
    }

    .sidebar-profile-avatar {
        width: 48px !important;
        height: 48px !important;
        margin: 0 auto 4px !important;
        position: relative;
        flex-shrink: 0;
    }

    .sidebar-profile-avatar-img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .sidebar-profile-name {
        font-size: 0.85rem !important;
        margin: 0 !important;
        font-weight: 600;
        text-align: center;
        width: 100%;
        line-height: 1.2;
    }

    .sidebar-profile-info {
        font-size: 0.7rem !important;
        margin: 0 !important;
        opacity: 0.85;
        text-align: center;
        width: 100%;
        line-height: 1.2;
    }

    .sidebar-profile-stats {
        margin: 0 !important;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .sidebar-stat-compact {
        padding: 3px 8px;
        display: inline-flex;
        justify-content: center;
        align-items: center;
        gap: 4px;
        font-size: 0.65rem;
        margin: 0 auto;
        text-align: center;
    }

    .sidebar-stat-label-inline {
        font-size: 0.65rem;
        opacity: 0.9;
        white-space: nowrap;
    }

    .sidebar-stat-value-inline {
        font-size: 0.75rem;
        font-weight: 600;
    }

    .sidebar-plan-badge {
        font-size: 0.55rem !important;
        padding: 2px 5px !important;
        bottom: -1px !important;
        right: -1px !important;
    }

    /* Vertical menu in sidebar */
    .sidebar-menu {
        padding: 12px 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow-y: auto;
        overflow-x: hidden;
        gap: 0;
        flex: 1;
    }

    .sidebar-menu::-webkit-scrollbar {
        width: 4px;
    }

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

    .sidebar-menu li {
        margin: 0;
        flex-shrink: 0;
    }

    .sidebar-link {
        white-space: nowrap;
        border-left: 3px solid transparent;
        border-bottom: none;
        padding: 22px 22px !important;
        font-size: 1.4rem !important;
        gap: 22px;
        display: flex;
        flex-direction: row;
        align-items: center;
        text-align: left;
        min-width: auto;
        width: 100%;
    }

    .sidebar-link.active {
        border-left-color: var(--color-brand);
        border-bottom: none;
        background: rgba(59, 200, 143, 0.1);
    }

    .sidebar-link-icon {
        width: 72px !important;
        height: 72px !important;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar-link-icon img {
        width: 72px !important;
        height: 72px !important;
        object-fit: contain;
        padding: 6px;
        box-sizing: border-box;
    }

    /* Ensure consistent width for all sidebar links including Community and Membership */
    a[href="#community"].sidebar-link,
    a[href="#membership"].sidebar-link {
        width: 100% !important;
        padding: 18px 20px !important;
        box-sizing: border-box;
    }

    .sidebar-link span:not(.sidebar-link-icon) {
        font-size: 1.35rem;
        line-height: 1.4;
        font-weight: 600;
        flex: 1;
    }

    .sidebar-logout {
        border-top: 1px solid var(--color-border);
        padding: 0;
        margin-top: auto;
    }

    /* Show mobile header */
    .mobile-header {
        display: flex !important;
    }

    /* Main content - remove left margin and adjust for fixed header */
    .main-content-wrapper {
        margin-left: 0;
        width: 100%;
        padding-top: 0;
    }

    /* Remove top margin from first section to eliminate empty space */
    .page-section.active section:first-child {
        margin-top: var(--space-4) !important;
    }

    /* Eliminate empty space from dashboard cards */
    #dashboard-section .card {
        margin-top: var(--space-4) !important;
    }

    /* Container with tighter padding */
    .container {
        padding: 0 12px;
        max-width: 100%;
    }

    /* Hero section - ultra compact */
    .hero {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 16px 0;
    }

    .hero-content {
        gap: 16px;
    }

    .hero-content h1 {
        font-size: 1.5rem;
        line-height: 1.2;
    }

    .hero-subtitle {
        font-size: 0.9rem;
    }

    /* Remove all excessive top margins */
    main.container {
        padding-top: 0 !important;
    }

    .page-section {
        padding-top: 0 !important;
    }

    .page-section > section {
        margin-top: 12px !important;
        margin-bottom: 12px !important;
    }

    .page-section .card-header {
        padding-top: 0;
    }

    /* Ensure consistent container width across all sections */
    #dashboard-section .container,
    #profile-section .container,
    #creative-section .container,
    #breed-section .container,
    #health-section .container,
    #healthtracker-section .container,
    #findvet-section .container,
    #community-section .container,
    #membership-section .container {
        padding: 0 12px !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    /* Normalize all section cards padding */
    #dashboard-section .card,
    #profile-section .card,
    #creative-section .card,
    #breed-section .card,
    #health-section .card,
    #healthtracker-section .card,
    #findvet-section .card,
    #community-section .card,
    #membership-section .card {
        padding: 16px !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Override inline styles for community and membership sections */
    #community-section section.card,
    #membership-section section.card {
        margin-top: 12px !important;
        margin-bottom: 12px !important;
    }

    /* Reset community locked container padding on mobile */
    #community-locked-container {
        padding: 24px 16px !important;
    }

    /* Fix Community Section Overflow */
    #community-section .card-actions {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        width: 100% !important;
        margin-left: 0 !important;
    }

    #community-section .card-actions select {
        width: 100% !important;
    }

    #community-section .card-actions label {
        margin-right: 0 !important;
    }

    #community-section .form-group,
    #community-section .grid-2 {
        grid-template-columns: 1fr !important;
    }

    #community-section .community-profile-summary {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
    }

    /* Fix Membership Section Overflow */
    #membership-section > section > div[style*="padding"] {
        padding: 16px !important;
    }

    /* Force 3-column stats grid to single column on mobile */
    #membership-section div[style*="grid-template-columns: 1fr 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* Stack subscription plans vertically */
    #membership-section div[style*="display: flex"][style*="justify-content: center"] {
        flex-direction: column !important;
        gap: 16px !important;
    }

    #membership-section .card[style*="flex: 1"] {
        max-width: 100% !important;
        flex: none !important;
    }

    /* Stack token purchase buttons vertically */
    #membership-section button[style*="flex-basis"] {
        flex-basis: auto !important;
        width: 100% !important;
    }

    /* Compact grid layouts */
    .page-section > section > div[style*="grid-template-columns: 2fr 1fr"],
    .page-section > section > div[style*="grid-template-columns: repeat(4, 1fr)"] {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    /* Override all inline grid styles on mobile */
    #community-section .grid,
    #community-section .grid-2,
    #community-section .grid-3,
    #membership-section .grid,
    #membership-section .grid-2,
    #membership-section .grid-3 {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* Prevent any element from exceeding viewport width */
    #community-section *,
    #membership-section * {
        max-width: 100% !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        box-sizing: border-box !important;
    }

    /* Override inline flex layouts */
    #community-section div[style*="display: flex"],
    #membership-section div[style*="display: flex"] {
        flex-wrap: wrap !important;
    }

    /* Ensure sections don't overflow horizontally */
    #community-section,
    #membership-section {
        overflow-x: hidden !important;
        width: 100% !important;
    }

    #community-section .page-section,
    #membership-section .page-section {
        overflow-x: hidden !important;
    }

    /* Fix images that might cause overflow */
    #community-section img,
    #membership-section img {
        max-width: 100% !important;
        height: auto !important;
    }

    /* Make buttons fit on mobile */
    #community-section .btn,
    #membership-section .btn {
        max-width: 100% !important;
        white-space: normal !important;
    }

    /* KPI grid - single column */
    .kpi-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        margin: 16px 0;
    }

    .kpi-card {
        padding: 16px;
    }

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

    /* Cards - compact */
    .card {
        padding: 16px;
        border-radius: 14px;
    }

    .card-header {
        margin-bottom: 16px;
        flex-wrap: wrap;
        gap: 12px;
    }

    .card-title {
        font-size: 1.5rem;
        gap: 8px;
        font-weight: 700;
    }

    .card-icon {
        font-size: 1.3rem;
    }

    /* Dashboard action buttons - stack nicely */
    .dashboard-action-buttons {
        flex-direction: column;
        gap: 12px;
    }

    .dashboard-action-btn {
        width: 100%;
        flex: 1 1 auto;
        padding: 14px 16px;
    }

    .dashboard-action-btn .btn-label {
        font-size: 0.95rem;
    }

    .dashboard-action-btn .btn-helper {
        font-size: 0.8rem;
    }

    .dashboard-action-btn .btn-meta {
        margin-top: 8px;
        padding: 4px 10px;
        font-size: 0.7rem;
    }

    /* Quick actions wrap better */
    .quick-actions {
        gap: 10px;
        margin: 16px 0;
    }

    /* Buttons - more touchable */
    .btn {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 0.85rem;
    }

    .btn-pill {
        padding: 8px 14px;
        font-size: 0.75rem;
    }

    /* Forms - better touch targets */
    .form-group {
        margin-bottom: 14px;
    }

    .form-label {
        font-size: 0.8rem;
        margin-bottom: 6px;
    }

    .form-input,
    .form-select,
    .form-textarea {
        padding: 10px 12px;
        font-size: 0.85rem;
    }

    /* Tabs - horizontal scroll */
    .tabs {
        margin-bottom: 16px;
    }

    .tabs-list {
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap;
        gap: 6px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .tabs-list::-webkit-scrollbar {
        display: none;
    }

    .tab-trigger {
        padding: 10px 14px;
        font-size: 0.8rem;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Grid layouts - all single column */
    .grid-2,
    .grid-3,
    .grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* Upload zones - more compact */
    .upload-zone {
        padding: 20px;
    }

    .upload-title {
        font-size: 0.85rem;
    }

    .upload-hint {
        font-size: 0.7rem;
    }

    .cute-upload-zone {
        width: 100%;
        max-width: 280px;
        height: 200px;
        padding: 16px;
        margin: 0 auto;
    }

    .upload-paw-icon {
        font-size: 2.5rem;
    }

    .upload-cute-title {
        font-size: 0.95rem;
    }

    .upload-cute-subtitle {
        font-size: 0.8rem;
    }

    /* Preview boxes - fit mobile */
    .preview-frame {
        width: 180px;
        height: 180px;
    }

    .cute-remove-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    /* Gallery - 2 columns max */
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 10px;
        padding: 10px;
    }

    .gallery-item {
        border-radius: 12px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .gallery-item img {
        flex: 1;
    }

    .gallery-item .gallery-overlay {
        position: static;
        opacity: 1;
        background: rgba(0, 0, 0, 0.75);
        padding: 8px;
        border-radius: 0 0 12px 12px;
        gap: 6px;
    }

    .gallery-item .gallery-overlay .btn {
        font-size: 0.75rem;
        width: 100%;
    }

    .gallery-item .gallery-overlay > div:first-child {
        flex-direction: column;
    }

    /* Feed posts - compact */
    .feed-post {
        padding: 16px;
        margin-bottom: 12px;
        border-radius: 14px;
    }

    .post-header {
        gap: 10px;
        margin-bottom: 12px;
    }

    .post-avatar {
        width: 36px;
        height: 36px;
    }

    .post-author {
        font-size: 0.9rem;
    }

    .post-pet {
        font-size: 0.8rem;
    }

    .post-time {
        font-size: 0.7rem;
    }

    .post-content {
        margin-bottom: 12px;
        font-size: 0.9rem;
    }

    .post-content img.post-image {
        max-height: 300px;
        border-radius: 10px;
        margin-top: 10px;
    }

    .post-actions {
        gap: 8px;
        padding-top: 12px;
        flex-wrap: wrap;
    }

    .post-action {
        padding: 8px 12px;
        font-size: 0.85rem;
        gap: 6px;
    }

    /* Chat - more compact */
    .chat-container {
        max-height: 400px;
        padding: 12px;
        gap: 12px;
    }

    .chat-message {
        max-width: 85%;
        gap: 8px;
    }

    .chat-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }

    .chat-bubble {
        padding: 10px 12px;
        font-size: 0.85rem;
    }

    /* Table - scroll horizontally */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .data-table {
        min-width: 600px;
    }

    .data-table th {
        padding: 10px;
        font-size: 0.7rem;
    }

    .data-table td {
        padding: 12px 10px;
        font-size: 0.85rem;
    }

    /* Modal adjustments */
    .image-modal .modal-close {
        top: 10px;
        right: 15px;
        font-size: 32px;
    }

    .modal-content-wrapper {
        max-width: 95%;
        max-height: 95%;
        gap: 12px;
    }

    .modal-image {
        max-height: 60vh;
    }

    .modal-controls {
        gap: 10px;
    }

    .modal-btn {
        font-size: 0.8rem;
        padding: 10px 14px;
    }

    .modal-prompt {
        font-size: 0.85rem;
    }

    .modal-date {
        font-size: 0.75rem;
    }

    /* Toast notifications - fit screen */
    .toast-container {
        top: 12px;
        right: 12px;
        left: 12px;
    }

    .toast {
        min-width: auto;
        width: 100%;
        padding: 14px;
    }

    /* Chips - smaller */
    .chip {
        padding: 6px 10px;
        font-size: 0.7rem;
        gap: 4px;
    }

    /* Reduce spacing variables for mobile */
    :root {
        --space-1: 4px;
        --space-2: 8px;
        --space-3: 10px;
        --space-4: 14px;
        --space-5: 18px;
        --space-6: 24px;
        --space-7: 30px;
        --space-8: 40px;
    }

    /* Optimize performance - reduce animations */
    .card:hover {
        transform: none;
    }

    .gallery-item:hover {
        transform: scale(1.01);
    }

    .btn:hover {
        transform: none;
    }

    .dashboard-action-btn:hover {
        transform: translateY(-1px);
    }

    /* Nav content wrap */
    .nav-content {
        flex-wrap: wrap;
        padding: 12px 0;
    }

    .nav-logo {
        font-size: 1.2rem;
    }

    .nav-logo img {
        height: 36px;
    }

    .nav-actions {
        gap: 10px;
    }

    .user-avatar {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }
}

/* Extra small devices - ultra compact */
@media (max-width: 480px) {
    html {
        font-size: 13px;
    }

    .container {
        padding: 0 10px;
    }

    .hero-content h1 {
        font-size: 1.3rem;
    }

    .card {
        padding: 14px;
    }

    .card-title {
        font-size: 1.35rem;
        font-weight: 700;
    }

    .kpi-value {
        font-size: 1.75rem;
    }

    .sidebar-link {
        min-width: 60px;
        padding: 6px 8px !important;
    }

    .sidebar-link span:not(.sidebar-link-icon) {
        font-size: 0.65rem;
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 8px;
    }

    .dashboard-action-btn {
        padding: 12px 14px;
    }

    .btn {
        padding: 9px 14px;
        font-size: 0.8rem;
    }

    .preview-frame {
        width: 150px;
        height: 150px;
    }
}

/* ==================== Accessibility ==================== */
.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 {
    outline: 2px solid var(--color-brand);
    outline-offset: 2px;
}
