/**
 * CCM Suburbs Lookup Styles
 * Professional styling consistent with other CCM Resource Tools
 * Bootstrap-compatible version - Fully Responsive
 *
 * @package CCMResourceTools
 * @version 2.1.0
 */

/* CRITICAL: Force hide desktop-only columns on mobile (must be at top for priority) */
@media (max-width: 767.98px) {
    .desktop-only-col {
        display: none !important;
        visibility: hidden !important;
        width: 0 !important;
        max-width: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        overflow: hidden !important;
    }
    
    th.desktop-only-col,
    td.desktop-only-col {
        display: none !important;
        visibility: hidden !important;
    }
}

/* Global overflow prevention */
html {
    overflow-x: hidden;
}

body {
    overflow-x: hidden;
}

/* Disable any responsive table labeling from DataTables or Bootstrap */
table.ccm-suburbs-table tbody td::before,
table.ccm-suburbs-table tbody th::before,
.ccm-suburbs-table tbody td::before,
.ccm-suburbs-table tbody th::before,
.dataTable tbody td::before,
.dataTable tbody th::before {
    content: none !important;
    display: none !important;
}

/* Main Container - matches other resource tools */
.ccm-resource-tools-wrapper.resource-tools-suburbs {
    max-width: 100%;
    margin: 0 auto;
    width: 100%;
}

/* Header Styling */
.ccm-suburbs-header {
    text-align: center;
    padding: 0 1rem;
}

.ccm-suburbs-meta i {
    margin-right: 5px;
    color: #007bff;
}

/* Search Card Container */
.ccm-suburbs-search-container {
    max-width: 800px;
    border-radius: 20px;
    overflow: visible;
}

@media (max-width: 767.98px) {
    .ccm-suburbs-search-container {
        margin-left: 0.5rem !important;
        margin-right: 0.5rem !important;
        border-radius: 12px;
    }
}

/* Search Card Collapse */
.ccm-suburbs-search-card.collapsed {
    display: none;
}

/* Ensure all form elements stay within bounds */
.ccm-suburbs-search-card .form-control,
.ccm-suburbs-search-card .form-select,
.ccm-suburbs-search-card input,
.ccm-suburbs-search-card select {
    max-width: 100%;
    box-sizing: border-box;
}

/* Prevent alert boxes from expanding container */
#ccm-suburb-note,
#ccm-draw-instructions {
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Form Icon Colors */
.form-label i,
label i,
.col-form-label i {
    margin-right: 5px;
    color: #007bff;
}

/* Results wrapper with max-width on desktop */
.ccm-results-wrapper {
    max-width: 800px;
    width: 100%;
}

@media (max-width: 767.98px) {
    .ccm-results-wrapper {
        max-width: 100%;
    }
}

/* Results Actions */
.ccm-results-actions {
    display: flex;
    gap: 0.5rem;
    overflow: visible;
}

@media (max-width: 575.98px) {
    .ccm-results-actions {
        flex-direction: column;
    }
    
    .ccm-results-actions .btn {
        width: 100%;
    }
}

@media (min-width: 576px) {
    .ccm-results-actions {
        flex-direction: row;
        justify-content: flex-end;
        flex-wrap: nowrap;
    }
    
    .ccm-results-actions .btn {
        width: auto;
        white-space: nowrap;
        flex-shrink: 0;
        overflow: visible;
        text-overflow: clip;
    }
}

/* Suburb name cells with tooltips */
.suburb-name-cell {
    color: #0066cc;
    cursor: help;
    position: relative;
}

.suburb-name-cell:hover {
    text-decoration: underline;
}

/* Results Table Styling */
.ccm-suburbs-table {
    font-size: 0.95rem !important;
    margin-bottom: 0;
    width: 100% !important;
    display: table !important; /* Force table display */
}

.ccm-suburbs-table thead {
    display: table-header-group !important;
}

.ccm-suburbs-table tbody {
    display: table-row-group !important;
}

