:root {
    --pelican-red: #b20f10;
    --pelican-red-soft: #e15b5b;
    --pelican-gold: #d7a94b;
    --pelican-gold-soft: #f2d690;
    --pelican-charcoal: #5e5e5e;
    --pelican-charcoal-dark: #4a4a4a;
    --pelican-ink: #1e2430;
    --pelican-muted: #66707f;
    --pelican-card: rgba(255, 255, 255, 0.96);
    --pelican-line: rgba(255, 255, 255, 0.16);
    --pelican-shadow: 0 18px 42px rgba(0, 0, 0, 0.12);
    --pelican-maxw: 1920px;
    --pelican-gutter: 22px;

    /* Light UI tokens using Pelican brand colors */
    --ui-bg: #eef2f7;
    --ui-card: #ffffff;
    --ui-border: rgba(15, 23, 42, 0.10);
    --ui-text: #0f172a;
    --ui-muted: #64748b;
    --ui-primary: var(--pelican-red);
    --ui-primary-soft: rgba(178, 15, 16, 0.12);
    --ui-accent: var(--pelican-gold);
    --ui-accent-soft: rgba(215, 169, 75, 0.18);

    /* Layout defaults (used with fallbacks so header/sidebar never overlap) */
    --sidebar-w: 252px;
    --topbar-h: 76px;
}

/* Layout variables (Unolo-inspired shell)
   NOTE: Do not self-reference CSS variables here; it makes them invalid on <body>.
   Keep defaults in :root and override via body classes (e.g. .sidebar-collapsed). */

/* Use higher specificity than page-local "body { ... }" rules */
html body:not(.pelican-login):not(.pelican-legacy) {
    background: var(--ui-bg);
    color: var(--ui-text);
    min-height: 100vh;
    /* Don't rely on body padding for layout; pages sometimes override it. */
    padding: 0 !important;
    margin: 0 !important;
}

/* Most legacy pages still render an old topbar; hide it in favor of app-topbar. */
html body:not(.pelican-login):not(.pelican-legacy) .topbar {
    display: none !important;
}

/* Sidebar + topbar shell (Unolo-inspired) */
.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w, 252px);
    /* Critical: include padding inside the declared width so the sidebar
       doesn't visually overlap the topbar/content (seen as "overlap" in header). */
    box-sizing: border-box;
    background-image:
        radial-gradient(rgba(255, 255, 255, 0.06) 0.8px, transparent 0.8px),
        radial-gradient(rgba(255, 255, 255, 0.03) 0.8px, transparent 0.8px),
        linear-gradient(180deg, #2b2f36 0%, #1f242c 55%, #181c23 100%);
    background-size: 10px 10px, 18px 18px, auto;
    background-position: 0 0, 6px 6px, 0 0;
    /* We'll draw the seam as a pseudo-element so it aligns with the topbar. */
    border-right: none;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    padding: 16px 14px;
    z-index: 1000;
    overflow: hidden;
}

.app-sidebar::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 1px;
    background: rgba(255, 255, 255, 0.10);
    pointer-events: none;
}

.app-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
    margin-bottom: 12px;
    position: relative;
}

.app-sidebar-logo {
    width: 44px;
    height: 44px;
    object-fit: contain;
    border-radius: 12px;
    background: linear-gradient(180deg, #c31314 0%, #920e0f 100%);
    padding: 8px;
}

.app-sidebar-name {
    font-weight: 950;
    letter-spacing: 0.02em;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.92);
    /* Wrap the product name instead of showing "..." */
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.1;
    max-width: 132px;
}

.app-sidebar-collapse {
    margin-left: auto;
    width: 36px;
    height: 36px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.app-sidebar-collapse:hover {
    background: rgba(255, 255, 255, 0.09);
    border-color: rgba(255, 255, 255, 0.18);
    transform: translateY(-1px);
}

.app-sidebar-collapse::before {
    content: "";
    width: 18px;
    height: 18px;
    background: rgba(255, 255, 255, 0.92);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M4 5h16a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1zm1 2v10h4V7H5zm6 0v10h8V7h-8z'/%3E%3C/svg%3E") no-repeat center / contain;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M4 5h16a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1zm1 2v10h4V7H5zm6 0v10h8V7h-8z'/%3E%3C/svg%3E") no-repeat center / contain;
}

.app-sidebar-nav {
    display: grid;
    gap: 12px;
    padding: 6px 4px 10px;
}

.nav-section {
    display: grid;
    gap: 6px;
    padding: 6px 0 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}

.nav-section:last-child {
    border-bottom: none;
}

.nav-section-title {
    padding: 0 12px;
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.62);
}

