/**
 * Responsive styles for JSM Dashboard
 * Applies to: login, overview, list profiles (dashboard), view profile
 * Breakpoints: 992px, 768px, 480px
 */

/* ========== Login page ========== */
@media (max-width: 768px) {
    .login-container {
        max-width: 100%;
        margin: 16px;
        padding: 24px 20px;
        border-radius: 12px;
    }
    .login-container h1 {
        font-size: 1.5rem;
        color: #333;
    }
    .login-container .subtitle {
        font-size: 0.9375rem;
        color: #666;
    }
    .login-container label {
        font-size: 0.9375rem;
        color: #333;
    }
    .login-container input[type="text"],
    .login-container input[type="password"] {
        padding: 14px 12px;
        font-size: 16px; /* prevents iOS zoom on focus */
        min-height: 48px;
    }
    .login-container .btn-login {
        padding: 14px;
        font-size: 1rem;
        min-height: 48px;
    }
    .login-container .error-message {
        font-size: 0.9375rem;
        padding: 14px;
    }
    .logo-container img {
        max-width: 140px;
    }
}

@media (max-width: 480px) {
    .login-container {
        margin: 12px;
        padding: 20px 16px;
    }
    .login-container h1 {
        font-size: 1.375rem;
    }
}

/* ========== Mobile app bar & drawer (screens under 768px) ========== */
/* Hide on desktop by default */
.mobile-appbar,
.drawer-overlay,
.mobile-drawer {
    display: none !important;
}

