/* Glass Optimizer - Mobile Responsive Styles */

/* Mobile-first approach with enhanced touch interactions */

/* Base mobile styles */
@media (max-width: 768px) {
    /* General mobile optimizations */
    body {
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
        touch-action: manipulation;
    }

    .container {
        padding: 0;
    }

    /* Header mobile styles */
    .header {
        padding: 0.75rem 1rem;
        position: relative;
    }

    .header > div {
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 1rem;
        flex-wrap: wrap;
    }

    .header > div > div:first-child {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }

    .header h1 {
        font-size: 1.25rem;
        margin-bottom: 0.5rem;
        cursor: pointer;
        text-decoration: none;
        color: white;
    }

    .header h1:hover {
        opacity: 0.9;
    }

    .header nav {
        display: flex;
        justify-content: flex-start;
        gap: 0.75rem;
        flex-wrap: wrap;
        margin-top: 0.5rem;
    }

    .header nav a {
        padding: 0.4rem 0.8rem;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 4px;
        font-size: 0.8rem;
        text-decoration: none;
        color: white;
        transition: all 0.2s ease;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        user-select: none;
    }

    .header nav a:hover,
    .header nav a.active {
        background: rgba(255, 255, 255, 0.2);
        transform: scale(1.05);
    }

    .header nav a:active {
        transform: scale(0.95);
    }

    /* Language selector mobile */
    .language-selector {
        justify-content: flex-end !important;
        gap: 0.5rem;
        flex-shrink: 0;
    }

    .lang-btn {
        min-height: 44px !important;
        min-width: 44px !important;
        padding: 0.5rem 1rem !important;
        font-size: 0.875rem !important;
        cursor: pointer !important;
        -webkit-tap-highlight-color: transparent !important;
        user-select: none !important;
        border: 1px solid rgba(255, 255, 255, 0.3) !important;
        transition: all 0.2s ease !important;
    }

    .lang-btn:hover {
        transform: scale(1.05) !important;
    }

    .lang-btn:active {
        transform: scale(0.95) !important;
    }

    /* Main content mobile */
    .main-content {
        padding: 1rem;
        flex: 1;
    }

    /* Dashboard mobile styles */
    .welcome-section {
        text-align: center;
        margin-bottom: 2rem;
    }

    .welcome-section h2 {
        font-size: 1.5rem;
        margin-bottom: 0.75rem;
    }

    .welcome-section p {
        font-size: 0.9rem;
        line-height: 1.5;
    }

    .quick-actions {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .action-card {
        padding: 1.5rem 1rem;
        text-align: center;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .action-card h3 {
        font-size: 1.125rem;
        margin-bottom: 0.75rem;
    }

    .action-card p {
        font-size: 0.875rem;
        margin-bottom: 1rem;
        line-height: 1.4;
    }

    .action-card .btn {
        width: 100%;
        min-height: 44px;
    }

    /* Stats grid mobile */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .stat-card {
        padding: 1rem;
        text-align: center;
        min-height: auto;
    }

    .stat-card h4 {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }

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

    /* Projects section mobile */
    .section-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch !important;
    }

    .section-header h2 {
        text-align: center;
        font-size: 1.25rem;
    }

    #btn-new-project {
        width: 100%;
        min-height: 44px;
        justify-content: center;
    }

    /* Project tree mobile */
    .project-node {
        margin-bottom: 1rem;
    }

    .project-header {
        padding: 1rem;
        border-radius: 8px;
        position: relative;
    }

    .project-title {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }

    .project-description {
        font-size: 0.875rem;
        line-height: 1.4;
        margin: 0.5rem 0;
    }

    .project-meta {
        flex-direction: column !important;
        gap: 0.5rem;
    }

    .project-meta-item {
        font-size: 0.8rem;
        display: flex;
        justify-content: space-between;
        padding: 0.25rem 0;
        border-bottom: 1px solid var(--border);
    }

    .project-meta-item:last-child {
        border-bottom: none;
    }

    .project-actions {
        position: static !important;
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px solid var(--border);
    }
}