.ccm-suburbs-table tr {
    display: table-row !important;
}

.ccm-suburbs-table th,
.ccm-suburbs-table td {
    display: table-cell !important;
    font-size: 0.95rem !important;
    padding: 0.75rem 0.5rem !important;
    vertical-align: middle;
    white-space: nowrap;
    text-align: left !important; /* Align all columns left */
}

.ccm-suburbs-table thead th {
    background-color: #f8f9fa;
    font-weight: 600;
    border-bottom: 2px solid #dee2e6;
    position: sticky;
    top: 0;
    z-index: 10;
    text-align: left !important; /* Align all headings left */
}

/* Desktop-only columns - hidden on mobile */
@media (max-width: 767.98px) {
    /* Hide all columns with desktop-only-col class with maximum specificity */
    .ccm-suburbs-table th.desktop-only-col,
    .ccm-suburbs-table td.desktop-only-col,
    table.ccm-suburbs-table th.desktop-only-col,
    table.ccm-suburbs-table td.desktop-only-col,
    .table.ccm-suburbs-table th.desktop-only-col,
    .table.ccm-suburbs-table td.desktop-only-col {
        display: none !important;
        visibility: hidden !important;
    }
    
    /* Ensure remaining columns still display as table cells */
    .ccm-suburbs-table th:not(.desktop-only-col),
    .ccm-suburbs-table td:not(.desktop-only-col) {
        display: table-cell !important;
    }
    
    /* Remove any pseudo-elements that might add content */
    .ccm-suburbs-table th::before,
    .ccm-suburbs-table th::after,
    .ccm-suburbs-table td::before,
    .ccm-suburbs-table td::after {
        content: none !important;
        display: none !important;
    }
    
    /* Mobile table - no horizontal scroll needed for 3 columns */
    .table-responsive table {
        min-width: auto !important;
    }
    
    /* Allow wrapping for suburb names on mobile */
    .ccm-suburbs-table th,
    .ccm-suburbs-table td {
        white-space: normal;
        word-wrap: break-word;
    }
    
    /* Keep state code and postcode nowrap */
    .ccm-suburbs-table td:nth-child(2),
    .ccm-suburbs-table td:nth-child(3) {
        white-space: nowrap;
    }
}

/* Map Styling */
.ccm-suburbs-map {
    width: 100%;
    z-index: 1;
}

.ccm-suburbs-map .leaflet-container {
    font-family: inherit;
}

/* DataTables - Keep pagination inline */
.dataTables_wrapper {
    width: 100%;
    max-width: 100%;
}

.dataTables_wrapper .dataTables_paginate .pagination {
    display: flex !important;
    flex-wrap: wrap !important;
    margin: 0 !important;
    gap: 0.25rem !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    display: inline-block !important;
    padding: 0 !important;
    margin: 0 !important;
    font-size: 0.85rem !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button a {
    padding: 0.375rem 0.75rem !important;
    margin: 0 !important;
    font-size: 0.85rem !important;
}

.dataTables_wrapper .row:last-child {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: space-between !important;
    align-items: center !important;
    margin-top: 1rem !important;
    margin-bottom: 0 !important;
}

.dataTables_wrapper .dataTables_info {
    padding-top: 0 !important;
    font-size: 0.85rem !important;
    margin-bottom: 0.5rem !important;
}

.dataTables_wrapper .dataTables_paginate {
    margin-top: 0 !important;
}

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    font-size: 0.9rem;
}

.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
    font-size: 0.9rem;
    padding: 0.25rem 0.5rem;
}

.dataTables_wrapper .row:first-child {
    margin-bottom: 0.75rem;
}

/* DataTables mobile responsiveness */
@media (max-width: 575.98px) {
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        text-align: center;
        margin-bottom: 0.5rem;
    }
    
    .dataTables_wrapper .dataTables_info {
        text-align: center;
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .dataTables_wrapper .dataTables_paginate {
        text-align: center;
        width: 100%;
    }
    
    .dataTables_wrapper .dataTables_paginate .pagination {
        justify-content: center !important;
    }
    
    .dataTables_wrapper .dataTables_paginate .paginate_button a {
        padding: 0.25rem 0.5rem !important;
        font-size: 0.75rem !important;
    }
}

