/* Bambini unified UI design system (P4UI) */

:root {
    --b-bg: #f4f7fb;
    --b-bg-soft: #eef3fb;
    --b-surface: #ffffff;
    --b-surface-soft: #f8fafc;
    --b-surface-2: var(--b-surface-soft);
    --b-text: #0f172a;
    --b-muted: #64748b;
    --b-border: rgba(15, 23, 42, 0.10);
    --b-primary: #2563eb;
    --b-primary-soft: #dbeafe;
    --b-action: #0f172a;
    --b-action-hover: #111827;
    --b-link: #0f172a;
    --b-link-hover: #000000;
    --b-danger: #dc2626;
    --b-success: #16a34a;

    --b-radius: 16px;
    --b-radius-sm: 10px;
    --b-radius-md: 14px;
    --b-radius-lg: 20px;

    --b-shadow: 0 10px 30px rgba(15, 23, 42, 0.07);
    --b-shadow-sm: 0 4px 14px rgba(15, 23, 42, 0.06);
    --b-shadow-md: 0 12px 32px rgba(15, 23, 42, 0.10);

    --b-topbar-height: 56px;
    --b-container: 1180px;
    --b-container-wide: 1360px;

    --b-space-1: 4px;
    --b-space-2: 8px;
    --b-space-3: 12px;
    --b-space-4: 16px;
    --b-space-5: 24px;
    --b-space-6: 32px;

    /* Legacy aliases (P4B) */
    --space-1: var(--b-space-1);
    --space-2: var(--b-space-2);
    --space-3: var(--b-space-3);
    --space-4: var(--b-space-4);
    --space-5: var(--b-space-5);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

.b-page,
.b-app-body {
    margin: 0;
    min-height: 100vh;
    background: var(--b-bg);
    color: var(--b-text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

.b-page-fullscreen {
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

.b-page-main {
    flex: 1;
}

.b-container,
.b-container-wide,
.b-app-shell {
    width: min(calc(100% - 40px), var(--b-container));
    max-width: var(--b-container);
    margin-inline: auto;
    padding-block: 32px 64px;
    padding-inline: 0;
}

.b-container-wide {
    max-width: var(--b-container-wide);
    width: min(calc(100% - 40px), var(--b-container-wide));
}

/* Top bar (P4UI2 / P4UI-6D contract) */
.b-topbar,
.b-topnav {
    flex: 0 0 auto;
    height: var(--b-topbar-height);
    min-height: var(--b-topbar-height);
    background: var(--b-surface);
    border-bottom: 1px solid var(--b-border);
    box-shadow: none;
    z-index: 100;
}

.b-topbar-inner {
    width: min(calc(100% - 40px), var(--b-container-wide));
    max-width: var(--b-container-wide);
    height: 100%;
    margin-inline: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: nowrap;
    padding: 0;
}

.b-brand,
.b-topnav-brand {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    height: 100%;
    line-height: 1;
    font-size: 15px;
    font-weight: 700;
    color: var(--b-text);
    text-decoration: none;
    letter-spacing: 0.02em;
}

.b-topbar-end {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    min-width: 0;
    flex: 1 1 auto;
}

.b-nav,
.b-topnav-links {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.b-nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 34px;
    min-height: 34px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: 999px;
    box-sizing: border-box;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    color: var(--b-muted);
    text-decoration: none;
    white-space: nowrap;
    flex: 0 0 auto;
    transition: background 0.15s, color 0.15s;
}

.b-nav-link:hover {
    color: var(--b-text);
    background: var(--b-primary-soft);
}

.b-nav-link-active,
.b-nav-link.is-active {
    color: var(--b-primary);
    font-weight: 500;
    background: var(--b-primary-soft);
    border-color: transparent;
}

.b-topbar-logout {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    margin: 0;
    padding: 0;
}

.b-topbar-logout-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    padding: 0 10px;
    margin: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--b-muted);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.b-topbar-logout-btn:hover {
    color: var(--b-text);
    background: var(--b-surface-soft);
}

.b-topbar-logout-btn:focus-visible {
    outline: 2px solid var(--b-primary);
    outline-offset: 2px;
}

/* Header nav: isolated from page-specific stylesheets */
.b-topbar .b-nav-link {
    height: 34px;
    min-height: 34px;
    padding: 0 14px;
    border: 1px solid transparent;
    font-weight: 500;
    line-height: 1;
    vertical-align: middle;
}

.b-topbar .b-nav-link.is-active,
.b-topbar .b-nav-link-active {
    font-weight: 500;
    padding: 0 14px;
}

.b-topbar .b-brand {
    font-size: 15px;
    font-weight: 700;
}

    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: var(--b-space-5);
}

.b-login-shell {
    width: min(100%, 420px);
}

.b-login-card {
    padding: var(--b-space-6) var(--b-space-5);
}

.b-login-title {
    margin: 0 0 var(--b-space-2);
    font-size: 28px;
    font-weight: 700;
}

.b-login-subtitle {
    margin: 0 0 var(--b-space-5);
    color: var(--b-muted);
}

.b-login-error {
    margin: 0 0 var(--b-space-4);
    padding: var(--b-space-3);
    border-radius: var(--b-radius-sm);
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.b-login-form .b-form-row {
    margin-bottom: var(--b-space-4);
}

.b-login-submit {
    width: 100%;
}

.b-page-header {
    margin-bottom: var(--b-space-5);
}

.b-page-header-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--b-space-4);
    margin-bottom: var(--b-space-5);
}

.b-page-header-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--b-space-2);
    margin-left: auto;
}

