/**
 * Page Layout CSS
 * Consistent layout for pages with content + ad sidebar
 * Use this for: News, Blogs, Rankings pages
 */

/* Main page wrapper with sidebar */
.page-wrapper {
    display: flex;
    gap: 30px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 20px;
}

/* Main content area */
.page-content {
    flex: 1;
    min-width: 0; /* Prevents flex item from overflowing */
}

/* Page header section */
.page-header {
    margin-bottom: 30px;
}

.page-title {
    font-size: 2rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 10px 0;
}

.page-subtitle {
    font-size: 1rem;
    color: #64748b;
    margin: 0;
}

/* Content sections */
.content-section {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 25px;
    margin-bottom: 25px;
}

.content-section-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0 0 20px 0;
    padding-bottom: 15px;
    border-bottom: 1px solid #e5e7eb;
}

/* Filter sidebar (for ranking pages) */
.filter-sidebar {
    width: 280px;
    min-width: 280px;
    flex-shrink: 0;
}

.filter-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 20px;
    position: sticky;
    top: 20px;
}

.filter-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0 0 20px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Close button — hidden on desktop, shown inside mobile overlay */
.filter-close-btn {
    display: none;
}

/* Mobile-injected elements — hidden on desktop */
.mobile-filter-trigger {
    display: none;
}

.mobile-search-bar {
    display: none;
}

.filter-group {
    margin-bottom: 20px;
}

.filter-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 8px;
}

.filter-input,
.filter-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
    color: #374151;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.filter-input:focus,
.filter-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.filter-input::placeholder {
    color: #9ca3af;
}

/* Three-column layout (filter + content + ads) */
.page-wrapper.three-column {
    gap: 25px;
}

.page-wrapper.three-column .page-content {
    order: 2;
}

.page-wrapper.three-column .filter-sidebar {
    order: 1;
}

.page-wrapper.three-column .ad-sidebar {
    order: 3;
}

/* Two-column layout (content + ads) */
.page-wrapper.two-column {
    gap: 30px;
}

.page-wrapper.two-column .page-content {
    order: 1;
}

.page-wrapper.two-column .ad-sidebar,
.page-wrapper.two-column .home-ad-sidebar {
    order: 2;
    width: 300px;
    min-width: 300px;
    flex-shrink: 0;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .page-wrapper {
        gap: 20px;
        padding: 20px 15px;
    }

    .filter-sidebar {
        width: 250px;
        min-width: 250px;
    }
}

@media (max-width: 1024px) {
    .page-wrapper {
        flex-wrap: wrap;
    }

    .page-wrapper.three-column .filter-sidebar,
    .page-wrapper.three-column .ad-sidebar,
    .page-wrapper.two-column .ad-sidebar,
    .page-wrapper.two-column .home-ad-sidebar,
    .page-wrapper.two-column .filter-sidebar {
        width: 100%;
        min-width: auto;
    }

    .page-wrapper.three-column .filter-sidebar {
        order: 1;
    }

    .page-wrapper.three-column .page-content {
        order: 2;
        width: 100%;
    }

    .page-wrapper.three-column .ad-sidebar {
        order: 3;
    }

    /* Two-column with filter sidebar */
    .page-wrapper.two-column .filter-sidebar {
        order: 1;
    }

    .page-wrapper.two-column .page-content {
        order: 2;
        width: 100%;
    }

    .filter-card {
        position: static;
    }

    /* Horizontal filter layout on tablet */
    .filter-card {
        display: flex;
        flex-wrap: wrap;
        gap: 15px;
        align-items: flex-end;
    }

    .filter-title {
        width: 100%;
        margin-bottom: 10px;
    }

    .filter-group {
        flex: 1;
        min-width: 200px;
        margin-bottom: 0;
    }
}

@media (max-width: 768px) {
    .page-wrapper {
        padding: 15px 10px;
        gap: 15px;
    }

    .page-title {
        font-size: 1.5rem;
    }

    .content-section {
        padding: 20px 15px;
        border-radius: 8px;
    }

    /* ========================================
       MOBILE FILTER OVERLAY
       ======================================== */
    .filter-sidebar {
        position: fixed !important;
        top: 0;
        left: -100%;
        width: 85%;
        max-width: 320px;
        height: 100vh;
        height: 100dvh;
        background: white;
        z-index: 1001;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
        order: 0 !important;
    }

    .filter-sidebar.active {
        left: 0;
    }

    .filter-card {
        flex-direction: column;
        padding: 20px;
        position: static;
        box-shadow: none;
        border-radius: 0;
        height: 100%;
    }

    /* filter-group inside mobile sidebar — reset flex expansion */
    .filter-sidebar .filter-group {
        width: 100%;
        min-width: auto;
        margin-bottom: 14px;
        flex: none;
        display: block;
        gap: 0;
    }

    .filter-sidebar .filter-group:last-child {
        margin-bottom: 0;
    }

    /* Filter overlay backdrop */
    body.filter-open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
    }

    body.filter-open {
        overflow: hidden;
    }

    /* Hide search from filter sidebar on mobile */
    .filter-sidebar #searchBox,
    .filter-sidebar .filter-group:has(#searchBox) {
        display: none !important;
    }

    /* Hide view toggle on mobile */
    .view-toggle {
        display: none !important;
    }

    /* Filter close button — force visible inside mobile overlay */
    .filter-sidebar .filter-close-btn {
        display: flex !important;
        background: none;
        border: none;
        font-size: 24px;
        line-height: 1;
        color: #64748b;
        cursor: pointer;
        padding: 0;
        width: 32px;
        height: 32px;
        align-items: center;
        justify-content: center;
        border-radius: 6px;
        flex-shrink: 0;
    }

    .filter-sidebar .filter-close-btn:active {
        background: #f1f5f9;
    }
}