/* Drawer site tool submenus: always collapsed unless expanded (works even if CSS cache is stale mid-update) */
.drawer-site-submenu[hidden] {
    display: none !important;
}
.drawer-site-submenu {
    display: none !important;
    background: #fafbff;
    padding: 4px 0 8px;
}
.drawer-site-submenu.expanded {
    display: block !important;
}
.drawer-site-group {
    border-bottom: 1px solid #f0f0f0;
}
.drawer-site-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: #333;
    font-size: 0.9375rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
    font-family: inherit;
}
.drawer-site-toggle:hover,
.drawer-site-toggle.expanded {
    background: #f8f9ff;
    color: #667eea;
}
.drawer-site-toggle-icon {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    color: #999;
}
.drawer-site-toggle.expanded .drawer-site-toggle-icon {
    transform: rotate(180deg);
    color: #667eea;
}
.drawer-sub-item {
    display: flex !important;
    align-items: center;
    gap: 10px;
    padding: 11px 20px 11px 28px;
    color: #333 !important;
    text-decoration: none !important;
    font-size: 0.9rem;
    font-weight: 500;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
    box-sizing: border-box;
}
.drawer-sub-item:hover {
    background: #eef1ff;
    color: #667eea !important;
}
.drawer-sub-item .submenu-icon {
    font-size: 14px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .mobile-appbar {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        padding: 0 16px;
        background-color: #667eea;
        color: white;
        z-index: 1002;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }
    .mobile-appbar-menu {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 48px;
        height: 48px;
        margin: 0 -8px 0 -8px;
        padding: 0;
        border: none;
        background: transparent;
        color: #ffffff !important;
        font-size: 1.5rem;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-appbar-menu:hover,
    .mobile-appbar-menu:focus {
        color: #ffffff !important;
    }
    .mobile-appbar-title {
        flex: 1;
        text-align: center;
        font-size: 1.125rem;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding: 0 8px;
    }
    .mobile-appbar-back {
        padding: 0 12px;
        height: 48px;
        min-width: 48px;
        border: none;
        background: transparent;
        color: #ffffff !important;
        font-size: 0.9375rem;
        font-weight: 500;
        cursor: pointer;
        flex-shrink: 0;
        -webkit-tap-highlight-color: transparent;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .mobile-appbar-back:hover,
    .mobile-appbar-back:focus {
        color: #ffffff !important;
    }
    .drawer-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        opacity: 0;
        transition: opacity 0.25s ease;
        pointer-events: none;
    }
    body.drawer-open .drawer-overlay {
        display: block !important;
        opacity: 1;
        pointer-events: auto;
    }
    .mobile-drawer {
        display: block !important;
    }
    /* Desktop header hidden on mobile */
    .header {
        display: none !important;
    }
    /* Body/main padding for fixed app bar */
    body.has-mobile-appbar {
        padding-top: 56px;
    }
    body.has-mobile-appbar .dashboard-layout {
        min-height: calc(100vh - 56px);
    }
    body.has-mobile-appbar .container {
        padding-top: 0;
    }
}

/* Drawer: mobile-only .mobile-drawer (desktop sidebar unchanged, hidden on mobile) */
@media (max-width: 768px) {
    .dashboard-layout .sidebar {
        display: none !important;
    }
    .mobile-drawer {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 85vw;
        background: white;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
        z-index: 1001;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
        padding: 56px 0 24px 0;
    }
    body.drawer-open .mobile-drawer {
        transform: translateX(0);
    }
    .drawer-user {
        padding: 20px 20px 16px;
        border-bottom: 1px solid #eee;
    }
    .drawer-user-avatar {
        width: 48px;
        height: 48px;
        border-radius: 50%;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.25rem;
        font-weight: 600;
        margin-bottom: 10px;
    }
    .drawer-user-name {
        font-size: 1rem;
        font-weight: 600;
        color: #333;
        margin-bottom: 4px;
    }
    .drawer-user-email {
        font-size: 0.875rem;
        color: #666;
    }
    .drawer-nav {
        padding: 12px 0;
        border-bottom: 1px solid #eee;
    }
    .drawer-nav-item {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 12px 20px;
        color: #333;
        text-decoration: none;
        font-size: 0.9375rem;
        -webkit-tap-highlight-color: transparent;
    }
    .drawer-nav-item:hover {
        background: #f8f9ff;
        color: #667eea;
    }
    .drawer-sites {
        padding: 12px 0 16px;
    }
    .drawer-sites-title {
        padding: 0 20px 10px;
        font-size: 0.75rem;
        font-weight: 700;
        text-transform: uppercase;
        color: #999;
        letter-spacing: 0.5px;
    }
    .drawer-site-item {
        display: block;
        padding: 10px 20px;
        color: #333;
        text-decoration: none;
        font-size: 0.9375rem;
        -webkit-tap-highlight-color: transparent;
    }
    .drawer-site-item:hover {
        background: #f8f9ff;
        color: #667eea;
    }
    .mobile-drawer .drawer-logout-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        margin: 16px 20px 0;
        padding: 12px 20px;
        width: calc(100% - 40px);
        margin-left: 20px;
        margin-right: 20px;
        background: #dc3545;
        color: white;
        border-radius: 8px;
        font-size: 1rem;
        font-weight: 500;
        text-decoration: none;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-drawer .drawer-logout-btn:hover {
        background: #c82333;
    }
}

/* Hide mobile app bar and drawer UI on desktop */
@media (min-width: 769px) {
    .mobile-appbar,
    .drawer-overlay {
        display: none !important;
    }
    body.has-mobile-appbar {
        padding-top: 0 !important;
    }
    .mobile-drawer {
        display: none !important;
    }
}

/* ========== Shared header (overview, dashboard, profile) ========== */
@media (max-width: 992px) {
    .header {
        flex-wrap: wrap;
        padding: 12px 20px;
        gap: 12px;
    }
    .header-left {
        gap: 12px;
    }
    .header .logo {
        max-height: 38px;
    }
    .header-center {
        order: 3;
        width: 100%;
        justify-content: flex-start;
    }
    /* profile page: breadcrumb is direct child of .header */
    .header > .breadcrumb {
        order: 3;
        width: 100%;
        flex-basis: 100%;
    }
    .header-right {
        margin-left: auto;
    }
    .user-info {
        padding: 6px 12px;
    }
    .welcome-text {
        font-size: 0.8125rem;
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .btn-logout {
        padding: 8px 14px;
        font-size: 0.8125rem;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 10px 16px;
    }
    .header .logo {
        max-height: 32px;
    }
    .breadcrumb {
        font-size: 0.8125rem;
    }
    .welcome-text {
        display: none;
    }
    .user-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.8125rem;
    }
}

@media (max-width: 480px) {
    .header-left .btn-back {
        padding: 6px 12px;
        font-size: 0.8125rem;
    }
    .header-right .btn-export-pdf {
        padding: 8px 14px;
        font-size: 0.8125rem;
    }
}

/* ========== Dashboard layout & sidebar (overview, list profiles) ========== */
@media (max-width: 992px) {
    .dashboard-layout {
        flex-direction: column;
        min-height: auto;
    }
    .dashboard-layout .sidebar {
        width: 100%;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
        padding: 12px 0;
    }
    .dashboard-layout .main-content {
        padding: 20px 16px;
        flex: 1;
    }
}

@media (max-width: 768px) {
    .dashboard-layout .main-content {
        padding: 16px 12px;
    }
    .sidebar-section {
        margin-bottom: 16px;
    }
    .sidebar-title {
        padding: 0 16px;
        font-size: 0.6875rem;
    }
    .site-link {
        padding: 12px 16px;
        font-size: 0.9375rem;
    }
    .site-icon {
        width: 28px;
        height: 28px;
        font-size: 0.8125rem;
    }
    .submenu-item {
        padding: 10px 16px 10px 52px;
        font-size: 0.9375rem;
    }
    .nav-overview {
        padding: 8px 16px;
    }
    .nav-overview a {
        font-size: 0.9375rem;
    }
}

/* ========== Overview page ========== */
@media (max-width: 992px) {
    .overview-title {
        font-size: 1.375rem;
        margin-bottom: 20px;
    }
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 16px;
        margin-bottom: 24px;
    }
    .stat-card {
        padding: 16px;
    }
    .stat-label {
        font-size: 0.6875rem;
    }
    .stat-value {
        font-size: 1.75rem;
    }
    .site-cards {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 16px;
    }
    .site-card {
        padding: 16px;
    }
    .site-card h4 {
        font-size: 0.9375rem;
    }
    .site-card .count {
        font-size: 1.5rem;
    }
    .site-card .btn-view-users {
        padding: 10px 14px;
        font-size: 0.8125rem;
    }
    .chart-section {
        padding: 20px 16px;
        max-width: 100%;
    }
    .chart-section h3 {
        font-size: 1rem;
    }
    .chart-wrapper {
        height: 280px;
    }
}

