/**
 * History Page Styles
 * Three-panel layout: tree (left), map (center), info (right)
 */

/* Full viewport layout */
.history-layout {
    display: flex;
    height: calc(100vh - 52px);
    overflow: hidden;
}

/* Left panel - Date selector and tree */
.history-left-panel {
    width: 320px;
    background: white;
    border-right: 1px solid #dbdbdb;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Date selector section */
.date-selector {
    padding: 1rem;
    border-bottom: 1px solid #dbdbdb;
    background: #fafafa;
}

.date-selector .field {
    margin-bottom: 0.75rem;
}

.date-selector .field:last-child {
    margin-bottom: 0;
}

.date-selector label {
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.date-selector .select {
    width: 100%;
}

.date-selector .select select {
    width: 100%;
}

/* Tree container */
.tree-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

/* Filters section */
.filters-section {
    margin-bottom: 1rem;
    border-bottom: 1px solid #dbdbdb;
    background: #fafafa;
    border-radius: 4px;
}

.filters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    user-select: none;
}

.filters-header:hover {
    background: #f0f0f0;
}

.filters-header-buttons {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filters-disclosure {
    color: #7a7a7a;
    transition: transform 0.2s ease;
    font-size: 0.9rem;
}

.filters-section.expanded .filters-disclosure {
    transform: rotate(180deg);
}

.filters-content {
    padding: 0 0.75rem 0.75rem 0.75rem;
    display: none;
}

.filters-section.expanded .filters-content {
    display: block;
}

.filter-group {
    margin-bottom: 1rem;
}

.filter-group:last-child {
    margin-bottom: 0;
}

.filter-group .label {
    color: #7a7a7a;
    font-weight: 600;
}

/* Ship type filters */
.ship-type-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.ship-type-filter-btn {
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    border: 1px solid #dbdbdb;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.ship-type-filter-btn:hover {
    border-color: #3298dc;
    background: #f0f8ff;
}

.ship-type-filter-btn.active {
    background: #3298dc;
    color: white;
    border-color: #3298dc;
}

.ship-type-filter-btn.active:hover {
    background: #2080c0;
    border-color: #2080c0;
}

/* Tree controls */
.tree-controls {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #dbdbdb;
}

.tree-controls .buttons {
    margin-bottom: 0;
}

/* Tree content area */
#tree-content {
    flex: 1;
    overflow-y: auto;
}

.tree-container::-webkit-scrollbar {
    width: 8px;
}

.tree-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.tree-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.tree-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Empty state */
.tree-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: #7a7a7a;
}

/* Loading state */
.tree-loading {
    text-align: center;
    padding: 2rem 1rem;
}

/* Vessel tree item */
.vessel-item {
    margin-bottom: 0.75rem;
}

.vessel-header {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    background: #f5f5f5;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.vessel-header:hover {
    background: #eeeeee;
}

.vessel-header.selected {
    background: #e8f4fd;
    border: 1px solid #3298dc;
}

.vessel-checkbox {
    margin-right: 0.5rem;
    cursor: pointer;
    flex-shrink: 0;
}

.disclosure-triangle {
    margin-left: 0.5rem;
    color: #7a7a7a;
    cursor: pointer;
    transition: transform 0.2s ease;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.disclosure-triangle:hover {
    color: #363636;
}

/* Rotate triangle when expanded */
.vessel-item:not(.collapsed) .disclosure-triangle {
    transform: rotate(90deg);
}

.vessel-name {
    flex: 1;
    min-width: 0; /* Allow text truncation */
    overflow: hidden;
}

.vessel-name .name-text {
    font-weight: 600;
    color: #363636;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Trip list */
.trip-list {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
}

.trip-item {
    display: flex;
    align-items: center;
    padding: 0.4rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-bottom: 0.25rem;
}

.trip-item:hover {
    background: #fafafa;
}

.trip-item.selected {
    background: #fff4e6;
    border: 1px solid #ffdd57;
}

.trip-checkbox {
    margin-right: 0.5rem;
    cursor: pointer;
}

.trip-label {
    flex: 1;
    font-size: 0.9rem;
}

.trip-time {
    color: #363636;
}

/* Map container */
.history-map {
    flex: 1;
    position: relative;
}

#history-map {
    width: 100%;
    height: 100%;
}

/* Right panel - Info pane */
.history-right-panel {
    width: 340px;
    background: white;
    border-left: 1px solid #dbdbdb;
    overflow-y: auto;
    padding: 1rem;
}

.history-right-panel::-webkit-scrollbar {
    width: 8px;
}

.history-right-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.history-right-panel::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.history-right-panel::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Info pane content */
.info-section {
    margin-bottom: 1.5rem;
}

.info-section:last-child {
    margin-bottom: 0;
}

.info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.info-label {
    color: #7a7a7a;
}

.info-value {
    text-align: right;
}

/* Loading indicator */
.loading-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    text-align: center;
}

.loading-spinner {
    margin-bottom: 1rem;
}

