/**
 * Frontend styles for Company Directory plugin.
 *
 * @package CompanyDirectory
 */

/* ==========================================================================
   Wrapper - Complete Theme Isolation
   ========================================================================== */

.company-directory-wrapper {
    clear: both;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
}

/* ==========================================================================
   Reset and Isolation - Prevent WordPress Theme Conflicts
   ========================================================================== */

.company-directory-frontend {
    display: block;
    margin: 30px auto;
    max-width: 100%;
    width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #1f2937;
    box-sizing: border-box;
    background: transparent;
    position: relative;
}

/* Ensure all child elements use border-box and reset margins/paddings */
.company-directory-frontend *,
.company-directory-frontend *::before,
.company-directory-frontend *::after {
    box-sizing: border-box;
}

.company-directory-frontend > * {
    margin-top: 0;
    margin-bottom: 20px;
}

.company-directory-frontend > *:last-child {
    margin-bottom: 0;
}

/* ==========================================================================
   Filters Section - Hidden (Feature Removed)
   ========================================================================== */

.cd-filters {
    display: none;
}

.cd-search-box {
    display: flex;
    flex: 1 1 auto;
    min-width: 180px;
    max-width: 280px;
}

.cd-search-input {
    flex: 1;
    padding: 7px 11px;
    border: 1px solid #d1d5db;
    border-right: none;
    border-radius: 6px 0 0 6px;
    font-size: 13px;
    outline: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.cd-search-input:hover {
    border-color: #9ca3af;
}

.cd-search-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1), 0 1px 2px rgba(0, 0, 0, 0.05);
    background: #ffffff;
}

.cd-search-input::placeholder {
    color: #9ca3af;
    font-size: 12px;
}

