/* app.css — structure and layout for Life Dashboard.
 *
 * This file owns geometry only: boxes, flow, sizing, spacing and stacking.
 * Every colour, font, border weight, corner radius and shadow is read from a
 * custom property that a theme in themes/*.css defines. Adding a theme should
 * never require touching this file.
 *
 * Tokens a theme must define:
 *   Surfaces   --bg-color --card-bg --nav-bg --surface-muted --border-color
 *   Text       --text-color --text-muted
 *   Accents    --primary-color --primary-text --secondary-color --accent-color
 *   States     --hover-surface --row-hover-bg --row-hover-text
 *              --nav-active-bg --nav-active-text --focus-color
 *   Charts     --chart-red --chart-green --chart-blue --chart-cyan
 *              --chart-magenta --chart-yellow --chart-orange
 *   Notes      --note-color --note-bg --note-text --note-inline-color
 *   Type       --font-ui --font-display --font-mono --font-size-base
 *              --line-height --weight-heading --weight-strong
 *              --label-transform --label-tracking
 *   Shape      --radius --radius-lg --border-width --border-width-strong
 *              --card-shadow --shadow-pop
 */

:root {
    /* Layout constants: shared by every theme, overridable by any of them. */
    --header-height: 48px;
    --spacing-unit: 8px;
    --control-height: 36px;

    font-family: var(--font-ui);
    font-size: var(--font-size-base);
    line-height: var(--line-height);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

/* Tells the browser which appearance its own widgets should render in: without
   it the date input's calendar icon stays black on a dark background. */
:root {
    color-scheme: light;
}

[data-theme="dark"] {
    color-scheme: dark;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* App-like feel */
}

::selection {
    background: var(--primary-color);
    color: var(--primary-text);
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: var(--nav-bg);
    border-left: var(--border-width) solid var(--border-color);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border: var(--border-width) solid var(--nav-bg);
    border-radius: var(--radius);
}

::-webkit-scrollbar-corner {
    background: var(--nav-bg);
}


/* Header & Nav */
.app-header {
    height: var(--header-height);
    background-color: var(--bg-color);
    border-bottom: var(--border-width-strong) solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-left h1 {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: var(--weight-heading);
}

@media (max-width: 1200px) {
    .header-left h1 {
        display: none;
    }
}

.main-nav {
    display: flex;
    height: 100%;
    align-items: stretch;
}

.nav-btn {
    background: none;
    border: none;
    padding: 0 1.5rem;
    color: var(--text-color);
    cursor: pointer;
    font-weight: var(--weight-strong);
    font-size: 0.9rem;
    text-decoration: none;
    display: flex;
    align-items: center;
    height: 100%;
}

.nav-btn:hover {
    background-color: var(--hover-surface);
}

.nav-btn.active {
    background-color: var(--nav-active-bg);
    color: var(--nav-active-text);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Settings popover: opened by the header gear, dismissed by Esc or a click
   outside (native popover behaviour, no JS). */
.settings-panel {
    position: fixed;
    inset: auto 1rem auto auto;
    top: calc(var(--header-height) + 4px);
    margin: 0;
    grid-template-columns: max-content minmax(0, 10rem);
    gap: 0.5rem 1rem;
    align-items: center;
    padding: 1rem;
    background: var(--card-bg);
    color: var(--text-color);
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-pop);
}

/* The UA stylesheet hides a closed popover; only reveal it when open. */
.settings-panel:popover-open {
    display: grid;
}

.settings-panel label {
    font-weight: var(--weight-strong);
    font-size: 0.85rem;
    text-transform: var(--label-transform);
    letter-spacing: var(--label-tracking);
}

.settings-panel::backdrop {
    background: transparent;
}

/* Buttons */
.primary-btn,
.secondary-btn,
.icon-btn {
    height: var(--control-height);
    padding: 0 1rem;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-ui);
    font-weight: var(--weight-strong);
    font-size: 0.8rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-transform: var(--label-transform);
    letter-spacing: var(--label-tracking);
    background: var(--bg-color);
    color: var(--text-color);
    vertical-align: middle;
}

.primary-btn {
    background-color: var(--primary-color);
    color: var(--primary-text);
    border-color: var(--primary-border, var(--border-color));
}

.secondary-btn:hover {
    background-color: var(--hover-surface);
}

.icon-btn {
    padding: 4px;
    min-width: 32px;
    min-height: 32px;
}

/* Form Elements */
.select-input,
.date-input,
.file-input,
input[type="text"],
input[type="number"],
input[type="date"],
select {
    height: var(--control-height);
    padding: 0 8px;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--radius);
    background: var(--card-bg);
    color: var(--text-color);
    font-family: var(--font-ui);
    font-size: 0.9rem;
    vertical-align: middle;
}