/* Designer mobile styles */
@media (max-width: 768px) {
    .designer-layout {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto 1fr auto;
        height: 100vh;
        position: relative;
    }

    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 60vh;
        height: auto;
        background: var(--surface);
        border-top: 2px solid var(--primary);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        z-index: 1000;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
    }

    .sidebar.mobile-expanded {
        transform: translateY(0);
    }

    .sidebar::before {
        content: "";
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: rgba(0, 0, 0, 0.3);
        border-radius: 2px;
    }

    .sidebar h3 {
        font-size: 1rem;
        margin-bottom: 0.75rem;
        padding: 1.5rem 1rem 0.75rem;
        position: sticky;
        top: 0;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .sidebar h3:first-of-type::after {
        content: "▲";
        font-size: 0.8rem;
        color: var(--text-secondary);
        transition: transform 0.3s ease;
    }

    .sidebar:not(.mobile-expanded) h3:first-of-type::after {
        transform: rotate(180deg);
    }

    .tool-list {
        padding: 0 1rem 1rem;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .tool-btn {
        min-height: 44px;
        font-size: 0.875rem;
        padding: 0.75rem 0.5rem;
        text-align: center;
        border-radius: 6px;
    }

    .properties {
        padding: 0 1rem 1rem;
    }

    .properties label {
        display: flex;
        flex-direction: column;
        margin-bottom: 1rem;
    }

    .properties input,
    .properties select {
        margin-top: 0.25rem;
        min-height: 44px;
        padding: 0.75rem;
        font-size: 1rem;
    }

    /* Canvas area mobile */
    .canvas-area {
        order: 2;
        display: flex;
        flex-direction: column;
        min-height: 60vh;
    }

    .canvas-toolbar {
        padding: 0.75rem 1rem;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: center;
    }

    .canvas-toolbar .btn {
        min-height: 44px;
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        flex: 1;
        min-width: 120px;
        max-width: 200px;
    }

    #design-canvas {
        flex: 1;
        min-height: 300px;
        touch-action: pan-x pan-y;
        cursor: crosshair;
    }

    .canvas-info {
        padding: 1rem;
        background: var(--bg);
        font-size: 0.875rem;
        line-height: 1.4;
        max-height: 200px;
        overflow-y: auto;
    }

    .canvas-info ul {
        margin-left: 1rem;
    }

    .canvas-info li {
        margin-bottom: 0.5rem;
    }

    /* Holes section mobile */
    #holes-section {
        padding: 0 1rem 1rem;
    }

    .holes-list {
        max-height: none;
        overflow: visible;
    }

    .hole-item {
        padding: 1rem;
        margin-bottom: 0.75rem;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface);
    }

    .hole-item.selected {
        border-color: var(--primary);
        background: rgba(37, 99, 235, 0.05);
    }

    .hole-item h4 {
        font-size: 1rem;
        margin-bottom: 0.75rem;
        color: var(--primary);
    }

    .hole-properties {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .hole-properties label {
        display: flex;
        flex-direction: column;
        font-size: 0.875rem;
    }

    .hole-properties input {
        margin-top: 0.25rem;
        min-height: 40px;
        padding: 0.5rem;
        border: 1px solid var(--border);
        border-radius: 4px;
        font-size: 0.875rem;
    }

    .hole-actions {
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px solid var(--border);
        display: flex;
        gap: 0.5rem;
        justify-content: center;
    }

    .hole-actions .btn {
        flex: 1;
        min-height: 40px;
        font-size: 0.875rem;
    }
}

