/* =================================================================
   TTI PROGRAM INDEX - Dedicated Styles
   ================================================================= */

/* =================================================================
   GLOBAL & SHARED STYLES (scoped to TTI index)
   ================================================================= */

/* Hides the default dropdown arrow for operator sections only */
.tti-program-index-wrapper summary::-webkit-details-marker,
.tti-program-index-wrapper summary::marker {
    display: none;
}

/* Fallback to ensure no list-style icon appears in operator sections */
.tti-program-index-wrapper summary {
    list-style: none;
}

/* Show/Hide text based on details open/closed state */
.tti-program-index-wrapper .closed-text {
    display: inline;
}

.tti-program-index-wrapper .open-text {
    display: none;
}

.tti-program-index-wrapper details[open] > summary .closed-text {
    display: none;
}

.tti-program-index-wrapper details[open] > summary .open-text {
    display: inline;
}

/* =================================================================
   TTI PROGRAM INDEX CONTAINER
   ================================================================= */

.tti-program-index-wrapper {
    font-family: sans-serif;
    font-size: 17px;
    line-height: 1.6;
    max-width: 900px;
    margin: 0 auto;
}

.tti-program-index-wrapper h1,
.tti-program-index-wrapper h2,
.tti-program-index-wrapper h4 {
    font-family: sans-serif;
    margin: 0;
}

/* --- Alphabet Filter (Navy Blue Theme) --- */
#alphabet-filter {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 2em;
    padding-bottom: 1.5em;
    border-bottom: 1px solid #dddddd;
}

#alphabet-filter button {
    padding: 8px 15px;
    text-decoration: none;
    background-color: #00004d;
    color: #ffffff;
    border: 1px solid #dddddd;
    border-radius: 4px;
    font-weight: bold;
    transition: all 0.2s ease;
    cursor: pointer;
}

#alphabet-filter button.active {
    background-color: #00004d;
    color: #ffffff;
    border-color: #dddddd;
}

/* Facility card text colors - WHITE backgrounds get BLACK text */
.tti-program-index-wrapper .facility-card,
.tti-program-index-wrapper .facility-card *,
.tti-program-index-wrapper .facility-card p,
.tti-program-index-wrapper .facility-card span,
.tti-program-index-wrapper .facility-card div {
    color: #000000 !important;
}

.tti-program-index-wrapper .facility-card .facility-details p {
    color: #000000 !important;
}

.tti-program-index-wrapper .facility-card .facility-details strong {
    color: #333333 !important;
}

.tti-program-index-wrapper .facility-card .facility-name {
    color: #000000 !important;
}

/* =================================================================
   FACILITY DIRECTORY
   ================================================================= */

.facility-card {
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #FFFFFF 0%, #FFF5CB 100%);
    color: #000000;
    word-wrap: break-word;
    border: 5px solid #e0e0e0;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.facility-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
}

