/**
 * TMS Frontend Styles — replaces Tailwind CDN (~3MB → ~12KB)
 * All rules scoped under .tms-wrap to avoid Elementor conflicts
 * Mobile-first responsive design
 *
 * SAFCEC Branding:
 *   Primary:   #0A4B47  (dark teal)
 *   Secondary: #B37629  (gold)
 */

/* =============================================
   BASE / RESET (scoped)
   ============================================= */
.tms-wrap {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    color: #333;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.tms-wrap *,
.tms-wrap *::before,
.tms-wrap *::after {
    box-sizing: inherit;
}

.tms-wrap img { max-width: 100%; height: auto; }
.tms-wrap a { color: #0A4B47; text-decoration: none; }
.tms-wrap a:hover { color: #B37629; }

/* =============================================
   LAYOUT
   ============================================= */
.tms-container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 16px;
}

@media (min-width: 768px) {
    .tms-container { padding: 0 24px; }
}

/* =============================================
   CARD
   ============================================= */
.tms-card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
    padding: 20px;
    margin-bottom: 24px;
}

@media (min-width: 768px) {
    .tms-card { padding: 28px; }
}

/* =============================================
   GRID (CSS Grid, mobile-first)
   ============================================= */
.tms-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}

.tms-grid-2 { grid-template-columns: 1fr; }
.tms-grid-3 { grid-template-columns: 1fr; }
.tms-grid-5 { grid-template-columns: 1fr; }