.b-breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--b-space-2);
    margin: 0 0 var(--b-space-3);
    font-size: 14px;
}

.b-breadcrumbs a {
    color: var(--b-muted);
    text-decoration: none;
}

.b-breadcrumbs a:hover {
    color: var(--b-primary);
}

.b-stat-card,
.b-stat-grid .b-stat-card {
    background: var(--b-surface);
    border: 1px solid var(--b-border);
    border-radius: var(--b-radius-sm);
    padding: var(--b-space-4);
    box-shadow: var(--b-shadow-sm);
    min-height: 88px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.b-stat-card .b-stat-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: var(--b-space-1);
}

.b-stat-card .b-stat-label {
    font-size: 13px;
    color: var(--b-muted);
    line-height: 1.35;
}

.b-stat-card small {
    display: block;
    margin-top: var(--b-space-1);
    font-size: 11px;
    color: var(--b-muted);
    line-height: 1.3;
}

.b-stat-section {
    margin-bottom: var(--b-space-6);
}

.b-stat-section h2 {
    margin: 0 0 var(--b-space-3);
    font-size: 18px;
    font-weight: 700;
}

.b-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--b-space-3);
}

/* Readiness dashboard — progress bars (P3F) */
.b-progress-list {
    display: flex;
    flex-direction: column;
    gap: var(--b-space-3);
}

.b-progress-card {
    background: var(--b-surface);
    border: 1px solid var(--b-border);
    border-radius: var(--b-radius-sm);
    padding: var(--b-space-4);
    box-shadow: var(--b-shadow-sm);
}

