/**
 * app.css — custom layer on top of Bootstrap 5 for the app shell (sidebar +
 * bottom nav), excel-dense list tables, KPI boxes, and CSS-only bar charts.
 * See views/layout.php, views/list.php, views/dashboard.php for the markup
 * these classes target.
 */

:root {
    --app-sidebar-width: 220px;
    --app-border-color: #dee2e6;
    --app-accent: #0d6efd;
}

body.app-body {
    margin: 0;
    background: #f5f6f8;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

/* Desktop sidebar */
.app-sidebar {
    width: var(--app-sidebar-width);
    flex-shrink: 0;
    background: #1c2333;
    color: #cfd3dc;
    padding: 1rem 0;
    overflow-y: auto;
}

.app-sidebar-brand {
    font-weight: 600;
    font-size: 1.1rem;
    color: #fff;
    padding: 0 1rem 1rem;
}

.app-menu-group {
    margin-bottom: 0.75rem;
}

.app-menu-group-label {
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    color: #7c8497;
    padding: 0.25rem 1rem;
}

.app-menu-item {
    display: block;
    padding: 0.4rem 1rem;
    color: #cfd3dc;
    text-decoration: none;
}

.app-menu-item:hover {
    background: #2a3247;
    color: #fff;
}

.app-menu-item-dashboard {
    font-weight: 600;
    color: #fff;
    border-bottom: 1px solid #2a3247;
    margin-bottom: 0.5rem;
    padding-bottom: 0.6rem;
}

/* Main column */
.app-main {
    flex-grow: 1;
    min-width: 0;
}

.app-topbar {
    background: #fff;
    border-bottom: 1px solid var(--app-border-color);
    padding: 0.5rem 1rem;
}

.app-topbar-brand {
    font-weight: 600;
    text-decoration: none;
    color: inherit;
}

.app-logout-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--app-accent);
    text-decoration: underline;
    cursor: pointer;
    font-size: inherit;
}

/* Breadcrumbs */
.app-breadcrumbs {
    margin-bottom: 0.75rem;
}

.app-breadcrumbs .breadcrumb {
    margin-bottom: 0;
    font-size: 0.85rem;
}

.app-content {
    padding: 1rem;
}

/* Mobile bottom nav */
.app-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid var(--app-border-color);
    padding: 0.5rem;
    justify-content: space-around;
    z-index: 1030;
}

.app-bottom-nav a,
.app-bottom-nav button {
    text-decoration: none;
    color: inherit;
    background: none;
    border: none;
}

/* Excel-dense list table */
.app-list-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--app-border-color);
    border-radius: 0.25rem;
}

.app-list-table {
    background: #fff;
    font-size: 0.8125rem;
    margin-bottom: 0;
    font-variant-numeric: tabular-nums;
}

.app-list-table th,
.app-list-table td {
    border-color: var(--app-border-color);
    padding: 0.3rem 0.6rem;
    vertical-align: middle;
    white-space: nowrap;
}

.app-list-table thead th {
    position: sticky;
    top: 0;
    background: #f1f3f5;
    box-shadow: inset 0 -1px 0 var(--app-border-color);
    z-index: 1;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #495057;
}

.app-list-table tbody tr:nth-child(even) {
    background: #fafbfc;
}

.app-list-row {
    cursor: pointer;
}

.app-list-row:hover {
    background: #eef4ff !important;
}

.app-cell-numeric {
    font-variant-numeric: tabular-nums;
}

/* Sortable column headers */
.app-sort-link {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.app-sort-link:hover {
    color: var(--app-accent);
}

.app-sort-active {
    color: var(--app-accent);
    font-weight: 600;
}

.app-sort-arrow {
    font-size: 0.65rem;
}

/* Pager */
.app-pager {
    padding: 0.5rem 0.1rem 0;
    font-size: 0.85rem;
}

/* List toolbar — search, column picker, views, export/import, save-view */
.app-list-toolbar {
    background: #fff;
    border: 1px solid var(--app-border-color);
    border-radius: 0.25rem;
    padding: 0.5rem;
}

.app-list-filters {
    background: #fafbfc;
    border: 1px solid var(--app-border-color);
    border-radius: 0.25rem;
    padding: 0.5rem 0.75rem;
}

.app-filter-group input[type="date"],
.app-filter-group select {
    width: auto;
}

/* Bulk operations + recycle bin */
.app-col-checkbox {
    width: 2rem;
    text-align: center;
}

.app-bulk-bar {
    display: flex;
    justify-content: flex-end;
}

.app-list-search {
    width: 220px;
}

.app-column-picker-menu {
    min-width: 220px;
    max-height: 320px;
    overflow-y: auto;
}

.app-views-menu {
    min-width: 240px;
}

.app-views-menu-item {
    padding: 0 0.25rem 0 0;
}

.app-views-menu-item .dropdown-item {
    white-space: normal;
}

.app-view-delete-btn {
    text-decoration: none;
    line-height: 1;
    padding: 0.25rem 0.5rem;
}

.app-save-view-form {
    flex-shrink: 0;
}

/* CSV import mapping */
.app-import-csv-data {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

.app-import-map-table th,
.app-import-map-table td {
    vertical-align: middle;
}

/* File field — list/card previews */
.app-file-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
}

.app-file-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.5rem;
    border: 1px solid var(--app-border-color);
    border-radius: 1rem;
    background: #f8f9fa;
    font-size: 0.75rem;
    color: #495057;
    text-decoration: none;
    max-width: 160px;
}

