@media print {
    html, body {
        font-size: 10px;
    }

    table {
        page-break-after: auto
    }

    tbody {
        display: table-row-group;
    }

    tbody::after {
        display: block;
        page-break-inside: avoid;
        page-break-before: avoid;
    }

    tr {
        page-break-inside: avoid;
        page-break-after: auto
    }

    td {
        page-break-inside: avoid;
        page-break-after: auto;
        word-wrap: break-word;
    }

    thead {
        display: table-header-group
    }

    tfoot {
        display: table-footer-group
    }
}

/* ── Logo: never invert/filter regardless of theme ── */
.navbar-brand-image,
.navbar-brand-autodark .navbar-brand-image {
    filter: none !important;
}

/* Sanfter Übergang beim Wechsel zwischen Light/Dark Theme */
html,
body,
.page,
.page-wrapper,
.card,
.navbar,
.dropdown-menu,
.table,
.form-control,
.form-select,
.btn {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
    html,
    body,
    .page,
    .page-wrapper,
    .card,
    .navbar,
    .dropdown-menu,
    .table,
    .form-control,
    .form-select,
    .btn {
        transition: none;
    }
}

/* ── Validierungsfehler: roter Rahmen + rote Fehlermeldung unter dem Feld ── */
.is-invalid {
    border-color: #d63939 !important;
    box-shadow: 0 0 0 3px rgba(214, 57, 57, 0.15) !important;
}

.is-invalid:focus {
    border-color: #d63939 !important;
    box-shadow: 0 0 0 3px rgba(214, 57, 57, 0.25) !important;
}

.invalid-feedback {
    display: block;
    font-size: 0.78rem;
    color: #d63939;
    margin-top: 0.25rem;
    line-height: 1.3;
}

/* Roter Rahmen auch bei select.is-invalid */
select.is-invalid {
    border-color: #d63939 !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24'%3E%3Cpath fill='%23d63939' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z'/%3E%3C/svg%3E") !important;
}

/* Sanfter scroll-Marker für fokussiertes ungültiges Feld */
.is-invalid:focus-visible {
    outline: none;
}

/* ── Filter bar: full-width card, search grows to fill remaining space ── */
.filter-bar .card-body { padding: .875rem 1.25rem; }
.filter-bar-search { min-width: 220px; }
.filter-bar-select { width: auto; min-width: 150px; }
.filter-bar-select-sm { min-width: 120px; }
@media (max-width: 575.98px) {
    .filter-bar-search { flex-basis: 100%; }
    .filter-bar-select { flex: 1 1 auto; min-width: 0; }
}

.ts-control {
  flex-wrap: nowrap !important;
}

/* Override Tabler: card-options margin-left:auto in minified file */
.card-options {
  margin-left: 0 !important;
}

.card-header {
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ── Sidebar: match site theme + simple border separator ───────────── */
#main-sidebar {
  background-color: var(--tblr-bg-surface, #fff) !important;
  border-right: 1px solid var(--tblr-border-color, #e6e7e9) !important;
  box-shadow: none !important;
}

/* Active nav item matches site primary color */
#main-sidebar .nav-item.active > .nav-link,
#main-sidebar .nav-item.active > .nav-link:hover {
  color: var(--tblr-primary) !important;
  background-color: rgba(var(--tblr-primary-rgb), 0.08) !important;
}

/* Dark mode: sidebar background follows body dark theme */
[data-bs-theme="dark"] #main-sidebar {
  background-color: var(--tblr-bg-surface, #1e293b) !important;
  border-right-color: var(--tblr-border-color, #334155) !important;
}

/* Dark mode: nav links readable on hover and active */
[data-bs-theme="dark"] #main-sidebar .nav-link {
  color: #cbd5e1 !important;
}
[data-bs-theme="dark"] #main-sidebar .nav-link:hover {
  color: #f1f5f9 !important;
  background-color: rgba(255, 255, 255, 0.07) !important;
}
[data-bs-theme="dark"] #main-sidebar .nav-item.active > .nav-link,
[data-bs-theme="dark"] #main-sidebar .nav-item.active > .nav-link:hover {
  color: #60a5fa !important;
  background-color: rgba(96, 165, 250, 0.12) !important;
}

/* ══════════════════════════════════════════════════════════
   DARK MODE – alle Formularelemente und UI-Komponenten
   ══════════════════════════════════════════════════════════ */