.b-progress-card.status-ok {
    border-left: 4px solid var(--b-success, #2e7d32);
}

.b-progress-card.status-warn {
    border-left: 4px solid var(--b-warning, #ed6c02);
}

.b-progress-card.status-bad {
    border-left: 4px solid var(--b-danger, #d32f2f);
}

.b-progress-card.status-info {
    border-left: 4px solid var(--b-border);
}

.b-progress-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--b-space-4);
    margin-bottom: var(--b-space-3);
}

.b-progress-head p {
    margin: var(--b-space-1) 0 0;
    font-size: 13px;
    color: var(--b-muted);
    line-height: 1.4;
}

.b-progress-number {
    font-size: 18px;
    font-weight: 700;
    white-space: nowrap;
}

.b-progress-track {
    height: 8px;
    background: var(--b-surface-2);
    border-radius: 999px;
    overflow: hidden;
}

.b-progress-fill {
    height: 100%;
    background: var(--b-primary);
    border-radius: 999px;
    min-width: 2px;
}

.b-progress-card.status-ok .b-progress-fill {
    background: var(--b-success, #2e7d32);
}

.b-progress-card.status-warn .b-progress-fill {
    background: var(--b-warning, #ed6c02);
}

.b-progress-card.status-bad .b-progress-fill {
    background: var(--b-danger, #d32f2f);
}

.b-progress-foot {
    display: flex;
    justify-content: space-between;
    margin-top: var(--b-space-2);
    font-size: 12px;
    color: var(--b-muted);
}

.b-alert-list {
    display: flex;
    flex-direction: column;
    gap: var(--b-space-2);
}

.b-alert {
    padding: var(--b-space-3) var(--b-space-4);
    border-radius: var(--b-radius-sm);
    font-size: 14px;
    line-height: 1.45;
}

.b-alert-warn {
    background: #fff4e5;
    border: 1px solid #ffcc80;
    color: #663c00;
}

.b-alert-info {
    background: #e8f4fd;
    border: 1px solid #90caf9;
    color: #0d47a1;
}

.b-service-list {
    display: flex;
    flex-direction: column;
    gap: var(--b-space-3);
    margin-bottom: var(--b-space-5);
}

.b-service-card {
    background: var(--b-surface);
    border: 1px solid var(--b-border);
    border-radius: var(--b-radius-sm);
    padding: var(--b-space-4);
    box-shadow: var(--b-shadow-sm);
}

.b-service-card.status-ok {
    border-left: 4px solid var(--b-success, #2e7d32);
}

.b-service-card.status-warn {
    border-left: 4px solid var(--b-warning, #ed6c02);
}

.b-service-card.status-bad {
    border-left: 4px solid var(--b-danger, #d32f2f);
}

.b-service-head {
    display: flex;
    justify-content: space-between;
    gap: var(--b-space-4);
    margin-bottom: var(--b-space-3);
}

.b-service-state {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 13px;
    gap: 2px;
}

.b-service-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--b-space-2);
    align-items: center;
}

.b-service-actions form {
    display: inline;
    margin: 0;
}

.b-subsection-title {
    font-size: 15px;
    font-weight: 700;
    margin: var(--b-space-4) 0 var(--b-space-3);
}

.b-unit-code {
    font-size: 11px;
    color: var(--b-muted);
}

.b-stat-card.status-ok {
    border-left: 3px solid var(--b-success, #2e7d32);
}

.b-stat-card.status-warn {
    border-left: 3px solid var(--b-warning, #ed6c02);
}

.b-stat-card.status-bad {
    border-left: 3px solid var(--b-danger, #d32f2f);
}

.b-form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--b-space-4);
}

.b-form-row {
    display: flex;
    flex-direction: column;
    gap: var(--b-space-1);
}

.b-form-row label {
    font-size: 13px;
    font-weight: 600;
    color: var(--b-muted);
}

.b-form-actions {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: var(--b-space-2);
    margin-top: var(--b-space-2);
}

.catalog-filter-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--b-space-4);
}

.catalog-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: var(--b-space-3);
}

.catalog-summary-panel {
    margin-bottom: var(--b-space-4);
}

.catalog-summary-summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 15px;
    list-style: none;
}

.catalog-summary-summary::-webkit-details-marker {
    display: none;
}

.catalog-summary-text {
    margin: var(--b-space-3) 0 var(--b-space-2);
    font-size: 15px;
    line-height: 1.55;
    color: var(--b-text);
}

.catalog-summary-hint {
    margin: 0;
    font-size: 13px;
}

.catalog-stat-item {
    font-size: 14px;
    line-height: 1.5;
}

.catalog-stat-item b {
    display: block;
    font-size: 20px;
    color: var(--b-text);
}

/* People index spacing (P4UI4) */
.people-search-panel {
    margin-bottom: 24px;
}

.people-stats {
    margin-bottom: 36px;
}

.people-section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: var(--b-space-3);
    margin-top: 32px;
    margin-bottom: 18px;
}

.people-section-header h2 {
    margin: 0;
    font-size: 24px;
}

.people-section-header .p40-muted {
    margin: 0;
}

.people-profile-grid {
    margin-top: 18px;
    gap: 20px;
}

body.b-body-chat {
    overflow: hidden;
}

.b-link-action {
    font-size: 14px;
    font-weight: 600;
    color: var(--b-link);
    text-decoration: none;
}

.b-link-action:hover {
    color: var(--b-link-hover);
}

.b-page-main a:not(.b-button):not(.b-nav-link):not(.b-brand):not(.js-media-lightbox) {
    color: var(--b-link);
}

.b-page-main a:not(.b-button):not(.b-nav-link):not(.b-brand):hover {
    color: var(--b-link-hover);
}

.b-section-title {
    margin: 0 0 var(--b-space-3);
    font-size: 16px;
    font-weight: 700;
}

.b-page-title {
    margin: 0 0 var(--b-space-2);
    font-size: 28px;
    line-height: 1.2;
    font-weight: 700;
}

.b-page-subtitle,
.b-muted,
.muted,
.pp-muted,
.p40-muted,
.pc44-muted {
    color: var(--b-muted);
    font-size: 15px;
}

.b-page-subtitle {
    margin: 0 0 var(--b-space-4);
}

.b-panel,
.b-card {
    background: var(--b-surface);
    border: 1px solid var(--b-border);
    border-radius: var(--b-radius-md);
    box-shadow: var(--b-shadow-sm);
    padding: var(--b-space-4);
}

.b-card + .b-card,
.b-panel + .b-panel {
    margin-top: var(--b-space-4);
}

.b-grid {
    display: grid;
    gap: var(--b-space-4);
}

.b-stack {
    display: flex;
    flex-direction: column;
    gap: var(--b-space-3);
}

.b-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--b-space-2) var(--b-space-3);
}

