@tailwind base;
@tailwind components;
@tailwind utilities;

/* CRITICAL: Global color classes for DOCX formatting preservation */
/* These classes are applied by HybridRenderer for semantic color preservation */
.red {
    color: red !important;
}

.blue {
    color: blue !important;
}

@layer base {
    html {
        @apply text-sm md:text-base;
        font-family: 'Vazir', Arial, sans-serif;
    }
    
    body {
        @apply bg-gray-50 min-h-screen mb-16;
        font-family: 'Vazir', Arial, sans-serif;
    }
}

@layer components {
    /* Mention link styles */
    .mention-link {
        @apply text-blue-600 hover:text-blue-800 underline cursor-pointer;
        text-decoration: underline;
        transition: color 0.2s ease;
    }
    
    .mention-link:hover {
        @apply text-blue-800;
    }
    
    .form-container {
        @apply min-h-[calc(100vh-60px)] flex items-center justify-center py-4 px-4 sm:py-8;
    }
    
    .form-card {
        @apply w-full max-w-lg mx-auto shadow-lg rounded-lg overflow-hidden bg-white;
    }
    
    .form-card .card-header {
        @apply bg-blue-600 text-white border-0 p-4 md:p-6;
    }
    
    .form-card .card-body {
        @apply p-4 md:p-6;
    }
    
    .form-label {
        @apply block text-sm font-medium text-gray-700 dark:text-white mb-2;
    }
    
    .form-control, .form-select {
        @apply w-full rounded-lg border-gray-300 shadow-sm;
        min-height: 44px;
        padding: 0.625rem 0.75rem;
        font-size: 1rem;
        line-height: 1.5;
        transition: all 0.2s ease;
    }
    .form-control:focus, .form-select:focus {
        @apply border-blue-500 ring-2 ring-blue-200;
    }

    /* Dark mode styles handled by @media (prefers-color-scheme: dark) - system preference only */

    .input-group {
        @apply flex flex-col sm:flex-row gap-2;
    }
    
    .form-control:focus, .form-select:focus {
        @apply border-blue-500 ring-2 ring-blue-200;
    }
    
    .input-group {
        @apply flex flex-col sm:flex-row gap-2;
    }
    
    .input-group .input-group-text {
        min-width: 36px;
        max-width: 40px;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        justify-content: center;
    }
    
    .input-group .form-control {
        flex: 1 1 auto;
        width: 1%;
        min-width: 0;
    }
    
    .btn {
        @apply inline-flex items-center justify-center gap-2 px-4 py-2.5 font-medium rounded-lg transition-colors;
        min-height: 44px;
    }
    
    .btn-primary {
        @apply bg-blue-600 text-white hover:bg-blue-700 focus:ring-2 focus:ring-blue-200;
    }
    
    .btn-outline-secondary {
        @apply border-gray-300 text-gray-700 hover:bg-gray-50 focus:ring-2 focus:ring-gray-200;
    }
    
    .alert {
        @apply p-4 rounded-lg mb-4;
    }
    
    .alert-info {
        @apply bg-blue-50 text-blue-700 border border-blue-200;
    }
    
    .alert-danger {
        @apply bg-red-50 text-red-700 border border-red-200;
    }
    
    /* Role selection styles */
    .role-checkbox-group {
        @apply grid grid-cols-1 sm:grid-cols-2 gap-3;
    }
    
    .role-checkbox-label {
        @apply flex items-start p-4 border rounded-lg cursor-pointer hover:bg-gray-50 transition-colors;
        min-height: 44px;
    }
    
    .role-checkbox-label input[type="checkbox"] {
        @apply w-5 h-5 mt-1 mr-3;
    }
    
    .role-checkbox-label span {
        @apply flex-1;
    }
    
    .role-checkbox-label small {
        @apply block text-gray-500 mt-1;
    }
    
    /* Form check styles for proper alignment */
    .form-check {
        display: flex;
        align-items: flex-start;
        margin-bottom: 0.5rem;
        gap: 0.5rem;
    }
    
    .form-check-input {
        margin-top: 0.25rem;
        margin-right: 0;
        flex-shrink: 0;
        width: 1.25rem;
        height: 1.25rem;
    }
    
    .form-check-label {
        line-height: 1.4;
        flex: 1;
        margin-top: 0.25rem;
        padding-left: 0;
    }
    
    /* Additional checkbox alignment fixes */
    .form-check-input[type="checkbox"] {
        position: relative;
        top: 0.125rem;
    }
    
    /* Social media input styles */
    .social-media-input-group {
        @apply flex flex-col sm:flex-row gap-2;
    }
    
    .social-media-input-group .form-select {
        @apply rounded-t sm:rounded-tr-none sm:rounded-l;
        min-width: 140px;
    }
    
    .social-media-input-group .form-control {
        @apply rounded-b sm:rounded-bl-none sm:rounded-r flex-1;
    }
    
    .social-media-input-group .btn {
        @apply sm:self-end;
    }
    
    .list-group-item {
        @apply flex items-center justify-between p-3 border-b last:border-b-0;
    }
    
    .list-group-item .btn-sm {
        @apply p-2;
        min-height: 32px;
    }
}

