/* Mobile-First Responsive CSS for CMly Application */

/* ============================================
   BASE MOBILE STYLES (Mobile-First Approach)
   ============================================ */

/* Ensure viewport meta tag exists - add to all templates */
/* <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=yes"> */

/* Prevent horizontal scrolling */
html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* Base container - only adjust on mobile */
@media (max-width: 767px) {
    .container {
        width: 100%;
        max-width: 100%;
        padding: 16px;
        margin: 0 auto;
    }
}

/* Typography - Mobile First - only on mobile */
@media (max-width: 767px) {
    body {
        font-size: 16px; /* Prevent zoom on iOS */
        line-height: 1.5;
        -webkit-text-size-adjust: 100%;
        -moz-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    h1 {
        font-size: 24px;
        line-height: 1.3;
        margin-bottom: 20px;
    }

    h2 {
        font-size: 20px;
        line-height: 1.3;
    }

    h3 {
        font-size: 18px;
        line-height: 1.3;
    }
}

/* ============================================
   TOUCH-FRIENDLY INTERACTIVE ELEMENTS
   ============================================ */

/* Minimum 44px tap targets (Apple HIG / Material Design) */
/* Touch-friendly buttons - only on mobile */
@media (max-width: 767px) {
    button,
    a.btn,
    .toolbar-btn,
    .create-link-btn,
    .action-btn-primary,
    .action-btn-menu,
    .qr-dropdown-btn,
    .user-menu-btn,
    .tab,
    .form-close-btn,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
        font-size: 16px; /* Prevent zoom on iOS */
        touch-action: manipulation; /* Disable double-tap zoom */
        -webkit-tap-highlight-color: rgba(102, 126, 234, 0.3);
    }
}

/* Form inputs - prevent zoom on iOS (mobile only) */
@media (max-width: 767px) {
    input[type="text"],
    input[type="url"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 44px;
        padding: 12px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
}

/* Labels should not overlap inputs */
label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
}

/* ============================================
   NAVIGATION - HAMBURGER MENU
   ============================================ */

/* Hamburger menu button */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1001;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    width: 48px;
    height: 48px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    touch-action: manipulation;
}

.mobile-menu-toggle:focus {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

.mobile-menu-toggle span {
    display: block;
    width: 24px;
    height: 3px;
    background: white;
    margin: 4px 0;
    transition: all 0.3s;
    border-radius: 2px;
}

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

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

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

/* Mobile menu overlay */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
}

.mobile-menu-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile menu panel */
.mobile-menu-panel {
    position: fixed;
    top: 0;
    right: -100%;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    background: white;
    z-index: 1000;
    overflow-y: auto;
    transition: right 0.3s ease;
    box-shadow: -2px 0 10px rgba(0,0,0,0.2);
}

.mobile-menu-panel.active {
    right: 0;
}

.mobile-menu-header {
    padding: 20px;
    background: #667eea;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mobile-menu-header h3 {
    margin: 0;
    font-size: 18px;
    color: white;
}

.mobile-menu-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-menu-content {
    padding: 20px 0;
}

.mobile-menu-item {
    display: block;
    padding: 16px 20px;
    color: #333;
    text-decoration: none;
    border-bottom: 1px solid #f0f0f0;
    font-size: 16px;
    transition: background 0.2s;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.mobile-menu-item:hover,
.mobile-menu-item:focus {
    background: #f8f9fa;
    outline: none;
}

.mobile-menu-item.active {
    background: #e7ecff;
    color: #667eea;
    font-weight: 600;
}

/* ============================================
   TABLES - MOBILE RESPONSIVE
   ============================================ */

/* Table container with horizontal scroll - always enabled */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    -ms-overflow-style: -ms-autohiding-scrollbar;
    position: relative;
    width: 100%;
    margin: 0;
}

/* Mobile-specific table adjustments */
@media (max-width: 767px) {

/* Add scroll indicator on mobile */
.table-container::after {
    content: '→';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.9));
    padding: 20px 10px;
    pointer-events: none;
    font-size: 24px;
    color: #667eea;
    opacity: 0.5;
    display: none;
}

/* Table styling for mobile */
table {
    width: 100%;
    min-width: 600px; /* Minimum width to prevent cramping */
    border-collapse: collapse;
    font-size: 14px;
}

/* Table cells - mobile only */
@media (max-width: 767px) {
    th, td {
        padding: 12px 8px;
        text-align: left;
        white-space: nowrap;
    }
}

/* Table header - mobile only adjustments */
@media (max-width: 767px) {
    th {
        font-size: 12px;
        font-weight: 600;
        position: sticky;
        top: 0;
        background: #f8f9fa;
        z-index: 10;
    }

    /* Make important columns more visible on mobile */
    td:first-child,
    th:first-child {
        position: sticky;
        left: 0;
        background: white;
        z-index: 5;
        box-shadow: 2px 0 4px rgba(0,0,0,0.1);
        padding-left: 12px;
    }

    tr:hover td:first-child {
        background: #f8f9fa;
    }
}

/* ============================================
   FORMS - MOBILE OPTIMIZED
   ============================================ */

