/* ═══════════════════════════════════════════════════════════
   AVTARIUM - Responsive Utilities v1.0
   Автор: Claude Code
   Дата: 2026-01-15

   Breakpoints:
   - xs: 0-479px (мобильные телефоны, портрет)
   - sm: 480-767px (мобильные телефоны, ландшафт)
   - md: 768-1023px (планшеты)
   - lg: 1024-1199px (маленькие ноутбуки)
   - xl: 1200px+ (десктопы)
   ═══════════════════════════════════════════════════════════ */

/* ══════ TABLE RESPONSIVE ══════ */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: var(--space-4);
}

.table-responsive table {
    min-width: 600px;
}

.table-responsive::-webkit-scrollbar {
    height: 6px;
}

.table-responsive::-webkit-scrollbar-track {
    background: var(--bg-main);
    border-radius: 3px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}

/* ══════ RESPONSIVE VISIBILITY UTILITIES ══════ */

/* Hide on mobile (xs, sm) */
.hide-mobile {
    display: block;
}

/* Hide on desktop (lg, xl) */
.hide-desktop {
    display: none;
}

/* Show only on mobile */
.show-mobile-only {
    display: none;
}

/* Show only on desktop */
.show-desktop-only {
    display: block;
}

@media (max-width: 767px) {
    .hide-mobile {
        display: none !important;
    }

    .show-mobile-only {
        display: block !important;
    }

    .hide-desktop {
        display: block;
    }

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

/* ══════ RESPONSIVE GRID UTILITIES ══════ */

/* Stack on mobile */
.stack-mobile {
    display: flex;
    flex-direction: row;
    gap: var(--space-4);
}

@media (max-width: 767px) {
    .stack-mobile {
        flex-direction: column;
    }
}

/* Responsive 2-column to 1-column */
.resp-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}

@media (max-width: 767px) {
    .resp-grid-2 {
        grid-template-columns: 1fr;
    }
}

/* Responsive 3-column to 1-column */
.resp-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-4);
}

@media (max-width: 1023px) {
    .resp-grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 767px) {
    .resp-grid-3 {
        grid-template-columns: 1fr;
    }
}

/* Responsive 4-column */
.resp-grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
}

@media (max-width: 1199px) {
    .resp-grid-4 {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 1023px) {
    .resp-grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 767px) {
    .resp-grid-4 {
        grid-template-columns: 1fr;
    }
}

/* ══════ RESPONSIVE FLEX UTILITIES ══════ */

/* Flex row that wraps on mobile */
.flex-row-wrap {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--space-3);
}

/* Flex that becomes column on mobile */
.flex-to-column {
    display: flex;
    flex-direction: row;
    gap: var(--space-4);
}

@media (max-width: 767px) {
    .flex-to-column {
        flex-direction: column;
    }
}

/* ══════ RESPONSIVE BUTTONS ══════ */

@media (max-width: 479px) {
    /* Full-width buttons on mobile */
    .btn-mobile-full {
        width: 100%;
    }

    /* Smaller buttons on very small screens */
    .btn {
        padding: 0.5rem 0.875rem;
        font-size: var(--text-xs);
    }

    .btn-lg {
        padding: 0.75rem 1.25rem;
        font-size: var(--text-sm);
    }

    /* Button row becomes vertical */
    .btn-row {
        flex-direction: column;
    }

    .btn-row .btn {
        width: 100%;
    }
}

/* ══════ RESPONSIVE FORMS ══════ */

/* Form row that stacks on mobile */
.form-row-responsive {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}

@media (max-width: 767px) {
    .form-row-responsive {
        grid-template-columns: 1fr;
    }
}

/* Form inline to vertical on mobile */
.form-inline-responsive {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: var(--space-3);
}

@media (max-width: 767px) {
    .form-inline-responsive {
        flex-direction: column;
        align-items: stretch;
    }

    .form-inline-responsive .form-group {
        width: 100%;
    }

    .form-inline-responsive .btn {
        width: 100%;
    }
}