/* Keep table responsive */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
}

/* Prevent table from breaking layout */
.table-responsive table {
    margin-bottom: 0;
    min-width: 600px; /* Minimum width for usability on desktop */
}

/* Override DataTables responsive classes that might interfere */
.ccm-suburbs-table.dataTable {
    display: table !important;
}

.ccm-suburbs-table.dataTable thead,
.ccm-suburbs-table.dataTable tbody,
.ccm-suburbs-table.dataTable tfoot {
    display: table-row-group !important;
}

.ccm-suburbs-table.dataTable thead {
    display: table-header-group !important;
}

.ccm-suburbs-table.dataTable tr {
    display: table-row !important;
}

.ccm-suburbs-table.dataTable th,
.ccm-suburbs-table.dataTable td {
    display: table-cell !important;
}

/* Remove any ::before or ::after content that might add labels/colons */
.ccm-suburbs-table td::before,
.ccm-suburbs-table td::after,
.ccm-suburbs-table th::before,
.ccm-suburbs-table th::after {
    content: none !important;
    display: none !important;
}

/* Override Bootstrap responsive table styles */
.table-responsive .ccm-suburbs-table td::before,
.table-responsive .ccm-suburbs-table td::after {
    content: none !important;
    display: none !important;
}

/* Disable responsive table card mode */
@media (max-width: 767.98px) {
    .table-responsive .ccm-suburbs-table,
    .table-responsive .ccm-suburbs-table thead,
    .table-responsive .ccm-suburbs-table tbody,
    .table-responsive .ccm-suburbs-table th,
    .table-responsive .ccm-suburbs-table td,
    .table-responsive .ccm-suburbs-table tr {
        display: table !important;
    }
    
    .table-responsive .ccm-suburbs-table thead {
        display: table-header-group !important;
    }
    
    .table-responsive .ccm-suburbs-table tbody {
        display: table-row-group !important;
    }
    
    .table-responsive .ccm-suburbs-table tr {
        display: table-row !important;
    }
    
    .table-responsive .ccm-suburbs-table th,
    .table-responsive .ccm-suburbs-table td {
        display: table-cell !important;
    }
}

/* Hide DataTables responsive control column if it appears */
.ccm-suburbs-table td.dtr-control,
.ccm-suburbs-table th.dtr-control,
.ccm-suburbs-table td.control,
.ccm-suburbs-table th.control {
    display: none !important;
}

/* Hide child row details */
.ccm-suburbs-table tr.child {
    display: none !important;
}