/* Overview page: mobile-only tweaks (768px and below) */
@media (max-width: 768px) {
    .overview-title {
        display: none;
    }
    .overview-title + .stats-grid {
        display: flex;
        flex-wrap: nowrap;
        gap: 16px;
        margin-bottom: 24px;
    }
    .overview-title + .stats-grid .stat-card {
        flex: 1 1 0;
        min-width: 0;
    }
    .site-card .btn-view-users {
        width: 100%;
        display: block;
        text-align: center;
        box-sizing: border-box;
    }
    .dashboard-layout .main-content:has(.overview-title) {
        padding: 16px 16px 40px 16px;
    }
}

@media (max-width: 480px) {
    .overview-title {
        font-size: 1.25rem;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .site-cards {
        grid-template-columns: 1fr;
    }
    .chart-wrapper {
        height: 260px;
    }
}

/* ========== List profiles (dashboard with table) ========== */
@media (max-width: 992px) {
    .main-content .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 12px;
        margin-bottom: 20px;
    }
    .main-content .stat-card {
        padding: 14px;
    }
    .main-content .stat-label {
        font-size: 0.6875rem;
    }
    .main-content .stat-value {
        font-size: 1.5rem;
    }
    .filter-panel {
        padding: 16px 20px;
        margin-bottom: 16px;
    }
    .filter-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
    .filter-actions {
        flex-wrap: wrap;
    }
    .filter-actions .btn-action {
        padding: 10px 16px;
        font-size: 0.8125rem;
    }
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 16px;
    }
    .users-table {
        min-width: 560px;
    }
    .users-table th,
    .users-table td {
        padding: 12px 14px;
        font-size: 0.8125rem;
    }
    .users-table .profile-picture {
        width: 48px;
        height: 48px;
    }
    .profile-picture-cell {
        padding: 8px 14px !important;
    }
    .btn-view {
        padding: 6px 12px;
        font-size: 0.75rem;
    }
    .pagination {
        flex-wrap: wrap;
        gap: 8px;
        padding: 16px;
    }
    .pagination a,
    .pagination span {
        padding: 8px 12px;
        font-size: 0.8125rem;
    }
}