.app-file-chip:hover {
    background: #eef4ff;
    color: var(--app-accent);
}

.app-file-chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-file-chip-image {
    padding: 0;
    border-radius: 0.25rem;
    overflow: hidden;
    max-width: none;
}

.app-file-chip-image img {
    width: 32px;
    height: 32px;
    object-fit: cover;
    display: block;
}

.app-file-chip-more {
    font-size: 0.75rem;
    color: #6c757d;
}

/* File field — edit form existing-files list */
.app-files-existing li {
    padding: 0.25rem 0;
    border-bottom: 1px solid var(--app-border-color);
}

.app-files-existing li:last-child {
    border-bottom: none;
}

/* KPI boxes — cycled accent palette, applied via app-kpi-color-1..6.
   Rendered as <a class="card app-kpi-box ...">, clickable through to the
   entity's list. */
.app-kpi-box {
    border: none;
    border-left: 4px solid var(--app-accent);
    display: block;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.app-kpi-box:hover {
    transform: translateY(-2px);
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.08);
}

.app-kpi-box .card-body {
    text-align: center;
}

.app-kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--app-accent);
}

.app-kpi-label {
    font-size: 0.8rem;
    color: #6c757d;
}

.app-kpi-color-1 { border-left-color: #0d6efd; background: #eaf2ff; }
.app-kpi-color-1 .app-kpi-value { color: #0d6efd; }

.app-kpi-color-2 { border-left-color: #198754; background: #e9f7ef; }
.app-kpi-color-2 .app-kpi-value { color: #198754; }

.app-kpi-color-3 { border-left-color: #fd7e14; background: #fff2e6; }
.app-kpi-color-3 .app-kpi-value { color: #fd7e14; }

.app-kpi-color-4 { border-left-color: #6f42c1; background: #f2ecfc; }
.app-kpi-color-4 .app-kpi-value { color: #6f42c1; }

.app-kpi-color-5 { border-left-color: #0dcaf0; background: #e7f9fd; }
.app-kpi-color-5 .app-kpi-value { color: #0aa8c9; }

.app-kpi-color-6 { border-left-color: #d63384; background: #fdecf4; }
.app-kpi-color-6 .app-kpi-value { color: #d63384; }

/* CSS-only bar chart */
.app-bar-row {
    margin-bottom: 0.5rem;
}

.app-bar-label {
    width: 40%;
    font-size: 0.8rem;
    color: #6c757d;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-bar-track {
    background: #eef0f3;
    border-radius: 3px;
    height: 0.6rem;
    overflow: hidden;
}

.app-bar-fill {
    background: var(--app-accent);
    height: 100%;
}

.app-bar-value {
    width: 2rem;
    text-align: right;
    font-size: 0.8rem;
}

/* Classic key/value form & view rows — plain label, boxed value, inline */
.app-kv-table {
    background: transparent;
}

.app-kv-table-name {
    max-width: 640px;
}

.app-kv-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 0.4rem 0;
}

.app-kv-label {
    width: 200px;
    flex-shrink: 0;
    padding: 0 0.75rem 0 0;
    font-size: 0.8rem;
    color: #495057;
    display: flex;
    align-items: center;
}

.app-kv-value {
    flex: 1 1 240px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    min-width: 0;
}

.app-kv-value .form-control,
.app-kv-value .form-select,
.app-kv-value textarea {
    font-size: 0.9rem;
}

/* Read-only value box — mirrors the .form-control look so view and edit
   rows line up visually even though view mode has no real input. */
.app-kv-value-box {
    width: 100%;
    padding: 0.375rem 0.75rem;
    font-size: 0.9rem;
    border: 1px solid var(--app-border-color);
    border-radius: 0.375rem;
    background: #f8f9fa;
    min-height: calc(1.5em + 0.75rem + 2px);
    display: flex;
    align-items: center;
}

@media (max-width: 575.98px) {
    .app-kv-row {
        flex-direction: column;
    }

    .app-kv-label {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--app-border-color);
    }
}

/* Sectioned form/view tabs */
.app-form-tabs .nav-link,
.app-related-tabs .nav-link {
    color: #495057;
}

.app-view-card .app-form-tabs .tab-content {
    padding-top: 1rem !important;
}

/* Related-entity tab record counts */
.app-tab-count {
    background: #e9ecef;
    color: #495057;
    font-weight: 500;
    font-size: 0.7rem;
    vertical-align: middle;
}

.nav-link.active .app-tab-count {
    background: var(--app-accent);
    color: #fff;
}

/* Login page */
.app-login-body {
    min-height: 100vh;
    background: #1c2333;
}

.app-login-card {
    width: 100%;
    max-width: 360px;
}

@media (max-width: 767.98px) {
    .app-content {
        padding-bottom: 4rem;
    }
}