/* Enhanced Designer Mobile Layout */
@media (max-width: 768px) {
    /* Mobile-first designer layout */
    .designer-layout {
        display: flex !important;
        flex-direction: column !important;
        height: 100vh !important;
        overflow: hidden !important;
        position: relative !important;
    }

    /* Canvas area takes priority on mobile */
    .canvas-area {
        order: 1 !important;
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        min-height: calc(100vh - 160px) !important;
        overflow: hidden !important;
        padding-bottom: 80px !important;
    }

    /* Responsive canvas styling */
    #design-canvas {
        width: 100% !important;
        height: auto !important;
        max-width: calc(100vw - 20px) !important;
        max-height: 60vh !important;
        margin: 0 auto !important;
        touch-action: pan-x pan-y !important;
        -webkit-touch-callout: none !important;
        -webkit-user-select: none !important;
        user-select: none !important;
        cursor: crosshair !important;
        border: 2px solid var(--border) !important;
        border-radius: 8px !important;
        background: white !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
    }

    /* Canvas toolbar - compact mobile version */
    .canvas-toolbar {
        order: 2 !important;
        padding: 0.75rem !important;
        background: var(--surface) !important;
        border-top: 1px solid var(--border) !important;
        border-bottom: 1px solid var(--border) !important;
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        justify-content: space-between !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .canvas-toolbar .btn {
        min-height: 44px !important;
        padding: 0.5rem 0.75rem !important;
        font-size: 0.8rem !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
        min-width: 80px !important;
        border-radius: 6px !important;
    }

    /* Sidebar becomes slide-up bottom panel */
    .sidebar {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        max-height: 70vh !important;
        height: auto !important;
        background: rgba(255, 255, 255, 0.95) !important;
        border-top: 3px solid var(--primary) !important;
        border-radius: 20px 20px 0 0 !important;
        box-shadow:
            0 -8px 32px rgba(0, 0, 0, 0.15),
            0 -2px 8px rgba(0, 0, 0, 0.1) !important;
        z-index: 1500 !important;
        transform: translateY(100%) !important;
        transition:
            transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
            box-shadow 0.3s ease !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        backdrop-filter: blur(12px) !important;
        -webkit-backdrop-filter: blur(12px) !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* Floating action button to open tools menu */
    .mobile-tools-fab {
        position: fixed !important;
        bottom: 20px !important;
        right: 20px !important;
        width: 60px !important;
        height: 60px !important;
        background: var(--primary) !important;
        color: white !important;
        border: none !important;
        border-radius: 50% !important;
        box-shadow: 0 4px 20px rgba(37, 99, 235, 0.4) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-size: 1.5rem !important;
        font-weight: bold !important;
        cursor: pointer !important;
        z-index: 2000 !important;
        transition: all 0.3s ease !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
        user-select: none !important;
    }

    .mobile-tools-fab:hover {
        transform: scale(1.1) !important;
        box-shadow: 0 6px 24px rgba(37, 99, 235, 0.5) !important;
    }

    .mobile-tools-fab:active {
        transform: scale(0.95) !important;
    }

    .mobile-tools-fab.hidden {
        transform: scale(0) !important;
        opacity: 0 !important;
    }

    .sidebar.mobile-expanded {
        transform: translateY(0) !important;
        box-shadow:
            0 -12px 40px rgba(0, 0, 0, 0.2),
            0 -4px 12px rgba(0, 0, 0, 0.15) !important;
    }

    .sidebar::before {
        content: "" !important;
        position: absolute !important;
        top: 12px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: 40px !important;
        height: 5px !important;
        background: rgba(37, 99, 235, 0.6) !important;
        border-radius: 3px !important;
        cursor: pointer !important;
        transition: all 0.3s ease !important;
    }

    /* Overlay styles handled by JavaScript */

    /* Tool list - horizontal scrollable on mobile */
    .tool-list {
        display: flex !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 1rem !important;
        gap: 0.75rem !important;
        scroll-snap-type: x mandatory !important;
        flex-shrink: 0 !important;
    }

    .tool-btn {
        min-width: 100px !important;
        min-height: 60px !important;
        flex-shrink: 0 !important;
        scroll-snap-align: start !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0.75rem !important;
        font-size: 0.8rem !important;
        line-height: 1.2 !important;
        text-align: center !important;
        border-radius: 8px !important;
        border: 2px solid var(--border) !important;
        background: white !important;
        transition: all 0.2s ease !important;
    }

    .tool-btn.active {
        background: var(--primary) !important;
        color: white !important;
        border-color: var(--primary) !important;
        transform: scale(1.05) !important;
    }

    .tool-btn:hover,
    .tool-btn:active {
        background: var(--primary-light) !important;
        border-color: var(--primary) !important;
    }

    /* Glass properties - compact layout */
    .properties {
        padding: 1rem !important;
        background: var(--bg) !important;
    }

    .properties label {
        display: flex !important;
        flex-direction: column !important;
        margin-bottom: 1rem !important;
        font-size: 0.9rem !important;
        font-weight: 500 !important;
    }

    .properties input,
    .properties select {
        margin-top: 0.5rem !important;
        min-height: 48px !important;
        padding: 0.75rem !important;
        font-size: 1rem !important;
        border: 1px solid var(--border) !important;
        border-radius: 6px !important;
        background: white !important;
    }

    /* Holes section - expandable cards */
    #holes-section {
        padding: 1rem !important;
        background: var(--surface) !important;
        flex-shrink: 0 !important;
    }

    .holes-list {
        max-height: 200px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .hole-item {
        padding: 1rem !important;
        margin-bottom: 0.75rem !important;
        border: 2px solid var(--border) !important;
        border-radius: 12px !important;
        background: white !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
        transition: all 0.2s ease !important;
    }

    .hole-item:hover {
        transform: translateY(-2px) !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    }

    .hole-item.selected {
        border-color: var(--primary) !important;
        background: rgba(37, 99, 235, 0.05) !important;
        box-shadow: 0 4px 16px rgba(37, 99, 235, 0.2) !important;
    }

    .hole-item h4 {
        font-size: 1.1rem !important;
        margin-bottom: 0.75rem !important;
        color: var(--primary) !important;
        font-weight: 600 !important;
    }

    /* Hole properties in mobile cards */
    .hole-properties {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
        margin-bottom: 1rem !important;
    }

    .hole-properties label {
        display: flex !important;
        flex-direction: column !important;
        font-size: 0.85rem !important;
        font-weight: 500 !important;
        color: var(--text-secondary) !important;
    }

    .hole-properties input {
        margin-top: 0.25rem !important;
        min-height: 44px !important;
        padding: 0.5rem !important;
        border: 1px solid var(--border) !important;
        border-radius: 4px !important;
        font-size: 0.9rem !important;
        background: white !important;
    }

    /* Hole action buttons */
    .hole-actions {
        display: flex !important;
        gap: 0.5rem !important;
        justify-content: stretch !important;
        padding-top: 1rem !important;
        border-top: 1px solid var(--border) !important;
    }

    .hole-actions .btn {
        flex: 1 !important;
        min-height: 44px !important;
        font-size: 0.85rem !important;
        font-weight: 500 !important;
        padding: 0.75rem 1rem !important;
        border-radius: 6px !important;
    }

    /* Canvas info panel - collapsible */
    .canvas-info {
        padding: 1rem !important;
        background: var(--bg) !important;
        font-size: 0.85rem !important;
        line-height: 1.4 !important;
        border-top: 1px solid var(--border) !important;
        max-height: 120px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        flex-shrink: 0 !important;
    }

    .canvas-info ul {
        margin: 0.5rem 0 0 1rem !important;
        padding: 0 !important;
    }

    .canvas-info li {
        margin-bottom: 0.25rem !important;
    }

    /* Mobile sidebar toggle */
    .mobile-sidebar-toggle {
        display: block !important;
        position: fixed !important;
        bottom: 20px !important;
        right: 20px !important;
        width: 56px !important;
        height: 56px !important;
        background: var(--primary) !important;
        color: white !important;
        border: none !important;
        border-radius: 50% !important;
        font-size: 1.5rem !important;
        cursor: pointer !important;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2) !important;
        z-index: 1000 !important;
        transition: all 0.3s ease !important;
    }

    .mobile-sidebar-toggle:hover {
        transform: scale(1.1) !important;
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3) !important;
    }

    /* Responsive text scaling */
    .sidebar h3:first-of-type {
        font-size: 1.1rem !important;
        margin-bottom: 0.75rem !important;
        padding: 1.75rem 3rem 0.75rem 1rem !important;
        position: sticky !important;
        top: 0 !important;
        background: var(--surface) !important;
        border-bottom: 1px solid var(--border) !important;
        font-weight: 600 !important;
        cursor: pointer !important;
        display: block !important;
        user-select: none !important;
        position: relative !important;
    }

    /* Other h3 headers (non-clickable) */
    .sidebar h3:not(:first-of-type) {
        font-size: 1.1rem !important;
        margin-bottom: 0.75rem !important;
        padding: 1.75rem 1rem 0.75rem !important;
        position: sticky !important;
        top: 0 !important;
        background: var(--surface) !important;
        border-bottom: 1px solid var(--border) !important;
        font-weight: 600 !important;
        cursor: default !important;
        display: block !important;
        user-select: none !important;
    }

    .sidebar h3:first-of-type::after {
        content: "✕" !important;
        font-size: 1.1rem !important;
        color: var(--primary) !important;
        transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
        font-weight: bold !important;
        opacity: 1 !important;
        transform: scale(1) !important;
        position: absolute !important;
        right: 0.5rem !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
    }

    .sidebar.mobile-expanded h3:first-of-type::after {
        opacity: 1 !important;
        transform: scale(1) !important;
    }

    .sidebar::before:hover,
    .sidebar h3:first-of-type:hover::after {
        background: var(--primary) !important;
        color: var(--primary-dark) !important;
    }
}