/* Form sections - mobile only */
@media (max-width: 767px) {
    .form-section {
        padding: 16px;
        margin-bottom: 20px;
        max-width: 100%;
    }

    .form-group {
        flex-direction: column;
        gap: 12px;
    }

    .form-row {
        flex-direction: column;
        gap: 12px;
    }

    .form-group input,
    .form-group button,
    .form-row input,
    .form-row textarea,
    .form-row select {
        width: 100%;
        flex: 1 1 100%;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .btn-primary-create,
    .btn-secondary-cancel {
        width: 100%;
    }

    /* Form header on mobile */
    .form-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .form-header h2 {
        margin: 0;
        width: 100%;
    }
}

/* ============================================
   ACTION BARS & TOOLBARS - MOBILE ONLY
   ============================================ */

@media (max-width: 767px) {
    .top-action-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 16px;
    }

    .top-action-bar-left,
    .top-action-bar-right {
        width: 100%;
        flex-direction: column;
        gap: 12px;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 16px 0;
    }
}

@media (max-width: 767px) {
    .tabs {
        width: 100%;
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0;
    }

    .tab {
        flex: 1;
        text-align: center;
        white-space: nowrap;
        min-width: 120px;
    }

    .toolbar-actions {
        width: 100%;
        flex-direction: column;
        gap: 12px;
    }

    .toolbar-select,
    .toolbar-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================
   DROPDOWNS & MENUS
   ============================================ */

/* User menu dropdown - full width on mobile */
@media (max-width: 767px) {
    .user-menu-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        min-width: auto;
        margin: 0;
        border-radius: 12px 12px 0 0;
        max-height: 70vh;
        overflow-y: auto;
    }

    .qr-dropdown-content,
    .actions-menu-content {
        position: fixed;
        right: 16px;
        left: 16px;
        width: auto;
        max-width: calc(100vw - 32px);
        margin-top: 8px;
    }
}

/* ============================================
   BUTTONS & ACTIONS
   ============================================ */

.actions-btn-group {
    flex-wrap: wrap;
    gap: 8px;
}

.action-btn-primary,
.action-btn-menu {
    flex: 1;
    min-width: 120px;
}

/* Empty state buttons */
.empty-state-actions {
    flex-direction: column;
    gap: 12px;
}

    .empty-state-btn {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================
   ALERTS & MODALS
   ============================================ */

/* Alerts - mobile adjustments */
@media (max-width: 767px) {
    .alert {
        padding: 16px;
        margin-bottom: 16px;
        font-size: 14px;
        line-height: 1.5;
        word-wrap: break-word;
    }
}

.alert strong {
    display: block;
    margin-bottom: 8px;
    font-size: 15px;
}

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

/* Hide on mobile */
.mobile-hide {
    display: none !important;
}

/* Show only on mobile */
.mobile-only {
    display: block !important;
}

.desktop-only {
    display: none !important;
}

/* Full width on mobile */
.mobile-full-width {
    width: 100% !important;
    max-width: 100% !important;
}

/* ============================================
   MEDIA QUERIES - TABLET & DESKTOP
   ============================================ */

/* Tablet and up (768px+) */
@media (min-width: 768px) {
    .container {
        padding: 24px;
        max-width: 1400px;
    }

    h1 {
        font-size: 28px;
        margin-bottom: 30px;
    }

    .mobile-menu-toggle {
        display: none;
    }

    .mobile-menu-overlay,
    .mobile-menu-panel {
        display: none;
    }

    .top-action-bar {
        flex-direction: row;
        align-items: center;
    }

    .top-action-bar-left,
    .top-action-bar-right {
        width: auto;
        flex-direction: row;
    }

    .toolbar {
        flex-direction: row;
        align-items: center;
    }

    .tabs {
        width: auto;
    }

    .tab {
        flex: none;
    }

    .toolbar-actions {
        flex-direction: row;
        width: auto;
    }

    .toolbar-select,
    .toolbar-btn {
        width: auto;
    }

    .form-group {
        flex-direction: row;
    }

    .form-row {
        flex-direction: row;
    }

    .form-group input,
    .form-group button {
        width: auto;
        flex: 1 1 auto;
    }

    .user-menu-dropdown {
        position: absolute;
        top: 100%;
        bottom: auto;
        left: auto;
        right: 0;
        width: auto;
        min-width: 200px;
        max-width: 300px;
        border-radius: 6px;
        max-height: none;
    }

    .qr-dropdown-content,
    .actions-menu-content {
        position: absolute;
        right: 0;
        left: auto;
        width: auto;
        min-width: 140px;
        max-width: 300px;
    }

    .empty-state-actions {
        flex-direction: row;
    }

    .empty-state-btn {
        width: auto !important;
    }

    .mobile-hide {
        display: block !important;
    }

    .mobile-only {
        display: none !important;
    }

    .desktop-only {
        display: block !important;
    }

    table {
        font-size: 14px;
    }

    th, td {
        padding: 16px 12px;
    }

    td:first-child,
    th:first-child {
        position: static;
        box-shadow: none;
        padding-left: 12px;
    }
    
    /* Restore original h1 size on desktop */
    h1 {
        font-size: 28px;
        margin-bottom: 30px;
    }
    
    h2 {
        font-size: 22px;
    }
    
    h3 {
        font-size: 20px;
    }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
    .container {
        padding: 30px;
    }

    table {
        font-size: 15px;
    }

    .original-url {
        max-width: 300px;
    }
}

/* ============================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================ */

/* Focus indicators */
*:focus {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

/* Skip to content link */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: #667eea;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
}

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

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

@media print {
    .mobile-menu-toggle,
    .mobile-menu-overlay,
    .mobile-menu-panel,
    .top-action-bar,
    .toolbar,
    button,
    .actions-menu {
        display: none !important;
    }

    .container {
        box-shadow: none;
        padding: 0;
    }

    table {
        font-size: 12px;
    }
}