/* Focus Indicators */
:focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
}

.nav-btn:focus-visible {
    outline-offset: -2px;
}

.select-input:focus,
.date-input:focus,
input:focus {
    outline: 2px solid var(--focus-color);
    outline-offset: 1px;
}

/* Main Content */
#app-content {
    flex: 1;
    overflow: hidden;
    position: relative;
    padding: 0;
    background-color: var(--bg-color);
}

.view-container {
    height: 100%;
    overflow-y: auto;
    background: var(--bg-color);
    padding: 0;
}

.placeholder-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    gap: 1rem;
    border: var(--border-width) dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

/* Generic Tables */
.data-table,
.generic-table {
    width: 100%;
    border-collapse: collapse;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.85rem;
}

.data-table th,
.generic-table th {
    background: var(--surface-muted);
    border-bottom: var(--border-width-strong) solid var(--border-color);
    border-right: var(--table-cell-border) solid var(--border-color);
    padding: 8px;
    text-align: left;
    text-transform: var(--label-transform);
    letter-spacing: var(--label-tracking);
    font-weight: var(--weight-heading);
}

.data-table td,
.generic-table td {
    border-bottom: var(--border-width) solid var(--border-color);
    border-right: var(--table-cell-border) solid var(--border-color);
    padding: 6px 8px;
}

.data-table tr:hover td,
.generic-table tr:hover td {
    background-color: var(--row-hover-bg);
    color: var(--row-hover-text);
}

/* Page controls of a table showing one page of a larger set of rows */
.table-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
    font-size: 0.8rem;
}

.table-pagination[hidden] {
    display: none;
}

.pagination-btn {
    background: none;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-color);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-family: var(--font-ui);
    font-weight: var(--weight-strong);
}

.pagination-btn:hover:not([disabled]) {
    background: var(--row-hover-bg);
    color: var(--row-hover-text);
}

.pagination-btn[disabled] {
    opacity: 0.4;
    cursor: not-allowed;
}


/* View Specific Padding */
finance-view,
health-view,
timeline-view,
energy-view,
raw-data-view,
import-view {
    display: block;
    padding: 1rem;
    height: 100%;
    /* Ensure height for scroll if needed, though view-container handles scroll */
}

/* Map View needs no padding for full bleed */
map-view {
    display: block;
    height: 100%;
    width: 100%;
}

/* Health View */
.health-nav {
    margin-bottom: 1rem;
}

/* Finance View */
.finance-dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.card,
.movie-card,
.import-card,
.day-card {
    background: var(--card-bg);
    padding: var(--card-padding);
    border: var(--card-border-width) solid var(--border-color);
    border-bottom: var(--border-width) solid var(--border-color);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    margin-bottom: var(--card-gap);
}

.card h3 {
    border-bottom: var(--border-width) solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 0.5rem;
    text-transform: var(--label-transform);
    letter-spacing: var(--label-tracking);
    font-size: 0.9rem;
}

.amount {
    font-size: 1.5rem;
    font-weight: var(--weight-heading);
    font-family: var(--font-mono);
}

/* Modals */
.modal-overlay {
    background: var(--overlay-bg);
    backdrop-filter: blur(2px);
}

.modal-content {
    background: var(--card-bg);
    padding: 1rem;
    border: var(--border-width-strong) solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-pop);
}

.close-modal {
    top: 0;
    right: 0;
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: var(--primary-text);
    border-left: var(--border-width) solid var(--border-color);
    border-bottom: var(--border-width) solid var(--border-color);
    font-family: var(--font-ui);
    font-weight: var(--weight-strong);
}

.close-modal:hover {
    background: var(--text-color);
    color: var(--bg-color);
}

/* Timeline */
.timeline-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-height: 1.2rem;
    margin-bottom: 0.5rem;
    padding-right: 40px; /* Clear the timeline scale */
}

#timeline-stats {
    font-size: 0.8rem;
    text-transform: var(--label-transform);
    color: var(--text-muted);
}

/* Marks the end of the loaded days: scrolling to it loads the next batch */
.timeline-sentinel {
    padding: 1rem;
    text-align: center;
    font-size: 0.8rem;
    text-transform: var(--label-transform);
    color: var(--text-muted);
    overflow-anchor: none;
}