/* Error state */
.error-message {
    padding: 1rem;
    margin: 1rem;
    border-radius: 4px;
}

/* ═══════════════════════════════════════════════
   Grid Modal (history-grid A/B test)
   ═══════════════════════════════════════════════ */

/* Modal card: fill most of the viewport */
.grid-modal-card {
    width: 90vw;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

/* Scrollable body */
.grid-modal-body {
    overflow-y: auto;
    overflow-x: auto;
    padding: 0;
    flex: 1 1 auto;
}

/* Grid table */
.grid-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

/* Base styles shared by all sticky header cells */
.grid-table thead th {
    position: sticky;
    top: 0; /* overridden per-row below or via JS */
    background: #f5f5f5;
    z-index: 2;
    white-space: nowrap;
    text-align: center;
    vertical-align: bottom;
    padding: 0.5rem 0.5rem 0.4rem;
    cursor: pointer;
    user-select: none;
    border-bottom: 2px solid #dbdbdb;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

/* Ship-type header cells: fixed equal width, centered, allow text to wrap */
.grid-table thead th.grid-ship-type-header {
    width: 128px;
    min-width: 128px;
    max-width: 128px;
    text-align: center;
    white-space: normal;
    word-break: break-word;
}

/* Corner cell: sticky on both axes, spans both header rows */
.grid-corner {
    position: sticky !important;
    top: 0;
    left: 0;
    z-index: 3 !important;
    background: #f5f5f5 !important;
    min-width: 5.5rem;
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.08);
}

/* ── Group header row (row 1) ── */

.grid-group-header {
    background: #ebebeb !important;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-align: center !important;
    text-transform: uppercase;
    border-bottom: 2px solid #c0c0c0 !important;
    padding: 0.45rem 0.6rem !important;
    vertical-align: middle !important;
}

/* ── Ship-type header row (row 2) — top set by JS after layout ── */

.grid-table thead tr.grid-ship-type-row th {
    background: #f5f5f5;
    /* top is set dynamically in JS via requestAnimationFrame */
}

/* ── Group boundary: thick left border on first column of each group ── */

.grid-group-start {
    border-left: 3px solid #aaaaaa !important;
}


/* Sticky date column */
.grid-table tbody th.grid-date-header {
    position: sticky;
    left: 0;
    background: #fafafa;
    z-index: 1;
    white-space: nowrap;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5em;
    padding: 0.2rem 0.6rem;
    cursor: pointer;
    user-select: none;
    border-right: 2px solid #dbdbdb;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.06);
}

/* Data cells */
.grid-table tbody td.grid-cell {
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    padding: 0.2rem 0.4rem;
    width: 128px;
    min-width: 128px;
    max-width: 128px;
}

/* Zero-count cells: dimmed */
.grid-cell-zero {
    color: #c0c0c0;
}

/* ── Selected states ── */

.grid-cell.is-selected {
    background-color: #3e8ed0 !important;
    color: white !important;
    font-weight: 600;
}

.grid-date-header.is-selected,
.grid-ship-type-header.is-selected,
.grid-group-header.is-selected {
    background-color: #3e8ed0 !important;
    color: white !important;
    box-shadow: none !important;
}

/* Partially selected headers */
.grid-date-header.is-selected-partial,
.grid-ship-type-header.is-selected-partial,
.grid-group-header.is-selected-partial {
    background-color: #c8e0f4 !important;
    color: #363636 !important;
}

/* ── Hover states ── */

.grid-table tbody td.grid-cell:hover {
    background-color: #e8f4fd !important;
}

.grid-cell.is-selected:hover {
    background-color: #2d7dbf !important;
}

.grid-date-header:hover,
.grid-ship-type-header:hover,
.grid-group-header:hover {
    background-color: #daeaf8 !important;
}

.grid-date-header.is-selected:hover,
.grid-ship-type-header.is-selected:hover,
.grid-group-header.is-selected:hover {
    background-color: #2d7dbf !important;
    color: white !important;
}

/* ── Header label typography ── */

.grid-header-name {
    display: inline;
    font-size: 0.8rem;
    font-weight: 600;
}

.grid-header-count {
    display: inline;
    font-size: 0.7rem;
    font-weight: 400;
    opacity: 0.75;
    margin-left: 0.2em;
}

/* Search summary line below the "Date and Types" button */
#search-summary {
    margin-top: 0.5rem;
    padding: 0.3rem 0.6rem;
    background: #f0f8ff;
    border-left: 3px solid #3298dc;
    border-radius: 0 4px 4px 0;
}

/* Date-types button: subtle badge state when a selection is committed */
#date-types-button.has-selection {
    border-color: #1a76bc;
    box-shadow: 0 0 0 2px rgba(50, 152, 220, 0.25);
}

/* Responsive adjustments */
@media screen and (max-width: 1200px) {
    .history-left-panel {
        width: 280px;
    }
    
    .history-right-panel {
        width: 300px;
    }
}

@media screen and (max-width: 968px) {
    .history-right-panel {
        display: none;
    }
}
