/**
 * Historical Timeline Frontend Styles
 */

/* Container */
.htl-timeline-container {
    position: relative;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    min-height: 300px;
}

.htl-timeline-container.htl-expanded {
    height: auto !important;
    max-height: none !important;
}

/* Controls bar */
.htl-controls {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    padding: 0px 10px;
    background: #e9ecef !important;
    border-bottom: 1px solid #dee2e6;
    gap: 6px;
    flex-wrap: wrap;
    min-height: 22px;
}

.htl-controls-left,
.htl-controls-right {
    display: flex !important;
    align-items: center;
    gap: 2px;
}

.htl-year-nav {
    display: flex !important;
    align-items: center;
    gap: 8px;
}

.htl-year-display {
    display: flex !important;
    align-items: center;
    gap: 8px;
}

.htl-year-input {
    width: 80px;
    padding: 6px 10px;
    border: 1px solid #ced4da !important;
    border-radius: 4px;
    font-size: 14px;
    text-align: center;
    background: #fff !important;
    color: #212529 !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.htl-year-separator {
    color: #6c757d !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.htl-btn,
.htl-nav-btn {
    padding: 3px 8px;
    border: 1px solid #ced4da !important;
    background: #fff !important;
    background-color: #fff !important;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    color: #212529 !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    text-decoration: none !important;
    box-shadow: none !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.htl-btn:hover,
.htl-nav-btn:hover {
    background: #e9ecef !important;
    background-color: #e9ecef !important;
    border-color: #adb5bd !important;
    color: #212529 !important;
}

.htl-nav-btn {
    padding: 3px 8px;
    font-weight: bold;
    min-width: 28px;
}

/* Specific button overrides to ensure visibility */
.htl-apply-range,
.htl-nav-prev,
.htl-nav-next {
    display: inline-flex !important;
    background: #fff !important;
    background-color: #fff !important;
    color: #212529 !important;
    border: 1px solid #ced4da !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.htl-apply-range:hover,
.htl-nav-prev:hover,
.htl-nav-next:hover {
    background: #e9ecef !important;
    background-color: #e9ecef !important;
}

.htl-category-filter,
.htl-year-grouping,
.htl-row-selector {
    padding: 2px 6px;
    border: 1px solid #ced4da !important;
    border-radius: 4px;
    font-size: 12px;
    min-width: 70px;
    background: #fff !important;
    color: #212529 !important;
    opacity: 1 !important;
    visibility: visible !important;
    -webkit-appearance: menulist !important;
    appearance: menulist !important;
}

.htl-category-filter {
    min-width: 100px;
}

.htl-zoom-controls {
    display: flex !important;
    gap: 2px;
}

.htl-zoom-controls .htl-btn {
    padding: 3px 8px;
    font-weight: bold;
}

/* Reset View button */
.htl-reset-view {
    background: #6c757d !important;
    color: #fff !important;
    border-color: #6c757d !important;
    font-weight: 500;
    margin-left: 8px;
}

.htl-reset-view:hover {
    background: #5a6268 !important;
    border-color: #545b62 !important;
    color: #fff !important;
}

.htl-control-group {
    display: flex !important;
    align-items: center;
    gap: 4px;
}

.htl-control-group label {
    font-size: 12px;
    color: #495057 !important;
    white-space: nowrap;
    opacity: 1 !important;
    visibility: visible !important;
}

.htl-control-group select {
    padding: 2px 6px;
    border: 1px solid #ced4da !important;
    border-radius: 4px;
    font-size: 12px;
    min-width: 70px;
    background: #fff !important;
    color: #212529 !important;
    opacity: 1 !important;
    visibility: visible !important;
    -webkit-appearance: menulist !important;
    appearance: menulist !important;
}

/* Search controls */
.htl-search-container {
    display: flex !important;
    align-items: center;
    gap: 2px;
}

.htl-search-input {
    width: 140px;
    padding: 2px 6px;
    border: 1px solid #ced4da !important;
    border-radius: 4px;
    font-size: 12px;
    background: #fff !important;
    color: #212529 !important;
}

.htl-search-input:focus {
    outline: none;
    border-color: #86b7fe !important;
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.25);
}

.htl-search-btn,
.htl-search-clear {
    padding: 2px 6px !important;
    font-size: 11px;
    min-width: auto;
}

.htl-search-clear {
    display: none;
}

.htl-search-clear.htl-visible {
    display: inline-flex !important;
}

.htl-search-results-info {
    font-size: 12px;
    color: #6c757d;
    white-space: nowrap;
    margin-left: 6px;
}

.htl-search-results-info.htl-has-results {
    color: #198754;
    font-weight: 500;
}

.htl-search-results-info.htl-no-results {
    color: #dc3545;
}

/* Highlight matched events */
.htl-event.htl-search-match {
    box-shadow: 0 0 0 3px #ffc107, 0 2px 8px rgba(0, 0, 0, 0.3) !important;
    z-index: 10 !important;
}

.htl-event.htl-search-dimmed {
    opacity: 0.4;
}

/* Era selector */
/* Tag filter row (second row) */
.htl-tag-row {
    background: #fff;
    border-bottom: 1px solid #dee2e6;
    padding: 0px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-height: 22px;
}

.htl-tag-label {
    font-size: 11px;
    font-weight: 600;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.htl-tag-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.htl-tag-btn {
    padding: 2px 10px;
    background: #444;
    border: 1px solid #333;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    color: #fff;
    transition: all 0.2s;
    white-space: nowrap;
}

.htl-tag-btn:hover {
    background: #555;
    border-color: #444;
}

.htl-tag-btn.htl-active {
    background: var(--htl-all-dates-button, #198754);
    border-color: var(--htl-all-dates-button, #198754);
    color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.htl-tag-clear {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid #dc3545;
    border-radius: 12px;
    cursor: pointer;
    font-size: 11px;
    color: #dc3545;
    transition: all 0.2s;
}

.htl-tag-clear:hover {
    background: #dc3545;
    color: #fff;
}

/* Era/Date range row (third row) */
.htl-era-row {
    display: flex;
    align-items: stretch;
    background: #e9ecef;
    border-bottom: 1px solid #dee2e6;
    min-height: 36px;
}

.htl-era-row .htl-year-nav-btn {
    width: 40px;
    min-width: 40px;
    padding: 0;
    margin: 0;
    border: none;
    background: #495057;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.htl-era-row .htl-year-nav-btn:hover {
    background: #343a40;
}

.htl-era-row .htl-year-nav-btn:active {
    background: #212529;
}

.htl-era-buttons {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    flex: 1;
    padding: 4px 10px;
    align-items: center;
}

.htl-era-btn {
    flex: 1;
    padding: 3px 6px;
    background: #444;
    border: 1px solid #333;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    text-align: center;
    transition: all 0.2s;
    white-space: nowrap;
    color: #fff;
}

.htl-era-btn:hover {
    background: #555;
    border-color: #444;
}

.htl-era-btn.htl-active {
    background: var(--htl-era-button, #0d6efd);
    border-color: var(--htl-era-button, #0d6efd);
    color: #fff;
}

.htl-era-btn.htl-era-all {
    background: #444;
    border-color: #333;
    color: #fff;
}

.htl-era-btn.htl-era-all.htl-active {
    background: var(--htl-all-dates-button, #198754);
    border-color: var(--htl-all-dates-button, #198754);
    color: #fff;
}

/* Timeline header wrapper */
.htl-timeline-header-wrapper {
    display: flex;
    align-items: stretch;
    background: #fff;
    border-bottom: 2px solid #dee2e6;
}

.htl-timeline-header {
    flex: 1;
    background: #fff;
    height: var(--htl-year-header-height, 40px);
    overflow: hidden;
}

.htl-header-scroll {
    position: relative;
    height: 100%;
}

.htl-year-marker {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--htl-grid-line, #dee2e6);
    font-size: var(--htl-year-font-size, 14px);
    font-weight: 600;
    color: #495057;
    padding: 0 4px;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.htl-year-marker .htl-year-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.htl-year-marker .htl-bce-label {
    font-size: 9px;
    color: #6c757d;
    font-weight: normal;
}

.htl-year-marker.htl-half-century {
    background: #f1f3f5;
}

.htl-year-marker.htl-decade {
    background: #e9ecef;
}

.htl-year-marker.htl-century {
    background: #dee2e6;
    font-weight: 700;
}

/* Timeline body */
.htl-timeline-body {
    flex: 1;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

.htl-timeline-container.htl-expanded .htl-timeline-body {
    flex: none;
    height: auto;
    overflow: visible;
}

/* Events area - main scrollable container */
.htl-events-area {
    cursor: grab;
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    margin: 0;
    padding: 0;
}

.htl-timeline-container.htl-expanded .htl-events-area {
    overflow-y: visible;
}

/* Custom scrollbar styling for events area */
.htl-events-area::-webkit-scrollbar {
    height: 14px;
}

.htl-events-area::-webkit-scrollbar-track {
    background: #e9ecef;
    border-radius: 7px;
}

.htl-events-area::-webkit-scrollbar-thumb {
    background: #adb5bd;
    border-radius: 7px;
    border: 2px solid #e9ecef;
}

.htl-events-area::-webkit-scrollbar-thumb:hover {
    background: #6c757d;
}

/* Draggable cursor */
.htl-events-area.htl-dragging {
    cursor: grabbing;
    user-select: none;
}

.htl-events-scroll {
    position: relative;
    min-width: 100%;
    margin: 0;
    padding: 0;
}

/* Row labels - hidden to give more space for events */
.htl-row-labels {
    display: none;
}

/* Grid lines */
.htl-grid-lines {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.htl-grid-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--htl-grid-line, #e9ecef);
}

.htl-grid-line.htl-half-century {
    background: #dee2e6;
}

.htl-grid-line.htl-decade {
    background: #dee2e6;
}

.htl-grid-line.htl-century {
    background: #ced4da;
    width: 2px;
}

/* Events container */
.htl-events-container {
    position: relative;
    background: var(--htl-background, #ffffff);
    margin: 0;
    padding: 0;
}

.htl-event-row {
    height: var(--htl-row-height, 50px);
    border-bottom: 1px solid var(--htl-grid-line, #e9ecef);
    position: relative;
    background: var(--htl-row-odd, #ffffff);
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.htl-event-row:nth-child(even) {
    background: var(--htl-row-even, #f8f9fa);
}

/* Event items */
.htl-event {
    position: absolute;
    height: var(--htl-event-height, 40px);
    top: calc((var(--htl-row-height, 50px) - var(--htl-event-height, 40px)) / 2);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: var(--htl-event-vertical-align, center);
    justify-content: var(--htl-event-text-align, left);
    padding: 0px 8px 0px 6px;
    font-size: var(--htl-event-font-size, 9px);
    color: #fff;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s, box-shadow 0.15s;
    z-index: 1;
}

.htl-event:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.25);
    z-index: 5;
}

.htl-event-point {
    min-width: 20px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    padding: 0;
    justify-content: center;
}

.htl-event-title {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.2;
    white-space: normal;
    word-break: break-word;
    font-size: var(--htl-event-font-size, 9px);
    max-width: calc(100% - 34px);
}

/* No text wrapping - single line with ellipsis */
.htl-no-wrap .htl-event-title {
    white-space: nowrap;
    display: block;
    -webkit-line-clamp: unset;
    -webkit-box-orient: unset;
}

.htl-event-icon {
    width: var(--htl-icon-size, 24px);
    height: var(--htl-icon-size, 24px);
    min-width: var(--htl-icon-size, 24px);
    border-radius: 3px;
    margin-right: 6px;
    flex-shrink: 0;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.2);
}

.htl-event-point .htl-event-icon {
    display: none;
}

.htl-event-point .htl-event-title {
    display: none;
}

/* Auto-width events (single-period) - sized to content */
.htl-event-auto-width {
    width: auto !important;
    min-width: var(--htl-event-width, 100px);
    max-width: var(--htl-event-width, 100px);
    flex-shrink: 0;
    padding-right: 10px; /* Extra padding so text doesn't touch edge */
}

.htl-event-auto-width .htl-event-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    -webkit-line-clamp: unset;
    -webkit-box-orient: unset;
    max-width: none;
}

/* Loading overlay */
.htl-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.htl-loading.htl-visible {
    opacity: 1;
    pointer-events: auto;
}

.htl-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e9ecef;
    border-top-color: #3498db;
    border-radius: 50%;
    animation: htl-spin 1s linear infinite;
}

@keyframes htl-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Modal */
.htl-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.htl-modal.htl-open {
    opacity: 1;
    visibility: visible;
}

.htl-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
}

.htl-modal-content {
    position: relative;
    background: #fff;
    border-radius: 8px;
    max-width: 700px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    transform: translateY(-20px);
    transition: transform 0.3s;
}

.htl-modal.htl-open .htl-modal-content {
    transform: translateY(0);
}

.htl-modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 36px;
    height: 36px;
    border: none;
    background: var(--htl-popup-close, #dc3545);
    border-radius: 50%;
    font-size: 22px;
    font-weight: 300;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    z-index: 1;
    line-height: 1;
}

.htl-modal-close:hover {
    background: var(--htl-popup-close, #dc3545);
    filter: brightness(0.85);
    transform: scale(1.1);
}

.htl-modal-header {
    padding: 25px 25px 15px;
    border-bottom: 1px solid #e9ecef;
}

/* Category wrapper with icon */
.htl-modal-category-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.htl-modal-category-icon {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
}

.htl-modal-category {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
}

.htl-modal-title {
    margin: 0 0 8px 0;
    font-size: 24px;
    font-weight: 600;
    color: #212529;
}

.htl-modal-date {
    color: #6c757d;
    font-size: 14px;
}

.htl-modal-body {
    padding: 25px;
}

.htl-modal-images {
    margin-bottom: 20px;
}

.htl-modal-images img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin-bottom: 10px;
}

.htl-modal-description {
    font-size: 15px;
    line-height: 1.7;
    color: #495057;
}

.htl-modal-description p {
    margin: 0 0 15px;
}

.htl-modal-description p:last-child {
    margin-bottom: 0;
}

/* Modal footer with edit link */
.htl-modal-footer {
    padding: 15px 25px;
    border-top: 1px solid #e9ecef;
    text-align: right;
}

.htl-modal-edit-link {
    display: inline-block;
    padding: 6px 14px;
    background: #0d6efd;
    color: #fff !important;
    text-decoration: none !important;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.2s;
}

.htl-modal-edit-link:hover {
    background: #0b5ed7;
    color: #fff !important;
}

/* No events message */
.htl-no-events {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #6c757d;
    font-size: 14px;
}

/* More rows message */
.htl-more-rows-message {
    background: linear-gradient(to bottom, rgba(248, 249, 250, 0.9), #f8f9fa);
    border-top: 1px solid #dee2e6;
    padding: 12px 16px;
    text-align: center;
}

.htl-show-more-rows {
    background: var(--htl-more-rows-button-color, #0d6efd);
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s, filter 0.2s;
}

.htl-show-more-rows:hover {
    filter: brightness(0.85);
}

.htl-hidden-rows-count {
    font-weight: 700;
}

/* Responsive */
@media screen and (max-width: 768px) {
    .htl-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .htl-controls-left,
    .htl-controls-right {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .htl-year-nav {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .htl-row-labels {
        width: 60px;
    }
    
    .htl-timeline-header {
        margin-left: 60px;
    }
    
    .htl-tag-row {
        justify-content: center;
    }
    
    .htl-era-row {
        padding-left: 8px;
        padding-right: 8px;
    }
    
    .htl-era-buttons {
        justify-content: center;
    }
    
    .htl-control-group {
        flex: 1 1 45%;
        justify-content: center;
    }
    
    .htl-modal-content {
        width: 95%;
        max-height: 95vh;
    }
    
    .htl-modal-title {
        font-size: 20px;
    }
}
