/* ==============================================
   UNFOLD CUSTOM STYLES - Автобус Валера
   ============================================== */

/* === Улучшенная типографика === */
body {
    font-feature-settings: "kern" 1, "liga" 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* === Sidebar улучшения === */
.sidebar {
    backdrop-filter: blur(10px);
}

/* Активный элемент меню */
nav a[aria-current="page"],
nav a.active {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15) 0%, rgba(99, 102, 241, 0.08) 100%) !important;
    border-left: 3px solid rgb(99, 102, 241) !important;
}

/* Hover эффект для меню — только при наличии мыши */
@media (hover: hover) {
    nav a:hover {
        background: rgba(99, 102, 241, 0.08) !important;
        transform: translateX(2px);
        transition: all 0.2s ease;
    }
}

/* === Карточки и контейнеры === */
.card,
.bg-white,
.module {
    border-radius: 12px !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06) !important;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

@media (hover: hover) {
    .card:hover,
    .module:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06) !important;
    }
}

/* === Таблицы === */
table {
    border-collapse: separate;
    border-spacing: 0;
}

table thead th {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%) !important;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    color: #64748b !important;
    border-bottom: 2px solid #e2e8f0 !important;
}

table tbody tr {
    transition: background-color 0.15s ease;
}

@media (hover: hover) {
    table tbody tr:hover {
        background-color: rgba(99, 102, 241, 0.04) !important;
    }
}

table tbody tr:nth-child(even) {
    background-color: rgba(248, 250, 252, 0.5);
}

.dark table tbody tr:nth-child(even) {
    background-color: rgba(30, 41, 59, 0.5);
}

/* === Кнопки === */
button,
.btn,
[type="submit"],
a.button {
    border-radius: 8px !important;
    font-weight: 500;
    transition: all 0.2s ease !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

@media (hover: hover) {
    button:hover,
    .btn:hover,
    [type="submit"]:hover,
    a.button:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }
}

button:active,
.btn:active,
[type="submit"]:active,
a.button:active {
    transform: translateY(0);
}

/* Primary кнопки */
.btn-primary,
button[type="submit"].default,
input[type="submit"].default {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%) !important;
    border: none !important;
    color: white !important;
}

@media (hover: hover) {
    .btn-primary:hover,
    button[type="submit"].default:hover,
    input[type="submit"].default:hover {
        background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%) !important;
    }
}

/* === Формы === */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="tel"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
textarea,
select {
    border-radius: 8px !important;
    border: 1px solid #e2e8f0 !important;
    padding: 10px 14px !important;
    transition: all 0.2s ease !important;
    background-color: #ffffff !important;
}

input:focus,
textarea:focus,
select:focus {
    border-color: #6366f1 !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15) !important;
    outline: 2px solid transparent !important; /* Visible via box-shadow; transparent outline for Windows High Contrast */
    outline-offset: 2px !important;
}

/* === Badges === */
.badge,
[class*="badge"] {
    border-radius: 9999px;
    font-weight: 500;
    font-size: 0.75rem;
    padding: 2px 8px;
}

/* Status badges — scoped to results table and explicit status classes */
.status-pending,
.results span[class*="pending"],
.booking-status.pending {
    background-color: #fef3c7 !important;
    color: #92400e !important;
}

.status-confirmed,
.results span[class*="confirmed"],
.results span[class*="success"],
.booking-status.confirmed {
    background-color: #d1fae5 !important;
    color: #065f46 !important;
}

.status-cancelled,
.results span[class*="cancelled"],
.results span[class*="danger"],
.booking-status.cancelled {
    background-color: #fee2e2 !important;
    color: #991b1b !important;
}

/* === Алерты и уведомления === */
.messagelist li,
.alert {
    border-radius: 10px !important;
    padding: 12px 16px !important;
    margin-bottom: 12px !important;
    border-left: 4px solid;
}

.messagelist .success,
.alert-success {
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%) !important;
    border-left-color: #10b981 !important;
    color: #065f46 !important;
}

.messagelist .warning,
.alert-warning {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%) !important;
    border-left-color: #f59e0b !important;
    color: #92400e !important;
}

.messagelist .error,
.alert-error,
.alert-danger {
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%) !important;
    border-left-color: #ef4444 !important;
    color: #991b1b !important;
}

