/* Mobile Optimizations for 9:16 Format */
/* With fallbacks for older browsers */

@media (max-width: 768px) {

    /* ========== LIGHT MODE MOBILE OVERRIDES ========== */
    body.light-mode .sidebar {
        background: rgba(255, 255, 255, 0.95) !important;
        border-right: 1px solid rgba(0, 0, 0, 0.08);
    }
    
    body.light-mode .sidebar-overlay {
        background: rgba(0, 0, 0, 0.3);
    }
    
    body.light-mode .top-bar {
        background: #f8fafc;
    }

    /* Top bar - sticky */
    .top-bar {
        padding: 1rem;
        -webkit-flex-wrap: wrap;
        flex-wrap: wrap;
        position: -webkit-sticky;
        position: sticky;
        top: 0;
        background: #0f172a;
        background: var(--bg-color);
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
        z-index: 100;
        border-bottom: 1px solid rgba(148, 163, 184, 0.1);
        border-bottom: 1px solid var(--border);
    }

    .top-bar > * {
        margin-bottom: 0.75rem;
    }

    .actions {
        width: 100%;
        margin-top: 0.75rem;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-flex-wrap: wrap;
        flex-wrap: wrap;
    }
    
    .actions > * {
        margin-right: 0.75rem;
        margin-bottom: 0.75rem;
    }
    
    .actions > *:last-child {
        margin-right: 0;
    }

    /* Primary "Новая задача" gets its own full-width row on top; the secondary
       controls (Файлы проекта, помощь, удалить) share the row below so the
       delete button no longer wraps alone. */
    #add-task-btn {
        order: -1;
        flex: 1 1 100%;
        justify-content: center;
        padding: 0.875rem;
        font-size: 1rem;
        min-height: 50px;
    }

    #task-archive-btn,
    #project-files-btn {
        flex: 1 1 auto;
        justify-content: center;
        min-height: 50px;
        padding: 0.875rem 1rem;
        margin-right: 0.75rem;
    }

    #task-archive-btn {
        flex-basis: calc(50% - 0.5rem);
    }

    #project-files-btn {
        flex-basis: calc(50% - 0.5rem);
    }

    #help-btn {
        flex: 0 0 auto;
        padding: 0.875rem;
        min-width: 50px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #delete-project-btn {
        flex: 0 0 auto;
        padding: 0;
        min-width: 50px;
        width: 50px;
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        z-index: 10;
        pointer-events: auto !important;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        cursor: pointer;
    }

    #delete-project-btn i {
        font-size: 1.1rem;
        pointer-events: none; /* Let clicks pass through to button */
    }
    
    #delete-project-btn:active {
        transform: scale(0.95);
        opacity: 0.8;
    }

    /* Main content must have fixed height with dvh for mobile browsers */
    .main-content {
        height: 100dvh !important; /* Dynamic viewport height */
        height: 100vh; /* Fallback */
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important; /* Prevent main content from scrolling */
        position: relative !important;
    }

    /* Board container - hidden by default, shown when active */
    .board-container {
        display: none !important;
        flex-direction: column;
        padding: 1rem;
        padding-bottom: 5rem;
        gap: 2rem;
        
        /* CRITICAL SCROLLING FIXES */
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        
        flex: 1 1 auto;
        min-height: 0;
        height: 100%;
    }

    .board-container.active {
        display: flex !important;
    }

    .kanban-columns {
        display: block;
        flex: 0 0 auto;
        min-height: auto;
        overflow: visible;
    }

    .kanban-columns .column {
        display: none !important;
    }

    .kanban-columns .column.active {
        display: flex !important;
    }

    /* Mobile board: use single selector instead of tabs */
    .board-tabs {
        display: none !important;
    }

    #category-picker {
        display: flex !important;
    }

    /* Project items with deadline on mobile */
    .project-item {
        padding: 0.875rem 1rem !important;
    }
    
    .project-item-content {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
        width: 100%;
    }
    
    .project-item-main {
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }
    
    .project-item-name {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .project-deadline {
        display: flex !important;
        font-size: 0.7rem;
        color: var(--text-secondary);
        padding-left: 1.75rem;
        opacity: 0.8;
        align-items: center;
        gap: 0.3rem;
    }
    
    .project-deadline i {
        font-size: 0.65rem;
    }
    
    .project-deadline.soon {
        color: var(--warning);
    }
    
    .project-deadline.overdue {
        color: var(--danger);
    }

    /* Empty state - centered on mobile */
    .empty-state {
        flex: 1;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 2rem;
        text-align: center;
    }

    .empty-state i {
        font-size: 4rem;
        opacity: 0.3;
        margin-bottom: 1.5rem;
        color: var(--primary);
    }

    .empty-state p {
        font-size: 1.1rem;
        color: var(--text-secondary);
        max-width: 250px;
        line-height: 1.5;
    }

    /* Ensure body doesn't scroll */
    body {
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
        overflow: hidden !important;
    }

    .app-container {
        height: 100dvh !important;
        height: 100vh;
        overflow: hidden !important;
    }

    .column {
        min-height: 100px !important;
        height: auto !important; /* Allow column to grow with content */
        max-height: none !important;
        overflow: visible !important;
        margin-bottom: 0 !important;
        flex: 0 0 auto !important; /* Do not stretch, let it be auto height */
        background: rgba(15, 23, 42, 0.4);
    }

    .task-list {
        max-height: none !important;
        overflow-y: visible !important;
        min-height: 50px;
        height: auto !important;
    }

    /* Fix task layout on mobile */
    .task-card {
        width: 100%;
        box-sizing: border-box;
        /* Enable vertical pan for scrolling, disable horizontal to prevent swipe nav interference */
        touch-action: pan-y; 
    }

    .task-title {
        font-size: 1.1rem;
        margin-bottom: 0.75rem;
        line-height: 1.5;
        word-wrap: break-word;
    }

    .task-meta {
        flex-wrap: wrap;
        gap: 0.5rem;
        align-items: center; /* Align items vertically */
    }

    .deadline {
        flex-wrap: wrap;
        /* Ensure text doesn't overflow if it's long like 'ПРОСРОЧЕНО' */
        max-width: 100%;
        gap: 0.4rem;
    }

    .days-left {
        font-size: 0.85rem;
        margin-right: 8px;
        /* Ensure it wraps if needed */
        white-space: normal; 
    }

    /* Toolbar styles for mobile */
    .task-toolbar {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .toolbar-left {
        gap: 0.4rem;
    }
    
    .task-separator {
        margin-bottom: 0.5rem;
    }

    /* Status Badge - Same as PC (solid, high-contrast chips) */
    .status-badge {
        padding: 6px 12px;
        border-radius: 999px;
        font-size: 0.8rem;
        font-weight: 700;
        letter-spacing: 0.02em;
        text-transform: uppercase;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        transition: all 0.2s;
        user-select: none;
        border: none;
        color: #fff;
        width: fit-content;
        min-height: 36px; /* Ensure touch target */
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);

        /* Force consistent appearance */
        -webkit-appearance: none;
        appearance: none;
    }

    .status-badge:hover,
    .status-badge:active {
        transform: translateY(-1px);
        filter: brightness(1.08);
    }

    .status-assigned {
        background: #e67e22 !important;
        color: #fff !important;
        border-color: transparent !important;
    }

    .status-in-work {
        background: #3b82f6 !important;
        color: #fff !important;
        border-color: transparent !important;
    }

    .status-review {
        background: #eab308 !important;
        color: #fff !important;
        border-color: transparent !important;
    }

    .status-done {
        background: #16a34a !important;
        color: #fff !important;
        border-color: transparent !important;
    }

    /* Dropdown Container */
    .status-dropdown-container {
        position: relative;
        display: inline-block;
    }

    /* Status Dropdown - Same as PC */
    .status-dropdown {
        position: absolute;
        top: 100%;
        left: 4px; /* Shifted right */
        right: auto;
        margin-top: 6px;
        background: #1e293b; /* Solid background */
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 8px;
        padding: 4px;
        box-shadow: 0 10px 40px rgba(0,0,0,0.7);
        z-index: 9999;
        display: none;
        min-width: 220px;
    }

    body.light-mode .status-dropdown {
        background: #ffffff;
        border: 1px solid #cbd5e1;
    }

    .status-dropdown.active {
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .status-option {
        padding: 12px 14px; /* Larger padding for touch */
        border-radius: 6px;
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 10px;
        color: var(--text-secondary);
        transition: all 0.2s;
        font-size: 0.95rem;
        min-height: 44px; /* Touch target */
        
        -webkit-tap-highlight-color: transparent;
    }

    .status-option:active {
        background: rgba(255, 255, 255, 0.1);
        color: var(--text-primary);
    }

    .status-option i {
        width: 20px;
        text-align: center;
        font-size: 1rem;
    }

    /* Task card z-index fix for dropdown */
    .task-card.active-dropdown {
        z-index: 100 !important;
    }

    /* Task title - no padding needed with toolbar */
    .task-title {
        font-size: 1.1rem;
        margin-bottom: 0.75rem;
        line-height: 1.5;
        word-wrap: break-word;
    }

    /* Hide old check buttons completely */
    .check-btn {
        display: none !important;
    }

    .assignee-complete-btn {
        display: none !important;
    }

    /* Login/Register form styles */
    .login-overlay {
        padding: 1rem;
    }

    .login-card {
        width: 100%;
        max-width: 100%;
        padding: 1.5rem;
        border-radius: 16px;
        margin: 0;
    }

    .login-card .brand {
        font-size: 1.3rem;
        margin-bottom: 1.5rem !important;
    }

    .login-card h2 {
        font-size: 1.4rem;
        margin-bottom: 0.5rem;
    }

    #auth-subtitle {
        margin-bottom: 1.5rem !important;
        font-size: 0.9rem;
    }

    /* Modal */
    .modal {
        padding: 0;
        align-items: stretch;
        padding-top: 0;
    }

    .modal-content {
        width: 100%;
        max-width: 100%;
        padding: 0;
        /* dvh must come LAST so it wins where supported: plain 100vh on iOS
           Safari is taller than the visible area, which pushed modal footers /
           chat inputs down behind the browser toolbar. */
        max-height: 100vh;
        max-height: 100dvh;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
        margin: 0;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .modal-header {
        margin-bottom: 0;
        padding: 1rem 1.5rem;
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
        background: #1e293b;
    }

    body.light-mode .modal-header {
        background: #ffffff;
    }

    .modal-header h2 {
        font-size: 1.3rem;
        margin: 0;
    }

    /* Task Modal - Full Screen with Fixed Header/Footer */
    #task-modal {
        padding: 0 !important;
        align-items: stretch !important;
    }

    #task-modal .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        padding: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    #task-modal .modal-header {
        flex-shrink: 0;
        background: transparent;
    }

    /* Scrollable form content wrapper */
    #task-modal .task-form-body {
        flex: 1 1 auto;
        overflow-y: auto;
        padding: 1.5rem;
        padding-bottom: 2rem;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        min-height: 0;
    }

    #task-modal #task-form {
        display: block;
    }

    /* Custom scrollbar for form body */
    #task-modal .task-form-body::-webkit-scrollbar {
        width: 4px;
    }

    #task-modal .task-form-body::-webkit-scrollbar-track {
        background: transparent;
    }

    #task-modal .task-form-body::-webkit-scrollbar-thumb {
        background: rgba(99, 102, 241, 0.3);
        border-radius: 4px;
    }

    /* Task Modal Footer - Fixed at Bottom */
    .task-modal-footer {
        display: flex !important;
        gap: 1rem;
        padding: 1rem 1.5rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid var(--border);
        flex-shrink: 0;
        background: #1e293b !important;
    }

    body.light-mode .task-modal-footer {
        background: #ffffff !important;
    }

    .task-modal-footer button {
        flex: 1;
        padding: 1rem;
        font-size: 1rem;
        min-height: 52px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
    }

    /* ========== Task Modal Form - Mobile adjustments ========== */
    
    /* Prevent horizontal scroll */
    #task-modal .modal-content {
        overflow-x: hidden !important;
    }

    #task-modal .task-form-body {
        overflow-x: hidden !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    #task-modal #task-form {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    /* Stack form-row vertically on mobile */
    #task-modal .form-row {
        display: flex !important;
        flex-direction: column !important;
        gap: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    #task-modal .form-row .form-group {
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 1rem;
        box-sizing: border-box !important;
    }
    
    #task-modal .form-group {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    #task-modal input,
    #task-modal textarea,
    #task-modal select {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        font-size: 16px !important; /* Prevent iOS zoom */
    }
    
    #task-modal .assignee-search-input {
        font-size: 16px !important;
    }

    select {
        -webkit-appearance: none;
        appearance: none;
        /* Use a real caret (triangle), not a "checkmark" chevron */
        background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3e%3cpath fill='white' d='M7,10L12,15L17,10Z'/%3e%3c/svg%3e");
        background-repeat: no-repeat;
        background-position: right 1rem center;
        background-size: 1.2rem;
        padding-right: 3rem;
    }

    body.light-mode select {
        background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3e%3cpath fill='%230f172a' d='M7,10L12,15L17,10Z'/%3e%3c/svg%3e");
    }

    /* Regular modal footer */
    .modal-footer {
        display: flex;
        justify-content: center;
        gap: 1rem;
        margin-top: 2rem;
        padding-top: 1.5rem;
        border-top: 1px solid var(--border);
        flex-direction: row;
    }

    .modal-footer button {
        flex: 0 1 auto;
        padding: 1rem 1.5rem;
        font-size: 1rem;
        min-height: 52px;
        justify-content: center;
        border-radius: 8px;
    }

    .close-modal {
        font-size: 1.5rem;
        padding: 0.5rem;
        min-width: 44px;
        min-height: 44px;
    }

    /* Other modals (not task modal) - keep normal behavior */
    #project-modal .modal-content,
    #help-modal .modal-content,
    #admin-panel-modal .modal-content,
    #my-tasks-modal .modal-content,
    #files-list-modal .modal-content,
    #project-files-modal .modal-content,
    #day-tasks-modal .modal-content {
        height: auto;
        max-height: 90dvh;
        max-height: 90vh;
        overflow-y: auto;
        padding: 0;
        border-radius: 16px;
    }

    #project-modal,
    #help-modal,
    #admin-panel-modal,
    #my-tasks-modal,
    #files-list-modal,
    #project-files-modal,
    #day-tasks-modal {
        padding: 1rem;
        align-items: flex-start;
        padding-top: 2rem;
    }

    #project-modal .modal-header,
    #help-modal .modal-header,
    #admin-panel-modal .modal-header,
    #my-tasks-modal .modal-header,
    #files-list-modal .modal-header,
    #project-files-modal .modal-header,
    #day-tasks-modal .modal-header {
        padding: 1.5rem 1.5rem 1rem;
    }

    #project-modal form,
    #help-modal .help-content,
    #admin-panel-modal .admin-panel-content {
        padding: 0 1.5rem 1.5rem;
    }
    
    /* Project form spacing on mobile */
    #project-modal form {
        padding-top: 1rem;
    }
    
    /* Project deadline fields centered on mobile */
    #project-modal .form-group {
        width: 100%;
        text-align: center;
    }
    
    #project-modal .checkbox-label {
        justify-content: center;
    }
    
    #project-modal #p-deadline-group {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
    }
    
    #project-modal #p-deadline-group label {
        text-align: center;
        width: 100%;
    }
    
    #project-modal #p-deadline {
        width: 100%;
        max-width: 250px;
        text-align: center;
    }

    @media (max-height: 700px) {
        .column {
            min-height: 200px !important;
        }
    }
}