.app-sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    text-decoration: none !important;
    color: rgba(255, 255, 255, 0.88) !important;
    font-weight: 850;
    font-size: 13px;
    border: 1px solid transparent;
}

.app-sidebar-nav a::before {
    content: "";
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    background-color: currentColor;
    opacity: 0.9;
    -webkit-mask: var(--nav-icon) no-repeat center / contain;
    mask: var(--nav-icon) no-repeat center / contain;
}

.app-sidebar-nav a:hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.10);
}

.app-sidebar-nav a.active {
    background: rgba(255, 255, 255, 0.10);
    color: #ffffff !important;
    border-color: rgba(225, 91, 91, 0.38);
    box-shadow: inset 0 0 0 1px rgba(225, 91, 91, 0.20);
}

.app-sidebar-nav a.active::before {
    opacity: 1;
    background-color: var(--pelican-red-soft);
}

/* Sidebar icons (mask SVGs) */
.app-sidebar-nav a.nav-dashboard { --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M3 3h8v8H3V3zm10 0h8v5h-8V3zM3 13h5v8H3v-8zm7 0h11v8H10v-8z'/%3E%3C/svg%3E"); }
.app-sidebar-nav a.nav-customerdash { --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M4 6a2 2 0 0 1 2-2h5a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6Zm9 1h5l2 2v7a2 2 0 0 1-2 2h-5V7Zm-9 8h8v3a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-3Zm11 4h4v2h-4v-2Z'/%3E%3C/svg%3E"); }
.app-sidebar-nav a.nav-engineers { --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M12 12a4 4 0 1 0-4-4a4 4 0 0 0 4 4zm0 2c-4.4 0-8 2.1-8 4.7V21h16v-2.3c0-2.6-3.6-4.7-8-4.7z'/%3E%3C/svg%3E"); }
.app-sidebar-nav a.nav-customers { --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M16 11c1.7 0 3-1.6 3-3.5S17.7 4 16 4s-3 1.6-3 3.5S14.3 11 16 11zM8 11c1.7 0 3-1.6 3-3.5S9.7 4 8 4S5 5.6 5 7.5S6.3 11 8 11zm0 2c-2.7 0-5 1.3-5 3v3h10v-3c0-1.7-2.3-3-5-3zm8 0c-.3 0-.6 0-.9.1c1.1.8 1.9 1.9 1.9 3.2V21h6v-3c0-1.7-2.3-3-5-3z'/%3E%3C/svg%3E"); }
.app-sidebar-nav a.nav-machines { --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M4 6h10v6H4V6zm12 0h4v10h-4V6zM6 14h8v4H6v-4zm10 4h4v2h-4v-2z'/%3E%3C/svg%3E"); }
.app-sidebar-nav a.nav-visit { --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M7 2h10v2h3v18H4V4h3V2zm-1 6v12h12V8H6zm2 2h8v2H8v-2zm0 4h6v2H8v-2z'/%3E%3C/svg%3E"); }
.app-sidebar-nav a.nav-reports { --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M6 2h9l3 3v17H6V2zm8 1.5V6h2.5L14 3.5zM8 9h8v2H8V9zm0 4h8v2H8v-2zm0 4h6v2H8v-2z'/%3E%3C/svg%3E"); }
.app-sidebar-nav a.nav-expenses { --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M12 2a7 7 0 0 0-7 7v4a5 5 0 0 0 5 5h9v-2H10a3 3 0 0 1-3-3V9a5 5 0 0 1 10 0v1h2V9a7 7 0 0 0-7-7zm-2 9h4v2h-4v-2z'/%3E%3C/svg%3E"); }
.app-sidebar-nav a.nav-backup { --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M12 3a7 7 0 0 0-7 7H3l3.5 3.5L10 10H7a5 5 0 1 1 1.5 3.5L7 15a7 7 0 1 0 5-12zm-1 5h2v5h-2V8zm0 7h2v2h-2v-2z'/%3E%3C/svg%3E"); }
.app-sidebar-nav a.nav-visitlist { --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M7 2a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8.83a2 2 0 0 0-.59-1.41l-3.83-3.83A2 2 0 0 0 13.17 3H7Zm6 1.5V8a1 1 0 0 0 1 1h4.5V20a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h6Zm-5 9.5a1 1 0 0 1 1-1h6a1 1 0 1 1 0 2H9a1 1 0 0 1-1-1Zm0 4a1 1 0 0 1 1-1h6a1 1 0 1 1 0 2H9a1 1 0 0 1-1-1Z'/%3E%3C/svg%3E"); }
.app-sidebar-nav a.nav-daily { --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M7 2a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8.83a2 2 0 0 0-.59-1.41l-3.83-3.83A2 2 0 0 0 13.17 3H7Zm6 1.5V8a1 1 0 0 0 1 1h4.5V20a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h6Zm-3 10.5h1.5V12a1 1 0 1 1 2 0v2h1.5a1 1 0 1 1 0 2H13.5v2a1 1 0 1 1-2 0v-2H10a1 1 0 1 1 0-2Z'/%3E%3C/svg%3E"); }
.app-sidebar-nav a.nav-traveldash { --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M2 16.5 21 12 2 7.5v3.5l13 1-13 1v3.5Zm2 1.3V18l5.6-1.1L4 17.8Z'/%3E%3C/svg%3E"); }
.app-sidebar-nav a.nav-travelreq { --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M6 2h9l5 5v15H6V2Zm8 1.5V8h4.5L14 3.5ZM8 11h10v2H8v-2Zm0 4h10v2H8v-2Zm0-8h4v2H8V7Z'/%3E%3C/svg%3E"); }

.app-sidebar-footer {
    margin-top: auto;
    display: flex;
    gap: 10px;
    padding: 14px 6px 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.10);
}

.app-sidebar-footer a {
    flex: 1 1 0;
    text-align: center;
    padding: 10px 10px;
    border-radius: 12px;
    text-decoration: none !important;
    font-weight: 950;
    font-size: 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: rgba(255, 255, 255, 0.92) !important;
    background: rgba(255, 255, 255, 0.06);
}

.app-sidebar-footer a.warn {
    color: #ffffff !important;
    border-color: rgba(225, 91, 91, 0.36);
    background: linear-gradient(180deg, rgba(225, 91, 91, 0.26) 0%, rgba(178, 15, 16, 0.18) 100%);
}

.app-topbar {
    position: fixed;
    left: var(--sidebar-w, 252px);
    right: 0;
    top: 0;
    height: var(--topbar-h, 76px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 22px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--ui-border);
    z-index: 900;
    box-shadow: 0 6px 18px rgba(2, 8, 23, 0.06);
    box-sizing: border-box;
    /* The sidebar already draws the vertical seam. Avoid a double seam line. */
    border-left: none;
}

/* Main content wrapper inserted by header_nav.php (prevents sidebar overlap everywhere). */
.app-content {
    margin-left: var(--sidebar-w, 252px);
    padding: calc(var(--topbar-h, 76px) + 16px) var(--pelican-gutter) 28px;
    min-height: 100vh;
    box-sizing: border-box;
}

/* ------------------------------
   Table UX (resize + sort)
------------------------------ */
.pelican-table-wrap {
    width: 100%;
    overflow: auto;
    border-radius: 16px;
    border: 1px solid var(--ui-border);
    background: #fff;
    box-shadow: 0 18px 42px rgba(2, 8, 23, 0.08);
}

table.pelican-table {
    /* Allow horizontal overflow when there are many columns */
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: auto;
}

table.pelican-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.86) 0%, rgba(15, 23, 42, 0.78) 100%);
    color: rgba(255, 255, 255, 0.92);
    font-weight: 950;
    font-size: 13px;
    padding: 12px 12px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    user-select: none;
}

table.pelican-table thead th:last-child {
    border-right: none;
}

table.pelican-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    border-right: 1px solid rgba(15, 23, 42, 0.06);
    font-size: 13px;
    color: #0f172a;
    background: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

table.pelican-table tbody tr:nth-child(even) td {
    background: rgba(15, 23, 42, 0.02);
}

table.pelican-table tbody td:last-child {
    border-right: none;
}

.pelican-th {
    position: relative;
}

.pelican-th.sortable {
    cursor: pointer;
}

.pelican-th .th-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.pelican-th .sort-indicator {
    width: 10px;
    height: 10px;
    opacity: 0.85;
    transform: translateY(1px);
}

.pelican-th[data-sort="asc"] .sort-indicator {
    opacity: 1;
    transform: rotate(180deg) translateY(-1px);
}

.pelican-th[data-sort="desc"] .sort-indicator {
    opacity: 1;
    transform: rotate(0deg) translateY(1px);
}

.pelican-th[data-sort="none"] .sort-indicator {
    opacity: 0.25;
}

.pelican-col-resizer {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    width: 10px;
    cursor: col-resize;
    touch-action: none;
}

.pelican-col-resizer::after {
    content: "";
    position: absolute;
    right: 4px;
    top: 25%;
    bottom: 25%;
    width: 2px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.22);
}

/* ------------------------------
   List toolbar (Unolo-like)
------------------------------ */
.list-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid rgba(15, 23, 42, 0.10);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 14px 28px rgba(2, 8, 23, 0.08);
    margin: 0 auto 14px;
}

.list-toolbar-title {
    font-weight: 950;
    color: #0f172a;
    font-size: 15px;
    white-space: nowrap;
}

.list-toolbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.list-search {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: #ffffff;
    min-width: 260px;
}

.list-search input {
    border: none;
    outline: none;
    width: 100%;
    font-size: 13px;
    background: transparent;
    color: #0f172a;
}

.list-search .icon {
    width: 16px;
    height: 16px;
    opacity: 0.75;
    background: #0f172a;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M10 2a8 8 0 1 1 5.3 14l4.4 4.4-1.4 1.4-4.4-4.4A8 8 0 0 1 10 2zm0 2a6 6 0 1 0 0 12a6 6 0 0 0 0-12z'/%3E%3C/svg%3E") no-repeat center / contain;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M10 2a8 8 0 1 1 5.3 14l4.4 4.4-1.4 1.4-4.4-4.4A8 8 0 0 1 10 2zm0 2a6 6 0 1 0 0 12a6 6 0 0 0 0-12z'/%3E%3C/svg%3E") no-repeat center / contain;
}

@media (max-width: 1100px) {
    .list-search { min-width: 200px; }
}

/* Allow wrapping in specific cells when needed */
table.pelican-table td.wrap {
    white-space: normal;
}

/* ------------------------------
   Sticky horizontal scroll controls (left/right buttons)
------------------------------ */
.pelican-hscroll {
    position: sticky;
    bottom: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 999px;
    border: 1px solid rgba(15, 23, 42, 0.10);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 14px 28px rgba(2, 8, 23, 0.10);
    z-index: 60;
    width: fit-content;
    margin: 10px auto 0;
}

.pelican-hscroll .hs-btn {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: rgba(15, 23, 42, 0.04);
    color: #0f172a;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 950;
    line-height: 1;
}

.pelican-hscroll .hs-btn:active {
    transform: translateY(1px);
}

.pelican-hscroll .hs-track {
    width: min(720px, calc(100vw - 420px));
    height: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.04);
    border: 1px solid rgba(15, 23, 42, 0.08);
}

.pelican-hscroll .hs-track::-webkit-scrollbar { height: 10px; }
.pelican-hscroll .hs-track::-webkit-scrollbar-thumb {
    background: rgba(15, 23, 42, 0.22);
    border-radius: 999px;
}

.pelican-hscroll .hs-inner { height: 1px; }

body.has-hscroll .app-content {
    padding-bottom: calc(28px + 56px);
}

/* Collapsed sidebar still reserves space (no overlap). */
html body.sidebar-collapsed {
    --sidebar-w: 86px;
}

html body.sidebar-collapsed .app-sidebar-name {
    display: none;
}

html body.sidebar-collapsed .app-sidebar-brand {
    justify-content: center;
    padding: 46px 6px 12px;
}

html body.sidebar-collapsed .app-sidebar-collapse {
    position: absolute;
    right: 10px;
    top: 10px;
}

html body.sidebar-collapsed .app-sidebar-logo {
    width: 42px;
    height: 42px;
    padding: 6px;
    border-radius: 14px;
}

html body.sidebar-collapsed .nav-section-title {
    display: none;
}

html body.sidebar-collapsed .nav-section {
    padding: 4px 0 10px;
}

html body.sidebar-collapsed .app-sidebar-nav {
    gap: 10px;
    padding-left: 0;
    padding-right: 0;
}

html body.sidebar-collapsed .app-sidebar-nav a {
    width: 54px;
    height: 46px;
    margin: 0 auto;
    justify-content: center;
    gap: 0;
    padding: 0;
    border-radius: 14px;
}

html body.sidebar-collapsed .app-sidebar-nav a {
    font-size: 0;
}

html body.sidebar-collapsed .app-sidebar-footer {
    flex-direction: column;
    padding: 12px 6px 10px;
}

html body.sidebar-collapsed .app-sidebar-footer a {
    padding: 9px 8px;
    font-size: 12px;
}

/* Keep footer text visible even in collapsed state (Back/Logout). */

.app-topbar::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 3px;
    background: linear-gradient(90deg, rgba(178, 15, 16, 0.0), rgba(178, 15, 16, 0.65), rgba(215, 169, 75, 0.55), rgba(178, 15, 16, 0.0));
    pointer-events: none;
}

.app-topbar-burger {
    display: none;
    width: 44px;
    height: 44px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 12px;
    background: #ffffff;
    cursor: pointer;
}

.app-topbar-burger span {
    display: block;
    width: 18px;
    height: 2px;
    background: #334155;
    margin: 4px auto;
    border-radius: 2px;
}

.app-topbar-title {
    display: grid;
    gap: 4px;
    margin-left: 6px;
}

.app-topbar-kicker {
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ui-muted);
    font-weight: 850;
}

.app-topbar-h1 {
    font-size: 22px;
    font-weight: 950;
    letter-spacing: 0.01em;
}

.app-topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-topbar-link {
    text-decoration: none !important;
    color: #334155 !important;
    font-weight: 900;
    font-size: 13px;
    padding: 8px 10px;
    border-radius: 10px;
}

.app-topbar-link:hover {
    background: var(--ui-accent-soft);
}

.app-topbar-user {
    padding: 9px 12px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.04);
    border: 1px solid rgba(15, 23, 42, 0.08);
    font-weight: 950;
    color: #334155;
    font-size: 13px;
}

.app-sidebar-scrim {
    display: none;
}

/* Common page primitives */
.page {
    width: min(98%, 1400px);
    margin: 18px auto 34px;
}

.card {
    background: var(--ui-card);
    border: 1px solid var(--ui-border);
    border-radius: 16px;
    box-shadow: 0 18px 42px rgba(2, 8, 23, 0.08);
}

.card.pad {
    padding: 16px 16px;
}

.card-title {
    margin: 0;
    font-size: 18px;
    font-weight: 950;
    letter-spacing: 0.01em;
}

.muted {
    color: var(--ui-muted);
}

.module-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    align-items: center;
    padding: 10px 6px 0;
}

.module-tabs a {
    text-decoration: none !important;
    color: #334155 !important;
    font-weight: 950;
    font-size: 13px;
    padding: 10px 10px;
    border-bottom: 2px solid transparent;
}

.module-tabs a.active {
    color: var(--ui-primary) !important;
    border-bottom-color: var(--ui-primary);
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
}

.toolbar .left,
.toolbar .right {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: #ffffff;
}

.field input,
.field select {
    border: none;
    outline: none;
    font-size: 13px;
    min-width: 160px;
    background: transparent;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: #ffffff;
    color: #0f172a;
    font-weight: 950;
    text-decoration: none !important;
    cursor: pointer;
    font-size: 13px;
}

.btn.primary {
    border-color: rgba(178, 15, 16, 0.22);
    background: var(--ui-primary-soft);
    color: var(--ui-primary);
}

.btn.primary-fill {
    border-color: rgba(178, 15, 16, 0.32);
    background: linear-gradient(180deg, rgba(225, 91, 91, 0.95) 0%, rgba(178, 15, 16, 0.95) 100%);
    color: #ffffff;
    box-shadow: 0 14px 26px rgba(178, 15, 16, 0.18);
}

.btn.primary-fill:hover {
    filter: brightness(1.02);
    transform: translateY(-1px);
}

.btn.primary-fill:active {
    transform: translateY(0);
}

.btn.dark {
    border-color: rgba(15, 23, 42, 0.14);
    background: rgba(15, 23, 42, 0.86);
    color: #ffffff;
}

/* ------------------------------
   Form grid (used by Daily Visit Entry / quick entry pages)
------------------------------ */
.pelican-form-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.pelican-form-head .title {
    font-size: 18px;
    font-weight: 950;
    letter-spacing: 0.01em;
    margin: 0;
}

.pelican-form-head .sub {
    color: var(--ui-muted);
    font-weight: 850;
    font-size: 13px;
}

.pelican-form-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 12px;
}

.pelican-field {
    grid-column: span 3;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(15, 23, 42, 0.10);
    border-radius: 16px;
    padding: 10px 12px;
    box-shadow: 0 10px 22px rgba(2, 8, 23, 0.03);
}

.pelican-field label {
    display: block;
    margin: 0 0 6px;
    font-size: 12px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-weight: 950;
    color: #475569;
}

.pelican-field input,
.pelican-field select,
.pelican-field textarea {
    width: 100%;
    height: 38px;
    border-radius: 12px;
    border: 1px solid rgba(15, 23, 42, 0.14);
    background: #ffffff;
    padding: 8px 10px;
    font-size: 13px;
    outline: none;
    box-sizing: border-box;
    line-height: 1.2;
}

.pelican-field input[type="date"] {
    /* Make native date fields look centered and consistent with other inputs. */
    font-variant-numeric: tabular-nums;
}

/* Chrome/Edge date field internals */
.pelican-field input[type="date"]::-webkit-datetime-edit {
    padding: 0;
    line-height: 1.2;
}

.pelican-field input[type="date"]::-webkit-datetime-edit-fields-wrapper {
    padding: 0;
}

.pelican-field input[type="date"]::-webkit-calendar-picker-indicator {
    opacity: 0.7;
    cursor: pointer;
}

.pelican-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    margin-top: 16px;
}