.messagelist .info,
.alert-info {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%) !important;
    border-left-color: #3b82f6 !important;
    color: #1e40af !important;
}

/* === Breadcrumbs === */
.breadcrumbs {
    background: transparent !important;
    padding: 0 !important;
    margin-bottom: 1rem;
}

.breadcrumbs a {
    color: #6366f1 !important;
    text-decoration: none;
    transition: color 0.15s ease;
}

@media (hover: hover) {
    .breadcrumbs a:hover {
        color: #4f46e5 !important;
        text-decoration: underline;
    }
}

/* Unfold header breadcrumbs truncation */
header h1,
header h1 a,
[class*="breadcrumb"] a,
.truncate a {
    max-width: 350px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: middle;
}

@media (max-width: 1024px) {
    header h1,
    header h1 a,
    [class*="breadcrumb"] a,
    .truncate a {
        max-width: 250px;
    }
}

@media (max-width: 768px) {
    header h1,
    header h1 a,
    [class*="breadcrumb"] a,
    .truncate a {
        max-width: 150px;
    }
}

/* === Pagination === */
.paginator {
    display: flex;
    gap: 4px;
    align-items: center;
}

.paginator a,
.paginator span {
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    transition: all 0.15s ease;
}

@media (hover: hover) {
    .paginator a:hover {
        background: #6366f1;
        color: white;
        border-color: #6366f1;
    }
}

.paginator .this-page {
    background: #6366f1;
    color: white;
    border-color: #6366f1;
    font-weight: 600;
}

/* === Fieldsets === */
fieldset {
    border: 1px solid #e2e8f0 !important;
    border-radius: 12px !important;
    padding: 20px !important;
    margin-bottom: 20px !important;
    background: #ffffff;
}

fieldset legend,
fieldset h2 {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%) !important;
    color: white !important;
    padding: 8px 16px !important;
    border-radius: 8px !important;
    font-weight: 600 !important;
    font-size: 0.875rem !important;
    letter-spacing: 0.025em;
}

/* === Collapsible sections === */
.collapse-toggle {
    cursor: pointer;
    user-select: none;
}

@media (hover: hover) {
    .collapse-toggle:hover {
        opacity: 0.8;
    }
}

/* === Loading states === */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.loading::after {
    content: '';
    animation: pulse 1.5s infinite;
}

/* === Tooltips === */
/* Removed overly broad [title] { position: relative } — it affected
   every element with a title attribute across the entire admin. */

/* === Scrollbar styling === */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* === Dark mode: scrollbar === */
.dark ::-webkit-scrollbar-track {
    background: #1e293b;
}

.dark ::-webkit-scrollbar-thumb {
    background: #475569;
}

.dark ::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* === Dark mode adjustments === */
.dark table thead th {
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%) !important;
    color: #94a3b8 !important;
    border-bottom-color: #334155 !important;
}

@media (hover: hover) {
    .dark table tbody tr:hover {
        background-color: rgba(99, 102, 241, 0.08) !important;
    }
}

.dark input,
.dark textarea,
.dark select {
    background-color: #1e293b !important;
    border-color: #334155 !important;
    color: #e2e8f0 !important;
}

.dark input:focus,
.dark textarea:focus,
.dark select:focus {
    border-color: #6366f1 !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25) !important;
}

.dark fieldset {
    background: #1e293b;
    border-color: #334155 !important;
}

/* === Dark mode: pagination === */
.dark .paginator a,
.dark .paginator span {
    border-color: #374151;
    color: #d1d5db;
}

.dark .paginator .this-page {
    background: #6366f1;
    color: white;
    border-color: #6366f1;
}

/* ===== MOBILE SIDEBAR FIX ===== */
/* Problem: Safari iOS does not collapse the sidebar's outer flex wrapper
 * when its children are display:none. The 288px inner element still
 * influences the flex item's intrinsic size, pushing #main to the right.
 *
 * Solution: use display:none on the wrapper (Safari definitely respects this)
 * + :has(#nav-sidebar) selector to reliably find the wrapper regardless of
 * what CSS classes unfold uses in different versions.
 */