/* Extra small mobile screens */
@media (max-width: 480px) {
    .canvas-area {
        min-height: 50vh !important;
    }

    #design-canvas {
        max-width: calc(100vw - 10px) !important;
        max-height: 50vh !important;
    }

    .canvas-toolbar .btn {
        min-width: 70px !important;
        font-size: 0.7rem !important;
        padding: 0.4rem 0.6rem !important;
    }

    .tool-btn {
        min-width: 80px !important;
        min-height: 50px !important;
        font-size: 0.75rem !important;
    }

    .hole-properties {
        grid-template-columns: 1fr !important;
    }

    .sidebar {
        max-height: 50vh !important;
        transform: translateY(100%) !important;
    }

    .sidebar::before {
        top: 8px !important;
        width: 32px !important;
        height: 4px !important;
    }
}

/* Optimizer mobile styles */
@media (max-width: 768px) {
    .optimizer-layout {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto 1fr;
        height: 100vh;
    }

    .optimizer-layout .sidebar {
        order: 1;
        max-height: none;
        border-left: none;
        border-bottom: 2px solid var(--border);
        background: var(--surface);
    }

    .optimizer-main {
        order: 2;
        display: flex;
        flex-direction: column;
    }

    /* Design list mobile */
    .design-list,
    .sheet-list {
        padding: 0 1rem;
        max-height: 200px;
        overflow-y: auto;
    }

    .design-item,
    .sheet-item {
        display: flex;
        align-items: flex-start;
        padding: 1rem;
        margin-bottom: 0.75rem;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface);
        cursor: pointer;
        gap: 0.75rem;
    }

    .design-item:hover,
    .sheet-item:hover {
        border-color: var(--primary);
        background: rgba(37, 99, 235, 0.05);
    }

    .design-item input,
    .sheet-item input {
        margin-top: 0.25rem;
        min-width: 20px;
        min-height: 20px;
    }

    .design-item label,
    .sheet-item label {
        flex: 1;
        font-size: 0.875rem;
        line-height: 1.4;
        cursor: pointer;
    }

    /* Algorithm selector mobile */
    .optimizer-layout select {
        width: 100%;
        min-height: 44px;
        padding: 0.75rem;
        font-size: 1rem;
        margin: 0 1rem 1rem;
        border: 1px solid var(--border);
        border-radius: 4px;
        background: var(--surface);
    }

    /* Optimizer toolbar mobile */
    .optimizer-toolbar {
        padding: 1rem;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        text-align: center;
    }

    .optimizer-toolbar .btn {
        width: 100%;
        min-height: 44px;
        font-size: 1rem;
        padding: 0.75rem;
    }

    /* Results area mobile */
    .results-area {
        flex: 1;
        padding: 1rem;
        overflow-y: auto;
    }

    .results-area h3 {
        font-size: 1.25rem;
        text-align: center;
        margin-bottom: 1rem;
    }

    .results-area .stats-grid {
        margin-bottom: 2rem;
    }

    .visualization {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 1rem;
        min-height: 300px;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .placeholder-message {
        padding: 2rem 1rem;
        text-align: center;
        color: var(--text-secondary);
        font-size: 0.875rem;
        line-height: 1.5;
    }
}