.pelican-field textarea {
    height: auto;
    min-height: 90px;
    resize: vertical;
}

.pelican-field input:focus,
.pelican-field select:focus,
.pelican-field textarea:focus {
    border-color: rgba(178, 15, 16, 0.45);
    box-shadow: 0 0 0 4px rgba(178, 15, 16, 0.10);
}

@media (max-width: 1100px) {
    .pelican-field { grid-column: span 6; }
}

@media (max-width: 640px) {
    .pelican-field { grid-column: span 12; }
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.table th,
.table td {
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    padding: 12px 12px;
    font-size: 13px;
    text-align: left;
    vertical-align: top;
}

.table th {
    color: #475569;
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-weight: 950;
    background: rgba(15, 23, 42, 0.02);
    position: sticky;
    top: 0;
    z-index: 2;
}

.table-wrap {
    overflow: auto;
    max-height: calc(100vh - 270px);
    border-top: 1px solid rgba(15, 23, 42, 0.06);
}

.kpi-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
}

.kpi {
    padding: 14px 14px;
    border-radius: 14px;
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.10);
}

.kpi .label {
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #64748b;
    font-weight: 900;
    margin-bottom: 8px;
}

.kpi .value {
    font-size: 22px;
    font-weight: 950;
}

@media (max-width: 1100px) {
    .kpi-grid { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
    .table-wrap { max-height: none; }
}

@media (max-width: 980px) {
    /* Keep a no-overlap layout even on smaller screens by defaulting to a slimmer sidebar. */
    html body { --sidebar-w: 86px; }
    .app-topbar-right { display: none; }
    .app-topbar-h1 { font-size: 18px; }
}

/* Legacy mobile overlay + legacy collapse CSS removed: collapse is handled by CSS variables above. */

/* ------------------------------
   Login page
   Scope everything to .pelican-login so the rest of the app is unaffected.
------------------------------ */
body.pelican-login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    margin: 0;
    background:
        radial-gradient(circle at 52% 34%, rgba(255, 255, 255, 0.20), transparent 42%),
        linear-gradient(120deg, #b20f10 0%, #7b4aa6 100%);
}

body.pelican-login::before {
    opacity: 0.22;
    background-image:
        radial-gradient(rgba(255, 255, 255, 0.10) 0.8px, transparent 0.8px);
    background-size: 10px 10px;
}

.pelican-login-card {
    width: min(680px, calc(100vw - 48px));
    background: rgba(255, 255, 255, 0.96);
    border-radius: 18px;
    padding: 34px 42px 40px;
    box-shadow: 0 26px 70px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(15, 23, 42, 0.10);
    text-align: center;
}

.pelican-login-brand {
    display: flex;
    justify-content: center;
    margin-bottom: 18px;
}

.pelican-login-logo {
    min-width: 260px;
    min-height: 88px;
    border-radius: 14px;
    gap: 12px;
}

.pelican-login-logo img {
    width: 160px;
    max-width: 100%;
}

.pelican-login-wordmark {
    display: none;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.92);
    letter-spacing: 0.08em;
}