@media (max-width: 480px) {
    .page-wrapper {
        padding: 10px 8px;
    }

    .page-title {
        font-size: 1.25rem;
    }

    .page-subtitle {
        font-size: 0.875rem;
    }

    .content-section {
        padding: 15px 12px;
    }

    .filter-card {
        padding: 12px;
    }

    .filter-input,
    .filter-select {
        font-size: 1rem; /* Prevent iOS zoom on focus */
    }
}

/* Rankings Table Styles */
.rankings-table {
    width: 100%;
    border-collapse: collapse;
}

.rankings-table th,
.rankings-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.rankings-table th {
    background: #f9fafb;
    font-weight: 600;
    color: #374151;
    font-size: 0.875rem;
}

.rankings-table tbody tr:hover {
    background: #f9fafb;
}

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: #1e40af;
    color: #fff;
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: 6px;
}

.institution-name {
    font-weight: 600;
    color: #1e293b;
}

.institution-location {
    font-size: 0.8rem;
    color: #64748b;
    margin-top: 2px;
}

.score-cell {
    font-weight: 600;
    color: #059669;
}

.action-link {
    color: #3b82f6;
    text-decoration: none;
    font-size: 0.875rem;
}

.action-link:hover {
    text-decoration: underline;
}

/* No results message */
.no-results {
    text-align: center;
    padding: 60px 20px;
    color: #64748b;
}

.no-results svg {
    width: 60px;
    height: 60px;
    margin-bottom: 15px;
    opacity: 0.5;
}

.no-results h3 {
    font-size: 1.25rem;
    color: #374151;
    margin: 0 0 10px 0;
}

.no-results p {
    margin: 0;
}

/* CSV Upload Section */
.upload-section {
    background: #f8fafc !important;
    border: 2px dashed #cbd5e1;
}

.upload-container {
    margin-top: 20px;
}