@layer utilities {
    /* RTL Specific Styles */
    .ml-1 { @apply mr-1 ml-0; }
    .ml-2 { @apply mr-2 ml-0; }
    .mr-1 { @apply ml-1 mr-0; }
    .mr-2 { @apply ml-2 mr-0; }
    .pl-3 { @apply pr-3 pl-0; }
    .pr-3 { @apply pl-3 pr-0; }
}

/* Responsive adjustments */
@media (max-width: 576px) {
    .form-container {
        @apply py-4;
    }
    
    .form-card {
        @apply shadow-none border border-gray-200;
    }
    
    .form-card .card-header {
        @apply p-4;
    }
    
    .form-card .card-body {
        @apply p-4;
    }
    
    .btn-group {
        @apply flex-col w-full gap-2;
    }
    
    .btn-group .btn {
        @apply w-full;
    }
    
    .modal-dialog {
        @apply m-2;
    }
    
    .modal-body {
        @apply p-4;
    }
    
    .role-checkbox-label {
        @apply p-3;
    }
    
    .social-media-input-group .btn {
        @apply w-full;
    }
    
    .list-group-item {
        @apply p-2.5;
    }
}

/* Form validation styles */
.form-control.is-invalid {
    @apply border-red-500 ring-2 ring-red-200;
}

.invalid-feedback {
    @apply text-red-500 text-sm mt-1;
}

.form-control.is-valid {
    @apply border-green-500 ring-2 ring-green-200;
}

.valid-feedback {
    @apply text-green-500 text-sm mt-1;
}

/* Loading states */
.btn-loading {
    @apply opacity-75 cursor-not-allowed;
    pointer-events: none;
}

.btn-loading .spinner-border {
    @apply w-4 h-4 mr-2;
}