.pelican-login-title {
    margin: 0 0 18px;
    font-size: 30px;
    letter-spacing: 0.02em;
    font-weight: 900;
    color: #0f172a;
}

.pelican-login-alert {
    background: rgba(255, 240, 240, 0.96);
    border-left: 4px solid #b91c1c;
    padding: 10px 12px;
    border-radius: 12px;
    color: #5f1b1b;
    margin: 0 auto 16px;
    text-align: left;
    font-size: 13px;
}

.pelican-login-form {
    display: grid;
    gap: 10px;
    text-align: left;
    margin-top: 6px;
}

.pelican-login-label {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.02em;
    color: #0f172a;
}

.pelican-login-input {
    width: 100%;
    padding: 14px 14px;
    border: 1px solid rgba(15, 23, 42, 0.14);
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    background: rgba(239, 246, 255, 0.78);
    transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.pelican-login-input:focus {
    border-color: rgba(178, 15, 16, 0.55);
    box-shadow: 0 0 0 4px rgba(178, 15, 16, 0.14);
    transform: translateY(-1px);
}

.pelican-login-button {
    margin-top: 12px;
    width: 100%;
    padding: 14px 16px;
    border: none;
    border-radius: 12px;
    color: #ffffff;
    font-size: 14px;
    font-weight: 900;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    background: linear-gradient(180deg, #e15b5b 0%, #c51617 100%);
    box-shadow: 0 16px 34px rgba(197, 22, 23, 0.25);
    transition: transform 140ms ease, filter 140ms ease;
}

.pelican-login-button:hover {
    filter: brightness(1.02);
    transform: translateY(-1px);
}

@media (max-width: 520px) {
    .pelican-login-card {
        padding: 26px 18px 28px;
    }
    .pelican-login-title {
        font-size: 24px;
    }
}

.topbar {
    background: rgba(52, 52, 52, 0.86) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12) !important;
    backdrop-filter: blur(8px);
}

.topbar a {
    color: #ffffff !important;
}

.header-nav-wrap {
    background:
        radial-gradient(circle at 14% 25%, rgba(215, 169, 75, 0.18), transparent 28%),
        radial-gradient(circle at 82% 20%, rgba(226, 96, 96, 0.22), transparent 32%),
        linear-gradient(135deg, #343434 0%, #2c2c2c 50%, #242424 100%) !important;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.2) !important;
    padding: 24px 20px 12px !important;
}

.header-nav-wrap--compact {
    padding: 14px 18px 10px !important;
}

.header-nav-wrap--compact .pelican-header-brand {
    margin-bottom: 12px;
}

.header-nav-wrap--compact .pelican-logo-box {
    min-width: 168px;
    min-height: 68px;
    padding: 10px 16px;
    border-radius: 14px;
}

.header-nav-wrap--compact .pelican-logo-box img {
    width: 130px;
}

.header-nav-wrap--compact .pelican-kicker {
    margin-bottom: 6px;
    font-size: 11px;
}

.header-nav-wrap--compact .header-title {
    font-size: 26px !important;
}

.header-nav-wrap--compact .header-nav {
    padding: 12px 14px;
    border-radius: 18px;
}

.header-nav-wrap--compact .header-nav a {
    padding: 10px 14px !important;
    font-size: 12px;
    min-width: 0;
}

.pelican-header-shell {
    max-width: var(--pelican-maxw);
    margin: 0 auto;
    padding: 0 var(--pelican-gutter);
}

.pelican-header-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
    padding: 0 8px;
}

.pelican-logo-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 208px;
    min-height: 88px;
    padding: 14px 22px;
    background: linear-gradient(180deg, #c31314 0%, #920e0f 100%);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.18);
}

.pelican-logo-box img {
    width: 150px;
    max-width: 100%;
    display: block;
}

.pelican-title-wrap {
    text-align: right;
}

.pelican-header-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px 14px;
    margin-bottom: 10px;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.01em;
}