.facility-card.status-open {
    border-color: #d45500; /* Accessible orange */
    border-left-width: 8px;
    background: linear-gradient(135deg, #FFFFFF 0%, #FFF0E6 100%);
}

.facility-card.status-transferred {
    border-color: #5a5a5a; /* Accessible gray */
    border-left-width: 8px;
    background: linear-gradient(135deg, #FFFFFF 0%, #F5F5F5 100%);
}

.facility-card.status-closed {
    border-color: #0d7a8a; /* Accessible teal */
    border-left-width: 8px;
    background: linear-gradient(135deg, #FFFFFF 0%, #E6F7F9 100%);
}

.facility-card.status-unknown {
    border-color: #767676; /* Accessible gray */
    border-left-width: 8px;
    background: linear-gradient(135deg, #FFFFFF 0%, #F9F9F9 100%);
}

/* =================================================================
   FACILITIES GRID & OPERATORS
   ================================================================= */

.facilities-database {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    max-width: 100%;
    margin: 0 auto;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(auto-fill, 220px);
    justify-content: center;
    gap: 20px;
    grid-auto-rows: auto;
    align-items: start;
}

.controls {
    margin-bottom: 20px;
    padding: 15px;
    background: linear-gradient(135deg, #FFF5CB 0%, #AEE0ED 100%);
    border-radius: 8px;
    border: 2px solid #33A7B5;
    box-shadow: 0 3px 8px rgba(51, 167, 181, 0.2);
}

.controls input,
.controls select {
    padding: 8px;
    margin-right: 10px;
    border: 1px solid #dddddd;
    border-radius: 4px;
}

.controls input {
    width: 300px;
}

.facility-name {
    font-size: 1em;
    font-weight: 700;
    margin: 0 0 4px 0; /* Reduced from 8px for subtext */
    color: #00004d;
    border-bottom: 2px solid #33A7B5;
    padding: 0 0 6px 0;
    line-height: 1.3;
}

.facility-header-subtext {
    display: block;
    font-size: 0.85em;
    color: #444444 !important;
    font-weight: 400;
    margin-top: 2px;
    margin-bottom: 8px; /* Added spacing */
    font-style: italic;
    line-height: 1.2;
}

.facility-details strong {
    color: #333333;
}

.status-badge {
    padding: 4px 10px;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 700;
    font-size: 0.75em;
    letter-spacing: 0.5px;
}

/* Status badge colors - WCAG AA compliant */
/* Higher specificity to override .facility-card * rule */
.tti-program-index-wrapper .facility-card .status-badge.status-open {
    color: #ffffff !important;
    background: #d45500;
}

.tti-program-index-wrapper .facility-card .status-badge.status-closed {
    color: #ffffff !important;
    background: #0d7a8a;
}

.tti-program-index-wrapper .facility-card .status-badge.status-transferred {
    color: #ffffff !important;
    background: #5a5a5a;
}

.tti-program-index-wrapper .facility-card .status-badge.status-unknown {
    color: #ffffff !important;
    background: #767676;
}

.facility-details {
    color: #000000;
    font-size: 0.9em;
}

/* Facility expanded details section */
.facility-expanded-info {
    margin-top: 10px;
    border-top: 2px solid #e0e0e0;
    padding-top: 10px;
}

.facility-expanded-info summary {
    cursor: pointer;
    color: #00004d;
    font-weight: 700;
    font-size: 0.9em;
    padding: 6px 10px;
    user-select: none;
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    border-radius: 4px;
    display: inline-block;
}

.facility-expanded-info summary:hover {
    background: linear-gradient(135deg, #e8e8e8 0%, #ddd 100%);
}

.tti-program-index-wrapper .facility-card .facility-expanded-info[open] summary,
.tti-program-index-wrapper .facility-card .facility-expanded-info[open] summary * {
    color: #ffffff !important;
}

.facility-expanded-info[open] summary {
    margin-bottom: 12px;
    background: #00004d;
    color: #ffffff !important;
}

summary.operator-header::after {
    content: '+ Click for details';
    font-size: 1em;
    font-weight: bold;
    color: #ffffff !important;
    pointer-events: none;
}

details[open] > summary.operator-header::after {
    content: '- Collapse details';
    color: #ffffff !important;
}

/* Removed table display - using grid from later definition */

/* Field rows - zebra striping ONLY for facility cards */
.facility-card .field-row:nth-child(odd) {
    background: #f5f5f5;
}

.facility-card .field-row:nth-child(even) {
    background: #fafafa;
}

/* Ensure operator details fields have NO background to avoid white-on-white */
.operator-details .field-row {
    background: transparent !important;
    display: grid; /* Use grid for internal row layout if needed, or stick to flex */
    grid-template-columns: 1fr;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 0;
}

/* .field-value styles defined per-context below */

.facility-extra-content a {
    color: #0066cc !important;
    text-decoration: none;
    word-break: break-all;
}

.facility-extra-content a:hover {
    text-decoration: underline;
    color: #004499 !important;
}

.field-note-inline {
    grid-column: 1 / -1;
    font-size: 0.85em;
    color: #555;
    font-style: italic;
    margin-top: -4px;
    margin-bottom: 8px;
    padding-left: 8px;
    border-left: 2px solid #ccc;
}

/* Facility summary info (location, years, status) */
.facility-summary {
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px dashed #ddd;
}

.facility-summary p {
    margin: 3px 0;
    font-size: 0.88em;
    color: #444444 !important;
}

.facility-location {
    font-weight: 500;
}

.facility-years {
    color: #666666 !important;
    font-size: 0.85em !important;
}

.facility-status {
    margin-top: 6px !important;
}

/* Operator section - NAVY backgrounds get WHITE text */
.operator-section {
    padding: 15px;
    width: 220px;
    min-height: 220px;
    background: #00004d;
    color: #ffffff !important;
    border-radius: 8px;
    box-sizing: border-box;
    border: 2px solid #33A7B5;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    box-shadow: 0 3px 8px rgba(51, 167, 181, 0.25);
}

/* Ensure ALL text within operator sections is white */
.operator-section *,
.operator-section p,
.operator-section span,
.operator-section div,
.operator-section strong {
    color: #ffffff !important;
}

.operator-section:hover {
    box-shadow: 0 4px 12px rgba(51, 167, 181, 0.35);
    transform: translateY(-2px);
}

.operator-name {
    color: #ffffff;
    padding: 12px;
    font-size: 1.4em;
    font-weight: bold;
    cursor: default;
    user-select: none;
    position: relative;
    margin: 0 auto;
    line-height: 1.2;
    text-align: center;
    overflow: hidden;
    display: block;
}

.operator-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.operator-name-long {
    font-size: 0.9em;
}

.operator-location {
    display: block;
    color: #fff;
    font-weight: normal;
    margin-top: 6px;
    margin-bottom: 6px;
    text-align: center;
    border-top: 1px solid #dddddd;
    line-height: 1.3em;
}

details.operator-section:not([open]) {
    width: 220px;
    height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
}

details.operator-section[open] {
    width: 100%;
    max-width: none;
    grid-column: span 3;
    height: auto;
}

details.operator-section[open] .operator-header {
    padding: 12px;
    flex-shrink: 0;
}

details.operator-section[open] .operator-content-scrollable {
    height: auto;
    max-height: 800px;
    overflow-y: auto;
    padding: 20px;
    background-color: rgba(255, 255, 255, 0.05);
    display: block; /* Stack facilities vertically */
}

/* Ensure facility cards inside the expanded operator take full width */
details.operator-section[open] .facility-card {
    width: 100%;
    max-width: 100%;
    margin-bottom: 15px;
    box-sizing: border-box;
}

.facility-extra-content {
    padding: 10px 0;
    display: grid;
    grid-template-columns: 1fr 1fr; /* Two columns of fields */
    column-gap: 20px;
    row-gap: 8px;
    width: 100%;
    font-size: 0.9em;
}

.operator-details {
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    display: grid;
    grid-template-columns: 1fr 1fr; /* Two columns of fields */
    column-gap: 20px;
    row-gap: 8px;
}

/* Ensure full width for resources or long text if needed */
.field-row.full-width {
    grid-column: 1 / -1;
}

/* Long lists (like Staff) span the full width and use their own internal grid */
.field-row.full-width-grid {
    grid-column: 1 / -1;
    display: block; /* Allow internal grid to flow */
}

.field-row.full-width-grid .field-value {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); /* Masonry-like grid for items */
    gap: 10px;
    margin-top: 5px;
}

.list-item {
    background: rgba(0,0,0,0.03);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* Field Row Styling inside Grid */
.field-row {
    display: flex;
    flex-direction: row; /* Label and value inline */
    align-items: baseline;
    gap: 8px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    padding-bottom: 4px;
    break-inside: avoid; /* Prevent split across columns if we used columns property */
}

/* Responsive: 1 column on small screens */
@media (max-width: 600px) {
    .facility-extra-content,
    .operator-details {
        grid-template-columns: 1fr;
    }
}

.facility-card .field-label {
    display: inline;
    font-size: 0.85em;
    font-weight: 700;
    color: #00004d !important; /* Force dark text on white card */
    flex-shrink: 0;
}

.facility-card .field-value {
    display: inline;
    padding: 0;
    color: #333333 !important; /* Force dark text on white card */
    word-break: break-word;
    line-height: 1.4;
}

.field-label::after {
    content: ':';
}

/* Operator details specific overrides (Dark background) */
.operator-details .field-label {
    color: #AEE0ED !important;
    display: inline;
    font-size: 0.85em;
    font-weight: 700;
    flex-shrink: 0;
}

.operator-details .field-value {
    color: #ffffff !important;
    display: inline;
    word-break: break-word;
    line-height: 1.4;
}

.operator-details p {
    margin: 3px 0;
    line-height: 1.4;
}

.operator-details a {
    color: #AEE0ED !important;
    text-decoration: none;
    word-break: break-all;
}

.operator-details a:hover {
    color: #ffffff !important;
    text-decoration: underline;
}

.operator-content-scrollable p {
    margin: 3px 0;
    line-height: 1.3;
    color: #ffffff;
}

.facilities-list {
    padding: 8px;
}

/* ==========================================================
CONTROLS
================================================================*/
.tti-program-index-wrapper .controls {
    grid-column: 1 / -1;
    margin-bottom: 10px;
    padding: 15px;
    background: linear-gradient(135deg, #AEE0ED 0%, #FFF5CB 100%);
    border-radius: 8px;
    border: 2px solid #33A7B5;
    box-shadow: 0 3px 8px rgba(51, 167, 181, 0.2);
}

.tti-program-index-wrapper .controls input[type="text"] {
    flex: 1;
    max-width: 400px;
    padding: 8px 12px;
    cursor: text;
}

.tti-program-index-wrapper .controls select {
    min-width: 180px;
    padding: 8px 12px;
    cursor: pointer;
}

.tti-program-index-wrapper .controls button {
    padding: 8px 16px;
    white-space: nowrap;
    cursor: pointer;
}

.open-text,
.closed-text {
    cursor: pointer;
}

/* ===========================================================
RESPONSIVE
===============================================================*/
@media (max-width: 768px) {
    .facilities-database {
        grid-template-columns: 1fr;
        padding: 5px;
        gap: 10px;
    }

    .operator-section,
    details.operator-section:not([open]),
    details.operator-section[open] {
        width: 100%;
        min-width: 100%;
        max-width: 100%;
        grid-column: 1 / -1;
    }

    details.operator-section:not([open]) {
        height: auto;
        min-height: 120px;
    }

    details.operator-section[open] .operator-content-scrollable {
        padding: 12px;
        max-height: none;
    }

    .facility-card {
        border-width: 4px;
        border-left-width: 6px !important;
        padding: 10px;
    }

    .facility-name {
        font-size: 1.1em;
        padding-bottom: 5px;
        margin-bottom: 6px;
    }

    .facility-summary p {
        font-size: 0.85em;
    }

    .status-badge {
        padding: 3px 8px;
        font-size: 0.7em;
    }

    .facility-expanded-info summary {
        font-size: 0.85em;
        padding: 5px 8px;
        display: block;
        text-align: center;
    }

    .facility-extra-content {
        font-size: 0.8em;
    }

    .field-label {
        padding: 2px 4px 2px 0;
    }

    .field-value {
        padding: 2px 0;
    }

    .operator-details {
        font-size: 0.8em;
    }

    #alphabet-filter {
        gap: 3px;
        padding-bottom: 1em;
        flex-wrap: wrap;
    }

    #alphabet-filter button {
        padding: 5px 8px;
        font-size: 0.8em;
    }

    .controls {
        padding: 10px;
    }

    .controls input,
    .controls select {
        width: 100%;
        max-width: 100%;
        margin-bottom: 8px;
    }

    .operator-name {
        font-size: 1.1em;
        padding: 8px;
    }
}

@media (max-width: 480px) {
    .facility-card {
        padding: 8px;
    }

    .facility-name {
        font-size: 1.1em;
    }

    .facility-extra-content,
    .operator-details {
        font-size: 0.95em;
    }

    .field-label {
        white-space: normal;
    }

    #alphabet-filter button {
        padding: 4px 6px;
        font-size: 0.75em;
    }

    .operator-name {
        font-size: 1em;
    }
}

/* =================================================================
   FIELD NOTE LINK PREVIEWS
   ================================================================= */

.tti-program-index-wrapper .facility-field-notes ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.tti-program-index-wrapper .facility-field-notes li {
    margin-bottom: 12px;
}

.tti-program-index-wrapper .field-note-text {
    margin: 6px 0 8px;
    color: #222222;
}

.tti-program-index-wrapper .field-note-link-card {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 8px;
    border: 1px solid #dddddd;
    border-radius: 8px;
    text-decoration: none;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.tti-program-index-wrapper .field-note-link-card:hover {
    border-color: #33A7B5;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.tti-program-index-wrapper .field-note-link-thumb {
    width: 72px;
    height: 72px;
    background: #f2f2f2;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tti-program-index-wrapper .field-note-link-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tti-program-index-wrapper .field-note-link-placeholder {
    font-size: 0.7em;
    color: #666666;
    text-align: center;
    padding: 6px;
}

.tti-program-index-wrapper .field-note-link-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.tti-program-index-wrapper .field-note-link-title {
    font-weight: 600;
    font-size: 0.9em;
    color: #000000;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tti-program-index-wrapper .field-note-link-domain {
    font-size: 0.75em;
    color: #555555;
}

/* =================================================================
   DOCUMENT LIBRARY OVERRIDES (TTI index only)
   ================================================================= */

.tti-program-index-wrapper .doc-layout-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.tti-program-index-wrapper .doc-layout-grid .doc-link {
    border-radius: 10px;
}

.tti-program-index-wrapper .doc-layout-grid .doc-thumbnail {
    height: 96px;
}

.tti-program-index-wrapper .doc-layout-grid .doc-info {
    padding: 8px;
    gap: 3px;
}

.tti-program-index-wrapper .doc-title {
    font-size: 13px;
    line-height: 1.25;
}

.tti-program-index-wrapper .doc-meta {
    font-size: 11px;
}

.tti-program-index-wrapper .doc-icon {
    width: 44px;
    height: 44px;
    font-size: 10px;
    border-radius: 8px;
}


/* =================================================================
   DOCUMENT MODAL (TTI index only)
   ================================================================= */

.kop-doc-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 200000;
}

.kop-doc-modal.is-open {
    display: flex;
}

.kop-doc-modal__dialog {
    width: min(960px, 95vw);
    max-height: 90vh;
    background: #ffffff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
}

.kop-doc-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e5e5;
    background: #F2EEDF;
}

.kop-doc-modal__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: #000000;
}

.kop-doc-modal__close {
    border: none;
    background: #ffffff;
    color: #000000;
    font-size: 22px;
    line-height: 1;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.kop-doc-modal__close:hover {
    background: #FFF5CB;
}

.kop-doc-modal__body {
    padding: 12px 16px;
    flex: 1;
    overflow: auto;
    background: #ffffff;
}

.kop-doc-modal__viewer {
    width: 100%;
    min-height: 60vh;
    background: #f7f7f7;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.kop-doc-modal__viewer iframe,
.kop-doc-modal__viewer video {
    width: 100%;
    height: 100%;
    border: none;
}

.kop-doc-modal__viewer img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
}

.kop-doc-modal__placeholder {
    font-size: 0.95rem;
    color: #555555;
}

.kop-doc-modal__footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid #e5e5e5;
    background: #ffffff;
}

.kop-doc-modal__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    background: #33A7B5;
    color: #ffffff;
    transition: background 0.2s ease;
}

.kop-doc-modal__btn:hover {
    background: #00004d;
    color: #ffffff;
}

body.kop-doc-modal-open {
    overflow: hidden;
}

@media (max-width: 600px) {
    .kop-doc-modal__dialog {
        width: 100%;
        max-height: 92vh;
    }

    .kop-doc-modal__viewer {
        min-height: 50vh;
    }
}

