:root {
    --portal-bg-start: #edf4ff;
    --portal-bg-end: #dcecff;
    --portal-primary: #0d6efd;
    --portal-primary-dark: #084bb4;
    --portal-surface: rgba(255, 255, 255, 0.84);
    --portal-border: rgba(13, 110, 253, 0.12);
    --portal-text: #10325a;
    --portal-btn-min-height: 2.4rem;
    --portal-btn-padding-y: 0.42rem;
    --portal-btn-font-size: 0.95rem;
    --portal-btn-line-height: 1.2;
}

body.portal-body {
    min-height: 100vh;
    margin: 0;
    font-family: "Noto Sans", "DejaVu Sans", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--portal-text);
    background:
        radial-gradient(circle at top left, rgba(13, 110, 253, 0.18), transparent 34%),
        radial-gradient(circle at bottom right, rgba(13, 202, 240, 0.18), transparent 28%),
        linear-gradient(135deg, var(--portal-bg-start), var(--portal-bg-end));
}

.portal-body .btn {
    /* Normalize button height across the portal (Bootstrap uses CSS variables for sizing). */
    --bs-btn-padding-y: var(--portal-btn-padding-y);
    --bs-btn-font-size: var(--portal-btn-font-size);
    --bs-btn-line-height: var(--portal-btn-line-height);

    min-height: var(--portal-btn-min-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.portal-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.portal-header {
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--portal-border);
}

.portal-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.portal-brand-logo {
    width: 148px;
    max-width: 34vw;
    height: auto;
    flex: 0 0 auto;
}

.portal-header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
}

.portal-header-meta,
.portal-header-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.6rem;
}

.portal-header-actions form {
    margin: 0;
}

.portal-footer {
    background: rgba(10, 37, 64, 0.88);
    color: rgba(255, 255, 255, 0.8);
}

.time-clock-shell {
    width: min(100%, 34rem);
    margin: 0 auto;
}

.time-clock-heading {
    display: grid;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    text-align: center;
}

.time-clock-stack {
    display: grid;
    gap: 1rem;
}

.time-company-picker {
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid rgba(13, 110, 253, 0.12);
}

.time-clock-card {
    width: 100%;
    min-height: 9.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(13, 110, 253, 0.16);
    border-radius: 2rem;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 18px 38px rgba(16, 50, 90, 0.12);
    cursor: pointer;
    transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

.time-clock-card:active {
    transform: scale(0.985);
}

.time-clock-card:focus-visible {
    outline: 4px solid rgba(13, 110, 253, 0.3);
    outline-offset: 3px;
}

.time-clock-card:disabled {
    cursor: wait;
    opacity: 0.58;
}

.time-clock-card span {
    font-size: clamp(3.5rem, 18vw, 6rem);
    font-weight: 800;
    letter-spacing: 0.08em;
    line-height: 1;
}

.time-clock-card-in {
    color: #146c43;
    background: linear-gradient(145deg, rgba(209, 250, 229, 0.96), rgba(255, 255, 255, 0.96));
}

.time-clock-card-out {
    color: #b02a37;
    background: linear-gradient(145deg, rgba(255, 226, 230, 0.96), rgba(255, 255, 255, 0.96));
}

.time-mobile-only {
    width: min(100%, 34rem);
    margin: 0 auto;
}

.db-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(13, 110, 253, 0.16);
    color: var(--portal-text);
    box-shadow: 0 12px 24px rgba(13, 110, 253, 0.08);
}

.release-status-badge {
    display: inline-flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.6rem 1rem;
    border-radius: 1.15rem;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(13, 110, 253, 0.16);
    color: var(--portal-text);
    box-shadow: 0 12px 24px rgba(13, 110, 253, 0.08);
    line-height: 1.15;
}

.release-status-line {
    font-size: 0.86rem;
    white-space: nowrap;
}

.db-status-dot {
    width: 0.9rem;
    height: 0.9rem;
    border-radius: 50%;
    box-shadow: 0 0 0 0.28rem rgba(25, 135, 84, 0.16);
    background: #198754;
    flex: 0 0 auto;
}

.db-status-badge-disconnected .db-status-dot {
    background: #dc3545;
    box-shadow: 0 0 0 0.28rem rgba(220, 53, 69, 0.16);
}