.pelican-header-links a,
.pelican-header-links a:link,
.pelican-header-links a:visited {
    color: rgba(255, 255, 255, 0.92) !important;
    text-decoration: none !important;
    padding: 6px 0;
    border-bottom: 2px solid transparent;
    transition: border-color 140ms ease, color 140ms ease;
    white-space: nowrap;
}

.pelican-header-links a:hover {
    border-bottom-color: rgba(242, 214, 144, 0.95);
}

.pelican-header-links .pelican-link-quiet {
    color: rgba(255, 255, 255, 0.75) !important;
}

.pelican-header-links .pelican-link-warn {
    color: rgba(242, 214, 144, 0.98) !important;
}

.pelican-header-links .pelican-link-warn:hover {
    border-bottom-color: rgba(225, 91, 91, 0.9);
}

.pelican-kicker {
    color: var(--pelican-gold-soft);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.header-title {
    text-align: right !important;
    color: #ffffff !important;
    font-size: 32px !important;
    font-weight: 800 !important;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 0 !important;
    text-shadow: 0 10px 22px rgba(0, 0, 0, 0.32);
}

.header-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    max-width: var(--pelican-maxw);
    margin: 0 auto;
    padding: 18px 20px;
    border-radius: 22px;
    background: rgba(18, 22, 30, 0.72) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(10px);
}

