﻿
/* ============================================
   20. CUSTOM SCROLLBAR
   ============================================ */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================
   21. MOBILE MENU & RESPONSIVE INFRASTRUCTURE
   ============================================ */

/* Hamburger button — hidden on desktop */
.hamburger-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 250;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: var(--surface-card);
    border: 1px solid var(--border-default);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast) var(--ease-spring);
    box-shadow: var(--shadow-md);
    -webkit-tap-highlight-color: transparent;
}

.hamburger-btn:hover {
    border-color: var(--brand);
    color: var(--brand);
    box-shadow: var(--shadow-md), 0 0 0 3px var(--brand-50);
}

.hamburger-btn:active {
    transform: scale(0.88);
    background: var(--brand-muted);
    border-color: var(--brand);
}

/* Sidebar close button — inside sidebar, mobile only */
.sidebar-close-btn {
    display: none;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast) var(--ease-spring);
    -webkit-tap-highlight-color: transparent;
}

.sidebar-close-btn:hover {
    background: var(--danger-muted);
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--danger);
}

.sidebar-close-btn:active {
    transform: scale(0.85) rotate(-90deg);
    background: var(--danger-muted);
    color: var(--danger);
}

/* Sidebar header row (brand + close) — mobile only */
.sidebar-header-mobile {
    display: contents;
}

/* Sidebar backdrop — mobile overlay */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 190;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration) var(--ease);
}

.sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

/* Main wrapper */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ---- Tablet: 769px–1024px ---- */
@media (max-width: 1200px) {
    .content {
        display: block !important;
    }

    .column {
        margin-right: 0;
        margin-bottom: 16px;
        max-height: 420px;
    }
}

@media (max-width: 1024px) {
    .stats {
        grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
        gap: 14px;
    }

    .content {
        padding: 20px 20px;
    }

    header {
        padding: 0 20px;
    }

    .modal-content {
        max-width: 90vw;
    }

    /* Table touch optimization */
    th, td {
        padding: 12px 14px;
    }

    .actions button {
        padding: 9px 14px;
        min-height: 40px;
    }

    .pagination button {
        min-height: 40px;
        padding: 9px 16px;
    }

    .filters select,
    .filters input[type="text"] {
        min-height: 40px;
    }

    /* Scroll-to-top — shift for iPad */
    .scroll-to-top {
        bottom: 24px;
        right: 24px;
    }
}

