/* ============================================
   MOBILE RESPONSIVE STYLES
   Comprehensive mobile-friendly design
   ============================================ */

/* === BASE MOBILE IMPROVEMENTS === */

/* Ensure touch targets are at least 44px */
@media (max-width: 768px) {
    button, .btn, a, input, select, textarea {
        min-height: 44px;
    }

    .btn-small {
        min-height: 36px;
        padding: 0.5rem 0.75rem !important;
    }
}

/* Prevent horizontal scroll */
html, body {
    overflow-x: hidden;
    width: 100%;
}

/* === MOBILE NAVIGATION WITH HAMBURGER === */

.mobile-menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: #e5e7eb;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    z-index: 1001;
}

@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Hide desktop nav on mobile */
    .navbar .nav-buttons {
        display: none;
    }

    .navbar {
        padding: 0.75rem 1rem !important;
    }

    .navbar .logo {
        font-size: 1rem !important;
    }
}

/* Mobile sidebar overlay */
@media (max-width: 768px) {
    .management-container {
        display: flex !important;
        flex-direction: column !important;
        padding: 70px 0.75rem 2rem !important;
        gap: 0 !important;
    }

    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: -100% !important;
        width: 85% !important;
        max-width: 320px !important;
        height: 100vh !important;
        z-index: 1000 !important;
        border-radius: 0 !important;
        transition: left 0.3s ease !important;
        overflow-y: auto !important;
        padding-top: 70px !important;
    }

    .sidebar.open {
        left: 0 !important;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.6);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Reset nav menu to vertical */
    .nav-menu {
        display: flex !important;
        flex-direction: column !important;
        overflow-x: visible !important;
        gap: 0.25rem !important;
        padding-bottom: 0 !important;
    }

    .nav-item {
        width: 100% !important;
        flex-shrink: 0 !important;
    }

    .nav-link {
        white-space: normal !important;
        padding: 0.9rem 1rem !important;
    }

    .nav-text {
        display: inline !important;
    }

    /* Main content takes full width */
    .main-content {
        width: 100% !important;
        min-width: 0 !important;
    }
}

/* === MOBILE CARDS & SECTIONS === */

@media (max-width: 768px) {
    .management-card {
        padding: 1rem !important;
        border-radius: 10px !important;
        margin-bottom: 1rem !important;
    }

    .card-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .card-header h3 {
        font-size: 1.1rem !important;
    }

    .management-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .section-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .section-header .btn {
        width: 100%;
        justify-content: center;
    }
}

/* === MOBILE MODALS === */