/* Stands in for the days not rendered yet, so the scrollbar reflects the whole selected range */
.timeline-spacer {
    pointer-events: none;
    /* Never anchor scrolling here: days loading above the spacer would push the view down */
    overflow-anchor: none;
}

.timeline-content .no-data {
    border: var(--border-width) dashed var(--border-color);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}

.timeline-item {
    border-left: var(--border-width-strong) solid var(--border-color);
    padding-left: 1rem;
    position: relative;
    margin-left: 0.5rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 0;
    width: 10px;
    height: 10px;
    background: var(--primary-color);
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--radius-pill);
}

.day-header {
    background: var(--day-header-bg);
    border-bottom: var(--border-width) solid var(--border-color);
    padding: 0.75rem;
    font-family: var(--font-display);
    font-weight: var(--weight-heading);
    text-transform: var(--label-transform);
    font-size: 1.3rem;
}

.day-stats-list {
    display: flex;
    flex-direction: column;
}

.stat-item {
    padding: 0.25rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Pixel icons from icons/*.svg. The artwork is black; the dark theme
   inverts it to stay legible on a dark background. */
.icon {
    display: inline-block;
    width: 1.1em;
    height: 1.1em;
    vertical-align: -0.2em;
    background-position: center;
    background-size: contain;
    background-repeat: no-repeat;
}

.icon-steps { background-image: url('icons/steps.svg'); }
.icon-sleep { background-image: url('icons/sleep.svg'); }
.icon-nutrition { background-image: url('icons/nutrition.svg'); }
.icon-weight { background-image: url('icons/weight.svg'); }
.icon-music { background-image: url('icons/music.svg'); }
.icon-dive { background-image: url('icons/dive.svg'); }
.icon-running { background-image: url('icons/running.svg'); }
.icon-cycling { background-image: url('icons/cycling.svg'); }
.icon-swimming { background-image: url('icons/swimming.svg'); }
.icon-hiking { background-image: url('icons/hiking.svg'); }
.icon-ski { background-image: url('icons/ski.svg'); }
.icon-multisport { background-image: url('icons/multisport.svg'); }
.icon-workout { background-image: url('icons/workout.svg'); }
.icon-calendar { background-image: url('icons/calendar.svg'); }
.icon-post { background-image: url('icons/post.svg'); }

/* Note marker: decorative, always precedes note text. */
.day-notes-header::before,
.timeline-inline-note::before {
    content: '';
    display: inline-block;
    width: 1.1em;
    height: 1.1em;
    vertical-align: -0.2em;
    margin-right: 0.25em;
    background: url('icons/note.svg') center / contain no-repeat;
}

[data-theme="dark"] .icon,
[data-theme="dark"] .day-notes-header::before,
[data-theme="dark"] .timeline-inline-note::before {
    filter: invert(1);
}

.stat-icon {
    display: inline-flex;
    align-items: center;
    color: var(--text-color);
}

.stat-value {
    font-weight: var(--weight-heading);
}

.stat-sub {
    color: var(--text-muted);
    font-size: 0.9em;
}

.stat-toggle {
    color: var(--text-color);
    cursor: pointer;
}

.stat-details-collapsible {
    padding-left: 1.75rem;
    font-size: 0.85em;
}

.sleep-phases {
    margin: 0;
    padding-left: 1.25rem;
    list-style: disc;
    color: var(--text-muted);
}

.nutrition-macros {
    margin-bottom: 0.25rem;
    font-weight: var(--weight-strong);
}

.nutrition-meal {
    margin-bottom: 0.25rem;
}

.nutrition-foods {
    margin: 0;
    padding-left: 1.25rem;
    list-style: disc;
    color: var(--text-muted);
}

/* Map */
.map-overlay {
    background: var(--card-bg);
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
}

/* Chart Card specific */
chart-card {
    display: block;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    padding: 1rem;
    background: var(--card-bg);
    min-width: 0;
}

chart-card .chart-container {
    position: relative;
    height: 300px;
    /* Fixed height to prevent growth loop */
    width: 100%;
    display: flex;
    flex-direction: column;
}

chart-card canvas {
    flex: 1;
    min-height: 0;
}

/* Helper Utils */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

/* Status Indicator */
#db-status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    font-size: 0.8rem;
    padding: 4px 8px;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--radius);
    background: var(--surface-muted);
    margin-right: 1rem;
}

/* With no database, or nothing unsaved, the chip has no content: show nothing
   rather than an empty box. */