/* My Tasks Button & Modal Mobile */
@media (max-width: 768px) {
    .my-tasks-btn {
        padding: 0.875rem 1rem;
        font-size: 1rem;
        min-height: 50px;
    }

    .my-tasks-count {
        top: -8px;
        right: -8px;
        min-width: 22px;
        height: 22px;
        font-size: 0.8rem;
    }

    .my-tasks-modal-content {
        max-width: 100%;
        width: 100%;
    }

    .my-tasks-list {
        max-height: 65vh;
        padding: 0 1rem 1rem;
    }

    .my-task-item {
        padding: 0.875rem;
        position: relative;
    }

    .my-task-header {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
        gap: 0.5rem;
        flex-wrap: nowrap;
    }

    .my-task-project {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: calc(100% - 90px);
    }

    .my-task-status {
        flex-shrink: 0;
    }

    .my-task-title {
        font-size: 1.05rem;
    }

    .my-task-meta {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .my-task-go {
        margin-left: 0;
        margin-top: 0.5rem;
        padding-top: 0.5rem;
        border-top: 1px dashed var(--border);
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    .modal {
        align-items: center;
        padding: 1rem;
    }

    .modal-content {
        max-width: 600px;
        max-height: calc(100vh - 2rem);
    }
}
/* ========== PIN Screen Mobile ========== */
@media (max-width: 768px) {
    .pin-container {
        padding: 1.5rem;
    }
    
    .pin-logo {
        width: 70px;
        height: 70px;
        border-radius: 20px;
        margin-bottom: 1.25rem;
    }
    
    .pin-logo i {
        font-size: 2rem;
    }
    
    .pin-title {
        font-size: 1.5rem;
    }
    
    .pin-subtitle {
        font-size: 0.95rem;
        margin-bottom: 1.5rem;
    }
    
    .pin-dots {
        gap: 0.875rem;
    }
    
    .pin-dot {
        width: 16px;
        height: 16px;
    }
    
    .pin-keypad {
        gap: 10px;
        max-width: 260px;
    }
    
    .pin-key {
        width: 68px;
        height: 68px;
        font-size: 1.5rem;
    }
    
    .pin-hint {
        font-size: 0.8rem;
    }
}

@media (max-width: 380px) {
    .pin-keypad {
        gap: 8px;
        max-width: 230px;
    }
    
    .pin-key {
        width: 60px;
        height: 60px;
        font-size: 1.35rem;
    }
}

/* ========== Disable double-tap zoom on mobile ========== */
* {
    touch-action: manipulation;
}

/* Extra protection for buttons and interactive elements */
button, a, input, select, textarea, .task-card, .project-item, .pin-key {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* ========== Info Task Button Mobile - Match status-badge ========== */
@media (max-width: 768px) {
    .info-task {
        padding: 6px 12px !important;
        border-radius: 999px !important;
        font-size: 0.9rem !important;
        font-weight: 700 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px !important;
        user-select: none !important;
        min-height: 36px !important;
        background: #6366f1 !important;
        border: none !important;
        color: #fff !important;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2) !important;
    }

    .info-task i {
        font-size: 0.9rem !important;
        color: #fff !important;
    }
}

/* ========== Task Details Modal Mobile ========== */
@media (max-width: 768px) {
    #task-details-modal .modal-content {
        height: 90vh !important;
        max-height: 90vh !important;
        display: flex;
        flex-direction: column;
        border-radius: 16px !important;
    }
    
    #task-details-modal .modal-header {
        flex-shrink: 0;
        position: sticky;
        top: 0;
        background: var(--card-bg);
        z-index: 10;
        border-bottom: 1px solid var(--border);
    }
    
    #task-details-content {
        flex: 1;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding: 1rem !important;
    }
}