.hero-card,
.info-panel,
.placeholder-panel {
    background: var(--portal-surface);
    border: 1px solid var(--portal-border);
}

.readonly-pill {
    display: inline-flex;
    align-items: center;
    min-height: var(--portal-btn-min-height);
    padding: 0.35rem 0.95rem;
    border-radius: 999px;
    background: rgba(13, 110, 253, 0.06);
    border: 1px solid rgba(13, 110, 253, 0.14);
    font-weight: 600;
}

.menu-icon {
    width: 3rem;
    height: 3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(13, 110, 253, 0.12);
    color: var(--portal-primary-dark);
    font-weight: 700;
}

.menu-logout-card {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(245, 249, 255, 0.92));
}

.menu-card-actions {
    display: grid;
    gap: 0.75rem;
    width: min(100%, 16rem);
}

.menu-card-actions form {
    margin: 0;
}

.account-action-stack {
    display: inline-flex;
    flex-direction: column;
    gap: 0.55rem;
}

.settings-action-stack {
    display: inline-grid;
    grid-template-columns: minmax(max-content, 1fr);
    gap: 1rem;
    max-width: 100%;
}

.settings-action-stack .btn {
    width: 100%;
}

.settings-form-actions {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.85rem;
}

.settings-sidebar {
    position: sticky;
    top: 1.5rem;
}

.company-list-item {
    border: 1px solid rgba(13, 110, 253, 0.1);
    background: rgba(255, 255, 255, 0.78);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.company-list-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(13, 110, 253, 0.08);
}

.company-list-item-active {
    border-color: rgba(13, 110, 253, 0.35);
    box-shadow: 0 14px 28px rgba(13, 110, 253, 0.12);
}

.import-progress {
    height: 1.2rem;
    background: rgba(13, 110, 253, 0.08);
}

.metric-card {
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(13, 110, 253, 0.1);
}

.metric-label {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #4e6d93;
}

.metric-value {
    font-size: 1.55rem;
    font-weight: 700;
    margin-top: 0.2rem;
}

.job-current-record,
.job-events-window {
    min-height: 8rem;
    max-height: 20rem;
    overflow: auto;
    background: rgba(10, 37, 64, 0.94);
    color: rgba(255, 255, 255, 0.92);
    border-radius: 1.5rem;
}

.job-current-record {
    white-space: pre-wrap;
    font-size: 0.92rem;
}

.job-event {
    display: flex;
    gap: 0.75rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.92rem;
}

.job-event:last-child {
    border-bottom: 0;
}

.job-event-time {
    color: rgba(255, 255, 255, 0.58);
    flex: 0 0 auto;
}

.job-event-warning {
    color: #ffe08a;
}

.job-event-error {
    color: #ff9898;
}

.generator-summary-card {
    background:
        linear-gradient(135deg, rgba(13, 110, 253, 0.08), rgba(13, 202, 240, 0.08)),
        rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(13, 110, 253, 0.14);
}

.generator-metric-value {
    font-size: 1.35rem;
}

.generator-period-pill {
    display: inline-flex;
    align-items: center;
    min-height: var(--portal-btn-min-height);
    padding: 0.35rem 0.95rem;
    border-radius: 999px;
    background: rgba(13, 110, 253, 0.08);
    border: 1px solid rgba(13, 110, 253, 0.12);
    font-weight: 600;
    color: #36557b;
}

.generator-period-pill-active {
    background: rgba(13, 110, 253, 0.16);
    border-color: rgba(13, 110, 253, 0.28);
    color: #0d4fb1;
    box-shadow: 0 10px 24px rgba(13, 110, 253, 0.08);
}