/* Modal mobile styles */
@media (max-width: 768px) {
    .modal {
        padding: 1rem;
        align-items: flex-start;
        padding-top: 2rem;
    }

    .modal-content {
        width: 100%;
        max-width: none;
        margin: 0;
        max-height: calc(100vh - 4rem);
        overflow-y: auto;
        border-radius: 8px;
    }

    .modal-header {
        padding: 1rem 1rem 0.5rem;
        border-bottom: 1px solid var(--border);
        position: sticky;
        top: 0;
        background: var(--surface);
        z-index: 10;
    }

    .modal-header h3 {
        font-size: 1.125rem;
        text-align: center;
    }

    .modal-close {
        min-height: 44px;
        min-width: 44px;
        font-size: 1.25rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .form-group {
        margin-bottom: 1.5rem;
    }

    .form-group label {
        font-size: 0.875rem;
        font-weight: 600;
        margin-bottom: 0.5rem;
        display: block;
    }

    .form-group input,
    .form-group textarea,
    .form-group select {
        width: 100%;
        min-height: 44px;
        padding: 0.75rem;
        font-size: 1rem;
        border: 1px solid var(--border);
        border-radius: 4px;
        background: var(--surface);
    }

    .form-group textarea {
        resize: vertical;
        min-height: 80px;
    }

    .modal-actions {
        padding: 1rem;
        border-top: 1px solid var(--border);
        display: flex;
        gap: 0.75rem;
        position: sticky;
        bottom: 0;
        background: var(--surface);
    }

    .modal-actions .btn {
        flex: 1;
        min-height: 44px;
        font-size: 1rem;
        padding: 0.75rem;
    }

    /* Design picker mobile */
    .picker-list {
        max-height: 300px;
        overflow-y: auto;
    }

    .design-picker-item {
        display: flex;
        align-items: center;
        padding: 1rem;
        border-bottom: 1px solid var(--border);
        cursor: pointer;
        transition: background-color 0.2s;
        gap: 0.75rem;
        min-height: 60px;
    }

    .design-picker-item:hover {
        background: var(--bg);
    }

    .design-picker-item:last-child {
        border-bottom: none;
    }

    /* Project tree selector mobile */
    .project-tree-selector {
        max-height: 200px;
        overflow-y: auto;
        border: 1px solid var(--border);
        border-radius: 4px;
        background: var(--surface);
    }

    .tree-node {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--border);
        cursor: pointer;
        font-size: 0.875rem;
    }

    .tree-node:hover {
        background: var(--bg);
    }

    .tree-node:last-child {
        border-bottom: none;
    }

    .tree-node.selected {
        background: rgba(37, 99, 235, 0.1);
        color: var(--primary);
        font-weight: 600;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .header {
        padding: 0.5rem;
    }

    .header h1 {
        font-size: 1.125rem;
    }

    .header nav a {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
        min-height: 40px;
    }

    .main-content {
        padding: 0.75rem;
    }

    .quick-actions {
        gap: 0.75rem;
    }

    .action-card {
        padding: 1.25rem 0.75rem;
    }

    .stats-grid {
        gap: 0.75rem;
    }

    .stat-card {
        padding: 0.75rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    /* Designer canvas mobile - very small screens */
    .canvas-area {
        min-height: 50vh;
    }

    #design-canvas {
        min-height: 250px;
    }

    .canvas-toolbar .btn {
        min-width: 100px;
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    .hole-properties {
        grid-template-columns: 1fr;
    }

    /* Modal adjustments for very small screens */
    .modal {
        padding: 0.5rem;
        padding-top: 1rem;
    }

    .modal-content {
        max-height: calc(100vh - 2rem);
    }

    .modal-actions {
        flex-direction: column;
    }

    .modal-actions .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .modal-actions .btn:last-child {
        margin-bottom: 0;
    }
}

/* Landscape orientation optimizations for mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .designer-layout {
        grid-template-columns: 250px 1fr;
        grid-template-rows: 1fr;
        height: 100vh;
    }

    .sidebar {
        order: 1;
        max-height: none;
        border-top: none;
        border-right: 2px solid var(--border);
        overflow-y: auto;
    }

    .canvas-area {
        order: 2;
        min-height: 100vh;
    }

    .canvas-info {
        display: none;
    }

    .optimizer-layout {
        grid-template-columns: 280px 1fr;
    }

    .optimizer-layout .sidebar {
        border-bottom: none;
        border-right: 2px solid var(--border);
    }
}

/* Touch-specific enhancements */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover states and add proper touch handling */
    * {
        -webkit-tap-highlight-color: transparent;
    }

    .btn,
    .tool-btn,
    .menu-item,
    .design-item,
    .sheet-item,
    .lang-btn {
        min-height: 44px;
        min-width: 44px;
        cursor: pointer;
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }

    .btn:hover,
    .tool-btn:hover,
    .menu-item:hover {
        transform: none;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }

    .btn:active,
    .tool-btn:active,
    .menu-item:active,
    .lang-btn:active {
        transform: scale(0.95) !important;
        transition: transform 0.1s ease !important;
        background-color: rgba(0, 0, 0, 0.1) !important;
    }

    /* Canvas touch optimizations */
    #design-canvas {
        touch-action: pan-x pan-y pinch-zoom;
    }

    /* Larger touch targets for small UI elements */
    .modal-close,
    .lang-btn,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Improved scrolling on touch devices */
    .holes-list,
    .design-list,
    .sheet-list,
    .picker-list,
    .project-tree-selector {
        -webkit-overflow-scrolling: touch;
        overflow-scrolling: touch;
    }
}