.cd-search-btn {
    padding: 7px 12px;
    background: linear-gradient(to bottom, #3b82f6 0%, #2563eb 100%);
    border: 1px solid #2563eb;
    border-radius: 0 6px 6px 0;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}

.cd-search-btn:hover {
    background: linear-gradient(to bottom, #2563eb 0%, #1d4ed8 100%);
    border-color: #1d4ed8;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.cd-search-btn:active {
    transform: scale(0.98);
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}

.cd-search-btn svg {
    width: 16px;
    height: 16px;
}

.cd-filter-group {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.cd-filter-select {
    padding: 7px 28px 7px 11px;
    background: linear-gradient(to bottom, #ffffff 0%, #f9fafb 100%);
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 130px;
    max-width: 160px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    appearance: none;
    background-image: 
        linear-gradient(to bottom, #ffffff 0%, #f9fafb 100%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat, no-repeat;
    background-position: left top, right 7px center;
    background-size: 100% 100%, 12px 12px;
}

.cd-filter-select:hover {
    border-color: #9ca3af;
    background: linear-gradient(to bottom, #fafafa 0%, #f3f4f6 100%);
    background-image: 
        linear-gradient(to bottom, #fafafa 0%, #f3f4f6 100%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat, no-repeat;
    background-position: left top, right 7px center;
    background-size: 100% 100%, 12px 12px;
}

.cd-filter-select:focus {
    border-color: #3b82f6;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1), 0 1px 2px rgba(0, 0, 0, 0.05);
    background-image: 
        none,
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%232563eb' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 7px center;
    background-size: 12px 12px;
}

.cd-clear-filters {
    padding: 7px 14px;
    background: linear-gradient(to bottom, #ffffff 0%, #f9fafb 100%);
    border: 1px solid #d1d5db;
    border-radius: 6px;
    color: #374151;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.cd-clear-filters:hover {
    background: linear-gradient(to bottom, #f9fafb 0%, #f3f4f6 100%);
    border-color: #9ca3af;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

.cd-clear-filters:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* ==========================================================================
   Results Info - Hidden (Feature Removed)
   ========================================================================== */

.cd-results-info {
    display: none !important;
    color: #4b5563;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.cd-total-count {
    font-weight: 700;
    color: #1f2937;
    font-size: 16px;
}

/* ==========================================================================
   Table Layout - Improved Desktop & Mobile
   ========================================================================== */

.cd-table-wrapper {
    overflow-x: auto;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.cd-table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    font-size: 15px;
    min-width: 800px;
    background: #ffffff;
}

.cd-table thead {
    background: #f3f4f6;
    border-bottom: 2px solid #d1d5db;
}

.cd-table th {
    padding: 14px 20px;
    text-align: left;
    font-weight: 600;
    color: #374151;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: all 0.2s;
    background: #f3f4f6;
    border-bottom: 2px solid #d1d5db;
}

.cd-table th:first-child {
    padding-left: 24px;
}

.cd-table th:last-child {
    padding-right: 24px;
}

.cd-table th:hover {
    background: #e5e7eb;
}

.cd-table th[data-sort] {
    padding-right: 35px;
}

.cd-sort-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid #9ca3af;
    opacity: 0.4;
    transition: all 0.2s;
}

.cd-table th:hover .cd-sort-icon {
    opacity: 0.8;
}

.cd-table th.sort-asc .cd-sort-icon {
    border-top: 6px solid #3b82f6;
    opacity: 1;
}

.cd-table th.sort-desc .cd-sort-icon {
    border-top: none;
    border-bottom: 6px solid #3b82f6;
    opacity: 1;
}

.cd-table tbody tr {
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    transition: all 0.15s;
}

.cd-table tbody tr:nth-child(even) {
    background: #f9fafb;
}

.cd-table tbody tr:hover {
    background: #f3f4f6 !important;
}

.cd-table tbody tr:last-child {
    border-bottom: none;
}

.cd-table td {
    padding: 16px 20px;
    color: #1f2937;
    vertical-align: middle;
    background: inherit;
}

.cd-table td:first-child {
    padding-left: 24px;
}

.cd-table td:last-child {
    padding-right: 24px;
}

.cd-col-no {
    width: 80px;
    font-weight: 700;
    color: #4b5563;
    font-size: 14px;
}

.cd-col-name {
    font-weight: 500;
    color: #111827;
    min-width: 250px;
}

.cd-col-commodity {
    min-width: 150px;
}

.cd-col-location {
    min-width: 200px;
    color: #4b5563;
}

.cd-badge {
    display: inline-block;
    padding: 6px 14px;
    background: #dbeafe;
    color: #1e40af;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

/* ==========================================================================
   Grid Layout
   ========================================================================== */

.cd-grid-layout {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.cd-grid-item {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 20px;
    transition: all 0.3s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.cd-grid-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.cd-grid-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.cd-grid-no {
    display: inline-block;
    width: 32px;
    height: 32px;
    background: #f3f4f6;
    border-radius: 50%;
    text-align: center;
    line-height: 32px;
    font-weight: 600;
    font-size: 14px;
    color: #6b7280;
}

.cd-grid-badge {
    display: inline-block;
    padding: 4px 12px;
    background: #dbeafe;
    color: #1e40af;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.cd-grid-title {
    margin: 0 0 12px 0;
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
    line-height: 1.4;
}

.cd-grid-location {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #6b7280;
    font-size: 14px;
}

.cd-grid-location svg {
    flex-shrink: 0;
}

/* ==========================================================================
   Pagination - Compact & Modern (Shadcn Style)
   ========================================================================== */

.cd-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
    padding: 14px 18px;
    background: linear-gradient(to bottom, #ffffff 0%, #fafafa 100%);
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
}

.cd-pagination-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: linear-gradient(to bottom, #ffffff 0%, #f9fafb 100%);
    border: 1px solid #d1d5db;
    border-radius: 6px;
    color: #374151;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 100px;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.cd-pagination-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.cd-pagination-btn:hover:not(:disabled) {
    background: linear-gradient(to bottom, #f9fafb 0%, #f3f4f6 100%);
    border-color: #3b82f6;
    color: #3b82f6;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
}

.cd-pagination-btn:hover:not(:disabled) svg {
    stroke: #3b82f6;
}

.cd-pagination-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.cd-pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #f3f4f6;
    border-color: #e5e7eb;
}

.cd-pagination-info {
    padding: 8px 18px;
    background: linear-gradient(to bottom, #f9fafb 0%, #f3f4f6 100%);
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 13px;
    color: #4b5563;
    font-weight: 500;
    min-width: 70px;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.cd-current-page {
    font-weight: 700;
    color: #1f2937;
    font-size: 15px;
}

.cd-total-pages {
    color: #6b7280;
    font-size: 13px;
}

/* ==========================================================================
   Loading State
   ========================================================================== */

.cd-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin: 20px 0;
}

.cd-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #f3f4f6;
    border-top: 4px solid #3b82f6;
    border-radius: 50%;
    animation: cd-spin 1s linear infinite;
}

@keyframes cd-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.cd-loading p {
    margin: 15px 0 0 0;
    color: #6b7280;
    font-size: 15px;
}

/* No Results */
.cd-no-results {
    text-align: center;
    padding: 60px 20px;
    color: #6b7280;
}

.cd-no-results p {
    margin: 0;
    font-size: 16px;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media screen and (max-width: 1280px) {
    .company-directory-frontend {
        margin: 20px 16px;
        padding: 0;
    }
}

@media screen and (max-width: 1024px) {
    .company-directory-frontend {
        margin: 20px auto;
        padding: 0 16px;
    }

    .cd-filters {
        flex-direction: column;
        align-items: stretch;
        padding: 10px;
        gap: 6px;
    }

    .cd-search-box {
        max-width: 100%;
        min-width: 0;
    }

    .cd-filter-group {
        width: 100%;
        flex-direction: column;
        gap: 6px;
    }

    .cd-filter-select,
    .cd-clear-filters {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    .cd-table {
        min-width: 700px;
    }
}

@media screen and (max-width: 768px) {
    .company-directory-frontend {
        margin: 16px auto;
        padding: 0 12px;
    }

    .cd-filters {
        padding: 12px;
        gap: 8px;
    }

    .cd-search-input,
    .cd-search-btn {
        padding: 8px 12px;
        font-size: 13px;
    }

    .cd-filter-select {
        padding: 8px 32px 8px 12px;
        font-size: 13px;
    }

    .cd-clear-filters {
        padding: 8px 14px;
        font-size: 13px;
    }

    /* Mobile Table - Card Style */
    .cd-table-wrapper {
        overflow-x: visible;
        border: none;
        background: transparent;
        box-shadow: none;
    }

    .cd-table {
        min-width: 0;
    }

    .cd-table thead {
        display: none;
    }

    .cd-table tbody {
        display: block;
    }

    .cd-table tbody tr {
        display: block;
        margin-bottom: 16px;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        overflow: hidden;
        background: #ffffff;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    }

    .cd-table tbody tr:last-child td:first-child,
    .cd-table tbody tr:last-child td:last-child {
        border-radius: 0;
    }

    .cd-table td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding: 14px 16px;
        border-bottom: 1px solid #f3f4f6;
    }

    .cd-table td:first-child {
        padding-left: 16px;
        background: #f9fafb;
        font-weight: 600;
    }

    .cd-table td:last-child {
        border-bottom: none;
        padding-right: 16px;
    }

    .cd-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6b7280;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        flex-shrink: 0;
        margin-right: 12px;
    }

    .cd-col-no,
    .cd-col-name,
    .cd-col-commodity,
    .cd-col-location {
        width: auto;
        min-width: 0;
        text-align: right;
    }

    .cd-col-name {
        font-size: 15px;
    }

    .cd-badge {
        font-size: 12px;
        padding: 5px 12px;
    }

    /* Mobile Grid Layout */
    .cd-grid-layout {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .cd-grid-item {
        padding: 16px;
    }

    /* Mobile Pagination */
    .cd-pagination {
        flex-wrap: wrap;
        gap: 10px;
        padding: 12px 14px;
    }

    .cd-pagination-btn {
        min-width: 0;
        flex: 1;
        padding: 10px 14px;
        font-size: 13px;
    }

    .cd-pagination-btn svg {
        width: 14px;
        height: 14px;
    }

    .cd-pagination-info {
        width: 100%;
        order: -1;
        padding: 8px 14px;
    }
}

@media screen and (max-width: 480px) {
    .cd-filters {
        padding: 10px;
    }

    .cd-search-input {
        font-size: 13px;
    }

    .cd-pagination {
        padding: 10px;
        gap: 8px;
    }

    .cd-pagination-btn {
        font-size: 12px;
        padding: 8px 10px;
        gap: 4px;
    }

    .cd-pagination-btn svg {
        width: 14px;
        height: 14px;
    }

    .cd-pagination-info {
        font-size: 12px;
        padding: 6px 12px;
    }
}

/* ==========================================================================
   WordPress Theme Compatibility & Reset Overrides
   ========================================================================== */

/* Reset WordPress theme styles that might interfere */
.company-directory-frontend h1,
.company-directory-frontend h2,
.company-directory-frontend h3,
.company-directory-frontend h4,
.company-directory-frontend h5,
.company-directory-frontend h6 {
    margin: 0;
    padding: 0;
    font-weight: 600;
    line-height: 1.2;
    color: inherit;
    background: none;
    border: none;
    text-transform: none;
    letter-spacing: normal;
}

.company-directory-frontend p {
    margin: 0;
    padding: 0;
    line-height: 1.6;
}

.company-directory-frontend a {
    color: inherit;
    text-decoration: none;
    background: none;
}

.company-directory-frontend ul,
.company-directory-frontend ol {
    list-style: none;
    margin: 0;
    padding: 0;
}

.company-directory-frontend button,
.company-directory-frontend input,
.company-directory-frontend select,
.company-directory-frontend textarea {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    outline: none;
    box-shadow: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.company-directory-frontend table {
    border-collapse: collapse;
    border-spacing: 0;
    width: 100%;
    background: none;
}

.company-directory-frontend th,
.company-directory-frontend td {
    text-align: left;
    vertical-align: top;
}

/* Prevent WordPress theme interference */
.company-directory-frontend img {
    max-width: 100%;
    height: auto;
    border: none;
}

.company-directory-frontend svg {
    display: inline-block;
    vertical-align: middle;
}

/* Override common theme resets */
.company-directory-frontend .cd-filters,
.company-directory-frontend .cd-table-wrapper,
.company-directory-frontend .cd-grid-layout,
.company-directory-frontend .cd-pagination {
    background: transparent;
    border: none;
    margin: 0;
    padding: 0;
}