.generator-console {
    min-height: 18rem;
    max-height: 30rem;
    overflow: auto;
    background:
        radial-gradient(circle at top right, rgba(32, 201, 151, 0.16), transparent 28%),
        linear-gradient(180deg, rgba(7, 22, 39, 0.97), rgba(13, 33, 56, 0.97));
    color: rgba(231, 243, 255, 0.96);
    border: 1px solid rgba(32, 201, 151, 0.16);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.generator-console-empty {
    border-color: rgba(13, 110, 253, 0.14);
}

.generator-console-line {
    padding: 0.35rem 0.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    white-space: pre-wrap;
    word-break: break-word;
}

.generator-console-line:last-child {
    border-bottom: 0;
}

.generator-console-line-warning {
    color: #ffe08a;
}

.generator-console-line-error {
    color: #ff9898;
}

.dashboard-filter-card {
    background:
        radial-gradient(circle at top left, rgba(13, 110, 253, 0.12), transparent 36%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(244, 249, 255, 0.94));
}

.dashboard-chart-card {
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid rgba(13, 110, 253, 0.12);
    box-shadow: 0 18px 30px rgba(13, 110, 253, 0.08);
}

.dashboard-chart-surface {
    position: relative;
    min-height: 22rem;
    padding: 1rem;
    border-radius: 1.75rem;
    background:
        linear-gradient(180deg, rgba(247, 251, 255, 0.96), rgba(238, 246, 255, 0.96)),
        rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(13, 110, 253, 0.08);
}

.dashboard-chart-surface canvas {
    width: 100% !important;
    height: 100% !important;
}

.placeholder-box {
    min-height: 5rem;
    border: 1px dashed rgba(13, 110, 253, 0.28);
    border-radius: 1.5rem;
    background: rgba(13, 110, 253, 0.04);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    text-align: center;
    color: #5a6e88;
    font-weight: 500;
}

.scanner-shell {
    max-width: 42rem;
    margin: 0 auto;
}

.scanner-topbar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-end;
}

.scanner-company-picker {
    width: min(100%, 18rem);
}

.scanner-camera-panel {
    position: relative;
    overflow: hidden;
    min-height: 18rem;
    border-radius: 1.5rem;
    background: rgba(10, 37, 64, 0.94);
    border: 1px solid rgba(13, 110, 253, 0.16);
}

.scanner-video {
    display: block;
    width: 100%;
    min-height: 18rem;
    max-height: 62vh;
    object-fit: cover;
}

.scanner-camera-state {
    position: absolute;
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    padding: 0.65rem 0.9rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--portal-text);
    font-weight: 600;
    text-align: center;
}

.scanner-scan-frame {
    position: absolute;
    left: 8%;
    top: 34%;
    width: 84%;
    height: 32%;
    border: 3px solid #fff;
    border-radius: 0.5rem;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

.scanner-choice-card:disabled {
    opacity: 0.65;
    cursor: default;
}

.scanner-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
}

.scanner-manual,
.scanner-reading-form,
.scanner-result {
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid rgba(13, 110, 253, 0.12);
}

.scanner-result-success {
    color: #0f5132;
    background: rgba(209, 231, 221, 0.9);
    border-color: rgba(25, 135, 84, 0.25);
}

.scanner-result-warning {
    color: #664d03;
    background: rgba(255, 243, 205, 0.92);
    border-color: rgba(255, 193, 7, 0.28);
}

.scanner-choice-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.scanner-choice-card {
    min-height: 5.25rem;
    border: 1px solid rgba(13, 110, 253, 0.18);
    border-radius: 1rem;
    background: #fff;
    color: var(--portal-text);
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    justify-content: center;
    padding: 0.9rem 1rem;
    width: 100%;
}

.scanner-choice-card:hover,
.scanner-choice-card:focus,
.scanner-choice-card.is-selected {
    border-color: rgba(13, 110, 253, 0.55);
    box-shadow: 0 10px 22px rgba(13, 110, 253, 0.12);
}

.scanner-choice-title {
    font-weight: 700;
    line-height: 1.25;
}

.scanner-choice-meta {
    color: #5a6e88;
    font-size: 0.9rem;
    line-height: 1.3;
}

.scanner-mode-note {
    color: #5a6e88;
    font-size: 0.86rem;
    font-weight: 600;
}

.scanner-machine-section {
    border: 1px solid rgba(13, 110, 253, 0.16);
    border-radius: 1rem;
    background: rgba(255, 255, 255, 0.78);
    padding: 1rem;
}

.scanner-machine-section-title {
    color: var(--portal-text);
    font-weight: 700;
}

.scanner-machine-section-meta {
    color: #5a6e88;
    font-size: 0.9rem;
    line-height: 1.3;
}

.scanner-machine-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.scanner-machine-summary-cell {
    border: 1px solid rgba(13, 110, 253, 0.14);
    border-radius: 0.85rem;
    background: rgba(255, 255, 255, 0.82);
    padding: 0.75rem;
    min-width: 0;
}