@media (max-width: 1279px) {
    /* 1a. Hide sidebar wrapper — by class (local dev DOM) */
    .flex.min-h-screen > .relative:not(.grow) {
        display: none !important;
    }

    /* 1b. Hide sidebar wrapper — by :has() (production-safe, any unfold version) */
    .flex.min-h-screen > *:has(#nav-sidebar) {
        display: none !important;
    }

    /* 2. Also hide the sidebar element itself */
    #nav-sidebar {
        display: none !important;
    }

    /* 3. Main content: full width always */
    #main,
    .flex.min-h-screen > .grow {
        margin-left: 0 !important;
        padding-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        flex: 1 1 100% !important;
    }

    /* 4. Sidebar backdrop */
    .admin-sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .admin-sidebar-backdrop.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
}

/* ===== FIX CARD CLIPPING ON NARROW SCREENS ===== */
@media (max-width: 768px) {
    .card, [class*="rounded-lg"], [class*="shadow"] {
        word-break: break-word;
        overflow-wrap: anywhere;
        max-width: 100vw;
        box-sizing: border-box;
    }

    td, th {
        max-width: 60vw;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .min-w-full {
        min-width: 0 !important;
    }

    .responsive-card, [data-label] {
        padding: 12px 16px;
    }

}

/* === Responsive adjustments === */
@media (max-width: 768px) {
    .card,
    .module {
        border-radius: 8px !important;
    }

    table {
        font-size: 0.875rem;
    }

    fieldset {
        padding: 12px !important;
    }
}

/* ===== MOBILE FORM IMPROVEMENTS ===== */
@media (max-width: 768px) {
    /* Single column layout */
    .flex-col, .grid, fieldset .grid {
        grid-template-columns: 1fr !important;
    }

    .lg\:grid-cols-2, .md\:grid-cols-2, .sm\:grid-cols-2 {
        grid-template-columns: 1fr !important;
    }

    /* Prevent form content overflow — clip wide related-widget-wrappers */
    #main, #page {
        overflow-x: hidden !important;
    }

    /* Fieldsets as accordions */
    fieldset.admin-accordion {
        border-radius: 12px;
        overflow: hidden;
        margin-bottom: 12px;
    }

    fieldset.admin-accordion > h2,
    fieldset.admin-accordion > legend,
    fieldset.admin-accordion .module > h2 {
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 14px 16px;
        margin: 0;
        background: var(--color-bg-secondary, #f9fafb);
        font-size: 0.9375rem;
        min-height: 48px;
        user-select: none;
        -webkit-user-select: none;
    }

    fieldset.admin-accordion > h2::after,
    fieldset.admin-accordion > legend::after,
    fieldset.admin-accordion .module > h2::after {
        content: '\25BC';
        font-size: 0.75rem;
        transition: transform 0.2s ease;
        color: var(--color-text-secondary, #9ca3af);
    }

    fieldset.admin-accordion.collapsed > h2::after,
    fieldset.admin-accordion.collapsed > legend::after,
    fieldset.admin-accordion.collapsed .module > h2::after {
        transform: rotate(-90deg);
    }

    fieldset.admin-accordion.collapsed > *:not(h2):not(legend),
    fieldset.admin-accordion.collapsed .module > *:not(h2) {
        display: none;
    }

    /* Filled indicator */
    fieldset.admin-accordion.has-filled > h2::before,
    fieldset.admin-accordion.has-filled > legend::before {
        content: '\2713';
        color: #22c55e;
        font-weight: 700;
        margin-right: 8px;
    }

    /* Sticky save buttons — django-unfold uses flex container, not .submit-row */
    .submit-row,
    form > .flex.flex-col-reverse,
    form + .flex.flex-col-reverse,
    [class*="flex"][class*="flex-col-reverse"][class*="container"] {
        position: fixed !important;
        bottom: 56px; /* Above bottom nav */
        left: 0;
        right: 0;
        z-index: 900;
        background: var(--color-bg-primary, #fff);
        border-top: 1px solid var(--color-border-primary, #e5e7eb);
        padding: 8px 16px !important;
        display: flex !important;
        flex-direction: row !important;
        gap: 8px;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
        margin: 0 !important;
    }

    .submit-row input[type="submit"],
    .submit-row button,
    .flex.flex-col-reverse button[type="submit"],
    [class*="flex-col-reverse"] button[name="_save"],
    [class*="flex-col-reverse"] button[name="_continue"],
    [class*="flex-col-reverse"] button[name="_addanother"] {
        flex: 1;
        min-height: 48px;
        font-size: 0.875rem;
        border-radius: 10px;
    }

    /* Reserve space for sticky footer */
    form {
        padding-bottom: 80px;
    }

    /* Inline forms: card style */
    .inline-group .inline-related {
        border: 1px solid var(--color-border-primary, #e5e7eb);
        border-radius: 12px;
        padding: 12px;
        margin-bottom: 12px;
    }

    .inline-group .add-row a {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 48px;
        background: var(--color-bg-secondary, #f3f4f6);
        border-radius: 10px;
        font-weight: 600;
    }

    /* Native date/time pickers */
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"] {
        -webkit-appearance: none;
        appearance: none;
        min-height: 44px;
        font-size: 1rem;
    }
}

/* === Print styles === */
@media print {
    .sidebar,
    nav,
    .no-print {
        display: none !important;
    }
    
    .card,
    .module {
        box-shadow: none !important;
        border: 1px solid #e2e8f0 !important;
    }
}

/* ==============================================
   MOBILE-FIRST RESPONSIVE DESIGN
   ============================================== */

/* Улучшенные touch targets для всех кликабельных элементов */
@media (max-width: 768px) {
    /* Минимум 44px для touch targets (Apple HIG) */
    button, 
    .btn,
    a.button,
    [type="submit"],
    input[type="checkbox"],
    input[type="radio"],
    select {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Увеличиваем область ссылок */
    table a,
    .results a {
        display: inline-block;
        padding: 8px 4px;
        margin: -8px -4px;
    }
    
    /* Filter panel as bottom sheet */
    #changelist-filter {
        position: fixed !important;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto !important;
        max-height: 70vh;
        background: var(--color-bg-primary, #fff);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        z-index: 1001;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
        padding: 16px 20px 80px;
    }

    #changelist-filter.mobile-visible {
        transform: translateY(0);
    }

    /* Filter trigger button */
    .admin-filter-btn {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 10px 16px;
        background: var(--color-bg-secondary, #f3f4f6);
        border: 1px solid var(--color-border-primary, #e5e7eb);
        border-radius: 8px;
        font-size: 0.875rem;
        color: var(--color-text-primary, #1f2937);
        margin: 8px 0;
        min-height: 44px;
        cursor: pointer;
    }

    /* Close button inside filter sheet */
    .admin-filter-close {
        position: sticky;
        top: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        margin-left: auto;
        background: none;
        border: none;
        cursor: pointer;
        border-radius: 50%;
        z-index: 1;
    }

    .admin-filter-close:active {
        background: var(--color-bg-secondary, #f3f4f6);
    }

    /* Apply button at bottom of filter sheet */
    .admin-filter-apply {
        position: sticky;
        bottom: 0;
        display: block;
        width: 100%;
        padding: 14px 16px;
        background: var(--color-primary-500, #6366f1);
        color: white;
        border: none;
        font-size: 1rem;
        font-weight: 600;
        min-height: 48px;
        cursor: pointer;
        border-radius: 10px;
        margin-top: 16px;
    }

    /* Filter backdrop */
    .admin-filter-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .admin-filter-backdrop.active {
        opacity: 1;
        visibility: visible;
    }
    
    /* Floating Action Button */
    .mobile-fab {
        position: fixed;
        bottom: 80px;
        right: 16px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: var(--color-primary-500, #6366f1);
        color: white;
        border: none;
        box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
        z-index: 900;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        text-decoration: none;
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    .mobile-fab:active {
        transform: scale(0.95);
    }
    
    /* Улучшенная пагинация на мобильных */
    .paginator {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }
    
    .paginator a,
    .paginator span {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 12px;
    }
}

/* ==============================================
   CSS-ONLY RESPONSIVE TABLES → CARDS
   ============================================== */

@media (max-width: 640px) {
    /* Скрываем заголовки таблицы */
    .results table thead {
        display: none;
    }
    
    /* Контейнер карточек */
    .results table tbody {
        display: flex;
        flex-direction: column;
        gap: 12px;
        padding: 8px;
    }
    
    /* Каждая строка становится карточкой */
    .results table tbody tr {
        display: block;
        position: relative;
        background: var(--color-bg-primary, white);
        border: 1px solid var(--color-border-primary, #e5e7eb);
        border-radius: 16px;
        padding: 16px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
        transition: all 0.2s ease;
    }
    
    /* Статус-индикатор слева */
    .results table tbody tr::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 4px;
        border-radius: 16px 0 0 16px;
        background: #94a3b8; /* Серый по умолчанию */
    }
    
    /* Цвета статусов */
    .results table tbody tr:has(.status-pending)::before,
    .results table tbody tr:has([class*="pending"])::before {
        background: #f59e0b; /* Жёлтый */
    }
    
    .results table tbody tr:has(.status-confirmed)::before,
    .results table tbody tr:has([class*="confirmed"])::before,
    .results table tbody tr:has([class*="success"])::before {
        background: #10b981; /* Зелёный */
    }
    
    .results table tbody tr:has(.status-cancelled)::before,
    .results table tbody tr:has([class*="cancelled"])::before {
        background: #ef4444; /* Красный */
    }
    
    .results table tbody tr:has(.status-completed)::before,
    .results table tbody tr:has([class*="completed"])::before {
        background: #6366f1; /* Индиго */
    }

    /* Статусы через data-status атрибут (устанавливается JS) */
    .results table tbody tr[data-status="active"]::before,
    .results table tbody tr[data-status="confirmed"]::before {
        background: #10b981; /* Зелёный */
    }
    .results table tbody tr[data-status="pending"]::before,
    .results table tbody tr[data-status="pending_moderation"]::before {
        background: #f59e0b; /* Жёлтый */
    }
    .results table tbody tr[data-status="rejected"]::before,
    .results table tbody tr[data-status="cancelled"]::before {
        background: #ef4444; /* Красный */
    }
    .results table tbody tr[data-status="draft"]::before {
        background: #94a3b8; /* Серый */
    }
    .results table tbody tr[data-status="needs_changes"]::before {
        background: #f97316; /* Оранжевый */
    }

    /* Active state для касания */
    .results table tbody tr:active {
        transform: scale(0.98);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    }
    
    /* Ячейки становятся блочными */
    .results table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 0;
        border-bottom: 1px solid var(--color-border-primary, #f3f4f6);
        gap: 12px;
    }
    
    .results table tbody td:last-child {
        border-bottom: none;
        padding-top: 16px;
        margin-top: 8px;
        justify-content: stretch;
        gap: 8px;
    }
    
    /* Label из data-label атрибута */
    .results table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--color-text-secondary, #6b7280);
        font-size: 0.6875rem;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        flex-shrink: 0;
    }
    
    /* Значение */
    .results table tbody td > * {
        text-align: right;
    }
    
    /* Чекбокс - в углу карточки */
    .results table tbody td:first-child {
        position: absolute;
        top: 12px;
        right: 12px;
        padding: 0;
        border: none;
    }
    
    .results table tbody td:first-child::before {
        display: none;
    }
    
    .results table tbody td:first-child input[type="checkbox"] {
        width: 24px;
        height: 24px;
        cursor: pointer;
    }
    
    /* ID/номер - заголовок карточки */
    .results table tbody td:nth-child(2) {
        font-size: 1.125rem;
        font-weight: 700;
        color: var(--color-text-primary, #111827);
        padding-bottom: 12px;
        margin-bottom: 4px;
        padding-right: 40px; /* Место для чекбокса */
    }
    
    .results table tbody td:nth-child(2)::before {
        font-weight: 500;
        color: var(--color-text-secondary, #6b7280);
        font-size: 0.75rem;
    }
    
    /* Кнопки действий - на всю ширину */
    .results table tbody td:last-child {
        display: flex;
        flex-wrap: wrap;
    }
    
    .results table tbody td .btn-quick,
    .results table tbody td button,
    .results table tbody td a.button {
        flex: 1;
        min-width: calc(50% - 4px);
        text-align: center;
        padding: 12px 16px;
        min-height: 48px;
        border-radius: 10px;
        font-weight: 600;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
    }
    
    /* WhatsApp кнопка */
    .results table tbody td .btn-quick.whatsapp,
    .results table tbody td a[href*="wa.me"] {
        background: #25d366;
        color: white;
    }
    
    /* Кнопка подтверждения */
    .results table tbody td .btn-quick.confirm {
        background: #10b981;
        color: white;
    }
    
    /* Кнопка отмены */
    .results table tbody td .btn-quick.cancel {
        background: #fee2e2;
        color: #991b1b;
    }
    
    /* Бейджи статусов - более заметные */
    .results table tbody td span[class*="badge"],
    .results table tbody td .inline-flex {
        font-size: 0.8125rem;
        padding: 6px 12px;
        border-radius: 20px;
        font-weight: 600;
    }
}

/* Очень маленькие экраны - вертикальная компоновка */
@media (max-width: 400px) {
    .results table tbody td {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    
    .results table tbody td::before {
        margin-bottom: 2px;
    }
    
    .results table tbody td > * {
        text-align: left;
        width: 100%;
    }
    
    .results table tbody td:last-child {
        flex-direction: column;
    }
    
    .results table tbody td .btn-quick,
    .results table tbody td button,
    .results table tbody td a.button {
        width: 100%;
        min-width: 100%;
    }
}

/* Dark mode для карточек */
.dark .results table tbody tr {
    background: var(--color-bg-primary, #1f2937);
    border-color: var(--color-border-primary, #374151);
}

.dark .results table tbody td {
    border-bottom-color: var(--color-border-primary, #374151);
}

.dark .results table tbody td .btn-quick.cancel {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

/* ==============================================
   HTMX ENHANCEMENTS
   ============================================== */

/* Индикатор HTMX загрузки */
.htmx-request {
    opacity: 0.6;
    pointer-events: none;
}

.htmx-request::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid rgba(99, 102, 241, 0.3);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: htmx-spin 0.8s linear infinite;
}

@keyframes htmx-spin {
    to { transform: rotate(360deg); }
}

/* Подсветка добавленных элементов */
.htmx-added {
    animation: htmx-flash 1s ease-out;
}

@keyframes htmx-flash {
    0% { background-color: rgba(99, 102, 241, 0.2); }
    100% { background-color: transparent; }
}

/* Кнопки HTMX */
[hx-post], [hx-get], [hx-put], [hx-delete] {
    cursor: pointer;
    transition: all 0.2s ease;
}

@media (hover: hover) {
    [hx-post]:hover, [hx-get]:hover {
        transform: translateY(-1px);
    }
}

/* Ошибка HTMX */
.htmx-error {
    background: #fee2e2;
    color: #991b1b;
    padding: 12px 16px;
    border-radius: 8px;
    border-left: 4px solid #ef4444;
    margin: 8px 0;
}

.dark .htmx-error {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border-left-color: #f87171;
}

/* ==============================================
   TOUCH OPTIMIZATION
   ============================================== */

/* Touch feedback for mobile — only on touch-only devices */
@media (hover: none) {
    .card:active,
    .btn:active,
    .results a:active,
    .action-btn:active,
    .admin-bottom-nav a:active,
    .paginator a:active,
    nav a:active,
    button:active {
        opacity: 0.7;
        transition: opacity 0.1s ease;
    }

    /* Disable hover transforms on touch devices */
    .card:hover,
    .btn:hover,
    button[type="submit"]:hover {
        transform: none !important;
    }
}

/* Ensure all clickable elements have adequate touch targets */
@media (max-width: 768px) {
    .results a, .action-btn, nav a, .admin-bottom-nav a,
    button, [role="button"], input[type="submit"],
    input[type="checkbox"] + label, .selector-label,
    select, .paginator a, .paginator span {
        min-height: 44px;
        min-width: 44px;
    }

    /* Larger checkboxes on mobile */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px;
        height: 24px;
    }
}

/* ===== MOBILE INLINE FORMS ===== */
@media (max-width: 767px) {
    /* Hide table headers — labels come from data-label */
    .inline-group table thead {
        display: none !important;
    }

    /* Each inline table row becomes a card */
    .inline-group table tbody tr {
        display: flex !important;
        flex-direction: column !important;
        background: var(--color-bg-primary, #ffffff);
        border-radius: 10px;
        padding: 12px;
        margin-bottom: 8px;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
        border: 1px solid #f3f4f6;
    }
    .dark .inline-group table tbody tr {
        background: var(--color-bg-primary, #1f2937);
        border-color: #374151;
    }

    /* Each cell becomes labeled field */
    .inline-group table tbody tr td {
        display: flex !important;
        flex-direction: column !important;
        padding: 4px 0 !important;
        border: none !important;
        width: 100% !important;
    }

    /* Show data-label as field label */
    .inline-group table tbody tr td[data-label]::before {
        content: attr(data-label);
        font-size: 12px;
        font-weight: 600;
        color: #6b7280;
        margin-bottom: 4px;
    }
    .dark .inline-group table tbody tr td[data-label]::before {
        color: #9ca3af;
    }

    /* Hide empty data-label pseudo-elements */
    .inline-group table tbody tr td[data-label=""]::before {
        display: none;
    }

    /* Image previews — full width */
    .inline-group img {
        max-width: 100% !important;
        height: auto !important;
        border-radius: 8px;
    }

    /* Delete checkbox — bigger touch target */
    .inline-group .delete label,
    .inline-group td.delete {
        min-height: 44px;
        display: flex !important;
        align-items: center;
        gap: 8px;
    }
    .inline-group .delete input[type="checkbox"] {
        transform: scale(1.3);
    }
}

/* ===== MOBILE BOOKING CARDS (improved hierarchy) ===== */
/* Note: Unfold uses Tailwind classes directly on elements (tr.block),
   no .results wrapper exists. Use #result_list as ancestor. */
@media (max-width: 767px) {
    /* Booking list: use flex for order-based reordering */
    #result_list tbody tr {
        display: flex !important;
        flex-direction: column !important;
    }

    /* Status cell — make it prominent at top of card */
    #result_list tbody tr td[data-label="Статус"],
    #result_list tbody tr td[data-label="Status"] {
        order: -10;
        font-weight: 700;
        font-size: 13px;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        padding-bottom: 6px !important;
        border-bottom: 1px solid #f3f4f6 !important;
        margin-bottom: 6px;
    }
    .dark #result_list tbody tr td[data-label="Статус"],
    .dark #result_list tbody tr td[data-label="Status"] {
        border-bottom-color: #374151 !important;
    }

    /* Client name — second priority */
    #result_list tbody tr td[data-label="Клиент"],
    #result_list tbody tr td[data-label="Customer"] {
        order: -9;
        font-weight: 600;
        font-size: 15px;
    }

    /* Tour title — third */
    #result_list tbody tr td[data-label="Экскурсия"],
    #result_list tbody tr td[data-label="Tour"] {
        order: -8;
    }

    /* Hide less important fields on mobile booking cards */
    /* Note: Unfold renders ID column as <th>, not <td> */
    #result_list tbody tr th[data-label="ID"],
    #result_list tbody tr td[data-label="ID"],
    #result_list tbody tr td[data-label="Select record"],
    #result_list tbody tr td[data-label="Сумма комиссии"],
    #result_list tbody tr td[data-label="Commission"],
    #result_list tbody tr td[data-label="Получит поставщик"],
    #result_list tbody tr td[data-label="Supplier receives"],
    #result_list tbody tr td[data-label="Код партнёра"],
    #result_list tbody tr td[data-label="Истекает"] {
        display: none !important;
    }

    /* Price — inline with date at bottom */
    #result_list tbody tr td[data-label="Общая стоимость"],
    #result_list tbody tr td[data-label="Total price"] {
        font-weight: 600;
    }

    /* === FIX: значения видны в мобильных карточках admin-списков ===
       Unfold по умолчанию рендерит каждую ячейку как flex-row:
       label (через before:mr-auto) + value. Длинные строки (title, supplier)
       уезжают за правый край экрана из-за overflow-hidden. Принудительно
       стэкаем label сверху, value снизу — для ВСЕХ td с data-label. */
    #result_list tbody tr td[data-label] {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 2px !important;
        overflow: visible !important;
        white-space: normal !important;
        word-break: break-word !important;
    }

    #result_list tbody tr td[data-label]::before {
        margin-right: 0 !important;
        font-size: 11px !important;
        text-transform: uppercase !important;
        letter-spacing: 0.04em !important;
        color: #6b7280 !important;
        font-weight: 600 !important;
    }

    .dark #result_list tbody tr td[data-label]::before {
        color: #9ca3af !important;
    }
}