[data-bs-theme="dark"] {

    /* ── Inputs, Textareas, Selects ── */
    .form-control,
    .form-select,
    textarea.form-control,
    input.form-control {
        background-color: #1e293b !important;
        color: #e2e8f0 !important;
        border-color: #334155 !important;
    }

    .form-control::placeholder,
    textarea.form-control::placeholder {
        color: #64748b !important;
    }

    .form-control:focus,
    .form-select:focus {
        background-color: #1e293b !important;
        color: #e2e8f0 !important;
        border-color: #60a5fa !important;
        box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2) !important;
    }

    .form-control:disabled,
    .form-control[readonly] {
        background-color: #0f172a !important;
        color: #94a3b8 !important;
    }

    /* ── Select options ── */
    select option {
        background-color: #1e293b;
        color: #e2e8f0;
    }

    /* ── Tom Select ── */
    .ts-wrapper .ts-control {
        background-color: #1e293b !important;
        border-color: #334155 !important;
        color: #e2e8f0 !important;
    }

    .ts-wrapper .ts-control input {
        color: #e2e8f0 !important;
        background: transparent !important;
    }

    .ts-wrapper .ts-control .item {
        background: #2d3f55 !important;
        color: #e2e8f0 !important;
        border-color: #475569 !important;
    }

    .ts-dropdown {
        background-color: #1e293b !important;
        border-color: #334155 !important;
        color: #e2e8f0 !important;
    }

    .ts-dropdown .option {
        color: #e2e8f0 !important;
    }

    .ts-dropdown .option:hover,
    .ts-dropdown .option.active {
        background-color: #2d3f55 !important;
        color: #fff !important;
    }

    .ts-dropdown .optgroup-header {
        color: #94a3b8 !important;
        background-color: #0f172a !important;
    }

    /* ── Cards ── */
    .card {
        background-color: #1e293b !important;
        border-color: #334155 !important;
    }

    .card-header,
    .card-footer {
        background-color: #0f172a !important;
        border-color: #334155 !important;
        color: #e2e8f0 !important;
    }

    /* ── Tables ── */
    .table {
        color: #e2e8f0 !important;
        border-color: #334155 !important;
    }

    .table thead th,
    .table-light th {
        background-color: #0f172a !important;
        color: #94a3b8 !important;
        border-color: #334155 !important;
    }

    .table td,
    .table th {
        border-color: #334155 !important;
    }

    .table-vcenter td {
        color: #e2e8f0 !important;
    }

    /* ── Dropdowns ── */
    .dropdown-menu {
        background-color: #1e293b !important;
        border-color: #334155 !important;
    }

    .dropdown-item {
        color: #e2e8f0 !important;
    }

    .dropdown-item:hover,
    .dropdown-item:focus {
        background-color: #2d3f55 !important;
        color: #fff !important;
    }

    .dropdown-divider {
        border-color: #334155 !important;
    }

    /* ── Badges ── */
    .bg-blue-lt {
        background-color: #1a3a5c !important;
        color: #93c5fd !important;
    }

    /* ── Navbar ── */
    .navbar {
        background-color: #0f172a !important;
        border-color: #1e293b !important;
    }

    .navbar-nav .nav-link {
        color: #cbd5e1 !important;
    }

    .navbar-nav .nav-link:hover {
        color: #fff !important;
    }

    /* ── Form labels & hints ── */
    .form-label {
        color: #cbd5e1 !important;
    }

    .form-hint,
    .text-muted {
        color: #64748b !important;
    }

    /* ── Buttons outline ── */
    .btn-outline-secondary {
        color: #94a3b8 !important;
        border-color: #475569 !important;
    }

    .btn-outline-secondary:hover {
        background-color: #334155 !important;
        color: #e2e8f0 !important;
    }

    /* ── hr-text ── */
    .hr-text {
        color: #64748b !important;
    }

    /* ── Pagination ── */
    .page-link {
        background-color: #1e293b !important;
        border-color: #334155 !important;
        color: #93c5fd !important;
    }

    .page-link:hover {
        background-color: #2d3f55 !important;
        color: #fff !important;
    }

    .page-item.active .page-link {
        background-color: #2563eb !important;
        border-color: #2563eb !important;
        color: #fff !important;
    }

    /* ── Modal ── */
    .modal-content {
        background-color: #1e293b !important;
        border-color: #334155 !important;
        color: #e2e8f0 !important;
    }

    .modal-header,
    .modal-footer {
        border-color: #334155 !important;
    }

    /* ── Input group ── */
    .input-group-text {
        background-color: #0f172a !important;
        border-color: #334155 !important;
        color: #94a3b8 !important;
    }

    /* ── Formula builder ── */
    #formula-builder {
        background: #0f172a !important;
        border-color: #475569 !important;
    }

    #calculation-raw {
        background: #0f172a !important;
        color: #e2e8f0 !important;
    }
}

