/* ========================================
   FINAL RESPONSIVE CSS - PERFECT MATCH
   Matching reference design with proper collapsible sidebar
   ======================================== */

/* Completely hidden sidebar on desktop */
@media (min-width: 1024px) {
  .sidebar-hidden aside[data-testid="sidebar"] {
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    border-right: 0 !important;
    overflow: hidden !important;
  }
}

/* Base Reset and Globals */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    overflow-x: hidden !important;
    max-width: 100vw;
    width: 100%;
    height: 100%;
}

#root {
    overflow-x: hidden !important;
    max-width: 100vw;
    width: 100%;
    min-height: 100vh;
}

/* ========================================
   SIDEBAR - COLLAPSIBLE & RESPONSIVE
   ======================================== */

/* Sidebar container */
.group\/sidebar-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    overflow: hidden;
}

/* Sidebar overlay for mobile */
[data-testid="sidebar-overlay"] {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-open [data-testid="sidebar-overlay"] {
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Main sidebar */
aside[data-testid="sidebar"] {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 16rem;
    z-index: 50;
    background: var(--sidebar);
    color: var(--sidebar-foreground);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-open aside[data-testid="sidebar"] {
    transform: translateX(0) !important;
}

/* Desktop sidebar - always visible */
@media (min-width: 1024px) {
    aside[data-testid="sidebar"] {
        position: static;
        transform: translateX(0) !important;
        box-shadow: none;
        border-right: 1px solid var(--border);
    }

    [data-testid="sidebar-overlay"] {
        display: none;
    }
}

/* Collapsed sidebar (desktop) */
.sidebar-collapsed aside[data-testid="sidebar"] {
    width: var(--sidebar-width-icon, 3.5rem) !important;
    min-width: var(--sidebar-width-icon, 3.5rem) !important;
    max-width: var(--sidebar-width-icon, 3.5rem) !important;
}
.sidebar-collapsed aside[data-testid="sidebar"] nav li a {
    justify-content: center;
}
.sidebar-collapsed aside[data-testid="sidebar"] nav li a .flex-1 {
    display: none !important;
}
.sidebar-collapsed aside[data-testid="sidebar"] .px-6.py-5 {
    justify-content: center;
}
.sidebar-collapsed aside[data-testid="sidebar"] .px-6.py-5 .text-lg,
.sidebar-collapsed aside[data-testid="sidebar"] .px-6.py-5 .text-sm {
    display: none !important;
}
.sidebar-collapsed aside[data-testid="sidebar"] .px-6.py-5 .leading-tight {
    display: none !important;
}
.sidebar-collapsed aside[data-testid="sidebar"] .wallet-widget .wallet-details {
    display: none !important;
}
.sidebar-collapsed aside[data-testid="sidebar"] .wallet-widget {
    justify-content: center;
}

/* Sidebar content structure */
aside[data-testid="sidebar"] .h-full {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Logo section */
aside[data-testid="sidebar"] .px-6.py-5 {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    min-height: 80px;
}

aside[data-testid="sidebar"] img {
    height: 28px;
    max-height: 28px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
}

/* Ensure brand text is horizontal and not rotated/squashed */
aside[data-testid="sidebar"] .px-6.py-5 .leading-tight,
aside[data-testid="sidebar"] .px-6.py-5 p {
    writing-mode: horizontal-tb !important;
    transform: none !important;
    rotate: 0deg !important;
    white-space: nowrap;
}

/* Navigation section */
aside[data-testid="sidebar"] nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
    -webkit-overflow-scrolling: touch;
}

aside[data-testid="sidebar"] nav ul {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    list-style: none;
}

aside[data-testid="sidebar"] nav li a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-family: texts, sans-serif;
    text-decoration: none;
    color: inherit;
    transition: all 0.15s ease;
    min-height: 44px;
    overflow: hidden;
}

aside[data-testid="sidebar"] nav li a:hover {
    background-color: var(--muted);
    color: var(--foreground);
}

aside[data-testid="sidebar"] nav li a[aria-current="page"],
aside[data-testid="sidebar"] nav li a.active {
    background-color: var(--primary);
    color: var(--primary-foreground);
}

/* Navigation icons */
aside[data-testid="sidebar"] nav li a .inline-flex {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 2rem;
    width: 2rem;
    min-width: 2rem;
    min-height: 2rem;
    border-radius: 0.375rem;
    background-color: var(--muted);
    color: var(--muted-foreground);
    transition: all 0.15s ease;
    flex-shrink: 0;
}

aside[data-testid="sidebar"] nav li a:hover .inline-flex {
    background-color: var(--primary);
    color: var(--primary-foreground);
}

aside[data-testid="sidebar"] nav li a svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Navigation text */
aside[data-testid="sidebar"] nav li a .flex-1 {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Connect wallet button section */
aside[data-testid="sidebar"] .border-t {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
}

button[data-testid="button-connect-wallet"] {
   
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    white-space: nowrap;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-family: texts, sans-serif;
    font-weight: 500;
    min-height: 2.25rem;
    padding: 0.5rem 1rem;
    background-color: var(--primary);
    color: var(--primary-foreground);
    border: 1px solid var(--primary-border);
    cursor: pointer;
    transition: all 0.15s ease;
}

button[data-testid="button-connect-wallet"]:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

button[data-testid="button-connect-wallet"] svg {
    width: 1rem;
    height: 1rem;
}

/* Wallet mini widget */
.wallet-widget {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.5rem;
    background: color-mix(in oklab, var(--muted), transparent 35%);
}
.wallet-widget .avatar {
    height: 2rem;
    width: 2rem;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: head, system-ui, sans-serif;
    color: white;
    background: linear-gradient(135deg, #22c55e, #16a34a);
}
.wallet-widget .wallet-details .label {
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--muted-foreground);
}
.wallet-widget .wallet-details .addr {
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-family: texts, ui-sans-serif, system-ui;
}

/* ========================================
   MAIN CONTENT AREA
   ======================================== */

.flex.flex-col.flex-1 {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Desktop layout adjustment */
@media (min-width: 1024px) {
    .flex.h-screen.w-full {
        margin-left: 0;
    }
}

/* ========================================
   HEADER/TOP BAR
   ======================================== */

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    background: rgba(var(--background), 0.95);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 10;
    min-height: 64px;
}

/* Hamburger menu button */
button[data-testid="button-sidebar-toggle"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    min-width: 2.5rem;
    min-height: 2.5rem;
    border-radius: 0.375rem;
    border: 1px solid transparent;
    background: transparent;
    color: var(--foreground);
    cursor: pointer;
    transition: all 0.15s ease;
}

button[data-testid="button-sidebar-toggle"]:hover {
    background-color: var(--muted);
    color: var(--foreground);
}

button[data-testid="button-sidebar-toggle"] svg {
    width: 1.5rem;
    height: 1.5rem;
}

/* Ensure desktop collapse button is visible on large screens */
@media (min-width: 1024px) {
  button[data-testid="button-sidebar-collapse"] {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }
  /* Ensure mobile close button never shows on desktop */
  button[data-testid="button-sidebar-close"] { display: none !important; }
}

/* Hide hamburger on desktop */
@media (min-width: 1024px) {
    button[data-testid="button-sidebar-toggle"] {
        display: none !important;
    }
}

/* Header buttons group */
header .flex.items-center.gap-2 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    margin-right: 0.75rem;
    min-width: 0;
}

/* Keep header actions pinned right and within viewport */
@media (min-width: 1024px) {
  header .flex.items-center.gap-2 { margin-left: auto; }
}

/* Compact header action buttons to avoid overflow */
header button[data-testid="button-connect-wallet"] {
  padding: 0.25rem 0.5rem;
  min-height: 1.75rem;
  font-size: 0.75rem;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
header button[data-testid="button-theme-toggle"] {
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  min-height: 2rem;
}

/* Theme toggle button */
button[data-testid="button-theme-toggle"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    min-width: 2.25rem;
    min-height: 2.25rem;
    border-radius: 0.375rem;
    border: 1px solid transparent;
    background: transparent;
    color: var(--foreground);
    cursor: pointer;
    transition: all 0.15s ease;
}

button[data-testid="button-theme-toggle"]:hover {
    background-color: var(--muted);
}

/* Header connect wallet button */
header button[data-testid="button-connect-wallet"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    white-space: nowrap;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    line-height: 1rem;
    font-family: texts, sans-serif;
    font-weight: 500;
    min-height: 2rem;
    padding: 0.25rem 0.75rem;
    background-color: var(--primary);
    color: var(--primary-foreground);
    border: 1px solid var(--primary-border);
    cursor: pointer;
    transition: all 0.15s ease;
}

/* ========================================
   MODAL - PERFECTLY CENTERED
   ======================================== */

[data-testid="wallet-modal"] {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100vw;
    height: fit-content;
    z-index: 120;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
[data-testid="wallet-modal"].hidden {
    display: none !important;
}

[data-testid="wallet-modal-overlay"] {
    position: absolute;
   
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
   
}

[data-testid="wallet-modal"] .relative {
    position: relative;
    z-index: 10;
  
    width: 100%;
    max-width: 28rem;
    border-radius: 0.75rem;
    border: 1px solid var(--card-border);
    background: var(--card);
    color: var(--card-foreground);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    padding: 1.5rem;
}

[data-testid="wallet-modal"] h2 {
    font-size: 1.25rem;
    line-height: 1.75rem;
    font-family: head, sans-serif;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

[data-testid="wallet-modal"] p {
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-family: texts, sans-serif;
    color: var(--muted-foreground);
    margin-bottom: 1.5rem;
}

[data-testid="wallet-modal"] .flex.flex-col {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

@media (min-width: 640px) {
    [data-testid="wallet-modal"] .flex.flex-col {
        flex-direction: row;
    }
}

[data-testid="wallet-modal"] button {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    white-space: nowrap;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-family: texts, sans-serif;
    font-weight: 500;
    min-height: 2.25rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

/* Modal close button (X) */
[data-testid="wallet-modal-close"].inline-flex.h-8.w-8 {
    position: absolute;
    top: 1rem;
    
    right: 1rem;
    width: 2rem;
    
    height: 2rem;
    min-width: 2rem;
    min-height: 2rem;
    padding: 0;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted-foreground);
}

[data-testid="wallet-modal-close"].inline-flex.h-8.w-8:hover {
    background-color: var(--muted);
    color: var(--foreground);
}

/* ========================================
   MAIN CONTENT PADDING
   ======================================== */

main {
    padding: 1.5rem;
    overflow-x: hidden;
    max-width: 100%;
    flex: 1;
}

@media (max-width: 768px) {
    main {
        padding: 1rem;
    }
}

@media (max-width: 640px) {
    main {
        padding: 0.75rem;
    }

    header {
        padding: 0.75rem;
    }
}

/* ========================================
   PREVENT BODY SCROLL WHEN SIDEBAR OPEN
   ======================================== */

.sidebar-open {
    overflow: hidden;
}

.sidebar-open body {
    overflow: hidden !important;
}

/* ========================================
   RESPONSIVE TYPOGRAPHY
   ======================================== */

h1, h2, h3, h4, h5, h6 {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

p, span, div, a, button, label {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* ========================================
   SMOOTH SCROLLING & ANIMATIONS
   ======================================== */

html {
    scroll-behavior: smooth;
}

* {
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   FOCUS STYLES FOR ACCESSIBILITY
   ======================================== */

*:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
}

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

@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;
    }
}

/* ========================================
   MOBILE SPECIFIC ADJUSTMENTS
   ======================================== */

@media (max-width: 640px) {
    /* Prevent iOS zoom on input focus */
    input,
    textarea,
    select {
        font-size: 16px !important;
    }

    /* Adjust sidebar for very small screens: do not cover full screen */
    aside[data-testid="sidebar"] {
        width: min(16rem, 85vw);
        max-width: min(16rem, 85vw);
    }

    /* Smaller modal on mobile */
    [data-testid="wallet-modal"] .relative {
        max-width: calc(100vw - 2rem);
        padding: 1rem;
    }

    /* Quick Actions: keep 2x2 grid on mobile */
    [data-testid="card-quick-actions"] .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    /* Marketplace tabs: mobile scroller and alignment fix */
    [data-testid="marketplace-tabs"] {
        display: flex !important;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        max-width: 100%;
        gap: 0.25rem;
        padding: 0.25rem;
    }
    [data-testid="marketplace-tabs"] > [role="tab"] {
        flex: 0 0 auto;
    }

    /* Wallet modal content polish for mobile */
    [data-testid="wallet-modal"] h2,
    [data-testid="wallet-modal"] p {
        text-align: center;
    }
    [data-testid="wallet-modal"] [data-testid="wallet-modal-close"] {
        min-width: 8rem;
    }
}

/* Ensure Quick Actions stays 2x2 on small tablets as well (<=768px) */
@media (max-width: 768px) {
    [data-testid="card-quick-actions"] .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

/* Mobile sidebar close button */
button[data-testid="button-sidebar-close"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    min-width: 2rem;
    min-height: 2rem;
    border-radius: 0.375rem;
    border: 1px solid transparent;
    background: transparent;
    color: var(--foreground);
}
button[data-testid="button-sidebar-close"]:hover {
    background-color: var(--muted);
}

/* ========================================
   LANDSCAPE ORIENTATION
   ======================================== */

@media (max-height: 500px) and (orientation: landscape) {
    aside[data-testid="sidebar"] .px-6.py-5 {
        padding: 0.75rem 1.5rem;
        min-height: 60px;
    }

    aside[data-testid="sidebar"] nav {
        padding: 0.5rem 0.75rem;
    }

    aside[data-testid="sidebar"] nav li a {
        min-height: 36px;
        padding: 0.25rem 0.75rem;
    }
}

/* ========================================
   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(1.5rem, env(safe-area-inset-left));
        padding-right: max(1.5rem, env(safe-area-inset-right));
        padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
    }

    aside[data-testid="sidebar"] {
        padding-left: max(0px, env(safe-area-inset-left));
    }
}

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

.break-words {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.text-ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.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;
}