@media (max-width: 768px) {
    .modal-content {
        max-width: 95vw !important;
        max-height: 90vh !important;
        margin: 5vh auto !important;
        border-radius: 12px !important;
        padding: 1rem !important;
    }

    .modal-content h3 {
        font-size: 1.1rem !important;
    }

    .modal-close {
        top: 0.75rem !important;
        right: 0.75rem !important;
        width: 36px !important;
        height: 36px !important;
        font-size: 1.5rem !important;
    }

    /* Data variable modals */
    .dv-modal,
    .items-modal,
    .item-form-modal {
        max-width: 95vw !important;
    }

    .dv-modal-header,
    .items-modal-header,
    .item-form-header {
        padding: 1rem !important;
        flex-wrap: wrap !important;
        gap: 0.75rem !important;
    }

    .dv-modal-icon,
    .items-modal-icon,
    .item-form-icon {
        width: 38px !important;
        height: 38px !important;
        font-size: 1rem !important;
    }

    .dv-modal-body,
    .item-form-container {
        padding: 1rem !important;
    }

    .dv-modal-footer,
    .items-modal-footer,
    .item-form-footer {
        padding: 0.75rem 1rem !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    .dv-modal-footer .btn,
    .items-modal-footer .btn,
    .item-form-footer .btn {
        flex: 1 1 auto;
        justify-content: center;
    }

    /* Schema fields */
    .dv-field-row {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    .dv-field-name-input {
        flex: 1 1 100% !important;
        order: 1 !important;
    }

    .dv-field-type-icon {
        order: 0 !important;
    }

    .dv-field-type-select {
        flex: 1 !important;
        order: 2 !important;
    }

    .dv-section {
        margin-bottom: 0.75rem !important;
    }

    .dv-section-content {
        padding: 0.75rem !important;
    }
}

/* === MOBILE ITEMS MANAGEMENT === */

@media (max-width: 768px) {
    .items-modal {
        max-width: 100vw !important;
        max-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }

    .items-modal-header {
        flex-wrap: wrap !important;
    }

    .items-modal-title-wrap {
        flex: 1 1 100% !important;
        order: 0 !important;
    }

    .items-add-btn {
        width: 100% !important;
        order: 2 !important;
    }

    .items-tools-bar {
        flex-direction: column !important;
        gap: 0.75rem !important;
        padding: 0.75rem 1rem !important;
    }

    .items-search-wrap {
        max-width: 100% !important;
        width: 100% !important;
    }

    .items-tools-actions {
        width: 100% !important;
        justify-content: space-between !important;
    }

    .items-tools-actions .btn {
        flex: 1 !important;
    }

    .item-card-v2 {
        flex-wrap: wrap !important;
    }

    .item-card-drag-handle {
        display: none !important;
    }

    .item-card-content {
        flex: 1 1 100% !important;
        order: 0 !important;
        padding: 0.75rem !important;
    }

    .item-card-index {
        position: absolute !important;
        top: 0.5rem !important;
        right: 0.5rem !important;
        width: 24px !important;
        height: 24px !important;
        font-size: 0.65rem !important;
        border-radius: 50% !important;
    }

    .item-card-actions {
        flex: 1 1 100% !important;
        order: 1 !important;
        justify-content: flex-end !important;
        border-left: none !important;
        border-top: 1px solid #334155 !important;
        padding: 0.5rem 0.75rem !important;
    }

    .item-card-btn {
        width: 40px !important;
        height: 40px !important;
    }
}

/* === MOBILE FORMS === */

@media (max-width: 768px) {
    .form-group {
        margin-bottom: 1rem !important;
    }

    .form-group label {
        font-size: 0.85rem !important;
        margin-bottom: 0.5rem !important;
    }

    input, select, textarea {
        font-size: 16px !important; /* Prevents iOS zoom */
        padding: 0.75rem !important;
    }

    .form-grid,
    .form-grid.two-column {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Generate Keys form */
    .generate-modal {
        max-width: 100vw !important;
        max-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        padding: 1rem !important;
    }

    .form-section {
        padding: 0.75rem !important;
        margin-bottom: 0.75rem !important;
    }

    .section-heading-with-icon {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }

    .quick-presets {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    .preset-btn {
        flex: 1 1 calc(50% - 0.25rem) !important;
        justify-content: center !important;
    }

    .subscription-checkbox-grid {
        grid-template-columns: 1fr !important;
    }

    .subscription-checkbox-item {
        padding: 0.75rem !important;
    }
}

/* === MOBILE TABLES & LISTS === */

@media (max-width: 768px) {
    /* Key items */
    .key-item {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
        padding: 1rem !important;
    }

    .key-identity {
        gap: 0.5rem !important;
    }

    .key-hash {
        font-size: 0.8rem !important;
        word-break: break-all !important;
    }

    .key-status {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    .key-actions {
        flex-direction: row !important;
        justify-content: flex-start !important;
        gap: 0.5rem !important;
        padding-top: 0.75rem !important;
        border-top: 1px solid rgba(99, 102, 241, 0.1) !important;
    }

    .key-actions .btn {
        flex: 1 !important;
        justify-content: center !important;
    }

    /* User items */
    .user-item {
        grid-template-columns: 1fr !important;
        padding: 1rem !important;
    }

    .user-identity {
        gap: 0.5rem !important;
    }

    .user-badges {
        flex-wrap: wrap !important;
    }

    .user-actions {
        flex-direction: row !important;
        gap: 0.5rem !important;
        padding-top: 0.75rem !important;
        border-top: 1px solid rgba(99, 102, 241, 0.1) !important;
    }

    .user-actions .btn {
        flex: 1 !important;
        justify-content: center !important;
    }

    /* Variable items */
    .variable-item {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .variable-item .variable-info {
        width: 100% !important;
    }

    .variable-item > div:last-child {
        width: 100% !important;
        display: flex !important;
        gap: 0.5rem !important;
    }

    .variable-item > div:last-child .btn {
        flex: 1 !important;
    }

    /* Variable cards */
    .variable-card {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    .variable-actions {
        justify-content: flex-start !important;
        flex-wrap: wrap !important;
    }
}

/* === MOBILE PAGINATION === */

@media (max-width: 768px) {
    .pagination-controls,
    #keyPaginationControls,
    #userPaginationControls {
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 0.5rem !important;
    }

    .pagination-controls .btn,
    #keyPaginationControls .btn,
    #userPaginationControls .btn {
        min-width: 40px !important;
        padding: 0.5rem !important;
    }
}

/* === MOBILE APP INFO HEADER === */

@media (max-width: 768px) {
    .app-info-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem !important;
    }

    .app-info-header img {
        width: 60px !important;
        height: 60px !important;
    }

    .app-info-header h2 {
        font-size: 1.2rem !important;
    }

    .app-info-badges {
        flex-wrap: wrap !important;
    }
}

/* === MOBILE STATS/METRICS === */

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }

    .stat-card {
        padding: 0.75rem !important;
    }

    .stat-value {
        font-size: 1.25rem !important;
    }

    .stat-label {
        font-size: 0.7rem !important;
    }
}

/* === MOBILE EMPTY STATES === */

@media (max-width: 768px) {
    .empty-state {
        padding: 2rem 1rem !important;
    }

    .empty-state i {
        font-size: 2rem !important;
    }

    .empty-state h4 {
        font-size: 1rem !important;
    }

    .empty-state p {
        font-size: 0.85rem !important;
    }
}

/* === MOBILE SEARCH BARS === */

@media (max-width: 768px) {
    .search-box,
    .search-input,
    [type="search"] {
        width: 100% !important;
        font-size: 16px !important;
    }

    .search-container {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }
}

/* === MOBILE TABS === */

@media (max-width: 768px) {
    .tabs {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
    }

    .tabs::-webkit-scrollbar {
        display: none !important;
    }

    .tab-btn {
        white-space: nowrap !important;
        flex-shrink: 0 !important;
        padding: 0.75rem 1rem !important;
    }
}

/* === MOBILE EDIT USER MODAL === */

@media (max-width: 768px) {
    .edit-user-modal {
        max-width: 100vw !important;
        max-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        padding: 1rem !important;
    }

    .edit-user-tabs {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        flex-wrap: nowrap !important;
        gap: 0.25rem !important;
    }

    .edit-user-tabs .tab-btn {
        flex-shrink: 0 !important;
        padding: 0.6rem 0.75rem !important;
        font-size: 0.75rem !important;
    }

    .edit-user-footer {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    .edit-user-footer-actions {
        width: 100% !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    .edit-user-footer-actions .btn {
        width: 100% !important;
    }
}

/* === MOBILE SETTINGS SECTIONS === */

@media (max-width: 768px) {
    .settings-section {
        padding: 1rem !important;
    }

    .setting-row {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }

    .setting-row label {
        font-size: 0.85rem !important;
    }

    .hwid-settings-grid,
    .app-settings-grid {
        grid-template-columns: 1fr !important;
    }
}

/* === MOBILE BLACKLIST/FILE PROXY === */

@media (max-width: 768px) {
    .blacklist-form,
    .file-proxy-form {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    .blacklist-entry,
    .file-proxy-entry {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .blacklist-entry .btn,
    .file-proxy-entry .btn {
        width: 100% !important;
    }
}

/* === MOBILE IMPORT DROP ZONE === */

@media (max-width: 768px) {
    .import-drop-zone {
        padding: 1.5rem !important;
    }

    .import-drop-zone i {
        font-size: 1.5rem !important;
    }

    .import-drop-zone p {
        font-size: 0.8rem !important;
        text-align: center !important;
    }
}

/* === SMALL PHONE ADJUSTMENTS === */

@media (max-width: 375px) {
    .management-container {
        padding: 65px 0.5rem 1.5rem !important;
    }

    .management-card {
        padding: 0.75rem !important;
    }

    .btn {
        padding: 0.6rem 0.75rem !important;
        font-size: 0.8rem !important;
    }

    .modal-content {
        padding: 0.75rem !important;
    }
}

/* === LANDSCAPE PHONE ADJUSTMENTS === */

@media (max-width: 768px) and (orientation: landscape) {
    .modal-content {
        max-height: 95vh !important;
    }

    .items-modal,
    .generate-modal,
    .edit-user-modal {
        max-height: 100vh !important;
    }
}

/* === TOUCH IMPROVEMENTS === */

@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .nav-link:hover {
        transform: none !important;
    }

    .key-item:hover,
    .user-item:hover,
    .variable-item:hover {
        transform: none !important;
    }

    /* Add active states instead */
    .btn:active {
        transform: scale(0.98) !important;
        opacity: 0.9 !important;
    }

    .nav-link:active {
        background: rgba(99, 102, 241, 0.15) !important;
    }

    /* Increase touch targets */
    .item-card-btn,
    .key-actions .btn,
    .user-actions .btn {
        min-width: 44px !important;
        min-height: 44px !important;
    }
}

/* === SAFE AREA INSETS (for notched phones) === */

@supports (padding: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .modal-content {
            padding-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
        }

        .items-modal-footer,
        .item-form-footer,
        .dv-modal-footer {
            padding-bottom: calc(0.75rem + env(safe-area-inset-bottom)) !important;
        }

        .sidebar {
            padding-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
        }
    }
}

/* === SUPER ADMIN PAGE === */

@media (max-width: 768px) {
    .app-container {
        padding: 1rem !important;
    }

    .nav-tabs {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        flex-wrap: nowrap !important;
        gap: 0.5rem !important;
        padding-bottom: 0.5rem !important;
    }

    .nav-tabs::-webkit-scrollbar {
        display: none !important;
    }

    .nav-tab {
        flex-shrink: 0 !important;
        padding: 0.6rem 1rem !important;
        font-size: 0.85rem !important;
        white-space: nowrap !important;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    .stat-card {
        padding: 0.75rem !important;
    }

    .card {
        padding: 0.75rem !important;
        margin-bottom: 1rem !important;
    }

    .card-header {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    .card-actions {
        width: 100% !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    .card-actions .btn,
    .card-actions button {
        flex: 1 1 calc(50% - 0.25rem) !important;
    }
}

/* === SUPER ADMIN LOGIN PAGE === */

@media (max-width: 768px) {
    .login-container {
        padding: 1rem !important;
        min-height: 100vh !important;
        align-items: flex-start !important;
        padding-top: 3rem !important;
    }

    .login-card {
        width: 100% !important;
        max-width: 100% !important;
        padding: 1.5rem !important;
        border-radius: 12px !important;
    }

    .login-card h1 {
        font-size: 1.5rem !important;
    }

    .login-card .form-group {
        margin-bottom: 1rem !important;
    }

    .login-card input {
        font-size: 16px !important;
        padding: 0.875rem !important;
    }

    .login-card button {
        padding: 0.875rem !important;
        font-size: 1rem !important;
    }
}

/* === DOCS PAGE === */

@media (max-width: 768px) {
    .navbar-content {
        padding: 0 1rem !important;
    }

    .nav-links {
        display: none !important;
    }

    .sidebar {
        position: fixed !important;
        top: 60px !important;
        left: -100% !important;
        width: 85% !important;
        max-width: 300px !important;
        height: calc(100vh - 60px) !important;
        z-index: 1000 !important;
        transition: left 0.3s ease !important;
        overflow-y: auto !important;
    }

    .sidebar.open {
        left: 0 !important;
    }

    .content-area {
        margin-left: 0 !important;
        padding: 1rem !important;
    }

    .endpoint-card {
        padding: 1rem !important;
    }

    .endpoint-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }

    .method-badge {
        font-size: 0.75rem !important;
    }

    .endpoint-path {
        font-size: 0.85rem !important;
        word-break: break-all !important;
    }

    pre, code {
        font-size: 0.8rem !important;
        overflow-x: auto !important;
    }

    .code-block {
        padding: 0.75rem !important;
    }
}

/* === INDEX/LANDING PAGE === */

@media (max-width: 768px) {
    /* Mobile nav overlay */
    .mobile-nav-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.6);
        z-index: 998;
    }

    .mobile-nav-overlay.active {
        display: block;
    }

    /* Mobile navigation dropdown */
    .nav-buttons {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: rgba(10, 12, 20, 0.98);
        padding: 1rem;
        flex-direction: column;
        gap: 0.75rem;
        border-bottom: 1px solid rgba(99, 102, 241, 0.2);
        z-index: 999;
    }

    .nav-buttons.mobile-open {
        display: flex;
    }

    .nav-buttons .btn {
        width: 100%;
        justify-content: center;
    }

    .hero {
        padding: 2rem 1rem !important;
        text-align: center !important;
    }

    .hero h1 {
        font-size: 1.75rem !important;
    }

    .hero p {
        font-size: 1rem !important;
    }

    .hero-buttons {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    .hero-buttons .btn {
        width: 100% !important;
    }

    .features-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
        padding: 0 1rem !important;
    }

    .feature-card {
        padding: 1.25rem !important;
    }

    .pricing-grid {
        grid-template-columns: 1fr !important;
        padding: 0 1rem !important;
    }

    footer {
        padding: 2rem 1rem !important;
    }

    .footer-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }
}

/* === APP PORTAL PAGE === */

@media (max-width: 768px) {
    .portal-container {
        padding: 1rem !important;
    }

    .portal-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem !important;
    }

    .portal-card {
        padding: 1rem !important;
    }

    .portal-stats {
        grid-template-columns: 1fr 1fr !important;
    }

    .portal-actions {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    .portal-actions .btn {
        width: 100% !important;
    }

    .license-info {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    .subscription-card {
        padding: 0.75rem !important;
    }
}

/* === ADMIN PAGE SPECIFIC === */

@media (max-width: 768px) {
    .admin-container {
        padding: 70px 1rem 2rem !important;
    }

    .admin-header {
        flex-direction: column !important;
        gap: 1rem !important;
        padding: 1rem !important;
    }

    .app-grid {
        grid-template-columns: 1fr !important;
    }

    .app-card {
        padding: 1rem !important;
    }

    .app-card-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .app-card-actions {
        width: 100% !important;
        display: flex !important;
        gap: 0.5rem !important;
    }

    .app-card-actions .btn {
        flex: 1 !important;
    }
}

/* === PRINT STYLES (hide non-essential on print) === */

@media print {
    .sidebar,
    .navbar,
    .mobile-menu-toggle,
    .modal {
        display: none !important;
    }

    .management-container {
        display: block !important;
        padding: 0 !important;
    }

    .main-content {
        width: 100% !important;
    }
}