.upload-box {
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    padding: 60px 40px;
    text-align: center;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

.upload-box:hover {
    border-color: #3b82f6;
    background: #eff6ff;
}

.upload-icon {
    display: block;
    margin: 0 auto 20px;
}

.upload-box p {
    color: #64748b;
    font-size: 1rem;
    margin: 15px 0;
}

.upload-box button {
    margin-top: 15px;
}

/* Custom Modal Styles */
.custom-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.custom-modal.show {
    opacity: 1;
}

.custom-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.custom-modal-content {
    position: relative;
    max-width: 500px;
    margin: 100px auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.custom-modal.show .custom-modal-content {
    transform: scale(1);
}

.custom-modal-header {
    padding: 24px 24px 16px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.custom-modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: #1e293b;
    font-weight: 600;
}

.custom-modal-close {
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

.custom-modal-close:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.custom-modal-body {
    padding: 24px;
    max-height: 60vh;
    overflow-y: auto;
}

.custom-modal-footer {
    padding: 16px 24px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: #f8fafc;
}

.custom-modal-content.success .custom-modal-header {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border-bottom: none;
}

.custom-modal-content.success .custom-modal-header h3,
.custom-modal-content.success .custom-modal-close {
    color: white;
}

.custom-modal-content.success .custom-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.custom-modal-content.error .custom-modal-header {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    border-bottom: none;
}

.custom-modal-content.error .custom-modal-header h3,
.custom-modal-content.error .custom-modal-close {
    color: white;
}

.custom-modal-content.error .custom-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.custom-modal-content.warning .custom-modal-header {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    border-bottom: none;
}

.custom-modal-content.warning .custom-modal-header h3,
.custom-modal-content.warning .custom-modal-close {
    color: white;
}

.custom-modal-content.warning .custom-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Form Inputs in Modals */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.form-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-input::placeholder {
    color: #94a3b8;
}

textarea.form-input {
    resize: vertical;
    min-height: 100px;
}

/* Button Styles */
.btn-primary, .btn-secondary, .btn-danger {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
    background: #64748b;
    color: white;
}

.btn-secondary:hover {
    background: #475569;
    transform: translateY(-1px);
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Action Buttons in Table */
.action-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.action-buttons button {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
}

.btn-edit {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

.btn-edit:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.btn-save {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.btn-save:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.btn-cancel {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
    color: white;
}

.btn-cancel:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(107, 114, 128, 0.4);
}

.btn-delete {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
}

.btn-delete:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

/* ===================================================================
   Pagination Styles
   =================================================================== */

.pagination-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
    padding: 1.5rem 0;
    border-top: 2px solid #e5e7eb;
}

.pagination {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.pagination-btn {
    padding: 0.5rem 1rem;
    border: 1px solid #d1d5db;
    background: white;
    color: #374151;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 40px;
}

.pagination-btn:hover:not(.disabled) {
    background: #f3f4f6;
    border-color: #1e40af;
    color: #1e40af;
}

.pagination-btn.active {
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    color: white;
    border-color: #1e40af;
}

.pagination-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination-ellipsis {
    padding: 0 0.5rem;
    color: #9ca3af;
}

.pagination-info {
    font-size: 0.9rem;
    color: #6b7280;
    font-weight: 500;
}

/* Responsive Pagination */
@media (max-width: 768px) {
    .pagination-container {
        flex-direction: column;
        gap: 1rem;
    }

    .pagination-info {
        order: -1;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    .pagination-ellipsis {
        display: none;
    }
}

/* ===================================================================
   View Toggle Buttons (Table/Card View)
   =================================================================== */
.view-toggle {
    display: flex;
    gap: 8px;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 8px;
}

.toggle-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-btn:hover {
    background: #e2e8f0;
    color: #475569;
}

.toggle-btn.active {
    background: white;
    color: #1e40af;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Mobile responsive view toggle */
@media (max-width: 768px) {
    .view-toggle {
        display: none !important;
    }
}

/* ===================================================================
   Mobile-Only Elements
   =================================================================== */
@media (max-width: 768px) {
    /* Show Filters Button */
    .mobile-filter-trigger {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        padding: 12px 16px;
        background: #3b82f6;
        color: white;
        border: none;
        border-radius: 8px;
        font-size: 0.95rem;
        font-weight: 600;
        cursor: pointer;
        margin-bottom: 15px;
        box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
    }

    .mobile-filter-trigger:active {
        transform: scale(0.98);
    }

    /* Mobile Search Bar (above cards) */
    .mobile-search-bar {
        display: block;
        margin-bottom: 15px;
    }

    .mobile-search-bar input {
        width: 100%;
        padding: 12px 16px 12px 44px;
        border: 1px solid #d1d5db;
        border-radius: 8px;
        font-size: 1rem;
        background: white url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%2364748b" stroke-width="2"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/></svg>') no-repeat 14px center;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }

    .mobile-search-bar input:focus {
        outline: none;
        border-color: #3b82f6;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }

    /* Hide table, show cards only — scoped to ranking pages (have .filter-sidebar) */
    .page-wrapper:has(.filter-sidebar) .rankings-table {
        display: none !important;
    }

    /* Force card view on ranking pages */
    .page-wrapper:has(.filter-sidebar) #cardView {
        display: block !important;
    }

    /* Hide table view on ranking pages only — business award pages are unaffected */
    .page-wrapper:has(.filter-sidebar) #tableView {
        display: none !important;
    }
}

/* card-rank row: rank number left, download icon right */
.card-rank {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-rank-download {
    margin-left: auto;
    flex-shrink: 0;
}

/* ── Autocomplete dropdown ── */
.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #d1d5db;
    border-top: none;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 1100;
    max-height: 280px;
    overflow-y: auto;
}

.autocomplete-item {
    padding: 10px 14px;
    font-size: 0.875rem;
    color: #1e293b;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    line-height: 1.4;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item:focus {
    background: #f0f9ff;
    color: #1e40af;
}

.autocomplete-item mark {
    background: transparent;
    color: #1e40af;
    font-weight: 700;
}

/* Disabled state for search input when location filter active */
.filter-input:disabled,
.mobile-search-bar input:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
    border-color: #e2e8f0;
}

@media (max-width: 480px) {
    /* Make table scrollable horizontally if needed */
    .content-section {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .rankings-table {
        min-width: 500px;
    }

    /* Or convert to card view automatically */
    .rankings-table.mobile-cards {
        display: block;
        min-width: auto;
    }

    .rankings-table.mobile-cards thead {
        display: none;
    }

    .rankings-table.mobile-cards tbody,
    .rankings-table.mobile-cards tr {
        display: block;
    }

    .rankings-table.mobile-cards tr {
        background: #f9fafb;
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 12px;
        border: 1px solid #e5e7eb;
    }

    .rankings-table.mobile-cards td {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border: none;
        border-bottom: 1px solid #e5e7eb;
    }

    .rankings-table.mobile-cards td:last-child {
        border-bottom: none;
    }

    .rankings-table.mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #64748b;
        font-size: 0.75rem;
        text-transform: uppercase;
    }
}