/* Responsive adjustments */
@media (max-width: 767.98px) {
    /* Main container padding */
    .ccm-resource-tools-wrapper.resource-tools-suburbs {
        padding: 0;
    }
    
    /* Container fluid adjustments */
    .container-fluid {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
    
    /* Search form card - adjust padding */
    .ccm-suburbs-search-container {
        padding: 1rem !important;
    }
    
    /* Remove min-width on mobile for 3-column table */
    .table-responsive table {
        min-width: 100% !important;
    }
    
    /* FORCE HIDE desktop-only columns on mobile with maximum specificity */
    .ccm-suburbs-table.table th.desktop-only-col,
    .ccm-suburbs-table.table td.desktop-only-col,
    table.ccm-suburbs-table th.desktop-only-col,
    table.ccm-suburbs-table td.desktop-only-col,
    .table-responsive .ccm-suburbs-table th.desktop-only-col,
    .table-responsive .ccm-suburbs-table td.desktop-only-col,
    .ccm-suburbs-table thead th.desktop-only-col,
    .ccm-suburbs-table tbody td.desktop-only-col,
    th.desktop-only-col,
    td.desktop-only-col {
        display: none !important;
        visibility: hidden !important;
        width: 0 !important;
        height: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
    }
    
    /* Table styling for mobile (3 columns only) */
    .ccm-suburbs-table {
        font-size: 0.875rem !important;
    }
    
    .ccm-suburbs-table th,
    .ccm-suburbs-table td {
        font-size: 0.875rem !important;
        padding: 0.6rem 0.4rem !important;
        text-align: left !important; /* Ensure left alignment on mobile */
    }
    
    /* First column (suburb name) takes more space */
    .ccm-suburbs-table th:nth-child(1),
    .ccm-suburbs-table td:nth-child(1) {
        width: 50%;
    }
    
    /* State code and postcode columns - also left aligned */
    .ccm-suburbs-table th:nth-child(2),
    .ccm-suburbs-table td:nth-child(2),
    .ccm-suburbs-table th:nth-child(3),
    .ccm-suburbs-table td:nth-child(3) {
        width: 25%;
        text-align: left !important;
    }
    
    /* Map height adjustment */
    .ccm-suburbs-map {
        height: 300px !important;
    }
    
    /* Form controls - full width on mobile */
    .form-control,
    .form-select {
        font-size: 16px !important; /* Prevents zoom on iOS */
    }
    
    /* Button styling */
    .btn-sm {
        font-size: 0.875rem;
        padding: 0.375rem 0.75rem;
        white-space: nowrap;
    }
    
    /* Ensure no horizontal overflow */
    .row {
        margin-left: 0;
        margin-right: 0;
    }
    
    .col-12, .col-sm-9, .col-sm-3 {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

/* Extra small devices (phones in portrait, less than 576px) */
@media (max-width: 575.98px) {
    /* Header text size */
    .ccm-suburbs-header h2 {
        font-size: 1.25rem;
    }
    
    .ccm-suburbs-header p {
        font-size: 0.875rem;
    }
    
    .ccm-suburbs-meta {
        font-size: 0.75rem;
    }
    
    /* Results info */
    .ccm-results-info h3 {
        font-size: 1.1rem;
    }
    
    /* Table adjustments for very small screens */
    .ccm-suburbs-table {
        font-size: 0.8rem !important;
    }
    
    .ccm-suburbs-table th,
    .ccm-suburbs-table td {
        font-size: 0.8rem !important;
        padding: 0.5rem 0.3rem !important;
    }
    
    /* Ensure icons don't break layout */
    .fa-light,
    .fa-solid {
        font-size: 0.85em;
        margin-right: 0.25rem;
    }
    
    /* Compact buttons */
    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
}

/* Landscape phone orientation */
@media (max-width: 767px) and (orientation: landscape) {
    .ccm-suburbs-map {
        height: 250px !important;
    }
}

/* Tablet devices (768px to 991px) */
@media (min-width: 768px) and (max-width: 991.98px) {
    .ccm-suburbs-table {
        font-size: 0.875rem !important;
    }
    
    .ccm-suburbs-table th,
    .ccm-suburbs-table td {
        font-size: 0.875rem !important;
        padding: 0.6rem 0.4rem !important;
    }
}

/* Medium and larger devices */
@media (min-width: 992px) {
    .ccm-suburbs-table th,
    .ccm-suburbs-table td {
        padding: 0.75rem 0.5rem !important;
    }
}

/* ====================================
   Custom Searchable Dropdown (Select2-like)
   ==================================== */

.ccm-searchable-dropdown {
    position: relative;
    width: 100%;
    max-width: 100%;
}

.ccm-dropdown-input-wrapper {
    position: relative;
    width: 100%;
}

.ccm-dropdown-input {
    width: 100%;
    padding-right: 35px !important;
    cursor: pointer;
    box-sizing: border-box;
}

.ccm-dropdown-input:focus {
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.ccm-dropdown-arrow {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
    pointer-events: none;
    transition: transform 0.2s ease;
}

.ccm-searchable-dropdown.active .ccm-dropdown-arrow {
    transform: translateY(-50%) rotate(180deg);
}

.ccm-dropdown-loading {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #007bff;
    pointer-events: none;
}

.ccm-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ced4da;
    border-top: none;
    border-radius: 0 0 0.25rem 0.25rem;
    max-height: 300px;
    overflow-y: auto;
    z-index: 9999;
    display: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-top: -1px;
    width: 100%;
}

.ccm-searchable-dropdown.active .ccm-dropdown-menu {
    display: block;
}

.ccm-dropdown-options {
    list-style: none;
    padding: 0;
    margin: 0;
}

.ccm-dropdown-option {
    padding: 10px 15px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    border-bottom: 1px solid #f0f0f0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.ccm-dropdown-option:last-child {
    border-bottom: none;
}

.ccm-dropdown-option:hover,
.ccm-dropdown-option.highlighted {
    background-color: #f8f9fa;
}

.ccm-dropdown-option.selected {
    background-color: #e7f3ff;
    color: #007bff;
    font-weight: 500;
}

.ccm-dropdown-option.selected::before {
    content: '\f00c';
    font-family: 'Font Awesome 6 Pro';
    font-weight: 300;
    margin-right: 8px;
    color: #007bff;
}

.ccm-dropdown-no-results {
    padding: 20px;
    text-align: center;
    color: #6c757d;
}

.ccm-dropdown-no-results i {
    display: block;
    font-size: 2rem;
    margin-bottom: 10px;
    opacity: 0.5;
}

/* Loading state */
.ccm-searchable-dropdown.loading .ccm-dropdown-arrow {
    display: none;
}

.ccm-searchable-dropdown.loading .ccm-dropdown-loading {
    display: block;
}

/* Disabled state */
.ccm-searchable-dropdown.disabled .ccm-dropdown-input {
    background-color: #e9ecef;
    cursor: not-allowed;
}

/* Focus state */
.ccm-searchable-dropdown.active .ccm-dropdown-input {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-color: #80bdff;
}

/* Keyboard navigation highlight */
.ccm-dropdown-option.keyboard-focus {
    background-color: #e7f3ff;
    outline: 2px solid #007bff;
    outline-offset: -2px;
}

/* Scrollbar styling for dropdown */
.ccm-dropdown-menu::-webkit-scrollbar {
    width: 8px;
}

.ccm-dropdown-menu::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.ccm-dropdown-menu::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.ccm-dropdown-menu::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Mobile responsiveness for dropdown */
@media (max-width: 575.98px) {
    .ccm-dropdown-menu {
        max-height: 200px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .ccm-dropdown-option {
        padding: 12px 15px;
        font-size: 0.95rem;
    }
    
    .ccm-dropdown-input {
        font-size: 16px !important; /* Prevent zoom on iOS */
    }
}

/* ============================================
   Modal Styles for Save Map URL
   ============================================ */

.ccm-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 1rem;
}

.ccm-modal-content {
    background: white;
    border-radius: 8px;
    max-width: 600px;
    width: 100%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ccm-modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ccm-modal-header h4 {
    margin: 0;
    font-size: 1.25rem;
    color: #212529;
}

.ccm-modal-header h4 i {
    margin-right: 0.5rem;
    color: #0d6efd;
}

.ccm-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6c757d;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s, color 0.2s;
}

.ccm-modal-close:hover {
    background-color: #f8f9fa;
    color: #212529;
}

.ccm-modal-body {
    padding: 1.5rem;
}

.ccm-modal-body .input-group {
    margin-bottom: 1rem;
}

.ccm-modal-body input[type="text"] {
    font-family: monospace;
    font-size: 0.875rem;
}

/* Mobile responsiveness for modal */
@media (max-width: 575.98px) {
    .ccm-modal-content {
        margin: 1rem;
        max-width: calc(100% - 2rem);
    }
    
    .ccm-modal-header,
    .ccm-modal-body {
        padding: 1rem;
    }
    
    .ccm-modal-body input[type="text"] {
        font-size: 0.75rem;
    }
}