/* Book card styles */
.card {
    transition: all 0.3s ease;
    border: none;
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.card .img-fluid {
    height: 200px;
    object-fit: cover;
    border-radius: 0.375rem 0.375rem 0 0;
}

.book-details {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(0,0,0,0.1);
}

.detail-item {
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    display: flex;
    align-items: flex-start;
}

.detail-label {
    font-weight: 500;
    color: #666;
    min-width: 120px;
    padding-right: 1rem;
}

.detail-value {
    color: #333;
    flex: 1;
}

.card .text-muted {
    font-size: 0.8rem;
}

.edit-book-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

/* Mobile Styles */
@media (max-width: 576px) {
    .card {
        margin-bottom: 1rem;
    }
    
    .card .img-fluid {
        height: 180px;
    }
    
    .card .card-body {
        padding: 1rem;
    }
    
    .card .card-title {
        font-size: 1.1rem;
        margin-bottom: 0.5rem;
    }
    
    .card .card-text {
        font-size: 0.9rem;
        margin-bottom: 0.75rem;
    }
    
    .detail-item {
        flex-direction: column;
        margin-bottom: 0.5rem;
    }
    
    .detail-label {
        min-width: auto;
        padding-right: 0;
        margin-bottom: 0.25rem;
    }
    
    .detail-value {
        padding-right: 0;
    }
    
    .btn {
        width: 100%;
        margin-top: 0.5rem;
    }
}

/* RTL Support */
[dir="rtl"] {
    .detail-label {
        padding-right: 0;
        padding-left: 1rem;
    }
    
    .btn i {
        margin-right: 0;
        margin-left: 0.5rem;
    }
    
    .social-links a {
        margin-right: 0;
        margin-left: 0.5rem;
    }
    
    .navbar-nav .nav-link i {
        margin-right: 0;
        margin-left: 0.5rem;
    }
    
    .form-check {
        padding-right: 0;
        padding-left: 0;
        display: flex;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .form-check-input {
        margin-right: 0;
        margin-left: 0;
        margin-top: 0.25rem;
        flex-shrink: 0;
        width: 1.25rem;
        height: 1.25rem;
    }
    
    .form-check-label {
        margin-right: 0;
        margin-left: 0;
        line-height: 1.4;
        margin-top: 0.25rem;
        padding-right: 0;
    }
    
    /* Additional checkbox alignment fixes for RTL */
    .form-check-input[type="checkbox"] {
        position: relative;
        top: 0.125rem;
    }
    
    .input-group-text {
        border-radius: 0 0.375rem 0.375rem 0;
    }
    
    .form-control {
        border-radius: 0.375rem 0 0 0.375rem;
    }
}

/* Touch Feedback */
@media (hover: none) {
    .btn:active,
    .card:active,
    .nav-link:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
    
    .btn:active {
        opacity: 0.9;
    }
}

/* Add the @media queries from _Layout.cshtml */
@media (max-width: 576px) {
    .chat-button {
        bottom: 70px;
        right: 15px;
        width: 45px;
        height: 45px;
    }
    .navbar-collapse {
        background-color: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(8px);
        border-color: #e2e8f0;
    }
    .navbar-nav .nav-item {
        border-color: #e2e8f0;
    }
    .footer {
        position: relative;
        margin-top: 2rem;
    }
    main {
        min-height: calc(100vh - 60px);
    }
}

/* Add the @media queries from Details.cshtml */
@media (max-width: 576px) {
    .profile-header {
        height: auto;
        padding: 1rem;
    }
    .profile-photo {
        width: 100px !important;
        height: 100px !important;
        border-radius: 50% !important;
        border-width: 3px;
        object-fit: cover !important;
        display: block !important;
        max-width: none !important;
        max-height: none !important;
        flex-shrink: 0 !important;
    }
    .stats-card {
        padding: 0.75rem;
        margin-bottom: 1rem;
    }
    .social-links {
        justify-content: center;
        gap: 0.5rem;
    }
    .social-links a {
        width: 2.5rem;
        height: 2.5rem;
    }
    .profile-section {
        padding: 1rem;
    }
    .badge-verified {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
    .publication-card, .article-card {
        margin-bottom: 1rem;
    }
}

/* Add the @media queries from _PhotoUpload.cshtml */
@media (max-width: 576px) {
    .photo-upload-container {
        padding: 1rem;
    }
    .photo-upload-preview {
        width: 150px;
        height: 150px;
    }
    .photo-upload-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    .photo-upload-actions button {
        width: 100%;
    }
}

/* Form labels: light mode default; dark mode via @media below (system preference only) */
.form-label { color: #374151; transition: color 0.3s; }

@media (prefers-color-scheme: dark) {
    .form-label,
    .card .form-label,
    .card-body .form-label {
        color: #e2e8f0 !important;
    }
    .control-label,
    .card .control-label,
    .card-body .control-label,
    .profile-form-isolated .control-label {
        color: #e2e8f0 !important;
    }
}

/* Modal styles are now handled by modal-fixes.css */

/* Comment delete button styles */
.delete-comment-btn {
    opacity: 0.8;
    transition: all 0.2s ease;
    border: 1px solid #dc3545;
    background: transparent;
    color: #dc3545;
    padding: 4px 8px;
    font-size: 0.875rem;
    border-radius: 4px;
    margin-left: 8px;
}

.delete-comment-btn:hover {
    opacity: 1;
    background-color: #dc3545;
    color: white;
    transform: scale(1.05);
}

.delete-comment-btn:focus {
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
    outline: none;
}

/* Comment like button styles - More specific rules */
.comment-like-btn.liked {
    color: #e0245e !important;
}

.comment-like-btn.liked i {
    color: #e0245e !important;
}

.comment-like-btn.liked i.fas.fa-heart {
    color: #e0245e !important;
}

/* Override any conflicting styles from image-upload.css */
.comment-like-btn.liked i.fas.fa-heart,
.comment-like-btn.liked i.far.fa-heart {
    color: #e0245e !important;
}

/* Ensure the button itself has the correct color */
.comment-like-btn.liked {
    background: none !important;
    box-shadow: none !important;
    border: none !important;
    color: #e0245e !important;
}

.comment-like-btn.like-loading {
    pointer-events: none;
}

/* Make sure delete button is visible */
.comment .delete-comment-btn {
    display: inline-block !important;
    visibility: visible !important;
}

/* Post image container and image styles */
.post-image-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 400px;
    height: 280px;
    background: #f8f9fa;
    margin: 0 auto;
    border: 2px dashed #007bff;
    overflow: visible !important;
    box-sizing: border-box;
}
.post-image-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    background: #f8f9fa;
    box-sizing: border-box;
}

/* Reviews tab - Grid layout moved to profile-grid-layout.css (shared across all tabs) */
/* This section now only contains review-specific non-grid rules if needed */

/* Profile posts grid layout - ONLY for Posts tab */
#posts-tab-pane .profile-posts-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 24px !important;
    justify-content: center;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.post-card-grid {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    overflow: hidden;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.post-image-container {
    width: 100%;
    height: 280px;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
}

.post-image-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    background: #f8f9fa;
}

.post-card-content {
    width: 100%;
    padding: 16px;
    box-sizing: border-box;
    text-align: left;
}

/* Post content truncation */
.post-card-content .card-text {
    max-height: 4.5em;
    overflow: hidden;
    position: relative;
    line-height: 1.5;
}

.post-card-content .card-text.expanded {
    max-height: none;
}

.post-card-content .see-more-btn {
    color: #007bff;
    background: none;
    border: none;
    padding: 0;
    font-size: 0.875rem;
    cursor: pointer;
    margin-top: 8px;
    text-decoration: underline;
}

.post-card-content .see-more-btn:hover {
    color: #0056b3;
}

/* Responsive grid */
@media (max-width: 1200px) {
    .profile-posts-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .profile-posts-grid {
        grid-template-columns: 1fr;
    }
    
    .post-image-container {
        height: 240px;
    }
}

/* Comment author profile links */
.comment strong a {
    color: #495057 !important;
    text-decoration: none !important;
    transition: color 0.2s ease;
}

.comment strong a:hover {
    color: #007bff !important;
    text-decoration: underline !important;
}

.comment strong a:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
    border-radius: 2px;
}

/* --- MODAL SAFETY NET: Prevent accidental dimming of modal or background --- */

/* Always keep .noise-pattern behind all content */
.noise-pattern {
    z-index: -1 !important;
}
/* --- END MODAL SAFETY NET --- */

/* Success/Error Message Animations for Cart */
@keyframes fadeIn {
    from { 
        opacity: 0; 
        transform: translateY(-5px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

@keyframes fadeOut {
    from { 
        opacity: 1; 
        transform: translateY(0); 
    }
    to { 
        opacity: 0; 
        transform: translateY(-5px); 
    }
}

.success-message, .error-message {
    display: block;
    margin-top: 0.25rem;
}

/* Cart Availability Styles */
.unavailable-item {
    opacity: 0.6;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.unavailable-indicator {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

#availability-warning {
    margin-bottom: 1rem;
}

.unavailable-item .btn {
    pointer-events: none;
    opacity: 0.5;
}

.unavailable-item .book-title {
    text-decoration: line-through;
    color: #6c757d;
}

/* Profile Actions Dropdown Fixes */
#profileActionsDropdown {
    position: relative !important;
    z-index: 1000 !important;
}

/* Ensure the dropdown container has proper positioning */
.dropdown:has(#profileActionsDropdown) {
    position: relative !important;
}

/* Ensure navbar doesn't clip the dropdown */
.navbar {
    overflow: visible !important;
}

.navbar-collapse {
    overflow: visible !important;
}

.navbar .container {
    overflow: visible !important;
}

/* Hide dropdown arrow for Profile Actions button - icon only */
#profileActionsDropdown::after {
    display: none !important;
}

#profileActionsDropdown + .dropdown-menu {
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    z-index: 9999 !important;
    min-width: 200px !important;
    display: none !important;
    background-color: #fff !important;
    border: 1px solid rgba(0,0,0,.15) !important;
    border-radius: 0.375rem !important;
    box-shadow: 0 0.5rem 1rem rgba(0,0,0,.175) !important;
    margin-top: 0.125rem !important;
    padding: 0.5rem 0 !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
}

#profileActionsDropdown + .dropdown-menu.show {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    z-index: 9999 !important;
    background-color: #fff !important;
    border: 2px solid #007bff !important;
    box-shadow: 0 0.5rem 1rem rgba(0,0,0,.175) !important;
}

#profileActionsDropdown + .dropdown-menu .dropdown-item {
    display: block !important;
    width: 100% !important;
    padding: 0.5rem 1rem !important;
    clear: both !important;
    font-weight: 400 !important;
    color: #212529 !important;
    text-align: inherit !important;
    text-decoration: none !important;
    white-space: nowrap !important;
    background-color: transparent !important;
    border: 0 !important;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out !important;
}

