body {
    background-color: #f3f4f6;
}

.btn {
    align-items: center;
    border: 1px solid transparent;
    border-radius: 0.375rem;
    cursor: pointer;
    display: inline-flex;
    font-weight: 600;
    justify-content: center;
    line-height: 1.2;
    padding: 0.5rem 0.875rem;
    text-align: center;
    text-decoration: none;
    transition:
        background-color 120ms ease,
        border-color 120ms ease,
        box-shadow 120ms ease,
        color 120ms ease;
    white-space: nowrap;
}

.btn:hover {
    text-decoration: none;
}

.btn:focus-visible {
    outline: 3px solid #93c5fd;
    outline-offset: 2px;
}

.btn-sm {
    font-size: 0.875rem;
    min-height: 2rem;
    padding: 0.375rem 0.625rem;
}

.btn-outline {
    background-color: #ffffff;
    border-color: #2563eb;
    color: #1d4ed8;
}

.btn-outline:hover,
.btn-outline:focus-visible {
    background-color: #eff6ff;
    border-color: #1d4ed8;
    color: #1e40af;
}

.btn-primary {
    background-color: #1d4ed8;
    border-color: #1d4ed8;
    color: #ffffff;
}

.btn-primary:hover,
.btn-primary:focus-visible {
    background-color: #1e40af;
    border-color: #1e3a8a;
    color: #ffffff;
}

.pack-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.badge {
    border-radius: 9999px;
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.125rem 0.5rem;
}