.header-nav a {
    background: rgba(255, 255, 255, 0.12) !important;
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: #ffffff !important;
    border-radius: 999px !important;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 13px;
    font-weight: 700;
    padding: 12px 18px !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.header-nav a:hover {
    background: rgba(255, 255, 255, 0.2) !important;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    max-width: var(--pelican-maxw);
    margin: 18px auto;
    padding: 16px 18px;
    border-radius: 22px;
    background: rgba(18, 22, 30, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    box-shadow: 0 18px 34px rgba(0, 0, 0, 0.16);
}

.page-actions.align-right {
    justify-content: flex-end;
}

.page-actions.compact {
    padding: 10px 12px;
    border-radius: 16px;
    gap: 10px;
}

.page-actions.compact a {
    min-width: auto;
    padding: 10px 14px;
    font-size: 12px;
    letter-spacing: 0.03em;
}

.page-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    max-width: var(--pelican-maxw);
    margin: 10px auto 14px;
    padding: 8px 10px 0;
    border-radius: 16px;
    background: rgba(18, 22, 30, 0.58);
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(10px);
    box-shadow: 0 16px 30px rgba(0, 0, 0, 0.14);
}

.page-tabs a,
.page-tabs a:link,
.page-tabs a:visited {
    display: inline-block;
    text-decoration: none !important;
    color: #ffffff !important;
    padding: 9px 12px;
    border-radius: 12px 12px 6px 6px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.02em;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.10);
    box-shadow: 0 8px 14px rgba(0, 0, 0, 0.12);
    position: relative;
    top: 0;
    transition: transform 140ms ease, background 140ms ease;
}

