/* ============================================
   Paddlelog UI - Modern, Compact, Dark-Aware
   ============================================ */

/* Root variables for compact mode */
:root {
    --compact-font-size: 0.9rem;
    --compact-table-padding-y: 0.4rem;
    --compact-table-padding-x: 0.5rem;
    --compact-btn-padding-y: 0.35rem;
    --compact-btn-padding-x: 0.65rem;
}

/* Light theme customizations */
[data-bs-theme="light"] {
    --bs-body-bg: #f4f6f8;
    --bs-border-color: #dee2e6;
}

/* Dark theme customizations */
[data-bs-theme="dark"] {
    --bs-body-bg: #1a1d20;
    --bs-border-color: #2d3338;
}

/* Global compact sizing */
html {
    font-size: var(--compact-font-size);
}

body {
    line-height: 1.5;
}

/* Compact headings */
h1 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Navbar refinements */
.navbar {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.navbar-brand {
    font-size: 1.1rem;
}

.navbar-nav .nav-link {
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
    font-size: 0.95rem;
}

.navbar-meta {
    min-width: 0;
}

.build-stamp {
    font-size: 0.7rem;
    opacity: 0.55;
    white-space: nowrap;
}

[data-bs-theme="dark"] .build-stamp {
    opacity: 0.65;
}

/* Card improvements */
.card {
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

[data-bs-theme="dark"] .card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Table improvements */
.table-compact {
    font-size: 0.9rem;
}

.table-compact th,
.table-compact td {
    padding: var(--compact-table-padding-y) var(--compact-table-padding-x);
    vertical-align: middle;
}

.table-compact thead th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    border-bottom-width: 2px;
}

/* Clickable rows */
.clickable-row {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.clickable-row:hover {
    --bs-table-hover-bg: rgba(0, 0, 0, 0.04);
}

[data-bs-theme="dark"] .clickable-row:hover {
    --bs-table-hover-bg: rgba(255, 255, 255, 0.06);
}

.clickable-row .actions-cell {
    cursor: default;
}

/* Sortable table headers */
.sortable-header {
    text-decoration: none;
    color: inherit;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.sortable-header:hover {
    color: var(--bs-link-color);
}

.sortable-header .sort-indicator {
    font-size: 0.7em;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s, visibility 0.0s linear 0.2s;
}

.sortable-header.active .sort-indicator {
    visibility: visible;
    opacity: 1;
    transition-delay: 0s;
}

/* Compact buttons */
.btn-compact {
    padding: var(--compact-btn-padding-y) var(--compact-btn-padding-x);
    font-size: 0.85rem;
}

/* Filter toolbar styling */
.filter-toolbar {
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 1rem;
}

.filter-toolbar .form-control,
.filter-toolbar .form-select {
    font-size: 0.9rem;
}

/* Stats dashboard ribbon */
.stats-ribbon {
    background: linear-gradient(135deg, var(--bs-primary) 0%, var(--bs-info) 100%);
    color: white;
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.stats-ribbon .stat-item {
    text-align: center;
}

.stats-ribbon .stat-label {
    font-size: 0.75rem;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.stats-ribbon .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.stats-link-pill {
    display: inline-block;
    border: 1px solid rgba(255, 255, 255, 0.45);
    color: #ffffff;
    text-decoration: none;
    border-radius: 999px;
    padding: 0.2rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.2px;
}

a.stats-link-pill:hover {
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.75);
    background: rgba(255, 255, 255, 0.1);
}

.stats-table-card {
    border-radius: 0.5rem;
}

.stats-table th,
.stats-table td {
    white-space: nowrap;
}

.stats-table tbody tr.stats-row-soft-highlight > th,
.stats-table tbody tr.stats-row-soft-highlight > td,
.stats-table tfoot tr.stats-row-soft-highlight > th,
.stats-table tfoot tr.stats-row-soft-highlight > td {
    background-color: rgba(var(--bs-emphasis-color-rgb), 0.04);
}

.stats-table .stats-col-strong-highlight {
    box-shadow: inset 0 0 0 9999px rgba(var(--bs-primary-rgb), 0.18);
    transition: box-shadow 0.12s ease;
}

.stats-table .trend-indicator {
    display: inline-block;
    width: 0.7em;
    text-align: center;
    margin-left: 0.22rem;
    font-size: 0.72em;
    font-weight: 600;
    opacity: 0.85;
    vertical-align: baseline;
}

.stats-table .trend-up {
    color: rgba(var(--bs-success-rgb), 0.95);
}

.stats-table .trend-down {
    color: rgba(var(--bs-danger-rgb), 0.95);
}

.stats-table .trend-flat {
    color: rgba(var(--bs-secondary-color-rgb), 0.55);
}

/* Definition lists in details view */
dl.row dt {
    font-weight: 500;
    color: var(--bs-secondary-color);
}

dl.row dd {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

/* Map and chart stacking - dynamic height allocation */
.map-chart-stack {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    height: calc(100vh - 100px);
    max-height: calc(100vh - 100px);
    min-height: 500px;
}

[data-bs-theme="dark"] .map-chart-stack {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.map-canvas {
    flex: 1 1 auto;
    min-height: 250px;
    width: 100%;
}

.mobile-scroll-handle {
    display: none;
}

.map-page-stack {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.filter-toolbar-actions {
    flex-wrap: wrap;
}

.big-map-canvas {
    height: calc(100vh - 180px);
    min-height: 560px;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    overflow: hidden;
}

.map-scheme-menu {
    position: relative;
}

.map-scheme-dropdown {
    position: absolute;
    top: calc(100% + 0.25rem);
    right: 0;
    z-index: 1100;
    min-width: 14rem;
    padding: 0.35rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    background: var(--bs-body-bg);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.map-scheme-option {
    display: block;
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 0;
    border-radius: 0.35rem;
    background: transparent;
    color: inherit;
    text-align: left;
}

.map-scheme-option:hover,
.map-scheme-option:focus,
.map-scheme-option.active {
    background: rgba(var(--bs-primary-rgb), 0.12);
    color: var(--bs-primary);
}

.map-load-progress {
    margin-top: 0.35rem;
}

.map-load-progress-bar-wrap {
    height: 0.45rem;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(var(--bs-secondary-rgb), 0.18);
}

.map-load-progress-bar {
    width: 0;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #0d6efd 0%, #38bdf8 100%);
    transition: width 0.18s ease;
}

.map-load-progress-meta {
    margin-top: 0.2rem;
}

.chart-canvas {
    flex: 0 0 110px;
    height: 110px;
    background: var(--bs-body-bg);
    border-top: 1px solid var(--bs-border-color);
}

.workout-visual-column {
    position: static;
}

@media (min-width: 992px) {
    .workout-visual-column {
        position: sticky;
        top: 0.5rem;
        align-self: flex-start;
    }
}

/* Action toolbar for workout detail */
.action-toolbar {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    align-items: center;
}

.action-toolbar .btn {
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
}

/* Code blocks in detail view */
code {
    word-break: break-all;
    font-size: 0.85em;
    padding: 0.2em 0.4em;
}

/* Turbo frame loading state */
turbo-frame[busy] {
    opacity: 0.6;
    transition: opacity 0.2s;
    pointer-events: none;
}

/* Leaflet map dark mode support */
[data-bs-theme="dark"] .leaflet-container {
    background: #2d3338;
}

[data-bs-theme="dark"] .leaflet-tile {
    filter: brightness(0.7) contrast(1.1);
}

/* Big-map colour scheme: dark tile filter */
.map-tiles-dark {
    filter: brightness(0.35) contrast(1.2) saturate(0.6);
}

/* Pagination improvements */
.pagination {
    --bs-pagination-border-radius: 0.375rem;
}

.pagination .page-link {
    font-size: 0.9rem;
}

/* Form spacing improvements */
.form-label {
    margin-bottom: 0.3rem;
    font-weight: 500;
    font-size: 0.85rem;
}

/* Alert improvements */
.alert {
    border-radius: 0.5rem;
    font-size: 0.9rem;
}

/* Modal improvements */
.modal-body .table {
    font-size: 0.9rem;
}

/* Actions column fixed width */
.actions-col {
    width: 100px;
}

/* N/A styling for missing values */
.na {
    opacity: 0.5;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .stats-ribbon {
        padding: 0.75rem;
    }
    
    .stats-ribbon .stat-value {
        font-size: 1.25rem;
    }
    
    .map-chart-stack {
        height: calc(100vh - 120px);
        min-height: 400px;
    }

    .big-map-canvas {
        height: calc(100vh - 220px);
        min-height: 420px;
    }

    .chart-canvas {
        flex: 0 0 90px;
        height: 90px;
    }

    .mobile-scroll-handle {
        display: block;
        flex: 0 0 18px;
        height: 18px;
        border-top: 1px solid var(--bs-border-color);
        border-bottom: 1px solid var(--bs-border-color);
        background:
            repeating-linear-gradient(
                90deg,
                rgba(var(--bs-secondary-rgb), 0.2),
                rgba(var(--bs-secondary-rgb), 0.2) 8px,
                transparent 8px,
                transparent 16px
            ),
            var(--bs-body-bg);
    }
}

@media (max-width: 991.98px) {
    .navbar {
        padding-top: 0;
        padding-bottom: 0;
        border-bottom: 0 !important;
        overflow: visible;
    }

    .navbar > .container-fluid {
        position: relative;
        min-height: 0;
        padding-top: 0;
        padding-bottom: 0;
    }

    .navbar-brand {
        display: none;
    }

    .navbar .navbar-toggler {
        position: absolute;
        top: 0.35rem;
        right: 0.75rem;
        z-index: 1200;
        padding: 0.2rem 0.45rem;
        background: rgba(var(--bs-body-bg-rgb), 0.96);
        border-color: var(--bs-border-color);
        box-shadow: 0 0.15rem 0.4rem rgba(0, 0, 0, 0.18);
    }

    .navbar .navbar-collapse {
        position: absolute;
        top: 2.7rem;
        right: 0.75rem;
        width: min(22rem, calc(100vw - 1.5rem));
        max-height: calc(100vh - 3.5rem);
        overflow-y: auto;
        margin-top: 0;
        padding: 0.65rem 0.75rem;
        border: 1px solid var(--bs-border-color);
        border-radius: 0.5rem;
        background: var(--bs-body-bg);
        box-shadow: 0 0.65rem 1.5rem rgba(0, 0, 0, 0.26);
        z-index: 1190;
    }

    .navbar-nav .nav-link {
        padding-left: 0.25rem;
        padding-right: 0.25rem;
    }

    .navbar-meta {
        width: 100%;
        margin-top: 0.4rem;
        padding-top: 0.55rem;
        border-top: 1px solid var(--bs-border-color);
    }

    .navbar-meta .build-stamp {
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .navbar-meta #theme-toggle {
        margin-left: -0.25rem;
        padding-left: 0.25rem;
    }
}