/* ---- Tablet & small desktop: ? 768px ---- */
@media (max-width: 768px) {
    /* Show hamburger */
    .hamburger-btn {
        display: flex;
    }

    /* Show backdrop */
    .sidebar-backdrop {
        display: block;
    }

    /* Sidebar becomes a drawer */
    .sidebar {
        width: var(--sidebar-w-open) !important;
        min-width: var(--sidebar-w-open) !important;
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 300;
        transform: translateX(-100%);
        transition: transform var(--duration-slow) var(--ease);
        box-shadow: none;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .sidebar:hover {
        width: var(--sidebar-w-open) !important;
        min-width: var(--sidebar-w-open) !important;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: var(--shadow-xl), 8px 0 32px rgba(0, 0, 0, 0.3);
    }

    /* Show all labels in mobile drawer */
    .sidebar .nav-item span,
    .sidebar-brand-text {
        display: inline !important;
        opacity: 1 !important;
        transform: none !important;
    }

    .sidebar:hover .nav-item span,
    .sidebar:hover .sidebar-brand-text {
        opacity: 1 !important;
        transform: none !important;
    }

    /* Sidebar header row with close button */
    .sidebar-header-mobile {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px 8px;
    }

    .sidebar-close-btn {
        display: flex;
    }

    /* Brand in mobile header */
    .sidebar-header-mobile .sidebar-brand {
        padding: 0;
    }

    /* Touch-friendly nav items */
    .sidebar .nav-item {
        padding: 14px 16px;
        font-size: 15px;
        min-height: 48px;
    }

    .sidebar .nav-item i {
        font-size: 18px;
        width: 24px;
    }

    .sidebar-footer {
        padding: 12px;
    }

    .sidebar .nav-item.logout {
        min-height: 48px;
        padding: 14px 16px;
    }

    /* Main content adjustments */
    .main-wrapper {
        margin-left: 0;
    }

    .main {
        margin-left: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    header {
        padding: 0 16px;
        padding-left: 60px;
    }

    header div {
        font-size: 15px;
    }

    .content {
        padding: 16px;
    }

    footer {
        padding: 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    /* Scroll-to-top — adjust for mobile safe area */
    .scroll-to-top {
        bottom: max(20px, env(safe-area-inset-bottom, 20px));
        right: 16px;
        width: 44px;
        height: 44px;
    }

    /* Stats grid */
    .stats {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .card {
        padding: 18px;
    }

    .card .number {
        font-size: 24px;
    }

    /* Tables — horizontal scroll */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    thead, tbody, tr {
        min-width: 600px;
    }

    table thead {
        display: table;
        width: 100%;
        table-layout: fixed;
    }

    table tbody {
        display: table;
        width: 100%;
        table-layout: fixed;
    }

    table tr {
        display: table-row;
    }

    th, td {
        padding: 12px 14px;
        font-size: 13px;
    }

    /* Modals */
    .modal-content {
        margin: 16px;
        max-width: calc(100vw - 32px);
        padding: 24px 20px;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* Filters */
    .filters {
        flex-direction: column;
        align-items: stretch;
    }

    .filters select,
    .filters input[type="text"] {
        width: 100%;
        min-height: 44px;
    }

    /* Growth section */
    .growth {
        padding: 20px;
    }

    .stat-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .stat-row > div:first-child {
        margin-right: 0;
    }

    .stat-value {
        text-align: left;
    }

    /* Columns (Dictionary multi-column) */
    .column {
        margin-right: 0;
        margin-bottom: 16px;
        min-height: 300px;
        max-height: 380px;
    }

    /* Pagination */
    .pagination {
        flex-wrap: wrap;
    }

    .pagination button {
        min-height: 44px;
        padding: 10px 16px;
    }
}

/* ---- Mobile: ? 480px ---- */
@media (max-width: 480px) {
    .hamburger-btn {
        top: 10px;
        left: 10px;
        width: 40px;
        height: 40px;
    }

    header {
        height: 56px;
        padding: 0 12px;
        padding-left: 56px;
    }

    header div {
        font-size: 14px;
        gap: 8px;
    }

    header div i {
        font-size: 16px;
    }

    .header-actions {
        gap: 8px;
    }

    .header-date {
        display: none;
    }

    .content {
        padding: 14px 12px;
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }
    .main > h3 {
        font-size: 17px;
    }

    footer {
        padding: 14px 12px;
        padding-bottom: max(14px, env(safe-area-inset-bottom));
        font-size: 11px;
    }

    /* Prevent iOS zoom on input focus */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px;
    }

    /* Stats — single column on very small screens */
    .stats {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .card {
        padding: 16px;
    }

    .card .icon {
        width: 38px;
        height: 38px;
        margin-bottom: 12px;
    }

    .card .icon i {
        font-size: 17px;
    }

    .card .number {
        font-size: 22px;
    }

    .card .label {
        font-size: 12px;
    }

    /* Table cells */
    th, td {
        padding: 10px 10px;
        font-size: 12px;
    }

    th {
        font-size: 11px;
    }

    /* Actions — stack vertically */
    .actions {
        flex-direction: column;
        gap: 4px;
    }

    .actions button {
        width: 100%;
        min-height: 40px;
        font-size: 12px;
        padding: 8px 10px;
    }

    /* Buttons */
    .add-main {
        width: 100%;
        justify-content: center;
        padding: 12px 16px;
        font-size: 14px;
        margin-right: 0;
    }

    /* Status toggles */
    .status-toggle {
        padding: 6px 12px;
        font-size: 11px;
    }

    /* Filters */
    .filters {
        padding: 12px;
        gap: 10px;
    }

    .filters select,
    .filters input[type="text"] {
        font-size: 14px;
        padding: 10px 12px;
    }

    /* Modals — full-width */
    .modal-content {
        margin: 8px;
        max-width: calc(100vw - 16px);
        padding: 20px 16px;
        border-radius: var(--radius-lg);
    }

    .modal-content h3,
    .modal-content h4 {
        font-size: 16px;
        margin-bottom: 18px;
        padding-bottom: 12px;
    }

    .modal-content label {
        font-size: 12px;
    }

    .modal-content input[type="text"],
    .modal-content input[type="password"],
    .modal-content input[type="file"],
    .modal-content select,
    .modal-content textarea {
        padding: 12px;
        font-size: 14px;
        min-height: 44px;
    }

    .modal-content button {
        padding: 12px 16px;
        font-size: 14px;
        min-height: 44px;
    }

    /* Pagination */
    .pagination {
        gap: 6px;
    }

    .pagination button {
        padding: 8px 12px;
        font-size: 12px;
        min-height: 40px;
    }

    .pagination span {
        padding: 8px 12px;
        font-size: 12px;
    }

    /* Audio player */
    audio {
        max-width: 100%;
    }

    /* Tree indent (Properties) */
    .tree-indent {
        padding-left: 16px;
        font-size: 13px;
    }

    /* Columns */
    .column {
        padding: 14px;
        min-height: 260px;
        max-height: 340px;
    }

    .column h3 {
        font-size: 14px;
    }

    .column input,
    .column select {
        font-size: 14px;
        padding: 10px;
        min-height: 44px;
    }

    .list > div {
        padding: 12px;
        font-size: 13px;
    }

    /* Growth section */
    .growth {
        padding: 16px;
    }

    .growth h2 {
        font-size: 15px;
    }

    /* Toast — full width on mobile */
    .Jirlee_contct-toast {
        left: 12px;
        right: 12px;
        bottom: max(16px, env(safe-area-inset-bottom));
        text-align: center;
        font-size: 13px;
    }

    /* Scroll-to-top — mobile safe area */
    .scroll-to-top {
        bottom: max(16px, env(safe-area-inset-bottom, 16px));
        right: 12px;
    }
}

/* ---- Very small screens: ? 360px ---- */
@media (max-width: 360px) {
    .hamburger-btn {
        width: 38px;
        height: 38px;
        font-size: 16px;
        top: 8px;
        left: 8px;
    }

    header {
        height: 52px;
        padding-left: 50px;
    }

    header div {
        font-size: 13px;
    }

    .content {
        padding: 12px 10px;
    }

    .card {
        padding: 14px;
    }

    .card .number {
        font-size: 20px;
    }

    th, td {
        padding: 8px;
        font-size: 11px;
    }
}

/* ============================================
   21b. RTL / LTR SUPPORT
   ============================================ */
[dir="rtl"] .sidebar,
html[dir="rtl"] .sidebar {
    left: auto;
    right: 0;
    border-right: none;
    border-left: 1px solid var(--border-subtle);
}

[dir="rtl"] .main,
html[dir="rtl"] .main {
    margin-left: 0;
    margin-right: var(--sidebar-w);
}

[dir="rtl"] .sidebar .nav-item::before,
html[dir="rtl"] .sidebar .nav-item::before {
    left: auto;
    right: 0;
    border-radius: 4px 0 0 4px;
}

[dir="rtl"] .hamburger-btn,
html[dir="rtl"] .hamburger-btn {
    left: auto;
    right: 12px;
}

[dir="rtl"] header,
html[dir="rtl"] header {
    padding-left: 16px;
    padding-right: 32px;
}

@media (max-width: 768px) {
    [dir="rtl"] .sidebar,
    html[dir="rtl"] .sidebar {
        transform: translateX(100%);
        left: auto;
        right: 0;
    }

    [dir="rtl"] .sidebar.mobile-open,
    html[dir="rtl"] .sidebar.mobile-open {
        transform: translateX(0);
    }

    [dir="rtl"] .main,
    html[dir="rtl"] .main {
        margin-right: 0;
    }

    [dir="rtl"] header,
    html[dir="rtl"] header {
        padding-left: 16px;
        padding-right: 60px;
    }
}

@media (max-width: 480px) {
    [dir="rtl"] .hamburger-btn,
    html[dir="rtl"] .hamburger-btn {
        right: 10px;
    }

    [dir="rtl"] header,
    html[dir="rtl"] header {
        padding-right: 56px;
        padding-left: 12px;
    }
}

/* ============================================
   21c. TOUCH & ACCESSIBILITY
   ============================================ */
@media (pointer: coarse) {
    .sidebar .nav-item {
        min-height: 48px;
    }

    .actions button {
        min-height: 44px;
        min-width: 44px;
    }

    .pagination button {
        min-height: 44px;
        min-width: 44px;
    }

    .status-toggle {
        min-height: 36px;
        padding: 8px 16px;
    }

    .toggle-btn {
        width: 36px;
        height: 36px;
    }

    .filters select,
    .filters input[type="text"] {
        min-height: 44px;
    }

    .column input,
    .column select {
        min-height: 44px;
    }

    .list > div {
        min-height: 48px;
    }

    .add-main {
        min-height: 44px;
    }
}

/* Focus-visible for keyboard navigation */
a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

/* Skip-to-content (screen reader) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================
   21d. LANDSCAPE PHONE OPTIMIZATION
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        height: 48px;
    }

    .content {
        padding: 12px 16px;
    }

    .sidebar .nav-item {
        padding: 8px 14px;
        min-height: 40px;
    }

    .card {
        padding: 14px;
    }

    .card .number {
        font-size: 20px;
    }

    .modal-content {
        max-height: 85vh;
    }
}