#profileActionsDropdown + .dropdown-menu .dropdown-item:hover {
    color: #1e2125 !important;
    background-color: #e9ecef !important;
}

#profileActionsDropdown + .dropdown-menu .dropdown-item:focus {
    color: #1e2125 !important;
    background-color: #e9ecef !important;
    outline: 0 !important;
}

#profileActionsDropdown + .dropdown-menu .dropdown-divider {
    height: 0 !important;
    margin: 0.5rem 0 !important;
    overflow: hidden !important;
    border-top: 1px solid rgba(0,0,0,.15) !important;
}

/* Dark mode support for Profile Actions dropdown */
@media (prefers-color-scheme: dark) {
    #profileActionsDropdown + .dropdown-menu {
        background-color: #1e293b !important;
        border-color: #475569 !important;
        box-shadow: 0 0.5rem 1rem rgba(0,0,0,.3) !important;
    }

    #profileActionsDropdown + .dropdown-menu.show {
        background-color: #1e293b !important;
        border-color: #60a5fa !important;
        box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.3) !important;
    }

    #profileActionsDropdown + .dropdown-menu .dropdown-item {
        color: #f1f5f9 !important;
    }

    #profileActionsDropdown + .dropdown-menu .dropdown-item:hover {
        color: #ffffff !important;
        background-color: #334155 !important;
    }

    #profileActionsDropdown + .dropdown-menu .dropdown-item:focus {
        color: #ffffff !important;
        background-color: #334155 !important;
    }

    #profileActionsDropdown + .dropdown-menu .dropdown-item.text-danger {
        color: #f87171 !important;
    }

    #profileActionsDropdown + .dropdown-menu .dropdown-item.text-danger:hover {
        background-color: #7f1d1d !important;
        color: #fca5a5 !important;
    }

    #profileActionsDropdown + .dropdown-menu .dropdown-divider {
        border-top-color: #475569 !important;
    }
}