/* Dark mode mobile adjustments */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
    .header nav a {
        background: rgba(255, 255, 255, 0.15);
    }

    .header nav a:hover,
    .header nav a.active {
        background: rgba(255, 255, 255, 0.25);
    }

    .modal-content {
        background: #1a1a1a;
        border: 1px solid #333;
    }

    .hole-item,
    .design-item,
    .sheet-item {
        background: #1a1a1a;
        border-color: #333;
    }

    .hole-item.selected,
    .design-item:hover,
    .sheet-item:hover {
        background: rgba(37, 99, 235, 0.15);
    }
}

/* Fix button interactions on mobile */
@media (max-width: 768px) {
    /* Ensure all buttons are clickable */
    .btn,
    .tool-btn,
    .lang-btn,
    .menu-item,
    .modal-close,
    .action-card .btn,
    button {
        cursor: pointer !important;
        -webkit-tap-highlight-color: transparent !important;
        user-select: none !important;
        -webkit-user-select: none !important;
        -webkit-touch-callout: none !important;
        touch-action: manipulation !important;
        pointer-events: auto !important;
        position: relative !important;
        z-index: 10 !important;
    }

    .btn:active,
    .tool-btn:active,
    .lang-btn:active,
    .menu-item:active,
    button:active {
        transform: scale(0.95) !important;
        transition: transform 0.1s ease !important;
    }

    /* Additional Designer Mobile Enhancements */
    /* Canvas touch improvements */
    #design-canvas {
        touch-action: pan-x pan-y !important;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }

    /* Mobile sidebar improvements */
    .mobile-sidebar-toggle {
        animation: pulse 2s infinite;
    }

    @keyframes pulse {
        0% {
            transform: scale(1);
        }
        50% {
            transform: scale(1.05);
        }
        100% {
            transform: scale(1);
        }
    }

    .sidebar.mobile-open {
        transform: translateY(0) !important;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    }

    /* Improve tool button responsiveness */
    .tool-btn:active,
    .btn:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }

    /* Canvas zoom controls for mobile */
    .canvas-zoom-controls {
        position: fixed;
        top: 50%;
        left: 10px;
        transform: translateY(-50%);
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        z-index: 500;
    }

    .zoom-btn {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.9);
        border: 1px solid var(--border);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.25rem;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }

    .zoom-btn:hover {
        background: white;
    }

    /* Fullscreen canvas button */
    .canvas-fullscreen-btn {
        position: absolute;
        top: 10px;
        right: 10px;
        width: 44px;
        height: 44px;
        background: rgba(255, 255, 255, 0.9);
        border: 1px solid var(--border);
        border-radius: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 100;
    }

    /* Enhanced hole properties for mobile */
    .hole-item {
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        transition: all 0.2s ease;
    }

    .hole-item:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    .hole-item.selected {
        border-width: 2px;
        box-shadow: 0 4px 16px rgba(37, 99, 235, 0.3);
    }

    /* Swipe gestures for tool switching */
    .tool-list {
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem;
    }

    .tool-btn {
        scroll-snap-align: start;
        flex-shrink: 0;
    }

    /* Mobile-specific canvas info */
    .canvas-info {
        position: relative;
    }

    .canvas-info::before {
        content: "💡";
        position: absolute;
        top: 1rem;
        right: 1rem;
        font-size: 1.5rem;
    }

    /* Print template mobile adjustments */
    @media print {
        .mobile-sidebar-toggle,
        .mobile-close-btn,
        .canvas-zoom-controls,
        .canvas-fullscreen-btn {
            display: none !important;
        }
    }
}