@media (min-width: 640px) {
    .tms-grid-2 { grid-template-columns: repeat(2, 1fr); }
    .tms-grid-3 { grid-template-columns: repeat(2, 1fr); }
    .tms-grid-5 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 768px) {
    .tms-grid-3 { grid-template-columns: repeat(3, 1fr); }
    .tms-grid-5 { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1024px) {
    .tms-grid-5 { grid-template-columns: repeat(5, 1fr); }
}

/* =============================================
   FLEX HELPERS
   ============================================= */
.tms-flex { display: flex; flex-wrap: wrap; }
.tms-flex-between { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.tms-flex-center { display: flex; align-items: center; }
.tms-gap-2 { gap: 8px; }
.tms-gap-3 { gap: 12px; }
.tms-gap-4 { gap: 16px; }

/* =============================================
   TYPOGRAPHY
   ============================================= */
.tms-wrap h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.3; margin: 0 0 8px; }
.tms-wrap h2 { font-size: 1.25rem; font-weight: 600; line-height: 1.3; margin: 0 0 8px; }
.tms-wrap h3 { font-size: 1rem;    font-weight: 600; line-height: 1.4; margin: 0 0 6px; }
.tms-wrap p  { margin: 0 0 6px; }

@media (min-width: 768px) {
    .tms-wrap h1 { font-size: 2rem; }
    .tms-wrap h2 { font-size: 1.375rem; }
}

.tms-text-primary   { color: #0A4B47; }
.tms-text-secondary { color: #B37629; }
.tms-text-muted     { color: #6b7280; }
.tms-text-sm        { font-size: 0.875rem; }
.tms-text-xs        { font-size: 0.75rem; }
.tms-text-bold      { font-weight: 700; }
.tms-text-semibold  { font-weight: 600; }
.tms-text-medium    { font-weight: 500; }
.tms-text-italic    { font-style: italic; }
.tms-text-uppercase { text-transform: uppercase; letter-spacing: 0.04em; }
.tms-text-center    { text-align: center; }

/* =============================================
   SPACING
   ============================================= */
.tms-mt-2 { margin-top: 8px; }
.tms-mt-4 { margin-top: 16px; }
.tms-mt-6 { margin-top: 24px; }
.tms-mb-2 { margin-bottom: 8px; }
.tms-mb-4 { margin-bottom: 16px; }
.tms-mb-6 { margin-bottom: 24px; }
.tms-py-6 { padding-top: 24px; padding-bottom: 24px; }
.tms-py-8 { padding-top: 32px; padding-bottom: 32px; }

/* =============================================
   BUTTONS
   ============================================= */
.tms-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.4;
    border: none;
    cursor: pointer;
    transition: background .2s, transform .15s, box-shadow .2s;
    text-decoration: none;
    white-space: nowrap;
}

.tms-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,.12);
}

.tms-btn:focus-visible {
    outline: 2px solid #0A4B47;
    outline-offset: 2px;
}
.tms-btn:active { transform: translateY(0); }
.tms-btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

.tms-btn-primary {
    background: #0A4B47;
    color: #fff !important;
}
.tms-btn-primary:hover { background: #083e3b; color: #fff !important; }

.tms-btn-secondary {
    background: #B37629;
    color: #fff !important;
}
.tms-btn-secondary:hover { background: #9a6623; color: #fff !important; }

.tms-btn-danger {
    background: #dc2626;
    color: #fff !important;
}
.tms-btn-danger:hover { background: #b91c1c; color: #fff !important; }

.tms-btn-outline {
    background: transparent;
    color: #6b7280 !important;
    border: 1px solid #d1d5db;
}
.tms-btn-outline:hover { background: #f3f4f6; color: #374151 !important; }

.tms-btn-sm { padding: 6px 14px; font-size: 0.8125rem; }
.tms-btn-block { width: 100%; }

@media (max-width: 639px) {
    .tms-btn { padding: 10px 16px; font-size: 0.8125rem; }
}

/* =============================================
   STATUS BADGES
   ============================================= */
.tms-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 12px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.5;
    white-space: nowrap;
}

.tms-badge-open       { background: #dcfce7; color: #166534; }
.tms-badge-closed     { background: #fee2e2; color: #991b1b; }
.tms-badge-awarded    { background: #dbeafe; color: #1e40af; }
.tms-badge-cancelled  { background: #f3f4f6; color: #4b5563; }

.tms-banner {
    display: inline-block;
    padding: 6px 16px;
    border-radius: 6px;
    border: 1px solid;
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tms-banner-open      { background: #dcfce7; color: #166534; border-color: #86efac; }
.tms-banner-closed    { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.tms-banner-awarded   { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.tms-banner-cancelled { background: #f3f4f6; color: #4b5563; border-color: #d1d5db; }

/* =============================================
   FORMS
   ============================================= */
.tms-input,
.tms-select {
    display: block;
    width: 100%;
    padding: 9px 12px;
    font-size: 0.875rem;
    line-height: 1.5;
    color: #374151;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
}

.tms-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.tms-input:focus,
.tms-select:focus {
    outline: none;
    border-color: #0A4B47;
    box-shadow: 0 0 0 3px rgba(10, 75, 71, .15);
}

.tms-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 4px;
}

.tms-checkbox-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.tms-checkbox-wrap input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #0A4B47;
    cursor: pointer;
}

/* =============================================
   INFO CARDS (single tender sections)
   ============================================= */
.tms-info-card {
    background: #f9fafb;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
}

.tms-info-card p {
    margin: 0 0 6px;
    font-size: 0.9rem;
}

.tms-info-card p:last-child { margin-bottom: 0; }

.tms-info-card strong {
    color: #0A4B47;
}

/* =============================================
   BREADCRUMB
   ============================================= */
.tms-breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    color: #6b7280;
    margin-bottom: 16px;
}

.tms-breadcrumb a { color: #6b7280; }
.tms-breadcrumb a:hover { color: #0A4B47; }
.tms-breadcrumb-sep { color: #9ca3af; }
.tms-breadcrumb-current { color: #374151; font-weight: 500; }

/* =============================================
   DOCUMENT CARD
   ============================================= */
.tms-doc-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: #f9fafb;
    padding: 14px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    transition: border-color .15s, box-shadow .15s;
}

.tms-doc-card:hover {
    border-color: #0A4B47;
    box-shadow: 0 2px 6px rgba(10, 75, 71, .08);
}

.tms-doc-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    color: #0A4B47;
}

.tms-doc-meta {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 2px;
}

/* =============================================
   CONTACT CARD
   ============================================= */
.tms-contact-card {
    background: #f9fafb;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.tms-contact-card h3 { margin-bottom: 8px; }

.tms-contact-card a {
    color: #0A4B47;
    word-break: break-all;
}

.tms-contact-card a:hover { color: #B37629; }

/* =============================================
   MESSAGES / ALERTS
   ============================================= */
.tms-alert {
    padding: 12px 16px;
    border-radius: 6px;
    border: 1px solid;
    font-size: 0.875rem;
    line-height: 1.5;
}

.tms-alert-success { background: #dcfce7; color: #166534; border-color: #86efac; }
.tms-alert-error   { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.tms-alert-warning { background: #fef9c3; color: #854d0e; border-color: #fde68a; }

.tms-alert-dismiss {
    float: right;
    background: none;
    border: none;
    font-size: 1.125rem;
    font-weight: 700;
    cursor: pointer;
    opacity: .6;
    line-height: 1;
    margin-left: 12px;
}

.tms-alert-dismiss:hover { opacity: 1; }

/* =============================================
   SUBSCRIPTION FORM
   ============================================= */
.tms-subscription-form {
    max-width: 640px;
}

.tms-subscription-form .tms-categories-list {
    max-height: 300px;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fafafa;
}

/* =============================================
   DATATABLE OVERRIDES (scoped)
   ============================================= */
.tms-wrap .dataTables_wrapper {
    font-size: 0.875rem;
}

.tms-wrap .dataTables_wrapper .dataTables_filter input {
    padding: 6px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
    margin-left: 8px;
}

.tms-wrap .dataTables_wrapper .dataTables_filter input:focus {
    outline: none;
    border-color: #0A4B47;
    box-shadow: 0 0 0 3px rgba(10, 75, 71, .15);
}

.tms-wrap .dataTables_wrapper .dataTables_length select {
    padding: 4px 28px 4px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
}

.tms-wrap table.dataTable {
    border-collapse: collapse !important;
    width: 100% !important;
    margin: 0 !important;
}

.tms-wrap table.dataTable thead th {
    background: #0A4B47;
    color: #fff;
    padding: 10px 14px;
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 2px solid #083e3b;
    white-space: nowrap;
}

.tms-wrap table.dataTable thead th:first-child { border-radius: 6px 0 0 0; }
.tms-wrap table.dataTable thead th:last-child  { border-radius: 0 6px 0 0; }

.tms-wrap table.dataTable tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
    font-size: 0.875rem;
}

.tms-wrap table.dataTable tbody tr:hover td {
    background: #f0fdfa;
}

.tms-wrap table.dataTable tbody tr:nth-child(even) td {
    background: #fafbfc;
}

.tms-wrap table.dataTable tbody tr:nth-child(even):hover td {
    background: #f0fdfa;
}

/* DataTables responsive child rows */
.tms-wrap table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control::before,
.tms-wrap table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control::before {
    background-color: #0A4B47 !important;
    border: none !important;
    box-shadow: 0 1px 3px rgba(0,0,0,.15);
}

.tms-wrap table.dataTable > tbody > tr.child ul.dtr-details {
    width: 100%;
}

.tms-wrap table.dataTable > tbody > tr.child ul.dtr-details > li {
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
}

.tms-wrap .dataTables_wrapper .dataTables_paginate .paginate_button.current,
.tms-wrap .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: #0A4B47 !important;
    color: #fff !important;
    border-color: #0A4B47 !important;
    border-radius: 4px;
}

.tms-wrap .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: #f3f4f6 !important;
    color: #0A4B47 !important;
    border-color: #d1d5db !important;
    border-radius: 4px;
}

.tms-wrap .dataTables_wrapper .dataTables_info {
    font-size: 0.8125rem;
    color: #6b7280;
    padding-top: 12px;
}

/* =============================================
   TABLE RESPONSIVE: HIDE COLUMNS ON SMALL
   On mobile, DataTables responsive collapses
   columns with responsive priority.
   These priority classes hide less-important
   columns first.
   ============================================= */
@media (max-width: 767px) {
    .tms-wrap .tms-filters-bar {
        flex-direction: column;
    }

    .tms-wrap .tms-filters-bar .tms-btn {
        width: 100%;
    }
}

/* =============================================
   LOADING SPINNER
   ============================================= */
@keyframes tms-spin {
    to { transform: rotate(360deg); }
}

.tms-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: tms-spin .6s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@media (prefers-reduced-motion: reduce) {
    .tms-spinner {
        animation: none;
        border-top-color: #fff;
        opacity: 0.7;
    }
}

/* =============================================
   HIDDEN UTILITY
   ============================================= */
.tms-hidden { display: none !important; }
.tms-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* =============================================
   ACCESSIBILITY — FOCUS STATES
   ============================================= */
.tms-wrap a:focus-visible {
    outline: 2px solid #0A4B47;
    outline-offset: 2px;
    border-radius: 2px;
}

.tms-wrap .tms-doc-card:focus-visible {
    outline: 2px solid #0A4B47;
    outline-offset: 2px;
}

.tms-wrap .tms-alert-dismiss:focus-visible {
    outline: 2px solid #991b1b;
    outline-offset: 1px;
    border-radius: 2px;
}

.tms-wrap .tms-select:focus-visible {
    outline: none;
    border-color: #0A4B47;
    box-shadow: 0 0 0 3px rgba(10, 75, 71, .15);
}

.tms-checkbox-wrap input[type="checkbox"]:focus-visible {
    outline: 2px solid #0A4B47;
    outline-offset: 2px;
}

/* =============================================
   ACCESSIBILITY — TOUCH TARGETS (44x44px min)
   ============================================= */
@media (pointer: coarse) {
    .tms-btn {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
    }

    .tms-btn-sm {
        min-height: 44px;
        padding: 10px 16px;
    }

    .tms-select,
    .tms-input {
        min-height: 44px;
        padding: 10px 12px;
    }

    .tms-checkbox-wrap {
        min-height: 44px;
        padding: 8px 0;
    }

    .tms-checkbox-wrap input[type="checkbox"] {
        width: 20px;
        height: 20px;
    }

    .tms-alert-dismiss {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* =============================================
   ACCESSIBILITY — HIGH CONTRAST
   ============================================= */
@media (prefers-contrast: more) {
    .tms-wrap {
        --tms-border: 2px solid #000;
    }

    .tms-card {
        border: 2px solid #333;
    }

    .tms-info-card {
        border: 2px solid #333;
    }

    .tms-badge {
        border: 1px solid currentColor;
    }

    .tms-input,
    .tms-select {
        border-width: 2px;
    }

    .tms-btn {
        border: 2px solid transparent;
    }

    .tms-btn-outline {
        border-width: 2px;
    }

    .tms-wrap a {
        text-decoration: underline;
    }
}

/* =============================================
   ELEMENTOR COMPAT
   Elementor adds its own container, so we
   make sure our wrapper doesn't fight it.
   ============================================= */
.elementor-widget-shortcode .tms-wrap,
.elementor-widget-text-editor .tms-wrap {
    max-width: 100%;
}

.elementor-section .tms-wrap .tms-card {
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

/* Fix Elementor's global link colors bleeding in */
.elementor-widget .tms-wrap a { color: #0A4B47; }
.elementor-widget .tms-wrap a:hover { color: #B37629; }
.elementor-widget .tms-wrap .tms-btn-primary,
.elementor-widget .tms-wrap .tms-btn-primary:hover { color: #fff !important; }
.elementor-widget .tms-wrap .tms-btn-secondary,
.elementor-widget .tms-wrap .tms-btn-secondary:hover { color: #fff !important; }
.elementor-widget .tms-wrap .tms-btn-danger,
.elementor-widget .tms-wrap .tms-btn-danger:hover { color: #fff !important; }

/* Fix Elementor column padding fights */
.elementor-widget .tms-wrap .tms-grid {
    margin-left: 0;
    margin-right: 0;
}

/* =============================================
   PRINT
   ============================================= */
@media print {
    .tms-wrap .tms-btn,
    .tms-wrap .tms-filters-bar,
    .tms-wrap .dataTables_filter,
    .tms-wrap .dataTables_length,
    .tms-wrap .dataTables_paginate,
    .tms-wrap .dataTables_info,
    .tms-wrap .tms-subscription-form,
    .tms-wrap .tms-alert-dismiss { display: none !important; }

    .tms-wrap { color: #000 !important; }
    .tms-wrap a { color: #000 !important; text-decoration: underline !important; }

    .tms-wrap .tms-card {
        box-shadow: none !important;
        border: 1px solid #ccc;
        break-inside: avoid;
    }

    .tms-wrap .tms-info-card {
        box-shadow: none !important;
        border: 1px solid #ccc;
        break-inside: avoid;
    }

    .tms-wrap table.dataTable thead th {
        background: #eee !important;
        color: #000 !important;
        border: 1px solid #999;
    }

    .tms-wrap table.dataTable tbody td {
        border: 1px solid #ddd;
    }

    .tms-wrap .tms-badge {
        border: 1px solid currentColor;
    }

    .tms-wrap .tms-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}