/* Mobile responsive: Smaller icon sizes for top-bar icons */
@media (max-width: 768px) {
    /* Profile Actions: hidden in top bar on mobile — see mobile-overlay.css (overlay menu only) */
    
    /* Search icon button */
    .search-icon-btn {
        min-width: 40px !important;
        min-height: 40px !important;
    }
    
    .search-icon-btn .search-icon {
        font-size: 1.2rem !important;
    }
    
    /* Cart icon button */
    .cart-icon-btn {
        min-width: 40px !important;
        min-height: 40px !important;
    }
    
    .cart-icon-btn .cart-icon {
        font-size: 1.2rem !important;
    }
    
    /* Profile icon button */
    .profile-icon-btn {
        min-width: 40px !important;
        min-height: 40px !important;
    }
    
    .profile-icon-btn .profile-icon {
        font-size: 1.2rem !important;
    }
    
    /* Notification bell button */
    .notification-bell-btn {
        min-width: 40px !important;
        min-height: 40px !important;
    }
    
    .notification-bell-btn .notification-icon {
        width: 1.2rem !important;
        height: 1.2rem !important;
    }
    
    /* Dark mode toggle container */
    #theme-toggle {
        font-size: 1.2rem !important;
    }
    
    /* Language switcher container */
    .language-switcher {
        height: 40px !important;
    }
}

/* CRITICAL: Override modal body padding for edit review modal */
#editReviewModal .modal-body,
.edit-review-modal .modal-body {
    padding: 0.25rem !important;
    margin: 0 !important;
}

/* Force eliminate spacing in edit review form */
#editReviewReferenceInfo {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

#editReviewReferenceInfo .card {
    margin-bottom: 0 !important;
}

#editReviewReferenceInfo .card-body {
    margin-bottom: 0 !important;
    padding-bottom: 0.25rem !important;
}

/* Target elements after Reviewing section */
#editReviewReferenceInfo + * {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

label[for="editReviewTitle"] {
    margin-top: 0.125rem !important;
    margin-bottom: 0.125rem !important;
}