/* ========================================
   RESPONSIVE MOBILE-FIRST CSS
   Final comprehensive fixes for mobile responsiveness
   ======================================== */

/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    overflow-x: hidden !important;
    max-width: 100vw;
    width: 100%;
    position: relative;
}

#root {
    overflow-x: hidden !important;
    max-width: 100vw;
    width: 100%;
}

/* ========================================
   SIDEBAR - SIMPLIFIED MOBILE RESPONSIVE
   ======================================== */

/* Sidebar Base */
aside[data-testid="sidebar"] {
    overflow-x: hidden !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Sidebar on Mobile - Hidden by default */
@media (max-width: 1023px) {
    aside[data-testid="sidebar"] {
        width: 16rem;
        max-width: 85vw;
    }

    /* When sidebar is open */
    .sidebar-open aside[data-testid="sidebar"] {
        transform: translateX(0) !important;
    }

    /* Overlay when sidebar is open */
    .sidebar-open [data-testid="sidebar-overlay"] {
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    /* Prevent body scroll when sidebar is open */
    .sidebar-open body {
        overflow: hidden;
    }
}

/* Sidebar on Desktop - Always visible */
@media (min-width: 1024px) {
    aside[data-testid="sidebar"] {
        position: static !important;
        transform: translateX(0) !important;
        width: 16rem;
        min-width: 16rem;
        max-width: 16rem;
        flex-shrink: 0;
    }
}

/* Sidebar Content - Centered Logo and Text */
aside[data-testid="sidebar"] .h-full {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

aside[data-testid="sidebar"] img {
    height: 4rem;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
}

aside[data-testid="sidebar"] h1 {
    font-size: 1.5rem;
    line-height: 2rem;
    font-weight: 700;
    text-align: center;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Small Mobile Screens */
@media (max-width: 640px) {
    aside[data-testid="sidebar"] {
        width: 100vw;
        max-width: 100vw;
    }

    aside[data-testid="sidebar"] img {
        height: 3.5rem;
    }

    aside[data-testid="sidebar"] h1 {
        font-size: 1.25rem;
    }
}

/* ========================================
   MAIN CONTENT AREA
   ======================================== */

.flex.flex-col.flex-1.overflow-hidden {
    overflow-x: hidden !important;
    max-width: 100%;
    width: 100%;
    flex: 1;
    min-width: 0;
}

main {
    overflow-x: hidden;
    max-width: 100%;
    width: 100%;
    padding: 1.5rem;
}

@media (max-width: 768px) {
    main {
        padding: 1rem;
    }
}

@media (max-width: 640px) {
    main {
        padding: 0.75rem;
    }
}

/* ========================================
   HEADER - RESPONSIVE
   ======================================== */

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    overflow-x: hidden;
    max-width: 100%;
}

header button {
    flex-shrink: 0;
}

/* Hamburger Menu Button */
button[data-testid="button-sidebar-toggle"] {
    height: 2.5rem;
    width: 2.5rem;
    min-height: 2.5rem;
    min-width: 2.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Hide hamburger on desktop */
@media (min-width: 1024px) {
    button[data-testid="button-sidebar-toggle"] {
        display: none !important;
    }
}

/* Mobile Header Adjustments */
@media (max-width: 640px) {
    header {
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    button[data-testid="button-sidebar-toggle"] {
        height: 2.25rem;
        width: 2.25rem;
        min-height: 2.25rem;
        min-width: 2.25rem;
    }

    button[data-testid="button-theme-toggle"] {
        height: 2.25rem;
        width: 2.25rem;
        min-height: 2.25rem;
        min-width: 2.25rem;
    }
}

/* ========================================
   BUTTONS - RESPONSIVE
   ======================================== */

button {
    overflow: hidden;
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

button[data-testid="button-connect-wallet"] {
    min-height: 2.5rem;
    padding: 0.5rem 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 640px) {
    button {
        font-size: 0.875rem;
        min-height: 2.25rem;
    }

    button[data-testid="button-connect-wallet"] {
        padding: 0.375rem 0.75rem;
        font-size: 0.8125rem;
    }
}

/* ========================================
   FORMS - RESPONSIVE
   ======================================== */

form {
    max-width: 100%;
    overflow: hidden;
}

form input,
form textarea,
form select {
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

/* Prevent iOS zoom on input focus */
@media (max-width: 640px) {
    input,
    textarea,
    select {
        font-size: 16px !important;
    }
}

label {
    overflow: hidden;
    text-overflow: ellipsis;
    word-wrap: break-word;
}

/* ========================================
   CARDS - RESPONSIVE
   ======================================== */

.shadcn-card,
[class*="card"] {
    overflow: hidden;
    max-width: 100%;
}

.shadcn-card h1,
.shadcn-card h2,
.shadcn-card h3,
.shadcn-card h4,
.shadcn-card h5,
.shadcn-card h6 {
    overflow: hidden;
    text-overflow: ellipsis;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.shadcn-card p,
.shadcn-card span {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

@media (max-width: 768px) {
    .shadcn-card {
        padding: 1rem;
    }
}

@media (max-width: 640px) {
    .shadcn-card {
        padding: 0.75rem;
    }

    .shadcn-card h2 {
        font-size: 1.25rem;
    }

    .shadcn-card h3 {
        font-size: 1.125rem;
    }
}

/* ========================================
   GRID LAYOUT - RESPONSIVE
   ======================================== */

.grid {
    display: grid;
    gap: 1rem;
    width: 100%;
    max-width: 100%;
}

@media (max-width: 768px) {
    .grid {
        gap: 0.75rem;
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 640px) {
    .grid {
        gap: 0.5rem;
    }
}

/* ========================================
   MODAL - RESPONSIVE
   ======================================== */

[data-testid="wallet-modal"] {
    max-width: min(500px, 90vw);
    max-height: 90vh;
    overflow-y: auto;
    margin: 1rem;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 640px) {
    [data-testid="wallet-modal"] {
        max-width: 95vw;
        max-height: 95vh;
        margin: 0.5rem;
    }

    [data-testid="wallet-modal"] h2 {
        font-size: 1.125rem;
    }

    [data-testid="wallet-modal"] p {
        font-size: 0.875rem;
    }

    [data-testid="wallet-modal"] button {
        min-height: 2.25rem;
        font-size: 0.875rem;
    }
}

/* ========================================
   TABLE - RESPONSIVE
   ======================================== */

table {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    display: block;
}

thead,
tbody,
tr {
    display: table;
    width: 100%;
    table-layout: fixed;
}

@media (max-width: 768px) {
    table {
        font-size: 0.875rem;
    }

    table th,
    table td {
        padding: 0.5rem;
        white-space: nowrap;
    }
}

@media (max-width: 640px) {
    table {
        font-size: 0.8125rem;
    }

    table th,
    table td {
        padding: 0.375rem;
    }
}

/* ========================================
   TEXT AND TYPOGRAPHY
   ======================================== */

h1,
h2,
h3,
h4,
h5,
h6,
p,
span,
div,
a,
button,
label {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.text-ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.break-words {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* ========================================
   FLEX CONTAINERS
   ======================================== */

.flex {
    min-width: 0;
}

.flex > * {
    min-width: 0;
}

.flex-1 {
    flex: 1;
    min-width: 0;
}

/* ========================================
   IMAGES - RESPONSIVE
   ======================================== */

img {
    max-width: 100%;
    height: auto;
}

/* ========================================
   LANDSCAPE ORIENTATION
   ======================================== */

@media (max-height: 500px) and (orientation: landscape) {
    aside[data-testid="sidebar"] .h-full {
        padding: 1rem;
    }

    aside[data-testid="sidebar"] img {
        height: 2.5rem;
    }

    aside[data-testid="sidebar"] h1 {
        font-size: 1.125rem;
    }

    header {
        padding: 0.5rem 1rem;
    }
}

/* ========================================
   SAFE AREA INSETS (for notched devices)
   ======================================== */

@supports (padding: max(0px)) {
    header {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    main {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }

    aside[data-testid="sidebar"] {
        padding-left: max(0px, env(safe-area-inset-left));
    }
}

/* ========================================
   SMOOTH SCROLLING
   ======================================== */

html {
    scroll-behavior: smooth;
}

/* ========================================
   TOUCH INTERACTIONS
   ======================================== */

@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets on touch devices */
    button,
    a,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    aside[data-testid="sidebar"] {
        display: none;
    }

    button[data-testid="button-sidebar-toggle"] {
        display: none;
    }

    header {
        position: static;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

/* Focus visible styles */
*:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@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;
    }
}

/* ========================================
   Z-INDEX MANAGEMENT
   ======================================== */

/* Desktop sidebar */
@media (min-width: 1024px) {
    aside[data-testid="sidebar"] {
        z-index: 1 !important;
    }
}

/* Mobile overlay */
[data-testid="sidebar-overlay"] {
    z-index: 40 !important;
}

/* Mobile sidebar */
@media (max-width: 1023px) {
    aside[data-testid="sidebar"] {
        z-index: 50 !important;
    }
}

/* Header */
header {
    z-index: 10 !important;
}

/* Modal */
[data-testid="wallet-modal"] {
    z-index: 120 !important;
}

/* ========================================
   CONTAINER QUERIES (Modern browsers)
   ======================================== */

@supports (container-type: inline-size) {
    @container (max-width: 400px) {
        aside[data-testid="sidebar"] h1 {
            font-size: 1.125rem;
        }

        aside[data-testid="sidebar"] img {
            height: 3rem;
        }
    }
}