@media (max-width: 768px) {
    /* Stats: one horizontal row */
    .main-content .stats-grid {
        display: flex;
        flex-wrap: nowrap;
        gap: 12px;
    }
    .main-content .stats-grid .stat-card {
        flex: 1 1 0;
        min-width: 0;
    }
    /* Hide Export Excel on mobile */
    .filter-actions a[href*="export_excel.php"] {
        display: none !important;
    }
    .filter-grid {
        grid-template-columns: 1fr;
    }
    .filter-actions {
        flex-direction: column;
    }
    .filter-actions .btn-action,
    .filter-actions a.btn-action {
        width: 100%;
        text-align: center;
    }
    .age-range {
        flex-wrap: wrap;
    }
    /* Mobile: hide I am a & Phone columns; hide table header; convert rows to cards */
    .users-table thead {
        display: none;
    }
    .users-table thead th:nth-child(4),
    .users-table thead th:nth-child(5),
    .users-table tbody td:nth-child(4),
    .users-table tbody td:nth-child(5) {
        display: none;
    }
    .table-container {
        overflow-x: visible;
    }
    .users-table {
        min-width: 0;
        width: 100%;
        display: block;
    }
    .users-table tbody {
        display: block;
    }
    .users-table tbody tr {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        padding: 16px;
        margin-bottom: 8px;
        background: white;
        border-radius: 12px;
        border: 1px solid #eee;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    }
    .users-table tbody td {
        border: none;
        padding: 4px 0;
        font-size: 0.875rem;
    }
    .users-table tbody .profile-picture-cell {
        order: 1;
        width: 64px;
        flex-shrink: 0;
        padding: 0 12px 0 0 !important;
    }
    .users-table tbody .profile-picture-cell .profile-picture {
        width: 54px;
        height: 54px;
        border-radius: 50%;
        display: block;
        object-fit: cover;
    }
    .users-table tbody td:nth-child(3) {
        order: 2;
        flex: 1 1 auto;
        min-width: 0;
        font-weight: 700;
        font-size: 1rem;
    }
    .users-table tbody td:nth-child(2) {
        order: 3;
        width: 100%;
        padding-left: 76px;
        font-size: 0.8125rem;
        color: #666;
    }
    .users-table tbody td:nth-child(6) {
        order: 4;
        width: 100%;
        padding-top: 12px;
    }
    .users-table tbody td:nth-child(6) .btn-view {
        width: 100%;
        display: block;
        text-align: center;
        box-sizing: border-box;
        padding: 10px 16px;
    }
}

@media (max-width: 480px) {
    .main-content .stats-grid {
        grid-template-columns: 1fr;
    }
    .error-message {
        font-size: 0.9375rem;
        padding: 12px 16px;
    }
}

/* ========== View profile page ========== */
@media (max-width: 992px) {
    .container {
        margin: 20px auto;
        padding: 0 16px;
    }
    .profile-header {
        flex-direction: column;
        text-align: center;
        padding: 24px 20px;
        gap: 20px;
    }
    .profile-avatar {
        width: 180px;
        height: 180px;
    }
    .profile-info h1 {
        font-size: 1.5rem;
    }
    .profile-username {
        font-size: 1rem;
    }
    .profile-id {
        font-size: 0.8125rem;
    }
    .field-group {
        padding: 20px 16px;
        margin-bottom: 16px;
    }
    .field-group-title {
        font-size: 1rem;
        margin-bottom: 16px;
    }
    .fields-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .field-value {
        font-size: 0.9375rem;
    }
}

@media (max-width: 768px) {
    /* Hide horoscope section on mobile */
    .field-item[data-field-id="330"] {
        display: none !important;
    }
    .profile-header {
        padding: 20px 16px;
    }
    .whatsapp-share-btn {
        display: block;
        width: 100%;
        background: #25D366;
        color: white;
        border: none;
        padding: 14px 20px;
        font-size: 1rem;
        font-weight: 600;
        border-radius: 8px;
        margin: 16px 0;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(37, 211, 102, 0.3);
        transition: background 0.2s, transform 0.1s;
    }
    .whatsapp-share-btn:hover {
        background: #20BA5A;
        transform: translateY(-1px);
    }
    .whatsapp-share-btn:active {
        transform: translateY(0);
    }
    .whatsapp-share-btn:disabled {
        opacity: 0.6;
        cursor: not-allowed;
    }
    .profile-avatar {
        width: 140px;
        height: 140px;
    }
    .profile-info h1 {
        font-size: 1.25rem;
    }
    .field-group {
        padding: 16px 12px;
    }
    .field-group-icon {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    .alert,
    .alert-success,
    .alert-error {
        font-size: 0.9375rem;
        padding: 12px 16px;
    }
    .btn-danger {
        font-size: 0.8125rem;
        padding: 8px 12px;
    }
}

@media (max-width: 480px) {
    .container {
        margin: 12px auto;
        padding: 0 12px;
    }
    .profile-header {
        padding: 16px 12px;
    }
    .profile-avatar {
        width: 120px;
        height: 120px;
    }
    .profile-info h1 {
        font-size: 1.125rem;
    }
    .breadcrumb {
        font-size: 0.75rem;
    }
}