/* ========== Completion Proof Modal Mobile ========== */
@media (max-width: 768px) {
    #completion-proof-modal .modal-content {
        height: auto !important;
        max-height: 90vh !important;
        max-height: 90dvh !important;
        overflow-y: auto !important;
        border-radius: 16px !important;
        display: flex;
        flex-direction: column;
    }
    
    #completion-proof-modal form {
        display: flex;
        flex-direction: column;
        flex: 1;
        overflow: hidden;
    }
    
    #completion-proof-modal form > div:first-child {
        flex: 1;
        overflow-y: auto;
    }
    
    #completion-proof-modal .modal-footer {
        flex-shrink: 0;
        padding: 1rem 1.5rem !important;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px)) !important;
        background: var(--card-bg);
        margin-top: 0 !important;
        display: flex !important;
        justify-content: center !important;
        gap: 1rem !important;
        width: 100%;
        box-sizing: border-box;
    }
    
    #completion-proof-modal .modal-footer button {
        flex: 0 1 auto;
        min-width: 120px;
        max-width: 180px;
        padding: 1rem 1.5rem;
    }
    
    /* Assignee Picker Mobile */
    .assignee-picker {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .assignee-search-wrapper {
        position: relative;
        width: 100%;
    }
    
    .selected-assignees {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-bottom: 0.25rem;
    }
    
    .selected-assignees:empty {
        display: none;
        margin-bottom: 0;
    }
    
    .assignee-chip {
        display: inline-flex;
        align-items: center;
        gap: 0.4rem;
        padding: 0.4rem 0.5rem 0.4rem 0.4rem;
        font-size: 0.85rem;
        background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.2));
        border: 1px solid rgba(99, 102, 241, 0.3);
        border-radius: 20px;
    }
    
    .assignee-chip-avatar {
        width: 24px;
        height: 24px;
        font-size: 0.65rem;
    }
    
    .assignee-chip-remove {
        width: 22px;
        height: 22px;
        font-size: 0.75rem;
        min-width: 22px;
    }
    
    .assignee-search-input {
        width: 100%;
        padding: 0.875rem 1rem;
        font-size: 16px !important;
        border-radius: 10px;
        min-height: 50px;
        box-sizing: border-box;
        border: 1px solid var(--border);
        background: var(--card-bg);
    }
    
    .assignee-dropdown {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        max-height: 180px !important;
        height: auto;
        z-index: 9999 !important;
        margin-top: 4px;
        border-radius: 10px;
        overflow-y: scroll !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain;
        touch-action: pan-y !important;
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
        background: var(--card-bg) !important;
        border: 1px solid var(--border) !important;
    }
    
    .assignee-dropdown.active {
        display: block !important;
    }
    
    .assignee-dropdown-item {
        padding: 0.875rem 1rem;
        min-height: 54px;
        display: flex !important;
        align-items: center;
        gap: 0.75rem;
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(99, 102, 241, 0.2);
        transition: background-color 0.15s;
        touch-action: manipulation;
        background: var(--card-bg);
        border-bottom: 1px solid var(--border);
    }
    
    .assignee-dropdown-item:last-child {
        border-bottom: none;
    }
    
    .assignee-dropdown-item:active {
        background: rgba(99, 102, 241, 0.2) !important;
    }
    
    .assignee-dropdown-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
    
    .assignee-dropdown-name {
        font-size: 0.9rem;
        font-weight: 500;
    }
    
    .assignee-dropdown-email {
        font-size: 0.75rem;
        opacity: 0.7;
    }
}