.scanner-machine-summary-label {
    display: block;
    color: #5a6e88;
    font-size: 0.78rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.scanner-machine-summary-cell strong {
    display: block;
    overflow-wrap: anywhere;
}

.scanner-recent-list {
    display: grid;
    gap: 0.65rem;
}

.scanner-recent-item {
    display: grid;
    gap: 0.35rem;
    padding: 0.8rem 0.9rem;
    border: 1px solid rgba(13, 110, 253, 0.14);
    border-radius: 0.85rem;
    background: rgba(255, 255, 255, 0.82);
}

.scanner-recent-main {
    display: grid;
    gap: 0.2rem;
}

.scanner-recent-main span,
.scanner-recent-meta {
    color: #5a6e88;
    font-size: 0.88rem;
}

.scanner-recent-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.75rem;
}

.card,
.btn,
.form-control,
.table {
    border-color: var(--portal-border);
}

.btn-primary {
    background: linear-gradient(135deg, var(--portal-primary), #3291ff);
    border-color: transparent;
    box-shadow: 0 10px 24px rgba(13, 110, 253, 0.22);
}

.btn-primary:hover,
.btn-primary:focus {
    background: linear-gradient(135deg, var(--portal-primary-dark), var(--portal-primary));
}

.btn-outline-primary {
    border-width: 2px;
}

.btn-pill-compact {
    /* Compact only in width, keep consistent height. */
    --bs-btn-padding-x: 0.9rem;
}

.btn-pill-xs {
    /* XS only in width, keep consistent height. */
    --bs-btn-padding-x: 0.7rem;
}

.table > :not(caption) > * > * {
    background: transparent;
}

@media (max-width: 767.98px) {
    .menu-card-actions {
        width: 100%;
    }

    .portal-brand {
        align-items: flex-start;
    }

    .portal-brand-logo {
        width: 118px;
    }

    .portal-header-right {
        align-items: stretch;
    }

    .portal-header-meta,
    .portal-header-actions {
        justify-content: flex-start;
    }

    .portal-header .btn,
    .portal-header form {
        width: 100%;
    }

    .settings-sidebar {
        position: static;
    }

    .scanner-topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .scanner-company-picker {
        width: 100%;
    }

    .scanner-choice-grid {
        grid-template-columns: 1fr;
    }

    .scanner-actions {
        grid-template-columns: 1fr;
    }

    .scanner-machine-summary {
        grid-template-columns: 1fr;
    }
}


/* Product overview: companies remain visible beside the product, with the count at the right. */
.product-view-switch {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    margin-left: auto;
}
.product-view-switch .btn { min-width: 120px; font-weight: 700; }
.products-overview-table { min-width: 860px; }
.products-overview-table th, .products-overview-table td { padding-top: 1rem; padding-bottom: 1rem; }
.product-overview-name { min-width: 160px; max-width: 250px; overflow-wrap: anywhere; }
.product-company-list { display: flex; flex-wrap: wrap; gap: .35rem .5rem; min-width: 260px; max-width: 520px; }
.product-company-link { display: inline-block; padding: .2rem .5rem; border-radius: .5rem; border: 1px solid transparent; background: var(--company-color, #eef5ff); color: #10325a; text-decoration: none; font-size: .85rem; }
.product-selection-toolbar { background: #f5f8fc; border: 1px solid #dde6f3; }
.product-save-bar { position: sticky; top: .5rem; z-index: 3; background: #fff; border: 1px solid #b8d2fa; box-shadow: 0 .25rem 1rem #10325a18; }
.product-name-cell { min-width: 220px; }
.product-history-cell { min-width: 180px; }
.product-selection-label { display: none; }
.product-pending-label { display: block; margin-top: .5rem; }
.product-row-changed .product-name-cell { border-left: 3px solid #0d6efd; }
.company-products-table .errorlist { padding-left: 1rem; margin: .5rem 0 0; color: #b02a37; }
@media (max-width: 991px) {
    .company-products-table, .company-products-table tbody, .company-products-table tr, .company-products-table td { display: block; width: 100%; min-width: 0; }
    .company-products-table thead { display: none; }
    .company-products-table tr { margin-bottom: 1rem; padding: .5rem; border: 1px solid #dde6f3; border-radius: 1rem; }
    .company-products-table td { border: 0; padding: .5rem; overflow-wrap: anywhere; }
    .company-products-table td[data-label]::before { content: attr(data-label) ": "; font-weight: 600; }
    .company-products-table .product-name-cell { border-radius: .5rem; }
    .product-selection-label { display: inline; }
    .product-save-bar { gap: .75rem; }
    .product-save-bar > div { font-size: .85rem; }
    .product-save-bar button { width: 100%; }
}
.product-select { width: 1.25rem; height: 1.25rem; cursor: pointer; }
.product-select:disabled { cursor: not-allowed; }
.product-company-row.product-row-selected > td { --bs-table-bg: #eef5ff; }
.product-company-link:hover, .product-company-link:focus-visible { background: var(--company-color, #eef5ff); color: #10325a; text-decoration: underline; box-shadow: inset 0 0 0 1px #10325a; }
.product-company-archived { border: 1px dashed #536174; }
.product-company-count { display: inline-flex; align-items: center; justify-content: center; min-width: 2.5rem; height: 2.5rem; padding: 0 .5rem; border-radius: 50%; background: #e6f0ff; color: #084bb4; font-size: 1.1rem; font-weight: 700; }
.product-company-row:target { outline: 2px solid #0d6efd; outline-offset: -2px; scroll-margin-top: 1rem; }
@media (max-width: 575px) {
    .product-view-switch { margin-left: 0; width: 100%; }
    .product-view-switch .btn { flex: 1; }
}


.company-color-options { display: flex; flex-wrap: wrap; gap: .5rem; }
.company-color-option, .company-color-preview { display: inline-block; padding: .45rem .8rem; border-radius: .6rem; background: var(--company-color, #eef5ff); color: #10325a; border: 2px solid transparent; }
.company-color-option { cursor: pointer; }
.company-color-options .btn-check:checked + .company-color-option { border-color: #10325a; box-shadow: 0 0 0 1px #10325a; }
.company-color-options .btn-check:focus-visible + .company-color-option { outline: 3px solid #0d6efd; outline-offset: 2px; }

/* Searchable machine selection for reading points. */
.machine-picker { position: relative; }
.machine-picker-input { padding-right: 2.8rem; }
.machine-picker-toggle { position: absolute; top: 0; right: 0; width: 2.6rem; height: 100%; border: 0; border-radius: 0 1rem 1rem 0; background: transparent; color: #10325a; }
.machine-picker-toggle:focus-visible { outline: 2px solid #0d6efd; outline-offset: -3px; }
.machine-picker-list { position: absolute; top: calc(100% + .25rem); left: 0; right: 0; max-height: 17rem; overflow-y: auto; overscroll-behavior: contain; z-index: 1050; background: #fff; border: 1px solid #a9c9f8; border-radius: .75rem; box-shadow: 0 .4rem 1rem #10325a26; padding: .25rem; }
.machine-picker-option, .machine-picker-empty { padding: .6rem .7rem; overflow-wrap: anywhere; border-radius: .5rem; }
.machine-picker-option { cursor: pointer; color: #10325a; }
.machine-picker-option:hover, .machine-picker-option.is-active { background: #e6f0ff; }
.machine-picker-option[aria-selected="true"] { font-weight: 700; }
.machine-picker-empty { color: #5a6e88; }

/* Company settings use the same header card and company colours as devices. */
.company-settings-section { scroll-margin-top: 1rem; }
#company-controls > .card-body > .d-flex > div { min-width: 0; }
#company-controls .company-color-preview, .company-list-item .company-color-preview { max-width: 100%; overflow-wrap: anywhere; }
.company-group-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.company-group-option { display: flex; align-items: flex-start; gap: .75rem; padding: 1rem; border: 1px solid #dce5ee; border-radius: 1rem; cursor: pointer; }
.company-group-option.is-selected { border-color: #8ab5f5; background: #f0f6ff; }
.company-group-option .form-check-input { flex-shrink: 0; margin-top: .2rem; }
.company-group-text { min-width: 0; overflow-wrap: anywhere; }
.company-group-option[hidden], .company-list-entry[hidden] { display: none; }
.user-list-entry[hidden] { display: none; }
.user-list-entry { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 767px) { .company-group-options { grid-template-columns: 1fr; } }