.page-tabs a:hover {
    background: rgba(255, 255, 255, 0.16);
    transform: translateY(-1px);
}

.page-tabs a.primary {
    background: linear-gradient(180deg, #e15b5b 0%, #c94a4a 100%) !important;
    border-color: rgba(197, 22, 23, 0.32) !important;
}

.page-tabs a.primary:hover {
    background: linear-gradient(180deg, #d65353 0%, #b94242 100%) !important;
}

.page-tabs a.danger {
    background: linear-gradient(180deg, #c51617 0%, #941010 100%) !important;
    border-color: rgba(197, 22, 23, 0.4) !important;
}

.page-tabs a.danger:hover {
    background: linear-gradient(180deg, #b11415 0%, #7f0e0f 100%) !important;
}

.page-actions a {
    display: inline-block;
    min-width: 140px;
    text-decoration: none !important;
    background: rgba(255, 255, 255, 0.12) !important;
    border: 1px solid rgba(255, 255, 255, 0.16) !important;
    color: #ffffff !important;
    padding: 12px 18px;
    border-radius: 999px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 13px;
    font-weight: 800;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.page-actions a:link,
.page-actions a:visited {
    color: #ffffff !important;
    text-decoration: none !important;
}

.page-actions a:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.18);
}

.page-actions a.primary {
    background: linear-gradient(180deg, #e15b5b 0%, #c94a4a 100%);
    border-color: rgba(197, 22, 23, 0.32);
}

.page-actions a.primary:hover {
    background: linear-gradient(180deg, #d65353 0%, #b94242 100%);
}

.page-actions a.danger {
    background: linear-gradient(180deg, #c51617 0%, #941010 100%) !important;
    border-color: rgba(197, 22, 23, 0.4) !important;
}

.page-actions a.danger:hover {
    background: linear-gradient(180deg, #b11415 0%, #7f0e0f 100%) !important;
}

.page-actions a.secondary {
    background: rgba(255, 255, 255, 0.12);
}

.header-nav .back-link {
    background: linear-gradient(180deg, #c51617 0%, #941010 100%) !important;
    border-color: rgba(197, 22, 23, 0.4) !important;
}

.container {
    background: var(--pelican-card) !important;
    border-radius: 18px !important;
    box-shadow: var(--pelican-shadow) !important;
    max-width: var(--pelican-maxw);
    margin-left: auto;
    margin-right: auto;
}

.note {
    background: rgba(255, 247, 247, 0.96) !important;
    border-left-color: var(--pelican-red-soft) !important;
    color: #5f4040 !important;
    border-radius: 8px;
}

input,
select,
textarea {
    border-radius: 8px !important;
    border-color: #d8dee8 !important;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--pelican-red-soft) !important;
    box-shadow: 0 0 0 3px rgba(225, 91, 91, 0.12);
}

.btn,
button[type="submit"] {
    background: linear-gradient(180deg, #e15b5b 0%, #c94a4a 100%) !important;
}

.btn:hover,
button[type="submit"]:hover {
    background: linear-gradient(180deg, #d65353 0%, #b94242 100%) !important;
}

table {
    background: rgba(255, 255, 255, 0.98) !important;
    box-shadow: var(--pelican-shadow) !important;
    border-radius: 16px;
    overflow: hidden;
}

table th {
    background: linear-gradient(180deg, #5e5e5e 0%, #4d4d4d 100%) !important;
    color: #ffffff !important;
}

table tr:nth-child(even) {
    background: #fafbfc !important;
}

@media (max-width: 900px) {
    .pelican-header-brand {
        flex-direction: column;
        align-items: flex-start;
    }

    .pelican-title-wrap {
        text-align: left;
    }

    .header-title {
        text-align: left !important;
        font-size: 24px !important;
    }

    .pelican-logo-box {
        min-width: 180px;
        min-height: 78px;
    }
}
