/* ========== MOBILE CSS - iPhone 14 Pro (393x852) optimized ========== */

/* --- Topbar Mobile Redesign --- */
@media (max-width: 768px) {
    #topbar {
        padding: 6px 0;
        font-size: 0.7rem;
        position: fixed;
        z-index: 1000;
    }

    #topbar .container-xl {
        padding: 0 8px;
    }

    /* Convert topbar to grid on mobile */
    #topbar .topbar-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 3px 8px;
        align-items: center;
    }

    #topbar .topbar-grid .topbar-item {
        padding: 2px 4px;
        font-size: 0.68rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #topbar .topbar-grid .topbar-item.full-width {
        grid-column: 1 / -1;
        text-align: center;
    }

    #topbar .topbar-grid .topbar-item b {
        font-size: 0.65rem;
        color: #adb5bd;
    }

    /* Hide less critical topbar items on mobile */
    #topbar .topbar-grid .topbar-hide-mobile {
        display: none;
    }

    /* Topbar actions row */
    #topbar .topbar-actions {
        display: flex;
        justify-content: center;
        gap: 8px;
        margin-top: 4px;
        padding-top: 4px;
        border-top: 1px solid #1d303b;
    }

    /* Adjust #app padding for the taller mobile topbar */
    #app {
        padding-top: 100px !important;
        padding-left: 8px !important;
        padding-right: 8px !important;
        padding-bottom: 80px !important;
    }

    /* Search and filter controls mobile */
    .search-sort-controls .col-md-4,
    .search-sort-controls .col-md-2,
    .search-sort-controls .col-md-3 {
        padding-left: 4px;
        padding-right: 4px;
    }

    .search-sort-controls .form-control-sm {
        font-size: 0.75rem;
        padding: 4px 8px;
    }

    /* Connection status summary mobile */
    .alert.connection-summary-alert {
        font-size: 0.75rem;
        padding: 8px 12px;
    }

    .connection-summary-details {
        display: block;
        margin-top: 2px;
    }
}

/* --- Tablet (768-1200px) --- */
@media (min-width: 769px) and (max-width: 1200px) {
    #app {
        padding: 50px 15px 15px 15px;
    }

    #topbar {
        font-size: 0.75rem;
    }

    /* Hide some table columns on tablets */
    .clients-list .col-hide-tablet {
        display: none !important;
    }

    .clients-list td,
    .clients-list th {
        padding: 0.2rem 0.3rem;
        font-size: 0.7rem;
    }
}

/* --- Desktop (>1200px) --- */
@media (min-width: 1201px) {
    #topbar .topbar-grid {
        display: flex !important;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 2px 0;
    }

    #topbar .topbar-grid .topbar-item {
        padding: 2px 6px;
        text-align: center;
        font-size: 0.85rem;
    }

    #topbar .topbar-grid .topbar-hide-mobile {
        display: block;
    }

    #topbar .topbar-actions {
        display: none;
    }
}

/* --- Ultra-wide (>1600px) --- */
@media (min-width: 1601px) {
    .container-xl {
        max-width: 1560px;
    }

    #topbar .topbar-grid .topbar-item {
        font-size: 0.9rem;
    }
}

/* ========== Topbar Collapsible Toggle ========== */
.topbar-toggle-btn {
    background: none;
    border: 1px solid #1d303b;
    color: #adb5bd;
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s;
}

.topbar-toggle-btn:hover,
.topbar-toggle-btn:focus {
    background-color: #2c4152;
    color: #fff;
    outline: none;
}

.topbar-collapsed-items {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.3s ease;
}

.topbar-collapsed-items.show {
    max-height: 200px;
}

@media (min-width: 769px) {
    .topbar-toggle-btn {
        display: none;
    }

    .topbar-collapsed-items {
        max-height: none !important;
        overflow: visible;
    }
}

/* ========== Improved Mobile Card Adjustments ========== */
@media (max-width: 768px) {
    .mobile-cards {
        padding: 0 !important;
    }

    .client-card {
        margin-bottom: 12px;
        padding: 12px;
        border-radius: 10px;
    }

    .card-header .username {
        font-size: 1rem;
        max-width: 65%;
    }

    .balance-section {
        gap: 8px;
        margin-bottom: 12px;
    }

    .balance-item {
        padding: 8px;
    }

    .balance-item .value {
        font-size: 0.8rem;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
        margin-bottom: 12px;
    }

    .stat-item {
        padding: 6px;
    }

    .stat-label {
        font-size: 0.65rem;
    }

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

    .additional-info {
        padding: 8px;
        margin-bottom: 12px;
    }

    .info-item {
        padding: 3px 0;
        font-size: 0.72rem;
    }

    .info-item span:last-child {
        font-size: 0.68rem;
        max-width: 55%;
    }

    .card-actions .btn {
        padding: 6px 10px;
        font-size: 0.75rem;
        min-width: 45px;
    }

    /* Mobile max LS and profit stats */
    .max-ls-display,
    .mobile-profit-stats {
        margin-bottom: 12px;
    }

    .max-ls-display .value {
        font-size: 1.3rem;
    }

    /* Scroll buttons - more compact */
    .scroll-buttons {
        bottom: 12px;
        right: 12px;
        gap: 6px;
    }

    .scroll-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    /* Global actions button */
    .mobile-global-actions {
        bottom: 120px;
        right: 12px;
    }

    .mobile-global-actions .mobile-btn-toggle {
        width: 44px;
        height: 44px;
        font-size: 0.9rem;
    }
}

/* ========== iPhone SE / small screens (< 375px) ========== */
@media (max-width: 374px) {
    #topbar .topbar-grid .topbar-item {
        font-size: 0.6rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .client-card {
        padding: 10px;
    }

    .card-header .username {
        font-size: 0.9rem;
    }
}

/* ========== Desktop Table Improvements ========== */
@media (min-width: 769px) {
    .table-responsive {
        overflow-x: auto;
    }

    .clients-list {
        font-size: 0.75rem;
    }

    .clients-list th {
        position: sticky;
        top: 0;
        z-index: 2;
        font-size: 0.72rem;
        padding: 0.35rem 0.4rem;
        white-space: nowrap;
    }

    .clients-list td {
        padding: 0.3rem 0.4rem;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .clients-list .username {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Connection status badge in table */
    .connection-status-badge {
        font-size: 0.6rem;
        padding: 1px 4px;
        border-radius: 3px;
        margin-top: 2px;
        display: inline-block;
    }

    .connection-status-badge.critical {
        background-color: rgba(220, 53, 69, 0.3);
        color: #ff6b6b;
    }

    .connection-status-badge.warning {
        background-color: rgba(255, 193, 7, 0.3);
        color: #ffc107;
    }

    .connection-status-badge.stale {
        background-color: rgba(108, 117, 125, 0.3);
        color: #adb5bd;
    }
}

/* Columns to hide on medium desktop (1200-1400px) */
@media (min-width: 769px) and (max-width: 1400px) {
    .col-hide-lg {
        display: none !important;
    }
}

/* ========== Smooth transitions ========== */
.client-card,
.stat-item,
.balance-item,
.info-item,
.missing-client-card {
    transition: all 0.2s ease;
}

/* ========== Print styles ========== */
@media print {
    #topbar,
    .mobile-global-actions,
    .scroll-buttons,
    .card-actions,
    .btn-group {
        display: none !important;
    }

    #app {
        padding: 0 !important;
    }

    .blur {
        filter: none !important;
    }
}