/* ========== Project files / calendar day-tasks / agent input (mobile) ========== */
@media (max-width: 768px) {
    /* Bigger, always-tappable delete target in the project files list */
    .file-delete-btn {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .file-list-item {
        gap: 0.75rem;
        padding: 0.875rem;
    }

    .file-list-item .attachment-name {
        word-break: break-word;
    }

    /* Calendar header keeps its gradient on mobile. The generic .modal-header
       rule (loaded after style.css) otherwise paints it white in light mode,
       which hid the white month title and the prev/next/«Сегодня» controls. */
    .calendar-header,
    body.light-mode .calendar-header {
        background: linear-gradient(135deg, #0ea5e9, #2563eb) !important;
    }

    .calendar-header h2,
    .calendar-header .icon-btn,
    .calendar-header #cal-today-btn,
    .calendar-header .close-modal {
        color: #fff !important;
    }

    /* Keep the calendar header on one compact row (it was wrapping into a tall
       blank block on narrow phones). */
    .calendar-header {
        flex-wrap: nowrap !important;
        gap: 0.5rem;
        padding: 0.75rem 1rem !important;
    }

    .calendar-header-nav {
        gap: 0.4rem !important;
        min-width: 0;
        flex: 1 1 auto;
    }

    .calendar-header h2 {
        min-width: 0 !important;
        font-size: 0.95rem !important;
    }

    .calendar-header-actions {
        gap: 0.4rem !important;
        flex-shrink: 0;
    }

    .calendar-header #cal-today-btn {
        padding: 0.4rem 0.6rem !important;
        font-size: 0.75rem !important;
    }

    /* Calendar "tasks of the day" modal: let the sheet grow and scroll */
    .day-tasks-body {
        max-height: none;
        padding: 1rem 1.25rem 1.25rem;
    }

    .day-task-row {
        padding: 0.875rem;
        min-height: 56px;
    }

    .day-tasks-footer {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }

    /* Prevent iOS zoom-on-focus for the agent chat composer */
    .agent-chat-input {
        font-size: 16px !important;
    }

    /* Full-screen agent chat: keep the composer above the iOS home indicator */
    .agent-chat-form {
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    }

    .agent-chat-messages {
        -webkit-overflow-scrolling: touch;
    }

    /* Name-setup (post-registration) inputs: 16px avoids iOS zoom */
    #name-setup-form input {
        font-size: 16px !important;
        min-height: 48px;
    }
}