.b-button,
.b-button-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--b-space-2);
    padding: 10px 14px;
    border-radius: var(--b-radius-sm);
    border: 1px solid var(--b-border);
    background: var(--b-surface);
    color: var(--b-text);
    font-size: 14px;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
}

.b-button:hover,
.b-button-secondary:hover {
    background: var(--b-surface-2);
}

.b-button-primary,
.p40-btn,
.pp-btn.b-button-primary {
    background: var(--b-action);
    color: #fff;
    border-color: var(--b-action);
}

.b-button-primary:hover {
    background: var(--b-action-hover);
    filter: none;
}

.b-button-danger {
    background: #fff;
    color: var(--b-danger);
    border-color: rgba(220, 38, 38, 0.35);
}

.b-input,
.b-select,
.b-textarea,
input.b-input,
select.b-select,
textarea.b-textarea {
    width: 100%;
    max-width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--b-border);
    border-radius: var(--b-radius-sm);
    background: var(--b-surface);
    color: var(--b-text);
    font: inherit;
}

.b-textarea {
    min-height: 96px;
    resize: vertical;
}

.b-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--b-primary-soft);
    color: var(--b-primary);
}

.b-subnav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--b-space-2) var(--b-space-3);
    margin: 0 0 var(--b-space-4);
    font-size: 14px;
    align-items: center;
}

.b-subnav a {
    color: var(--b-muted);
    text-decoration: none;
}

.b-subnav a:hover {
    color: var(--b-text);
    text-decoration: underline;
}

.b-subnav .b-button-primary {
    margin-left: auto;
}

/* Agent filter panel (Smart Chat) */
.agent-filter-panel.b-panel {
    display: grid;
    gap: var(--b-space-3);
}

.agent-filter-actions {
    margin-top: var(--b-space-3);
    display: flex;
    flex-direction: column;
    gap: var(--b-space-2);
}