/* ══════════════════════════════════════════════════════════
   DASHBOARD SIDEBAR – Mobile overlay (slides from left, no push)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 991.98px) {

    /* Sidebar top-bar: stays sticky at top as Tabler's horizontal nav */
    #main-sidebar {
        position: sticky !important;
        top: 0 !important;
        z-index: 1051 !important;
        width: 100% !important;
        transform: none !important;
    }

    /* Page content: never shifts */
    .page-wrapper {
        margin-left: 0 !important;
    }

    /* Dim backdrop behind open sidebar */
    .sidebar-mobile-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.5);
        z-index: 1049;
        opacity: 0;
        transition: opacity .3s;
    }
    .sidebar-mobile-overlay.show {
        display: block;
        opacity: 1;
    }

    /* The sidebar DRAWER — shown via JS class toggle.
       Column flex rather than block so the profile card's mt-auto can pin it to the
       bottom; in a block container mt-auto does nothing. */
    #sidebar-menu.mobile-open {
        display: flex !important;
        flex-direction: column !important;
        /* Tabler's .navbar-collapse centres its items; as a column that shrink-wraps
           the footer card to its text width and centres it, which is what made it read
           as a floating tooltip instead of a full-width footer. */
        align-items: stretch !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        width: 280px !important;
        max-width: 85vw !important;
        height: 100dvh !important;
        z-index: 1050 !important;
        background: var(--tblr-bg-surface, #fff) !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        box-shadow: 4px 0 32px rgba(10,20,60,.22) !important;
        animation: sidebarSlideIn .3s cubic-bezier(.4,0,.2,1) forwards !important;
        padding: 1rem 0 2rem !important;
    }

    /* The nav list is the scrolling region, the profile card stays pinned below it.
       Without this the list keeps flex-shrink:1 and gets squeezed to fit next to the
       card, then spills its items out of its own box (overflow is visible) straight
       over the card. min-height:0 is required — a flex item will not shrink below its
       content height without it, so the overflow-y would never engage. */
    #sidebar-menu.mobile-open > .navbar-nav {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    #sidebar-menu.mobile-open > .sidebar-profile-card {
        flex: 0 0 auto !important;
    }

    /* Footer strip, not a floating chip. The nav list scrolls behind it, so the
       background must be opaque; the divider + flush edges make it read as part of the
       rail, and the left padding lines the avatar up with the nav-link icons. */
    #sidebar-menu.mobile-open > .sidebar-profile-card {
        margin: 0 !important;
        padding: .8rem 1rem .8rem 2rem !important;
        border: 0 !important;
        border-top: 1px solid rgba(255, 255, 255, .08) !important;
        border-radius: 0 !important;
        background: var(--mw-sidebar-bg) !important;
    }

    #sidebar-menu.mobile-open .sidebar-profile-card .profile-avatar.avatar {
        width: 36px !important;
        height: 36px !important;
        font-size: .78rem !important;
    }

    /* A long address must ellipsis, not push the card wider */
    #sidebar-menu.mobile-open .sidebar-profile-card .profile-body {
        min-width: 0;
    }

    #sidebar-menu.mobile-open .sidebar-profile-card .profile-meta {
        min-width: 0;
    }

    #sidebar-menu.mobile-open .sidebar-profile-card .profile-email {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Match the rail exactly. In dark mode the rail is NOT --mw-sidebar-bg: it is
       `[data-bs-theme="dark"] #main-sidebar { background: var(--tblr-bg-surface) }`
       (#182433), which outranks the token rule. The old value here was
       `--tblr-bg-surface-dark` — a variable this theme never defines — so it silently
       fell back to #1e293b and the drawer came out a different colour from the rail. */
    [data-bs-theme="dark"] #sidebar-menu.mobile-open,
    [data-bs-theme="dark"] #sidebar-menu.mobile-open > .sidebar-profile-card {
        background: var(--tblr-bg-surface, #1e293b) !important;
    }

    @keyframes sidebarSlideIn {
        from { transform: translateX(-100%); }
        to   { transform: translateX(0); }
    }

    /* Bigger logo in sidebar on mobile */
    #main-sidebar .navbar-brand-image {
        height: 48px !important;
    }

    /* Workspace header stays compact next to the hamburger on mobile */
    .workspace-header {
        margin: 0 !important;
        padding: .5rem .5rem !important;
    }
}