/* Full-width inputs on mobile */
@media (max-width: 479px) {
    .form-input,
    .form-select,
    .form-control,
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    select,
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* ══════ RESPONSIVE CARDS ══════ */

@media (max-width: 767px) {
    .card {
        padding: var(--space-4);
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .card-title {
        font-size: var(--text-base);
    }

    .shop-card {
        padding: var(--space-4);
    }

    .shop-card-header {
        flex-direction: column;
        gap: var(--space-2);
    }

    .shop-name {
        font-size: var(--text-lg);
    }

    .shop-actions {
        width: 100%;
    }

    .shop-actions .btn {
        flex: 1;
    }
}

/* ══════ RESPONSIVE STATS/KPI CARDS ══════ */

@media (max-width: 767px) {
    .kpi-card {
        padding: var(--space-4);
    }

    .kpi-card .metric-value {
        font-size: var(--text-2xl);
    }

    .metric-card {
        padding: var(--space-4);
    }

    .metric-value {
        font-size: var(--text-xl);
    }

    .stat-card {
        padding: var(--space-3);
    }

    .stat-value {
        font-size: var(--text-xl);
    }
}

/* ══════ RESPONSIVE CHARTS ══════ */

.chart-container-responsive {
    position: relative;
    width: 100%;
}

.chart-container-responsive canvas {
    max-width: 100%;
}

@media (max-width: 767px) {
    .chart-container-responsive {
        min-height: 250px;
        max-height: 350px;
    }
}

@media (min-width: 768px) {
    .chart-container-responsive {
        min-height: 350px;
        max-height: 450px;
    }
}

/* ══════ RESPONSIVE HEADER/TITLES ══════ */

@media (max-width: 767px) {
    h1 {
        font-size: var(--text-2xl);
    }

    h2 {
        font-size: var(--text-xl);
    }

    h3 {
        font-size: var(--text-lg);
    }

    h4 {
        font-size: var(--text-base);
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .page-header-actions {
        width: 100%;
    }
}

/* ══════ RESPONSIVE SPACING ══════ */

@media (max-width: 767px) {
    .p-5 {
        padding: var(--space-3);
    }

    .p-6 {
        padding: var(--space-4);
    }

    .mt-5 {
        margin-top: var(--space-4);
    }

    .mb-5 {
        margin-bottom: var(--space-4);
    }

    .gap-5 {
        gap: var(--space-3);
    }
}

/* ══════ RESPONSIVE TEXT ══════ */

@media (max-width: 479px) {
    .text-truncate-mobile {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 150px;
    }

    /* Smaller text on very small screens */
    .text-sm-mobile {
        font-size: var(--text-xs);
    }
}

/* ══════ RESPONSIVE MODALS ══════ */

@media (max-width: 767px) {
    .modal {
        width: 95%;
        max-width: none;
        margin: var(--space-3);
    }

    .modal-content {
        padding: var(--space-4);
    }
}

/* ══════ RESPONSIVE ALERTS ══════ */

@media (max-width: 767px) {
    .alert {
        padding: var(--space-3);
        font-size: var(--text-sm);
    }
}

/* ══════ RESPONSIVE FILTERS ══════ */

@media (max-width: 767px) {
    .filters-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: var(--space-2);
    }

    .filter-tab {
        flex-shrink: 0;
        white-space: nowrap;
    }
}

/* ══════ RESPONSIVE NAVIGATION ══════ */

@media (max-width: 767px) {
    .nav-row {
        padding: 0 var(--space-3);
    }

    .nav-brand .wordmark {
        font-size: var(--text-lg);
    }
}

/* ══════ PRINT STYLES ══════ */

@media print {
    .hide-print {
        display: none !important;
    }

    .sidebar,
    .nav-burger,
    .sidebar-toggle,
    .topnav {
        display: none !important;
    }

    .container {
        max-width: 100%;
        padding: 0;
    }

    .card {
        break-inside: avoid;
        border: 1px solid #ddd;
        box-shadow: none;
    }

    body {
        background: white;
        color: black;
    }
}

/* ══════ TOUCH-FRIENDLY UTILITIES ══════ */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets on touch devices */
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    .nav-link {
        min-height: 44px;
    }

    .sidebar-link {
        min-height: 44px;
    }

    /* Remove hover effects on touch devices */
    .card:hover,
    .shop-card:hover,
    .module-card:hover,
    .btn:hover {
        transform: none;
    }
}

/* ══════ LANDSCAPE ORIENTATION FIXES ══════ */

@media (max-height: 500px) and (orientation: landscape) {
    .orgadmin-sidebar {
        padding-top: var(--space-3);
    }

    .sidebar-link {
        padding: 0.4rem var(--space-3);
    }

    .sidebar-section {
        margin-top: var(--space-3);
        padding-top: var(--space-3);
    }
}

/* ══════ SAFE AREA INSETS (для iPhone X+) ══════ */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .sidebar-toggle {
        bottom: calc(20px + env(safe-area-inset-bottom));
    }

    .orgadmin-main {
        padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
    }
}

/* ══════ REDUCED MOTION ══════ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ══════ HIGH CONTRAST MODE ══════ */

@media (prefers-contrast: high) {
    :root {
        --border: #555;
        --text-muted: #777;
    }

    .btn-primary {
        border: 2px solid var(--mint);
    }

    .card {
        border-width: 2px;
    }
}
