/* ==========================================================================
   Shared Components
   ========================================================================== */

/* Page header — the one "title + actions" bar. `.page-header`/`.page-actions`
   are aliases so both naming conventions render identically. */
.header-actions,
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.header-buttons,
.page-actions {
    display: flex;
    gap: 0.5rem;
}

@media (max-width: 768px) {
    .header-actions,
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .header-actions h2,
    .page-header h1,
    .page-header h2 {
        text-align: center;
    }

    .header-buttons,
    .page-actions {
        display: flex;
        flex-wrap: wrap;
        width: 100%;
    }

    .header-buttons .btn,
    .page-actions .btn {
        flex: 1 1 auto;
        text-align: center;
    }

    /* A dropdown in the bar takes its share of the row like a button. */
    .header-buttons > .menu,
    .page-actions > .menu {
        display: flex;
        flex: 1 1 auto;
    }

    .header-buttons > .menu > summary.btn,
    .page-actions > .menu > summary.btn {
        flex: 1;
        justify-content: center;
    }

    /* Opening towards the right keeps the panel on screen when the menu
       starts the row. */
    .header-buttons > .menu:first-child .menu-panel,
    .page-actions > .menu:first-child .menu-panel {
        left: 0;
        right: auto;
    }
}

/* Page intro — muted description paragraph under a page header.
   One canonical style so every page's lead text matches. */
.page-intro {
    color: var(--color-text-muted);
    max-width: 72ch;
    margin: -0.25rem 0 var(--space-lg);
    line-height: 1.55;
}

/* Info Tooltip (inline help marker used next to section titles) */
.info-tooltip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1em;
    height: 1.1em;
    border-radius: 50%;
    font-size: 0.85em;
    color: var(--color-primary, var(--primary-color));
    cursor: help;
    vertical-align: middle;
    margin-left: 0.25em;
}

.info-tooltip:hover,
.info-tooltip:focus {
    outline: 1px dashed currentColor;
    outline-offset: 2px;
}

/* Tooltip bubble from data-tip. Native title= never shows on touch;
   :focus (the element has tabindex) makes a tap reveal the text. */
.info-tooltip {
    position: relative;
}

.info-tooltip[data-tip]:hover::after,
.info-tooltip[data-tip]:focus::after {
    content: attr(data-tip);
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-tooltip, 1500);
    width: max-content;
    max-width: min(320px, 80vw);
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-md);
    background: var(--dark-color);
    color: white;
    font-size: 0.8rem;
    font-weight: 400;
    line-height: 1.45;
    text-align: left;
    white-space: normal;
    box-shadow: var(--shadow-md);
    pointer-events: none;
}

@media (max-width: 480px) {
    /* Near screen edges, anchor the bubble to the viewport-ish left. */
    .info-tooltip[data-tip]:hover::after,
    .info-tooltip[data-tip]:focus::after {
        left: 0;
        transform: none;
    }
}

/* Filter Card */
.filter-card {
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.filter-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
    width: 100%;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 120px;
}

/* The `display: flex` above would otherwise defeat the [hidden] attribute
   (UA display:none loses to a class rule), leaving a JS-toggled filter group
   — e.g. the stats custom-date range — visible when it should be hidden. */
.filter-group[hidden] {
    display: none;
}

.filter-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.4rem;
    color: var(--secondary-color);
    font-size: 0.85rem;
}

.filter-group.filter-actions {
    flex-direction: row;
    gap: 0.5rem;
    margin-left: auto;
}

@media (max-width: 768px) {
    .filter-row {
        flex-direction: column;
    }

    .filter-group {
        width: 100%;
    }

    .filter-group.filter-actions {
        margin-left: 0;
        flex-direction: column;
    }

    .filter-group.filter-actions .btn {
        width: 100%;
    }
}

/* Empty State */
/* Empty state — flat by default (works inside cards/widgets without
   double-boxing). Add .empty-state--card for a standalone boxed version
   on list pages. Single source; page-level overrides were removed. */
.empty-state {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    color: var(--color-text-muted);
}

.empty-state--card {
    padding: var(--space-3xl) var(--space-xl);
    background: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

.empty-state p {
    color: var(--color-text-muted);
    margin-bottom: 1rem;
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}
.empty-state-icon svg { color: var(--color-text-faint); }

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.pagination-info {
    color: var(--secondary-color);
    font-size: 0.9rem;
}

/* Dropdown menu — a trigger button and a floating panel of .menu-item.
   Used as <details class="menu"> (invoice exports) or as a scripted menu
   button (statistics blocks, panel toggled with [hidden]). */
.menu {
    position: relative;
    display: inline-block;
}
.menu > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu-caret {
    display: inline-block;
    box-sizing: border-box;
    width: 7px;
    height: 7px;
    margin-left: 0.5rem;
    margin-top: -4px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    font-size: 0;
    vertical-align: middle;
    transition: transform 0.15s ease;
}
.menu[open] > summary .menu-caret { transform: rotate(225deg); margin-top: 1px; }
.menu-panel {
        left: 0;
        right: auto;
    }
}