#db-status:empty {
    display: none;
}

/* Compact button inside the status chip */
.btn-small {
    height: 22px;
    padding: 0 0.5rem;
    border: var(--border-width) solid var(--primary-border, var(--border-color));
    border-radius: var(--radius);
    background: var(--primary-color);
    color: var(--primary-text);
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: var(--weight-strong);
    text-transform: var(--label-transform);
    letter-spacing: var(--label-tracking);
    line-height: 1;
    cursor: pointer;
}

/* Grids for Charts */
.charts-grid,
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

@media (min-width: 2000px) {
    .charts-grid,
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Map Dimensions DO NOT REMOVE */
.full-map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

.day-body {
    display: flex;
    flex-direction: row-reverse;
}

.day-map-container {
    width: 250px;
    min-width: 250px;
    height: 200px;
    background: var(--surface-muted);
    position: relative;
    z-index: 1;
}

.day-content {
    flex: 1;
    padding: 0.5rem;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    font-size: 1.5rem;
    font-weight: var(--weight-strong);
    text-transform: var(--label-transform);
    color: var(--text-color);
}

.loading-overlay.hidden {
    display: none !important;
}

/* Screen Reader Only */
.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;
}

/* Skip Link */
.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    z-index: 10000;
    padding: 0.5rem 1rem;
    background: var(--text-color);
    color: var(--bg-color);
    font-weight: var(--weight-strong);
    border: var(--border-width-strong) solid var(--border-color);
}

.skip-link:focus {
    top: 0;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Timeline Scale */
#timeline-scale {
    position: fixed;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    width: 40px;
    z-index: 999;
    pointer-events: none; /* Let clicks pass through to scrollbar if not on a marker */
}

.scale-marker {
    position: absolute;
    right: 15px; /* Clear the scrollbar */
    font-size: 0.7rem;
    font-weight: var(--weight-strong);
    color: var(--text-color);
    background: var(--card-bg);
    padding: 2px 4px;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    pointer-events: auto;
    transform: translateY(-50%);
    white-space: nowrap;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.scale-marker:hover {
    opacity: 1;
    background: var(--row-hover-bg);
    color: var(--row-hover-text);
    z-index: 1000;
}

.scale-marker.major {
    font-weight: var(--weight-heading);
    border-width: var(--border-width-strong);
    right: 15px;
}

#timeline-date-indicator {
    position: fixed;
    right: 60px; /* Left of scale */
    background: var(--primary-color);
    color: var(--primary-text);
    padding: 4px 8px;
    font-weight: var(--weight-strong);
    border: var(--border-width-strong) solid var(--border-color);
    border-radius: var(--radius);
    z-index: 10001;
    pointer-events: none;
    display: none; /* Hidden by default */
    white-space: nowrap;
    box-shadow: var(--shadow-pop);
}

/* Note Component Styles */
.day-notes-section {
    margin-top: 1rem;
    padding: 0.75rem;
    border: var(--border-width) dashed var(--border-color);
    border-radius: var(--radius);
    background: var(--surface-muted);
}

.day-notes-header {
    font-weight: var(--weight-strong);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    text-transform: var(--label-transform);
}

.day-notes-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.day-notes-list li {
    font-size: 0.85rem;
    padding: 0.2rem 0;
    border-bottom: 1px solid var(--hairline-color);
}

.day-notes-list li:last-child {
    border-bottom: none;
}

.day-note-type {
    font-weight: var(--weight-strong);
    color: var(--secondary-color);
}

.day-note-content {
    font-style: italic;
}

.timeline-inline-note {
    font-style: italic;
    color: var(--note-inline-color);
}

/* Chart Note Hover Banner */
.chart-note-hover {
    position: absolute;
    top: 35px;
    right: 10px;
    background: var(--note-bg);
    border: var(--border-width-strong) solid var(--note-color);
    border-radius: var(--radius);
    color: var(--note-text);
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: var(--weight-strong);
    z-index: 10;
    max-width: 250px;
    box-shadow: var(--shadow-pop);
    white-space: normal;
    word-wrap: break-word;
}

/* Add Row form (Explore and Add data section) */
.add-row-form {
    display: grid;
    grid-template-columns: max-content minmax(0, 320px);
    gap: 0.5rem 1rem;
    align-items: center;
    margin-top: 1rem;
}

.add-row-form label {
    font-weight: var(--weight-strong);
    font-size: 0.85rem;
}

.add-row-form button {
    justify-self: start;
}