@media (max-width: 900px) {
    .b-form-grid,
    .catalog-filter-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 860px) {
    .b-topbar-inner {
        width: min(calc(100% - 24px), 100%);
        gap: 12px;
    }

    .b-nav {
        gap: 4px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .b-nav::-webkit-scrollbar {
        display: none;
    }

    .b-topbar .b-nav-link,
    .b-nav-link {
        height: 34px;
        min-height: 34px;
        padding: 0 10px;
        font-size: 14px;
    }

    .b-topbar .b-nav-link.is-active,
    .b-nav-link.is-active,
    .b-nav-link-active {
        padding: 0 10px;
    }

    .b-topbar-logout-btn {
        font-size: 11px;
        padding: 0 8px;
    }
}

@media (max-width: 720px) {
    .b-container,
    .b-container-wide,
    .b-app-shell {
        width: min(calc(100% - 20px), 100%);
        padding-block: 20px 40px;
    }

    .b-page-title {
        font-size: 24px;
    }
}

@media (max-width: 480px) {
    .b-topbar-inner {
        gap: 10px;
    }

    .b-brand {
        font-size: 18px;
        flex-shrink: 0;
    }
}

/* P5A admin context */
.ctx-rule-form textarea,
.ctx-add-form textarea {
    width: 100%;
    max-width: 640px;
    font: inherit;
}

.ctx-rule-form,
.ctx-add-form {
    display: flex;
    flex-direction: column;
    gap: var(--b-space-2);
    margin: var(--b-space-2) 0;
}

.ctx-add-form label {
    font-size: 13px;
    color: var(--b-muted);
}

.ctx-overview {
    margin-bottom: var(--b-space-4);
}

.ctx-stats-list,
.ctx-legacy-list {
    margin: var(--b-space-2) 0;
    padding-left: 1.25rem;
    line-height: 1.6;
}

.ctx-seed-cmd {
    background: var(--b-surface-2);
    padding: var(--b-space-3);
    overflow-x: auto;
    font-size: 13px;
    border-radius: var(--b-radius-sm);
    white-space: pre-wrap;
    border: 1px solid var(--b-border);
}

/* Admin status — legacy .card alias → b-stat-card */
.admin-status-page .cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--b-space-3);
    margin-bottom: var(--b-space-5);
}

.admin-status-page .card,
.admin-status-page .cards .card {
    background: var(--b-surface);
    border: 1px solid var(--b-border);
    border-radius: var(--b-radius-sm);
    padding: var(--b-space-4);
    box-shadow: var(--b-shadow-sm);
    min-height: 88px;
}

.admin-status-page .card .num {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: var(--b-space-1);
}

.ctx-priority-input {
    width: 5em;
    max-width: 5em;
}

.ctx-ai-actions {
    margin-top: var(--b-space-3);
}

.admin-status-page .admin-table,
.admin-status-page table {
    width: 100%;
    border-collapse: collapse;
    background: var(--b-surface);
    margin-bottom: var(--b-space-5);
    border-radius: var(--b-radius-sm);
    overflow: hidden;
}

.admin-status-page th,
.admin-status-page td {
    border: 1px solid var(--b-border);
    padding: var(--b-space-2) var(--b-space-3);
    font-size: 14px;
    vertical-align: top;
}

.admin-status-page th {
    background: var(--b-surface-2);
    text-align: left;
}

.admin-status-page button {
    padding: 6px 10px;
    margin: 2px;
    border-radius: var(--b-radius-sm);
    border: 1px solid var(--b-border);
    background: var(--b-surface);
    cursor: pointer;
    font: inherit;
}

.admin-status-page .stats {
    background: var(--b-surface);
    border: 1px solid var(--b-border);
    padding: var(--b-space-4);
    border-radius: var(--b-radius-md);
    margin-bottom: var(--b-space-5);
}

.admin-status-page .err {
    color: var(--b-danger);
}

.ctx-ai-editor textarea {
    width: 100%;
    max-width: 100%;
}

.ctx-ai-result {
    margin-top: var(--b-space-4);
}

.ctx-ai-result h3 {
    margin: var(--b-space-3) 0 var(--b-space-2);
    font-size: 15px;
}

.ctx-ai-status.ok {
    color: var(--b-success);
}

.ctx-compiled-pre {
    background: var(--b-surface-2);
    border: 1px solid var(--b-border);
    border-radius: var(--b-radius-sm);
    padding: var(--b-space-3);
    overflow-x: auto;
    font-size: 12px;
    line-height: 1.45;
    max-height: 420px;
    white-space: pre-wrap;
    word-break: break-word;
}

.ctx-ai-raw pre {
    font-size: 12px;
    max-height: 320px;
    overflow: auto;
}