.badge-enabled  { background: #dcfce7; color: #15803d; }
.badge-disabled { background: #fee2e2; color: #b91c1c; }
.badge-fresh    { background: #dcfce7; color: #15803d; }
.badge-configured { background: #dcfce7; color: #166534; }
.badge-stale    { background: #fef3c7; color: #d97706; }
.badge-unavailable { background: #f3f4f6; color: #6b7280; }

/* Toggle switch for JK parameter controls */
.jk-parameter-switch {
    appearance: none;
    background: #d1d5db;
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    flex-shrink: 0;
    height: 1.75rem;
    padding: 0;
    position: relative;
    transition: background-color 200ms;
    width: 3rem;
}

.jk-parameter-switch::after {
    background: #ffffff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    content: '';
    height: 1.25rem;
    left: 0.25rem;
    position: absolute;
    top: 0.25rem;
    transition: transform 200ms;
    width: 1.25rem;
}

.jk-parameter-switch[aria-checked="true"] {
    background: #16a34a;
}

.jk-parameter-switch[aria-checked="true"]::after {
    transform: translateX(1.25rem);
}

.jk-parameter-switch[aria-disabled="true"],
.jk-parameter-switch:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.jk-parameter-switch:focus-visible {
    outline: 3px solid #93c5fd;
    outline-offset: 2px;
}

/* Compact parameter control rows */
.param-row {
    border: 1px solid #e5e7eb;
    margin-bottom: 0.375rem;
    padding: 0.5rem 0.75rem;
}

.param-row__main {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: space-between;
}

.param-row__label {
    align-items: center;
    display: flex;
    gap: 0.5rem;
    min-width: 0;
}

.param-row__title {
    font-weight: 600;
}

.param-row__controls {
    align-items: center;
    display: flex;
    flex-shrink: 0;
    gap: 0.5rem;
}

.param-row__status {
    color: #6b7280;
    font-size: 0.875rem;
    margin: 0.25rem 0 0;
}

.param-row__status:empty {
    display: none;
}

.param-row__status--muted {
    color: #9ca3af;
}

/* Mobile overrides for parameter control rows */
@media (max-width: 639px) {
    .param-row {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Toggle already shows state visually; hide redundant badge on small screens */
    .param-row__controls .badge {
        display: none;
    }
}

/* Control page layout */
.control-page {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    margin: 1rem auto;
    max-width: 1200px;
    padding: 0 0.5rem;
}

@media (min-width: 640px) {
    .control-page {
        margin: 2rem auto;
        padding: 0 1rem;
    }
}

.control-heading {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

@media (min-width: 640px) {
    .control-heading {
        font-size: 1.875rem;
    }
}

.control-identity {
    align-items: baseline;
    column-gap: 0.75rem;
    display: grid;
    grid-template-columns: auto 1fr;
    margin-bottom: 1rem;
    row-gap: 0.15rem;
}

.control-refresh {
    margin-bottom: 1rem;
}

.control-identity__label {
    color: #6b7280;
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
}

/* Control page alert banners (flash messages, staleness notices) */
.control-alert {
    border: 1px solid;
    border-radius: 0.25rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
}

.control-alert--success {
    background: #dcfce7;
    border-color: #15803d;
    color: #14532d;
}

.control-alert--error {
    background: #fee2e2;
    border-color: #b91c1c;
    color: #450a0a;
}

.control-alert--warning {
    background: #fef3c7;
    border-color: #b45309;
    color: #451a03;
}

.control-alert--info {
    background: #f3f4f6;
    border-color: #6b7280;
    color: #1f2937;
}

/* Pack configuration page */
.cfg-page {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    margin: 2rem auto;
    max-width: 1200px;
    padding: 0 1rem;
}

.cfg-identity {
    margin-bottom: 2rem;
}

/* Flash messages on the configuration page (replaces inline styles for dark-mode support) */
.cfg-flash {
    border: 1px solid;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
}

.cfg-flash--success {
    background: #dcfce7;
    border-color: #15803d;
    color: #14532d;
}

.cfg-flash--info {
    background: #dbeafe;
    border-color: #1d4ed8;
    color: #1e40af;
}

.cfg-flash--warning {
    background: #fef3c7;
    border-color: #b45309;
    color: #451a03;
}

.cfg-flash--error {
    background: #fee2e2;
    border-color: #b91c1c;
    color: #450a0a;
}

.cfg-identity-table-wrap {
    max-width: 36rem;
    overflow-x: auto;
}

.cfg-identity-table {
    border-collapse: collapse;
    width: 100%;
}

.cfg-identity-table th {
    padding: 0.5rem 0.75rem 0.5rem 0;
    text-align: left;
    white-space: nowrap;
}

.cfg-identity-table td {
    padding: 0.5rem 0;
}

.cfg-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    margin-bottom: 2rem;
    padding: 1.25rem 1.5rem;
}

.cfg-summary {
    margin-bottom: 1rem;
}

.cfg-summary-title {
    margin: 0 0 0.4rem;
}

.cfg-status-line {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.cfg-status-label {
    color: #4b5563;
    font-size: 0.875rem;
    font-weight: 600;
}

.cfg-meta {
    display: grid;
    gap: 0.75rem 1.25rem;
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
    margin: 0 0 1.5rem;
}

.cfg-meta dt {
    color: #6b7280;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.cfg-meta dd {
    margin: 0;
}

.cfg-group {
    margin-bottom: 1.75rem;
}

.cfg-group-header {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-start;
    margin-bottom: 0.5rem;
}

.cfg-group-action,
.cfg-refresh-action {
    background: #ffffff;
    border-color: #9ca3af;
    color: #374151;
    font-size: 0.75rem;
    min-height: 1.75rem;
    padding: 0.25rem 0.5rem;
}

.cfg-group-action:hover,
.cfg-group-action:focus-visible,
.cfg-refresh-action:hover,
.cfg-refresh-action:focus-visible {
    background: #f9fafb;
    border-color: #6b7280;
    color: #111827;
}

.cfg-refresh-action:disabled {
    background: #f3f4f6;
    border-color: #d1d5db;
    color: #6b7280;
    cursor: wait;
    opacity: 1;
}

.cfg-group-title {
    color: #6b7280;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    margin: 0;
    text-transform: uppercase;
}

.cfg-table-wrap {
    overflow-x: auto;
}

.cfg-group-context {
    align-items: center;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.375rem;
    flex-wrap: wrap;
    font-size: 0.875rem;
    gap: 0.375rem;
    margin-bottom: 0.5rem;
    padding: 0.5rem 0.75rem;
}

.cfg-group-context:not([hidden]) {
    display: flex;
}

.cfg-group-warning {
    color: #b45309;
    flex-basis: 100%;
    margin: 0;
}

.cfg-group-refresh-message {
    background: #dbeafe;
    border: 1px solid #1d4ed8;
    border-radius: 0.375rem;
    margin: 0 0 0.75rem;
    padding: 0.5rem 0.75rem;
}

.cfg-group-save-message {
    border: 1px solid;
    border-radius: 0.375rem;
    margin: 0 0 0.75rem;
    padding: 0.5rem 0.75rem;
}

.cfg-group-save-message--success {
    background: #dcfce7;
    border-color: #15803d;
}

.cfg-group-save-message--info {
    background: #dbeafe;
    border-color: #1d4ed8;
}

.cfg-group-save-message--error {
    background: #fee2e2;
    border-color: #b91c1c;
}

.cfg-group-save-message--warning {
    background: #fef3c7;
    border-color: #b45309;
}

.cfg-pending-lock {
    background: #f3f4f6;
    border: 1px solid #9ca3af;
    border-radius: 0.375rem;
    color: #6b7280;
    display: inline-flex;
    font-size: 0.75rem;
    font-weight: 600;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
    min-height: 1.75rem;
    padding: 0.25rem 0.5rem;
    white-space: nowrap;
}

.cfg-table {
    border-collapse: collapse;
    font-size: 0.875rem;
    min-width: 640px;
    table-layout: fixed;
    width: 100%;
}

.cfg-col-parameter {
    width: 45%;
}

.cfg-col-code {
    width: 16%;
}

.cfg-col-value {
    width: 31%;
}

.cfg-col-unit {
    width: 8%;
}

.cfg-table th {
    border-bottom: 2px solid #e5e7eb;
    font-weight: 600;
    padding: 0.5rem 0.75rem;
    text-align: left;
    white-space: nowrap;
}

.cfg-table td {
    border-bottom: 1px solid #f3f4f6;
    padding: 0.5rem 0.75rem;
    vertical-align: top;
}

.cfg-parameter,
.cfg-code {
    overflow-wrap: anywhere;
}

.cfg-param-name {
    display: block;
}

.cfg-param-code {
    color: #9ca3af;
    display: none;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.7rem;
    font-weight: 400;
    letter-spacing: 0.01em;
}

.cfg-vl-full {
    display: inline;
}

.cfg-vl-mob {
    display: none;
}

.cfg-value {
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.cfg-value .badge {
    line-height: 1.35;
    white-space: normal;
}

.cfg-value-content {
    align-items: center;
    display: flex;
    flex-wrap: nowrap;
    gap: 0.375rem 0.625rem;
}

.cfg-pending-value {
    align-items: flex-start;
    display: inline-flex;
    flex-direction: column;
    gap: 0.3rem;
}

.cfg-pending-change {
    align-items: center;
    display: inline-flex;
    font-size: 0.9375rem;
    font-weight: 700;
    gap: 0.375rem;
    line-height: 1.25;
    white-space: nowrap;
}

.cfg-reconciling-change {
    align-items: center;
    display: inline-flex;
    font-size: 0.9375rem;
    font-weight: 700;
    gap: 0.375rem;
    line-height: 1.25;
    white-space: nowrap;
}

.cfg-pending-desktop {
    align-items: center;
    display: inline-flex;
    gap: 0.375rem;
}

.cfg-pending-mobile {
    display: none;
}

.cfg-pending-old {
    color: #166534;
    font-weight: 700;
}

.cfg-pending-new {
    color: #92400e;
    font-weight: 800;
}

.cfg-reconciling-new {
    color: #b45309;
    font-weight: 800;
}

.cfg-reconciling-value {
    align-items: flex-start;
    color: #b45309;
    display: inline-flex;
    flex-direction: column;
    font-size: 0.875rem;
    gap: 0.3rem;
    font-weight: 700;
    line-height: 1.35;
    white-space: nowrap;
}

.cfg-pending-arrow {
    animation: cfg-pending-arrow 1.15s ease-in-out infinite;
    color: #b45309;
    display: inline-block;
    font-weight: 900;
    min-width: 1.1em;
    text-align: center;
}

@keyframes cfg-pending-arrow {
    0%,
    100% {
        opacity: 0.55;
        transform: translateX(0);
    }

    50% {
        opacity: 1;
        transform: translateX(4px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .cfg-pending-arrow {
        animation: none;
        opacity: 1;
        transform: none;
    }
}

.cfg-edit-value:not([hidden]),
.cfg-edit-value-label {
    align-items: center;
    display: inline-flex;
    gap: 0.375rem;
}

.cfg-edit-value-label > span,
.cfg-readonly-reason {
    color: #6b7280;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.cfg-input {
    border: 1px solid #9ca3af;
    border-radius: 0.25rem;
    font: inherit;
    max-width: 6rem;
    padding: 0.3rem 0.4rem;
    width: 100%;
}

.cfg-input:focus {
    border-color: #2563eb;
    outline: 2px solid #bfdbfe;
    outline-offset: 1px;
}

.cfg-unit {
    white-space: nowrap;
}

.cfg-group-edit-actions:not([hidden]) {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 0.75rem;
}

.cfg-feature-flags {
    margin-top: 1.5rem;
}

.cfg-feature-flags-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.5rem;
}

.cfg-feature-code {
    color: #6b7280;
    font-size: 0.75rem;
    overflow-wrap: anywhere;
}

.cfg-feature-switch {
    cursor: default;
    pointer-events: none;
}

@media (max-width: 640px) {
    .cfg-page {
        margin: 0.75rem auto;
        padding: 0 0.375rem;
    }

    .cfg-card {
        border-radius: 0.25rem;
        padding: 0.75rem 0.625rem;
    }

    .cfg-meta {
        grid-template-columns: 1fr;
    }

    .cfg-value-content {
        flex-wrap: nowrap;
        gap: 0.35rem;
    }

    /* Collapse Code and Unit columns; fill full card width */
    .cfg-table {
        min-width: 0;
        table-layout: fixed;
        width: 100%;
    }

    .cfg-col-parameter {
        width: 50%;
    }

    .cfg-col-code {
        width: 0;
    }

    .cfg-col-value {
        width: 50%;
    }

    .cfg-col-unit {
        width: 0;
    }

    .cfg-th-code,
    .cfg-code {
        display: none;
    }

    .cfg-th-unit,
    .cfg-unit {
        display: none;
    }

    /* Mobile parameter label: name stays, code column is hidden so show a compact code chip instead */
    .cfg-param-code {
        display: block;
        margin-top: 0.2rem;
    }

    /* Mobile value: compact parenthetical form */
    .cfg-vl-full {
        display: none;
    }

    .cfg-vl-mob {
        display: inline;
    }

    /* Mobile pending: hide old→new, show new value as non-wrapping pill */
    .cfg-pending-desktop {
        display: none;
    }

    .cfg-pending-mobile {
        align-items: center;
        display: inline-flex;
        max-width: 100%;
        white-space: nowrap;
        width: max-content;
    }

    .cfg-pending-mobile .cfg-pending-new,
    .cfg-pending-mobile .cfg-reconciling-new {
        align-items: center;
        background: #fef3c7;
        border-radius: 9999px;
        display: inline-flex;
        padding: 0.125rem 0.55rem;
        white-space: nowrap;
    }

    /* Prevent value badge becoming a tall pill — values are short on mobile */
    .cfg-value .badge {
        white-space: nowrap;
    }

    .cfg-edit-label {
        display: none;
    }

    .cfg-edit-value-label {
        align-items: center;
        display: inline-flex;
    }

    .cfg-input {
        box-sizing: border-box;
        flex: 0 0 5rem;
        font-size: 0.8125rem;
        max-width: 5rem;
        min-width: 5rem;
        padding: 0.2rem 0.3rem;
        width: 5rem;
    }
}

/* ==================== Portal pages ==================== */

.portal-page {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    margin: 1.5rem auto;
    max-width: 1200px;
    padding: 0 1rem;
}

@media (min-width: 640px) {
    .portal-page {
        margin: 2rem auto;
    }
}

.app-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 1.25rem 1.5rem;
}

.app-table-wrapper {
    overflow-x: auto;
}

.app-table {
    border-collapse: collapse;
    font-size: 0.9375rem;
    width: 100%;
}

.app-table th {
    background: #f9fafb;
    border-bottom: 2px solid #d1d5db;
    font-weight: 600;
    padding: 0.625rem 0.75rem;
    text-align: left;
    white-space: nowrap;
}

.app-table td {
    border-bottom: 1px solid #f0f0f0;
    padding: 0.625rem 0.75rem;
    vertical-align: top;
}

.app-table tbody tr:last-child td {
    border-bottom: none;
}

.app-table .col-number {
    text-align: right;
}

.empty-state {
    color: #6b7280;
    padding: 0.5rem 0;
}

.text-muted {
    color: #9ca3af;
}

.sr-only {
    border: 0;
    clip: rect(0, 0, 0, 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
}

/* Key/value grid shared by the customer detail page and the portal dashboard. */
.customer-meta,
.portal-summary {
    display: grid;
    font-size: 0.9375rem;
    gap: 0.375rem 1rem;
    grid-template-columns: max-content 1fr;
    margin: 0;
}

.customer-meta > div,
.portal-summary > div {
    display: contents;
}

.customer-meta dt,
.portal-summary dt {
    color: #6b7280;
    font-weight: 600;
}

/* Single headline number on a portal dashboard card. */
.portal-metric {
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.2;
    margin: 0.25rem 0 0.5rem;
}

.col-indicator {
    display: none;
}

.device-indicator {
    display: none;
}

.device-indicator svg {
    display: block;
    height: 1.125rem;
    width: 1.125rem;
}

.device-indicator--active {
    color: #16a34a;
}

.device-indicator--inactive {
    color: #9ca3af;
    opacity: 0.7;
}

@media (max-width: 639px) {
    /* Recover mobile width: page/card padding was too generous on small screens */
    .portal-page {
        padding: 0 0.625rem;
    }

    .app-card {
        padding: 1rem;
    }

    .app-table th,
    .app-table td {
        padding: 0.625rem 0.5rem;
    }

    /* Type/Status columns become a single compact icon column on mobile */
    .col-type,
    .col-status {
        display: none;
    }

    .col-indicator {
        display: table-cell;
        text-align: center;
        width: 2rem;
    }

    .device-indicator {
        align-items: center;
        display: inline-flex;
        justify-content: center;
    }
}

.customer-meta dd,
.portal-summary dd {
    margin: 0;
}

.btn-danger {
    background-color: #dc2626;
    border-color: #dc2626;
    color: #ffffff;
}

.btn-danger:hover,
.btn-danger:focus-visible {
    background-color: #b91c1c;
    border-color: #b91c1c;
    color: #ffffff;
}

/* Gateway MQTT credential issue/rotate/display pages */
.cred-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 1rem 1.25rem;
}

.cred-card__title {
    font-size: 1.0625rem;
    margin: 0 0 0.75rem;
}

.cred-card__subtitle {
    font-size: 0.9375rem;
    margin: 0.75rem 0 0.375rem;
}

.cred-list {
    display: grid;
    font-size: 0.9375rem;
    gap: 0.5rem 1rem;
    grid-template-columns: max-content 1fr;
    margin: 0;
}

.cred-list > div {
    display: contents;
}

.cred-list dt {
    color: #6b7280;
    font-weight: 600;
    padding-top: 0.25rem;
}

.cred-list dd {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0;
}

.cred-password {
    color: #b91c1c;
    font-weight: 700;
    user-select: all;
}

.cred-topic-list {
    margin: 0 0 0.5rem;
    padding-left: 1.25rem;
}

/* ==================== Global dark mode ==================== */

@media (prefers-color-scheme: dark) {
    body {
        background-color: #111827;
    }

    .control-page {
        color: #f3f4f6;
    }

    .control-page a {
        color: #93c5fd;
    }

    .control-identity__label {
        color: #9ca3af;
    }

    .param-row {
        border-color: #374151;
    }

    .param-row__status {
        color: #9ca3af;
    }

    .param-row__status--muted {
        color: #6b7280;
    }

    .badge-enabled,
    .badge-fresh,
    .badge-configured {
        background: #14532d;
        color: #86efac;
    }

    .badge-disabled {
        background: #450a0a;
        color: #fca5a5;
    }

    .badge-stale {
        background: #451a03;
        color: #fcd34d;
    }

    .badge-unavailable {
        background: #1f2937;
        color: #9ca3af;
    }

    .cfg-param-code {
        color: #6b7280;
    }

    /* Configuration page — dark mode */
    .cfg-page {
        color: #f3f4f6;
    }

    .cfg-page a {
        color: #93c5fd;
    }

    .cfg-page a:hover {
        color: #bfdbfe;
    }

    .cfg-card {
        background: #1e293b;
        border-color: #334155;
    }

    .cfg-status-label {
        color: #9ca3af;
    }

    .cfg-meta dt {
        color: #9ca3af;
    }

    .cfg-identity-table th {
        color: #9ca3af;
    }

    .cfg-group-title {
        color: #9ca3af;
    }

    .cfg-table th {
        border-bottom-color: #374151;
        color: #9ca3af;
    }

    .cfg-table td {
        border-bottom-color: #1f2937;
    }

    .cfg-group-context {
        background: #1f2937;
        border-color: #374151;
    }

    .cfg-group-refresh-message {
        background: #1e3a8a;
        border-color: #3b82f6;
        color: #bfdbfe;
    }

    .cfg-group-save-message--success {
        background: #052e16;
        border-color: #16a34a;
        color: #86efac;
    }

    .cfg-group-save-message--info {
        background: #0c1a40;
        border-color: #3b82f6;
        color: #93c5fd;
    }

    .cfg-group-save-message--error {
        background: #450a0a;
        border-color: #dc2626;
        color: #fca5a5;
    }

    .cfg-group-save-message--warning {
        background: #451a03;
        border-color: #d97706;
        color: #fcd34d;
    }

    .cfg-pending-lock {
        background: #374151;
        border-color: #6b7280;
        color: #9ca3af;
    }

    .cfg-pending-old {
        color: #4ade80;
    }

    .cfg-pending-new {
        color: #fb923c;
    }

    .cfg-pending-arrow {
        color: #f59e0b;
    }

    .cfg-pending-mobile .cfg-pending-new,
    .cfg-pending-mobile .cfg-reconciling-new {
        background: #451a03;
    }

    .cfg-reconciling-new {
        color: #f59e0b;
    }

    .cfg-reconciling-value {
        color: #f59e0b;
    }

    .cfg-group-action,
    .cfg-refresh-action {
        background: #1e293b;
        border-color: #6b7280;
        color: #d1d5db;
    }

    .cfg-group-action:hover,
    .cfg-group-action:focus-visible,
    .cfg-refresh-action:hover,
    .cfg-refresh-action:focus-visible {
        background: #273548;
        border-color: #9ca3af;
        color: #f3f4f6;
    }

    .cfg-refresh-action:disabled {
        background: #1f2937;
        border-color: #374151;
        color: #6b7280;
    }

    .cfg-input {
        background: #0f172a;
        border-color: #6b7280;
        color: #f3f4f6;
    }

    .cfg-input:focus {
        border-color: #60a5fa;
        outline-color: rgba(96, 165, 250, 0.2);
    }

    .cfg-flash--success {
        background: #052e16;
        border-color: #16a34a;
        color: #86efac;
    }

    .cfg-flash--info {
        background: #0c1a40;
        border-color: #3b82f6;
        color: #93c5fd;
    }

    .cfg-flash--warning {
        background: #451a03;
        border-color: #d97706;
        color: #fcd34d;
    }

    .cfg-flash--error {
        background: #450a0a;
        border-color: #dc2626;
        color: #fca5a5;
    }

    .jk-parameter-switch {
        background: #374151;
    }

    .btn-outline {
        background-color: #1e293b;
        border-color: #60a5fa;
        color: #93c5fd;
    }

    .btn-outline:hover,
    .btn-outline:focus-visible {
        background-color: #172554;
        border-color: #93c5fd;
        color: #bfdbfe;
    }

    .control-alert--success {
        background: #052e16;
        border-color: #16a34a;
        color: #86efac;
    }

    .control-alert--error {
        background: #450a0a;
        border-color: #dc2626;
        color: #fca5a5;
    }

    .control-alert--warning {
        background: #451a03;
        border-color: #d97706;
        color: #fcd34d;
    }

    .control-alert--info {
        background: #1f2937;
        border-color: #4b5563;
        color: #d1d5db;
    }

    /* Portal pages — dark mode */
    .portal-page {
        color: #f3f4f6;
    }

    .portal-page a {
        color: #93c5fd;
    }

    .portal-page a:hover {
        color: #bfdbfe;
    }

    .app-card {
        background: #1e293b;
        border-color: #334155;
    }

    .app-table th {
        background: #1f2937;
        border-bottom-color: #374151;
        color: #9ca3af;
    }

    .app-table td {
        border-bottom-color: #1f2937;
    }

    .empty-state {
        color: #9ca3af;
    }

    .text-muted {
        color: #9ca3af;
    }

    .customer-meta dt,
    .portal-summary dt {
        color: #9ca3af;
    }

    .device-indicator--active {
        color: #4ade80;
    }

    .device-indicator--inactive {
        color: #6b7280;
    }

    .cred-card {
        background: #1f2937;
        border-color: #374151;
    }

    .cred-list dt {
        color: #9ca3af;
    }

    .cred-password {
        color: #fca5a5;
    }
}

/* ==================== Portal shell ==================== */

/*
 * Tenant portal header + navigation (templates/portal/_layout.html.twig).
 *
 * Deliberately self-contained: the shared device dashboard include sets its own
 * `body` background, so the shell never styles `body` and never fights it.
 * Colors live in custom properties on `.portal-shell` (same pattern as
 * `.auth-page`) so the dark-mode override is a single block.
 */
.portal-shell {
    --portal-shell-bg: #ffffff;
    --portal-shell-border: #e5e7eb;
    --portal-shell-text: #111827;
    --portal-shell-muted: #6b7280;
    --portal-shell-badge-bg: #f3f4f6;
    --portal-shell-badge-text: #374151;
    --portal-shell-link: #4b5563;
    --portal-shell-link-hover: #111827;
    --portal-shell-link-hover-bg: #f3f4f6;
    --portal-shell-active: #1d4ed8;
    --portal-shell-control-bg: #ffffff;
    --portal-shell-control-border: #d1d5db;
    --portal-shell-control-text: #111827;
    --portal-shell-button-bg: #1d4ed8;
    --portal-shell-button-text: #ffffff;

    background: var(--portal-shell-bg);
    border-bottom: 1px solid var(--portal-shell-border);
    color: var(--portal-shell-text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.portal-shell__bar {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    justify-content: space-between;
    margin: 0 auto;
    max-width: 1200px;
    padding: 0.625rem 1rem;
    /* Reserve room for the fixed .locale-picker pinned to the top-right. */
    padding-right: 7.5rem;
}

.portal-shell__identity {
    align-items: baseline;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-width: 0;
}

.portal-shell__brand {
    font-size: 0.9375rem;
    font-weight: 600;
}

.portal-shell__org {
    align-items: baseline;
    color: var(--portal-shell-muted);
    display: inline-flex;
    font-size: 0.875rem;
    gap: 0.35rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.portal-shell__org-label {
    color: var(--portal-shell-muted);
    font-size: 0.75rem;
    font-weight: 600;
}

.portal-shell__org-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.portal-shell__org--none {
    font-style: italic;
}

.portal-shell__badge {
    background: var(--portal-shell-badge-bg);
    border-radius: 9999px;
    color: var(--portal-shell-badge-text);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 0.1rem 0.5rem;
    text-transform: uppercase;
    white-space: nowrap;
}

.portal-shell__account {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.8125rem;
}

.portal-shell__user {
    color: var(--portal-shell-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.portal-shell__signout {
    color: var(--portal-shell-link);
    text-decoration: none;
}

.portal-shell__signout:hover {
    color: var(--portal-shell-link-hover);
    text-decoration: underline;
}

.portal-shell__switcher {
    border-top: 1px solid var(--portal-shell-border);
}

.portal-org-switcher {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0 auto;
    max-width: 1200px;
    padding: 0.5rem 1rem;
}

.portal-org-switcher__label {
    color: var(--portal-shell-muted);
    font-size: 0.8125rem;
    font-weight: 600;
}

.portal-org-switcher__select {
    background: var(--portal-shell-control-bg);
    border: 1px solid var(--portal-shell-control-border);
    border-radius: 0.375rem;
    color: var(--portal-shell-control-text);
    font-size: 0.875rem;
    max-width: 22rem;
    min-height: 2.25rem;
    min-width: min(18rem, 100%);
    padding: 0.375rem 0.5rem;
}

.portal-org-switcher__button {
    background: var(--portal-shell-button-bg);
    border: 1px solid var(--portal-shell-button-bg);
    border-radius: 0.375rem;
    color: var(--portal-shell-button-text);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    min-height: 2.25rem;
    padding: 0.375rem 0.75rem;
}

.portal-org-switcher__button:hover {
    filter: brightness(0.96);
}

.portal-nav {
    border-top: 1px solid var(--portal-shell-border);
}

.portal-nav__list {
    display: flex;
    gap: 0.25rem;
    list-style: none;
    margin: 0 auto;
    max-width: 1200px;
    /* Many future menu items must scroll rather than wrap on narrow screens. */
    overflow-x: auto;
    padding: 0.25rem 0.625rem;
}

.portal-nav__item {
    flex: 0 0 auto;
}

.portal-nav__link {
    border-radius: 0.375rem;
    color: var(--portal-shell-link);
    display: block;
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
    text-decoration: none;
    white-space: nowrap;
}

.portal-nav__link:hover {
    background: var(--portal-shell-link-hover-bg);
    color: var(--portal-shell-link-hover);
}

.portal-nav__link--active {
    color: var(--portal-shell-active);
    font-weight: 600;
}

@media (max-width: 639px) {
    .portal-shell__bar {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.375rem;
        padding: 0.5rem 0.625rem;
        padding-right: 7rem;
    }

    .portal-shell__user {
        max-width: 100%;
    }

    .portal-org-switcher {
        padding: 0.5rem 0.625rem;
        padding-right: 7rem;
    }

    .portal-org-switcher__label,
    .portal-org-switcher__select,
    .portal-org-switcher__button {
        width: 100%;
    }

    .portal-org-switcher__select {
        max-width: none;
        min-width: 0;
    }
}

@media (prefers-color-scheme: dark) {
    .portal-shell {
        --portal-shell-bg: #1f2937;
        --portal-shell-border: #374151;
        --portal-shell-text: #f9fafb;
        --portal-shell-muted: #9ca3af;
        --portal-shell-badge-bg: #374151;
        --portal-shell-badge-text: #e5e7eb;
        --portal-shell-link: #d1d5db;
        --portal-shell-link-hover: #f9fafb;
        --portal-shell-link-hover-bg: #374151;
        --portal-shell-active: #93c5fd;
        --portal-shell-control-bg: #111827;
        --portal-shell-control-border: #4b5563;
        --portal-shell-control-text: #f9fafb;
        --portal-shell-button-bg: #2563eb;
        --portal-shell-button-text: #ffffff;
    }
}

/* -------------------- Gateway assignment (portal/_gateway_assignment_form) -------------------- */

.portal-assignment {
    --portal-assignment-label: #374151;
    --portal-assignment-field-bg: #ffffff;
    --portal-assignment-field-border: #d1d5db;
    --portal-assignment-field-text: #111827;
    --portal-assignment-submit-bg: #1d4ed8;
    --portal-assignment-submit-text: #ffffff;
    --portal-assignment-secondary-bg: transparent;
    --portal-assignment-secondary-border: #9ca3af;
    --portal-assignment-secondary-text: #374151;
}

.portal-assignment__form {
    align-items: flex-end;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.portal-assignment__label {
    color: var(--portal-assignment-label);
    display: block;
    flex-basis: 100%;
    font-size: 0.875rem;
    font-weight: 600;
}

.portal-assignment__select {
    background: var(--portal-assignment-field-bg);
    border: 1px solid var(--portal-assignment-field-border);
    border-radius: 0.375rem;
    color: var(--portal-assignment-field-text);
    flex: 1 1 18rem;
    max-width: 100%;
    min-width: 0;
    padding: 0.5rem 0.625rem;
}

.portal-assignment__submit {
    background: var(--portal-assignment-submit-bg);
    border: 1px solid transparent;
    border-radius: 0.375rem;
    color: var(--portal-assignment-submit-text);
    cursor: pointer;
    font-weight: 600;
    padding: 0.5rem 1rem;
}

.portal-assignment__submit--secondary {
    background: var(--portal-assignment-secondary-bg);
    border-color: var(--portal-assignment-secondary-border);
    color: var(--portal-assignment-secondary-text);
}

@media (prefers-color-scheme: dark) {
    .portal-assignment {
        --portal-assignment-label: #d1d5db;
        --portal-assignment-field-bg: #111827;
        --portal-assignment-field-border: #4b5563;
        --portal-assignment-field-text: #f9fafb;
        --portal-assignment-submit-bg: #2563eb;
        --portal-assignment-submit-text: #f9fafb;
        --portal-assignment-secondary-border: #6b7280;
        --portal-assignment-secondary-text: #e5e7eb;
    }
}

/* -------------------- Customer create/rename (portal/customers.html.twig, portal/customer_show.html.twig) -------------------- */

.portal-customer-form {
    --portal-customer-form-label: #374151;
    --portal-customer-form-field-bg: #ffffff;
    --portal-customer-form-field-border: #d1d5db;
    --portal-customer-form-field-text: #111827;
    --portal-customer-form-submit-bg: #1d4ed8;
    --portal-customer-form-submit-text: #ffffff;

    align-items: flex-end;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.portal-customer-form--inline {
    margin-top: 1rem;
}

.portal-customer-form__label {
    color: var(--portal-customer-form-label);
    display: block;
    flex-basis: 100%;
    font-size: 0.875rem;
    font-weight: 600;
}

.portal-customer-form__input {
    background: var(--portal-customer-form-field-bg);
    border: 1px solid var(--portal-customer-form-field-border);
    border-radius: 0.375rem;
    color: var(--portal-customer-form-field-text);
    flex: 1 1 18rem;
    max-width: 100%;
    min-width: 0;
    padding: 0.5rem 0.625rem;
}

.portal-customer-form__submit {
    background: var(--portal-customer-form-submit-bg);
    border: 1px solid transparent;
    border-radius: 0.375rem;
    color: var(--portal-customer-form-submit-text);
    cursor: pointer;
    font-weight: 600;
    padding: 0.5rem 1rem;
}

@media (max-width: 639px) {
    .portal-customer-form {
        flex-direction: column;
        align-items: stretch;
    }

    .portal-customer-form__input {
        flex-basis: auto;
    }
}

@media (prefers-color-scheme: dark) {
    .portal-customer-form {
        --portal-customer-form-label: #d1d5db;
        --portal-customer-form-field-bg: #111827;
        --portal-customer-form-field-border: #4b5563;
        --portal-customer-form-field-text: #f9fafb;
        --portal-customer-form-submit-bg: #2563eb;
        --portal-customer-form-submit-text: #f9fafb;
    }
}

/* ==================== Auth pages ==================== */

.auth-page {
    --auth-bg: #f1f5f9;
    --auth-card-bg: #ffffff;
    --auth-card-border: #e2e8f0;
    --auth-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.08);
    --auth-text: #0f172a;
    --auth-text-muted: #64748b;
    --auth-label: #374151;
    --auth-input-bg: #ffffff;
    --auth-input-border: #d1d5db;
    --auth-input-border-focus: #2563eb;
    --auth-input-ring-focus: rgba(37, 99, 235, 0.15);
    --auth-input-text: #111827;
    --auth-placeholder: #9ca3af;
    --auth-toggle-bg: transparent;
    --auth-toggle-hover-bg: #eff6ff;
    --auth-requirement-bg: #f8fafc;
    --auth-requirement-border: #dbeafe;
    --auth-link: #2563eb;
    --auth-link-hover: #1d4ed8;
    --auth-error-bg: #fef2f2;
    --auth-error-border: #fecaca;
    --auth-error-text: #b91c1c;
    --auth-info-bg: #eff6ff;
    --auth-info-border: #bfdbfe;
    --auth-info-text: #1e40af;
    --auth-divider: #e5e7eb;

    background-color: var(--auth-bg);
    box-sizing: border-box;
    color: var(--auth-text);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 2rem 1rem;
}

@media (prefers-color-scheme: dark) {
    .auth-page {
        --auth-bg: #0f172a;
        --auth-card-bg: #1e293b;
        --auth-card-border: #334155;
        --auth-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), 0 4px 24px rgba(0, 0, 0, 0.45);
        --auth-text: #f1f5f9;
        --auth-text-muted: #94a3b8;
        --auth-label: #d1d5db;
        --auth-input-bg: #0f172a;
        --auth-input-border: #4b5563;
        --auth-input-border-focus: #60a5fa;
        --auth-input-ring-focus: rgba(96, 165, 250, 0.2);
        --auth-input-text: #f9fafb;
        --auth-placeholder: #6b7280;
        --auth-toggle-bg: transparent;
        --auth-toggle-hover-bg: #172554;
        --auth-requirement-bg: #111827;
        --auth-requirement-border: #334155;
        --auth-link: #60a5fa;
        --auth-link-hover: #93c5fd;
        --auth-error-bg: #2d0b0b;
        --auth-error-border: #7f1d1d;
        --auth-error-text: #fca5a5;
        --auth-info-bg: #0c1a40;
        --auth-info-border: #1e3a8a;
        --auth-info-text: #93c5fd;
        --auth-divider: #374151;
    }
}

.auth-card-wrap {
    align-items: center;
    display: flex;
    flex: 1;
    justify-content: center;
}

.auth-card {
    background: var(--auth-card-bg);
    border: 1px solid var(--auth-card-border);
    border-radius: 0.75rem;
    box-shadow: var(--auth-card-shadow);
    max-width: 400px;
    padding: 2rem;
    width: 100%;
}

.auth-brand {
    align-items: center;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.auth-brand-icon {
    color: var(--auth-link);
    flex-shrink: 0;
    font-size: 1.25rem;
    line-height: 1;
}

.auth-brand-name {
    color: var(--auth-text);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.auth-title {
    color: var(--auth-text);
    font-size: 1.375rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 0 0 0.5rem;
    text-align: center;
}

.auth-subtitle {
    color: var(--auth-text-muted);
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 0 0 1.25rem;
    text-align: center;
}

.auth-alert {
    border: 1px solid;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    line-height: 1.4;
    margin-bottom: 1rem;
    padding: 0.625rem 0.875rem;
}

.auth-alert-error {
    background: var(--auth-error-bg);
    border-color: var(--auth-error-border);
    color: var(--auth-error-text);
}

.auth-alert-info {
    background: var(--auth-info-bg);
    border-color: var(--auth-info-border);
    color: var(--auth-info-text);
}

/* Form field spacing — covers both .auth-field divs (login) and
   form_row() output divs (reset password forms, including RepeatedType
   which renders two sibling divs inside one form > div). */
.auth-field,
.auth-body form > div,
.auth-body form > div > div {
    margin-bottom: 1rem;
}

.auth-body label,
.auth-field label {
    color: var(--auth-label);
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
}

.auth-body input[type="email"],
.auth-body input[type="password"],
.auth-body input[type="text"] {
    background: var(--auth-input-bg);
    border: 1px solid var(--auth-input-border);
    border-radius: 0.375rem;
    box-sizing: border-box;
    color: var(--auth-input-text);
    display: block;
    font-size: 1rem;
    line-height: 1.5;
    padding: 0.625rem 0.75rem;
    transition: border-color 150ms ease, box-shadow 150ms ease;
    width: 100%;
}

.auth-body input[type="email"]:focus,
.auth-body input[type="password"]:focus,
.auth-body input[type="text"]:focus {
    border-color: var(--auth-input-border-focus);
    box-shadow: 0 0 0 3px var(--auth-input-ring-focus);
    outline: none;
}

.auth-body input::placeholder {
    color: var(--auth-placeholder);
}

.auth-password-control {
    align-items: stretch;
    display: flex;
    position: relative;
}

.auth-password-control input[type="password"],
.auth-password-control input[type="text"] {
    padding-right: 3rem;
}

.auth-password-toggle {
    align-items: center;
    background: var(--auth-toggle-bg);
    border: 0;
    border-radius: 9999px;
    color: var(--auth-text-muted);
    cursor: pointer;
    display: inline-flex;
    height: 2rem;
    justify-content: center;
    margin: 0.25rem;
    padding: 0;
    position: absolute;
    right: 0;
    top: 0;
    width: 2rem;
}

.auth-password-toggle:hover,
.auth-password-toggle:focus-visible {
    background: var(--auth-toggle-hover-bg);
    color: var(--auth-link-hover);
    outline: none;
}

.auth-password-toggle:focus-visible {
    box-shadow: 0 0 0 3px var(--auth-input-ring-focus);
}

.auth-password-toggle__icon {
    display: inline-block;
    height: 1.125rem;
    width: 1.125rem;
}

.auth-password-toggle__icon svg {
    display: block;
    fill: none;
    height: 100%;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
    width: 100%;
}

[data-password-visible="true"] .auth-password-toggle__icon--hidden,
[data-password-visible="false"] .auth-password-toggle__icon--visible {
    display: none;
}

[data-password-visible="true"] .auth-password-toggle__icon--visible,
[data-password-visible="false"] .auth-password-toggle__icon--hidden {
    display: inline-block;
}

.auth-password-toggle__icon--visible {
    display: none;
}

.auth-password-requirements {
    background: var(--auth-requirement-bg);
    border: 1px solid var(--auth-requirement-border);
    border-radius: 0.375rem;
    color: var(--auth-text-muted);
    font-size: 0.875rem;
    line-height: 1.45;
    margin: 0 0 1rem;
    padding: 0.625rem 0.75rem;
}

/* Symfony form errors (plain <ul> from default form theme) */
.auth-body form ul {
    color: var(--auth-error-text);
    font-size: 0.8125rem;
    list-style: none;
    margin: 0 0 0.25rem;
    padding: 0;
}

.auth-body form ul li::before {
    content: "⚠ ";
}

.auth-submit {
    margin-top: 1.25rem;
}

.auth-body .btn-primary {
    display: block;
    font-size: 1rem;
    min-height: 2.625rem;
    padding: 0.6875rem 1rem;
    width: 100%;
}

.auth-footer {
    border-top: 1px solid var(--auth-divider);
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    text-align: center;
}

.auth-footer a {
    color: var(--auth-link);
    font-size: 0.875rem;
    text-decoration: none;
}

.auth-footer a:hover,
.auth-footer a:focus-visible {
    color: var(--auth-link-hover);
    text-decoration: underline;
}

.auth-info-block {
    color: var(--auth-text);
    font-size: 0.9375rem;
    line-height: 1.65;
}

.auth-info-block p {
    margin: 0 0 1rem;
}

.auth-info-block p:last-child {
    margin-bottom: 0;
}

.auth-info-block a {
    color: var(--auth-link);
    text-decoration: none;
}

.auth-info-block a:hover {
    color: var(--auth-link-hover);
    text-decoration: underline;
}

@media (max-width: 480px) {
    .auth-page {
        padding: 0;
    }

    .auth-card {
        border-left: none;
        border-radius: 0;
        border-right: none;
        box-shadow: none;
        padding: 2rem 1.25rem;
    }
}