/* ══════════════════════════════════════════════════════════
   V2 SHELL & DASHBOARD REDESIGN (2026-07)
   Modern SaaS shell: workspace header, nav pills, sticky top bar,
   collapsible colour-headed sections, softer cards, avatar stacks.
   Theme-aware — every surface has a matching dark-mode rule.
   ══════════════════════════════════════════════════════════ */

/* ── Sidebar: workspace header ───────────────────────────── */
.workspace-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .375rem;
    padding: 1rem .75rem;
    margin: .375rem .5rem .5rem;
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    text-align: center;
    transition: background-color .15s ease;
}
.workspace-header:hover { background-color: rgba(var(--tblr-primary-rgb), .06); }
.workspace-header-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
}
.workspace-header-logo img { width: 100%; max-width: 200px; height: auto; object-fit: contain; }
.workspace-header-meta { display: flex; flex-direction: column; align-items: center; line-height: 1.3; }
.workspace-header-sub { font-size: .85rem; font-weight: 600; color: var(--tblr-body-color); white-space: normal; overflow-wrap: break-word; }

[data-bs-theme="dark"] .workspace-header:hover { background-color: rgba(255, 255, 255, .06); }
[data-bs-theme="dark"] .workspace-header-sub { color: #f1f5f9; }

/* ── Sidebar: refined nav pills ──────────────────────────── */
#main-sidebar .navbar-nav { padding-left: .5rem; padding-right: .5rem; }
#main-sidebar .nav-item { margin-bottom: 2px; }
#main-sidebar .nav-link {
    border-radius: 9px;
    padding: .5rem .75rem;
    font-weight: 500;
}
#main-sidebar .nav-link:hover { background-color: rgba(var(--tblr-primary-rgb), .06); }
#main-sidebar .nav-item.active > .nav-link { font-weight: 600; }
#main-sidebar .nav-item-section-label .nav-link-title { padding: 1rem .75rem .35rem !important; }