/* Page intro — muted description paragraph under a page header.
   One canonical style so every page's lead text matches. */
.page-intro {
    color: var(--color-text-muted);
    max-width: 72ch;
    margin: -0.25rem 0 var(--space-lg);
    line-height: 1.55;
}

/* Info Tooltip (inline help marker used next to section titles) */
.info-tooltip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1em;
    height: 1.1em;
    border-radius: 50%;
    font-size: 0.85em;
    color: var(--color-primary, var(--primary-color));
    cursor: help;
    vertical-align: middle;
    margin-left: 0.25em;
}

.info-tooltip:hover,
.info-tooltip:focus {
    outline: 1px dashed currentColor;
    outline-offset: 2px;
}

/* Tooltip bubble from data-tip. Native title= never shows on touch;
   :focus (the element has tabindex) makes a tap reveal the text. */
.info-tooltip {
    position: relative;
}

.info-tooltip[data-tip]:hover::after,
.info-tooltip[data-tip]:focus::after {
    content: attr(data-tip);
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-tooltip, 1500);
    width: max-content;
    max-width: min(320px, 80vw);
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-md);
    background: var(--dark-color);
    color: white;
    font-size: 0.8rem;
    font-weight: 400;
    line-height: 1.45;
    text-align: left;
    white-space: normal;
    box-shadow: var(--shadow-md);
    pointer-events: none;
}

@media (max-width: 480px) {
    /* Near screen edges, anchor the bubble to the viewport-ish left. */
    .info-tooltip[data-tip]:hover::after,
    .info-tooltip[data-tip]:focus::after {
        left: 0;
        transform: none;
    }
}

/* Filter Card */
.filter-card {
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.filter-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
    width: 100%;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 120px;
}

/* The `display: flex` above would otherwise defeat the [hidden] attribute
   (UA display:none loses to a class rule), leaving a JS-toggled filter group
   — e.g. the stats custom-date range — visible when it should be hidden. */
.filter-group[hidden] {
    display: none;
}

.filter-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.4rem;
    color: var(--secondary-color);
    font-size: 0.85rem;
}

.filter-group.filter-actions {
    flex-direction: row;
    gap: 0.5rem;
    margin-left: auto;
}

@media (max-width: 768px) {
    .filter-row {
        flex-direction: column;
    }

    .filter-group {
        width: 100%;
    }

    .filter-group.filter-actions {
        margin-left: 0;
        flex-direction: column;
    }

    .filter-group.filter-actions .btn {
        width: 100%;
    }
}

/* Empty State */
/* Empty state — flat by default (works inside cards/widgets without
   double-boxing). Add .empty-state--card for a standalone boxed version
   on list pages. Single source; page-level overrides were removed. */
.empty-state {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    color: var(--color-text-muted);
}

.empty-state--card {
    padding: var(--space-3xl) var(--space-xl);
    background: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

.empty-state p {
    color: var(--color-text-muted);
    margin-bottom: 1rem;
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}
.empty-state-icon svg { color: var(--color-text-faint); }

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.pagination-info {
    color: var(--secondary-color);
    font-size: 0.9rem;
}

/* Dropdown menu — a trigger button and a floating panel of .menu-item.
   Used as <details class="menu"> (invoice exports) or as a scripted menu
   button (statistics blocks, panel toggled with [hidden]). */
.menu {
    position: relative;
    display: inline-block;
}
.menu > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.35rem);
    z-index: 30;
    min-width: 14rem;
    padding: var(--space-2xs) 0;
    background: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}
.menu-heading {
    padding: var(--space-xs) var(--space-sm) var(--space-2xs);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}
.menu-item {
    display: block;
    padding: var(--space-2xs) var(--space-sm) var(--space-2xs) var(--space-md);
    color: var(--color-text);
    text-decoration: none;
    font-size: var(--text-sm);
    white-space: nowrap;
}
.menu-item:hover,
.menu-item:focus-visible {
    background: rgba(var(--primary-rgb), 0.1);
    color: var(--primary-color);
    outline: none;
}
.menu-separator {
    height: 1px;
    margin: var(--space-2xs) 0;
    background: var(--border-color);
}
button.menu-item {
    width: 100%;
    border: 0;
    background: none;
    font: inherit;
    font-size: var(--text-sm);
    text-align: left;
    cursor: pointer;
}