/* Mobile Header Styles */
@media (max-width: 768px) {
    .app-header,
    .header {
        min-height: 60px !important;
        padding: 1rem !important;
        position: relative !important;
    }

    .app-header .flex.items-center.justify-between,
    .header > div {
        height: 100% !important;
        align-items: center !important;
    }

    .nav-brand,
    .header h1 {
        font-size: 1.1rem !important;
        margin: 0 !important;
    }

    /* Hide original navigation on mobile */
    .main-nav .nav-links,
    .header nav {
        display: none !important;
    }

    .language-selector {
        display: none !important;
    }
}

/* Mobile Sidebar Styles */
@media (max-width: 768px) {
    .mobile-sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        background: var(--primary-color, #2563eb);
        padding: 1rem;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
        z-index: 1000;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

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

    .mobile-close-btn {
        position: absolute !important;
        top: 1rem !important;
        right: 1rem !important;
        background: rgba(255, 255, 255, 0.15) !important;
        border: 2px solid rgba(255, 255, 255, 0.2) !important;
        border-radius: 8px !important;
        color: white !important;
        font-size: 1.25rem !important;
        font-weight: bold !important;
        padding: 8px !important;
        cursor: pointer !important;
        min-height: 40px !important;
        min-width: 40px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        z-index: 1001 !important;
        transition: all 0.2s ease !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
        user-select: none !important;
    }

    .mobile-close-btn:hover {
        background: rgba(255, 255, 255, 0.25) !important;
        border-color: rgba(255, 255, 255, 0.4) !important;
        transform: scale(1.1) !important;
    }

    .mobile-menu-content {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        padding-top: 3rem;
        width: 100%;
    }

    .mobile-nav-button {
        display: flex !important;
        align-items: center !important;
        width: 100% !important;
        padding: 16px 20px !important;
        margin: 4px 0 !important;
        color: white !important;
        background: transparent !important;
        border: 1px solid transparent !important;
        border-radius: 8px !important;
        text-align: left !important;
        font-size: 16px !important;
        font-weight: 500 !important;
        cursor: pointer !important;
        transition: all 0.2s ease !important;
        min-height: 48px !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
        user-select: none !important;
        box-sizing: border-box !important;
    }

    .mobile-nav-button:hover,
    .mobile-nav-button:active {
        background: rgba(255, 255, 255, 0.15) !important;
        border-color: rgba(255, 255, 255, 0.3) !important;
    }

    .mobile-lang-container {
        display: flex;
        gap: 8px;
        margin-top: 1rem;
        padding: 0 20px;
    }

    .mobile-lang-btn {
        flex: 1;
        padding: 12px !important;
        color: white !important;
        background: transparent !important;
        border: 1px solid rgba(255, 255, 255, 0.3) !important;
        border-radius: 6px !important;
        font-size: 14px !important;
        font-weight: 500 !important;
        cursor: pointer !important;
        transition: all 0.2s ease !important;
        min-height: 40px !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
        user-select: none !important;
    }

    .mobile-lang-btn.active {
        background: rgba(255, 255, 255, 0.2) !important;
    }

    .mobile-lang-btn:hover,
    .mobile-lang-btn:active {
        background: rgba(255, 255, 255, 0.25) !important;
        border-color: rgba(255, 255, 255, 0.5) !important;
    }

    .mobile-nav-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .mobile-nav-backdrop.active {
        opacity: 1;
    }

    .mobile-menu-toggle {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: rgba(255, 255, 255, 0.1) !important;
        border: 1px solid rgba(255, 255, 255, 0.2) !important;
        border-radius: 6px !important;
        color: white !important;
        font-size: 1.25rem !important;
        padding: 0.5rem !important;
        cursor: pointer !important;
        min-height: 44px !important;
        min-width: 44px !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
        user-select: none !important;
        position: absolute !important;
        top: 50% !important;
        right: 1rem !important;
        transform: translateY(-50%) !important;
        z-index: 1001 !important;
        transition: all 0.2s ease !important;
    }

    .mobile-menu-toggle:hover,
    .mobile-menu-toggle:active {
        background: rgba(255, 255, 255, 0.1) !important;
    }
}

/* Very small screens (320px and below) */
@media (max-width: 320px) {
    .header h1 {
        font-size: 1rem;
    }

    .header nav a {
        padding: 0.4rem 0.6rem;
        font-size: 0.75rem;
        min-height: 40px;
    }

    .canvas-toolbar .btn {
        min-width: 80px;
        padding: 0.5rem;
        font-size: 0.75rem;
    }

    .tool-list {
        grid-template-columns: 1fr;
    }

    .hole-properties {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }
}

/* Accessibility improvements for mobile */
@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
    .mobile-sidebar-toggle {
        animation: none;
    }

    .tool-btn:active,
    .btn:active,
    .hole-item:hover {
        transform: none;
        transition: none;
    }
}

/* High contrast mode for mobile */
@media (max-width: 768px) and (prefers-contrast: high) {
    .hole-item,
    .design-item,
    .sheet-item {
        border-width: 2px;
    }

    .tool-btn,
    .btn {
        border-width: 2px;
        font-weight: 600;
    }

    .mobile-sidebar-toggle {
        border: 3px solid white;
    }
}

/* Force hardware acceleration on mobile for smooth animations */
@media (max-width: 768px) {
    .sidebar,
    .modal-content,
    .tool-btn,
    .btn,
    .hole-item {
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
}