/* ── Top bar ─────────────────────────────────────────────── */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--tblr-body-bg, #f5f7fb);
}
.app-topbar-search {
    border-radius: 999px;
    min-width: 0;
}
@media (min-width: 768px) { .app-topbar-search { min-width: 15rem; } }
.app-topbar-breadcrumb .breadcrumb { margin-bottom: 0; }
[data-bs-theme="dark"] .app-topbar { background: var(--tblr-body-bg, #0f172a); }

/* ── Collapsible colour-headed sections ──────────────────── */
.section-group { overflow: visible; }
.section-group-header {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .75rem 1rem;
    cursor: pointer;
    user-select: none;
    font-weight: 600;
}
.section-group-icon { display: inline-flex; align-items: center; }
.section-group-title { font-size: .95rem; }
.section-group-count { font-size: .75rem; }
.section-group-chevron { display: inline-flex; transition: transform .2s ease; }
.section-group-header.collapsed .section-group-chevron { transform: rotate(-90deg); }
.section-group-body { padding: .25rem 1rem 1rem; }

/* ── Softer cards + hover lift for linked cards/tiles ────── */
.card {
    border-radius: 12px;
    transition: box-shadow .15s ease, transform .15s ease, background-color .2s ease, border-color .2s ease;
}
a.card { text-decoration: none; color: inherit; }
a.card:hover { transform: translateY(-2px); box-shadow: 0 .5rem 1.25rem rgba(24, 36, 51, .08); }
[data-bs-theme="dark"] a.card:hover { box-shadow: 0 .5rem 1.25rem rgba(0, 0, 0, .45); }

/* ── Avatar stacks: clean ring against the card surface ──── */
.avatar-list-stacked .avatar { box-shadow: 0 0 0 2px var(--tblr-card-bg, #fff); }
[data-bs-theme="dark"] .avatar-list-stacked .avatar { box-shadow: 0 0 0 2px var(--tblr-card-bg, #1e293b); }

/* Allow flex children to shrink so .text-truncate works inside rows */
.min-w-0 { min-width: 0 !important; }

/* ══════════════════════════════════════════════════════════
   DASHBOARD PANELS · STAT TILES · FILTER TABS (Confidency layout)
   ══════════════════════════════════════════════════════════ */

/* Grouped "Quick Stats" surface (slightly recessed vs. the page). */
.dash-panel-muted {
    background: #eef1f7;
    border: 1px solid #e6e9ef;
    border-radius: 16px;
    padding: 1.25rem;
    margin-bottom: 1rem;
}
[data-bs-theme="dark"] .dash-panel-muted {
    background: #0f172a;
    border-color: #1e293b;
}

.dash-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: 1rem;
}
.dash-panel-title { font-weight: 700; font-size: 1.05rem; margin: 0; }

/* Stat tile (icon square + label + big value + context) */
.stat-tile { height: 100%; }
.stat-tile .card-body { padding: 1rem; }
.stat-tile-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.stat-tile-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex-shrink: 0;
}
.stat-tile-label { font-size: .8rem; font-weight: 500; color: var(--tblr-secondary, #667382); }
.stat-tile-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; color: var(--tblr-body-color); }
.stat-tile-context { font-size: .75rem; margin-top: .25rem; }

/* Pill filter tabs (All / Unfulfilled / …) */
.dash-tabs.nav-pills { gap: .25rem; flex-wrap: wrap; }
.dash-tabs .nav-link {
    border-radius: 999px;
    padding: .4rem .9rem;
    font-size: .85rem;
    font-weight: 500;
    color: var(--tblr-secondary, #667382);
}
.dash-tabs .nav-link:hover { background: rgba(var(--tblr-primary-rgb), .06); }
.dash-tabs .nav-link.active {
    background-color: var(--tblr-primary) !important;
    color: #fff !important;
}
.dash-tabs .nav-link .badge { margin-left: .35rem; }
[data-bs-theme="dark"] .dash-tabs .nav-link { color: #94a3b8; }
[data-bs-theme="dark"] .dash-tabs .nav-link:hover { color: #e2e8f0; background: rgba(255, 255, 255, .06); }

/* ══════════════════════════════════════════════════════════
   MODERN DATA TABLES (app-wide, via x-ui.data-table)
   ══════════════════════════════════════════════════════════ */
.card-table thead th {
    background: var(--tblr-body-bg, #f8fafc);
    color: var(--tblr-secondary, #667382);
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--tblr-border-color, #e6e7e9);
    padding-top: .75rem;
    padding-bottom: .75rem;
}
.card-table.table-vcenter td { padding-top: .85rem; padding-bottom: .85rem; }
.card-table tbody tr { transition: background-color .12s ease; }
.card-table tbody tr:hover td { background-color: rgba(var(--tblr-primary-rgb), .035); }
[data-bs-theme="dark"] .card-table thead th { background: #0f172a; color: #94a3b8; border-bottom-color: #1e293b; }
[data-bs-theme="dark"] .card-table tbody tr:hover td { background-color: rgba(96, 165, 250, .07); }

/* ── Row-actions dropdown trigger ────────────────────────── */
.row-actions-menu .btn-ghost-secondary:hover { background-color: rgba(var(--tblr-primary-rgb), .08); }
[data-bs-theme="dark"] .row-actions-menu .btn-ghost-secondary:hover { background-color: rgba(255, 255, 255, .08); }

/* ── Meter-reading hub: prominent scan CTA ───────────────── */
.scan-hero { border: 1px dashed rgba(var(--tblr-primary-rgb), .35); background: rgba(var(--tblr-primary-rgb), .03); }
.scan-hero-btn {
    display: inline-flex;
    align-items: center;
    gap: .65rem;
    padding: 1rem 2.25rem;
    font-size: 1.05rem;
    font-weight: 600;
    border-radius: 14px;
    box-shadow: 0 10px 24px rgba(var(--tblr-primary-rgb), .28);
}
[data-bs-theme="dark"] .scan-hero { background: rgba(96, 165, 250, .06); border-color: rgba(96, 165, 250, .3); }

/* ── QR label print (counter pages) ─────────────────────────── */
.qr-print-sheet {
    display: none;
}

@media print {
    body.qr-printing * {
        visibility: hidden;
    }

    body.qr-printing .qr-print-sheet,
    body.qr-printing .qr-print-sheet * {
        visibility: visible;
    }

    body.qr-printing .qr-print-sheet {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        margin: 0;
        padding: 2rem 1rem;
    }

    body.qr-printing .qr-print-sheet__content {
        text-align: center;
        font-family: sans-serif;
    }

    body.qr-printing .qr-print-sheet img {
        display: block;
        margin: 0 auto;
    }

    body.qr-printing .qr-print-sheet__label {
        font-weight: bold;
        margin-top: 1rem;
        font-size: 14pt;
    }

    body.qr-printing .qr-print-sheet__meta {
        color: #444;
        font-size: 12pt;
        margin-top: 0.25rem;
    }
}
