/*
 * P4 Shared Component Layer
 * =========================
 * Styles for reusable UI primitives and shared page shells.
 * New shared component styling belongs here.
 */

/* ============================================
   PAGE HEADER SHELL
   ============================================ */

.p4-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 80px;
    padding: 16px 20px;
    background: var(--p4-surface, #FFFFFF);
    border-radius: var(--p4-shape-large, 8px);
    box-shadow: var(--p4-elevation-1, 0 1px 2px rgba(0,0,0,0.12));
    margin-bottom: 20px;
    gap: 16px;
}

/* Disables all interactive children while grid is loading */
.p4-actions-disabled {
    pointer-events: none;
    opacity: 0.5;
}

.p4-page-header-content,
.p4-page-header-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.p4-page-header-content .p4-page-title,
.p4-page-header-left .p4-page-title {
    display: inline;
}

.p4-page-header-content .p4-page-description,
.p4-page-header-left .p4-page-description {
    margin: 0;
}

.p4-page-header-left h1 {
    font-size: var(--p4-headline-large, 24px);
    font-weight: 600;
    color: var(--p4-on-surface);
    margin: 0;
}

.p4-page-header-right {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.p4-breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--p4-outline);
    margin-bottom: 8px;
}

.p4-breadcrumb a {
    color: var(--p4-primary);
    text-decoration: none;
}

.p4-breadcrumb a:hover {
    text-decoration: underline;
}

.p4-breadcrumb-separator {
    color: var(--p4-text-caption, #A0AEC0);
}

.p4-page-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--p4-on-surface);
    margin: 0 0 4px 0;
}

.p4-page-description {
    font-size: 14px;
    color: var(--p4-outline);
    margin: 0;
}

.p4-page-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    align-self: center;
}

.p4-page-header.ds-contextual-bar {
    background: var(--p4-primary-container, #DBEAFE);
    transition: background 0.2s ease;
}

.ds-selection-count {
    font-size: 14px;
    font-weight: 600;
    color: var(--p4-on-primary-container, #1E3A5F);
}

.theme-dark .p4-page-header,
body.e-dark-mode .p4-page-header {
    background: var(--p4-surface, #0F172A);
}

.theme-dark .p4-page-header.ds-contextual-bar,
body.e-dark-mode .p4-page-header.ds-contextual-bar {
    background: var(--p4-primary-container, #1E3A5F);
}

/* ============================================
   BADGES
   ============================================ */

.p4-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 12px;
    border-radius: var(--p4-shape-full, 9999px);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.2px;
    line-height: 1.4;
}

.p4-badge-primary {
    background: var(--p4-primary-container, #DBEAFE);
    color: var(--p4-on-primary-container, #1E3A5F);
}

.p4-badge-success {
    background: var(--p4-success-container, #F0FFF4);
    color: var(--p4-on-success-container, #2F855A);
}

.p4-badge-warning {
    background: var(--p4-warning-container, #FFFBEB);
    color: var(--p4-on-warning-container, #C05621);
}

.p4-badge-danger {
    background: var(--p4-error-container, #FEF2F2);
    color: var(--p4-on-error-container, #C53030);
}

.p4-badge-secondary {
    background: var(--p4-secondary-container, rgba(147, 149, 152, 0.1));
    color: var(--p4-on-secondary-container, #616263);
}

.p4-badge-info {
    background: var(--p4-info-container, #E1F5FE);
    color: var(--p4-on-info-container, #014361);
}

.p4-badge-muted {
    background: var(--p4-surface-variant, #E2E8F0);
    color: var(--p4-outline, #64748B);
}

/* P4 Warehouse status pill: vivid amber, larger, bold, intentionally eye-catching. */
.p4-badge.p4-badge-p4w {
    background: #F59E0B;
    color: #111827;
    font-size: 13px;
    font-weight: 700;
    padding: 5px 14px;
    letter-spacing: 0.4px;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.35);
}

.p4-badge-icon {
    font-size: 14px;
    line-height: 1;
}

.theme-dark .p4-badge-info,
body.e-dark-mode .p4-badge-info {
    background: var(--p4-info-container, #0E1F2D);
    color: var(--p4-info, #42A5F5);
}

.theme-dark .p4-badge-muted,
body.e-dark-mode .p4-badge-muted {
    background: var(--p4-surface-variant, #334155);
    color: var(--p4-outline, #94A3B8);
}

/* ============================================
   DOCUMENT STATUS TONES
   Canonical state -> color map. 8 tones; each
   document state in the system maps to exactly
   one tone via DocumentStatusBadge.GetTone(...).
   Source: decisions/document-status-colors.md
   ============================================ */

.p4-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: var(--ds-radius-badge, 9999px);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

/* draft — inert, not yet started */
.p4-status-draft {
    background: #F1F5F9;
    color: #64748B;
    border: 1px solid #E2E8F0;
}

/* pending — awaiting external/human action */
.p4-status-pending {
    background: #E2E8F0;
    color: #475569;
    border: 1px solid #CBD5E1;
}

/* active — live, in motion */
.p4-status-active {
    background: #EBF2FA;
    color: #0A5FAD;
    border: 1px solid rgba(10, 95, 173, 0.20);
}

/* partial — incomplete, attention required */
.p4-status-partial {
    background: #FFF8EE;
    color: #C77A1E;
    border: 1px solid rgba(251, 173, 72, 0.40);
}

/* complete — transaction settled positive */
.p4-status-complete {
    background: #F0FFF4;
    color: #16A34A;
    border: 1px solid rgba(22, 163, 74, 0.25);
}

/* closed — sealed/archived. Outline-only so it reads as terminal,
   not as a disabled button (the previous solid-gray fill did). */
.p4-status-closed {
    background: transparent;
    color: #475569;
    border: 1px solid #94A3B8;
}

/* voided — terminal negative */
.p4-status-voided {
    background: #FEF2F2;
    color: #DC2626;
    border: 1px solid rgba(220, 38, 38, 0.25);
}

/* reversed / amended — accounting correction (neutral) */
.p4-status-reversed {
    background: #FFF8EE;
    color: #7C2D12;
    border: 1px solid #FBAD48;
    font-style: italic;
}

/* ── Dark mode tone overrides ───────────────── */
[data-theme="fluent2-dark"] .p4-status-draft,
.theme-dark .p4-status-draft,
body.e-dark-mode .p4-status-draft {
    background: rgba(148, 163, 184, 0.12);
    color: #94A3B8;
    border-color: rgba(148, 163, 184, 0.30);
}

[data-theme="fluent2-dark"] .p4-status-pending,
.theme-dark .p4-status-pending,
body.e-dark-mode .p4-status-pending {
    background: rgba(148, 163, 184, 0.20);
    color: #CBD5E1;
    border-color: rgba(148, 163, 184, 0.40);
}

[data-theme="fluent2-dark"] .p4-status-active,
.theme-dark .p4-status-active,
body.e-dark-mode .p4-status-active {
    background: rgba(82, 150, 212, 0.18);
    color: #5296d4;
    border-color: rgba(82, 150, 212, 0.40);
}

[data-theme="fluent2-dark"] .p4-status-partial,
.theme-dark .p4-status-partial,
body.e-dark-mode .p4-status-partial {
    background: rgba(251, 173, 72, 0.18);
    color: #FBAD48;
    border-color: rgba(251, 173, 72, 0.45);
}

[data-theme="fluent2-dark"] .p4-status-complete,
.theme-dark .p4-status-complete,
body.e-dark-mode .p4-status-complete {
    background: rgba(102, 187, 106, 0.18);
    color: #66BB6A;
    border-color: rgba(102, 187, 106, 0.40);
}

[data-theme="fluent2-dark"] .p4-status-closed,
.theme-dark .p4-status-closed,
body.e-dark-mode .p4-status-closed {
    background: transparent;
    color: #94A3B8;
    border-color: rgba(148, 163, 184, 0.50);
}

[data-theme="fluent2-dark"] .p4-status-voided,
.theme-dark .p4-status-voided,
body.e-dark-mode .p4-status-voided {
    background: rgba(239, 83, 80, 0.18);
    color: #EF5350;
    border-color: rgba(239, 83, 80, 0.40);
}

[data-theme="fluent2-dark"] .p4-status-reversed,
.theme-dark .p4-status-reversed,
body.e-dark-mode .p4-status-reversed {
    background: rgba(251, 173, 72, 0.10);
    color: #FBAD48;
    border-color: rgba(251, 173, 72, 0.45);
}

/* ============================================
   COLLAPSIBLE SECTION SHELLS
   ============================================ */

.e-card.p4-collapsible-card .e-card-header {
    border-bottom: 1px solid var(--p4-outline-variant, #E2E8F0) !important;
    padding: 12px 16px !important;
}

.e-card.p4-collapsible-card .e-card-header > div {
    width: 100%;
}

.e-card.p4-collapsible-card .e-card-content {
    padding: 16px !important;
}

.p4-collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    cursor: pointer;
    user-select: none;
}

.p4-collapsible-header .p4-card-title {
    margin: 0;
    font-size: 15px;
    font-weight: 400;
    color: var(--p4-on-surface, #1E293B);
}

.p4-collapse-icon {
    font-size: 16px;
    color: var(--p4-outline, #94A3B8);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.p4-collapsible-header:hover .p4-collapse-icon {
    color: var(--p4-on-surface, #1E293B);
}

.p4-card.p4-card-shell {
    padding: 0;
    overflow: hidden;
}

.p4-section-icon {
    font-size: 18px;
    margin-right: 6px;
    color: var(--ds-primary, #0078d4);
    vertical-align: text-bottom;
}

.p4-section-body {
    padding: 16px 20px;
}

.p4-collapsible-section {
    width: 100%;
}

.p4-collapsible-section__header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    min-height: 44px;
    border-bottom: 1px solid var(--ds-border, #e2e8f0);
}

.p4-collapsible-section--divided > .p4-collapsible-section__header {
    border-top: 1px solid var(--ds-border, #e2e8f0);
}

.p4-collapsible-section__toggle {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
}

.p4-collapsible-section__toggle--static {
    cursor: default;
}

.p4-collapsible-section__toggle:focus-visible,
.p4-collapsible-section__chevron:focus-visible {
    outline: 2px solid var(--p4-primary, #1976D2);
    outline-offset: 2px;
}

.p4-collapsible-section__title {
    display: flex;
    align-items: center;
    min-width: 0;
}

.p4-collapsible-section__title .p4-card-title {
    margin: 0;
    font-size: 15px;
    font-weight: 400;
    color: var(--p4-on-surface, #1E293B);
}

.p4-collapsible-section__actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.p4-collapsible-section__chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    margin: 0;
    background: none;
    border: none;
    border-radius: var(--p4-shape-small, 4px);
    cursor: pointer;
    flex-shrink: 0;
    font: inherit;
}

.p4-card-section-divider {
    border: 0;
    border-top: 1px solid var(--p4-outline-variant, #E2E8F0);
    margin: 16px -20px;
}

[data-theme*="dark"] .p4-card-section-divider {
    border-top-color: var(--ds-outline-variant, #444);
}

/* ============================================
   DOCUMENT TRAIL
   ============================================ */

.p4-doc-trail-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px 12px;
    border-radius: 8px;
    background: var(--p4-surface, #FFFFFF);
    border: 1px solid var(--p4-outline-variant, #E2E8F0);
    margin-top: 6px;
    margin-bottom: 16px;
    font-size: 13px;
    color: var(--p4-on-surface-variant, #64748B);
}

.p4-doc-trail-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 5px;
    row-gap: 6px;
}

.p4-doc-trail-group-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--p4-outline, #94A3B8);
    margin-right: 2px;
}

.p4-doc-trail-step {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    border-radius: 6px;
    background: var(--p4-surface-container, #F1F5F9);
    white-space: nowrap;
    transition: background 0.15s ease;
}

.p4-doc-trail-step:hover:not(.current) {
    background: var(--p4-surface-container-high, #E2E8F0);
}

.p4-doc-trail-step.current {
    background: var(--p4-primary, #2563EB);
    color: var(--p4-on-primary, #FFFFFF);
}

.p4-doc-trail-label {
    font-weight: 500;
    font-size: 12px;
    opacity: 0.75;
}

.p4-doc-trail-code {
    font-weight: 600;
    font-size: 13px;
}

a.p4-doc-trail-code {
    color: var(--p4-primary, #2563EB);
    text-decoration: none;
}

a.p4-doc-trail-code:hover {
    text-decoration: underline;
}

.p4-doc-trail-step.current .p4-doc-trail-code {
    color: inherit;
}

.p4-doc-trail-sep {
    color: var(--p4-outline, #94A3B8);
    font-size: 12px;
    flex-shrink: 0;
}

.p4-doc-trail-dot {
    color: var(--p4-outline, #94A3B8);
    margin: 0 1px;
}

.theme-dark .p4-doc-trail-card,
body.e-dark-mode .p4-doc-trail-card {
    background: var(--p4-surface, #0F172A);
    border-color: var(--p4-outline-variant, #334155);
}

.theme-dark .p4-doc-trail-step,
body.e-dark-mode .p4-doc-trail-step {
    background: var(--p4-surface-container, #1E293B);
}

.theme-dark .p4-doc-trail-step.current,
body.e-dark-mode .p4-doc-trail-step.current {
    background: var(--p4-primary, #3B82F6);
}

/* ============================================
   DETAIL TABS
   ============================================ */

.p4-detail-tabs-sf {
    margin-top: 16px;
    margin-bottom: 4px;
}

.p4-detail-tabs-sf .e-tab-header {
    border-bottom: 1px solid var(--ds-border);
}

.p4-detail-tabs-sf .e-tab-header .e-toolbar-item .e-tab-text {
    font-size: 14px;
    font-weight: 500;
}

.p4-detail-tabs-sf .e-tab-header .e-toolbar-item.e-active .e-tab-text {
    color: var(--ds-primary);
    font-weight: 600;
}

.p4-detail-tabs-sf .e-tab-header .e-indicator {
    background: var(--ds-primary);
}

/* ============================================
   LINE DETAIL PANELS
   ============================================ */

.p4-line-detail-container {
    padding: 16px 20px;
    background: var(--ds-surface-container);
    border-top: 1px solid var(--ds-border-default);
}

/* Section-based panels (PO/Quote/Invoice/Delivery/Transfer/Shipment line details):
   lay the sections out as a responsive grid of boxed groups. Flex-list panels
   (Expense taxes, Employee concept breakdown) have no .p4-line-detail-section,
   so the :has() guard leaves them untouched. */
.p4-line-detail-container:has(.p4-line-detail-section) {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 12px;
    align-items: start;
}

/* Wide tables (4+ columns, e.g. Tax Breakdown, Profit) get a 2-track span so
   their columns don't cramp. Clamps to a single track on narrow viewports. */
.p4-line-detail-container:has(.p4-line-detail-section) .p4-line-detail-section:has(table thead th:nth-child(4)) {
    grid-column: span 2;
}

@media (max-width: 760px) {
    .p4-line-detail-container:has(.p4-line-detail-section) .p4-line-detail-section:has(table thead th:nth-child(4)) {
        grid-column: span 1;
    }
}

.p4-line-detail-section {
    margin-bottom: 16px;
}

.p4-line-detail-section:last-child {
    margin-bottom: 0;
}

/* Groups that contain a table become boxed cards. */
.p4-line-detail-section:has(table) {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px 16px;
    background: var(--ds-surface);
    border: 1px solid var(--ds-border-default);
    border-radius: 8px;
}

/* Tableless groups (e.g. Description) span the full width, no box. */
.p4-line-detail-container:has(.p4-line-detail-section) .p4-line-detail-section:not(:has(table)) {
    grid-column: 1 / -1;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.p4-line-detail-heading {
    margin: 0;
    font-size: 11px;
    font-weight: 600;
    color: var(--ds-on-surface-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.p4-line-detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.p4-line-detail-table thead th {
    text-align: left;
    padding: 0 8px 8px;
    font-weight: 600;
    color: var(--ds-on-surface-muted);
    border-bottom: 1px solid var(--ds-border-default);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
}

.p4-line-detail-table tbody td {
    padding: 8px;
    border-bottom: 1px solid var(--ds-border-subtle);
    color: var(--ds-on-surface);
    font-variant-numeric: tabular-nums;
}

/* First column is the label/code (left); every following column is numeric (right). */
.p4-line-detail-table thead th:not(:first-child),
.p4-line-detail-table tbody td:not(:first-child) {
    text-align: right;
}

.p4-line-detail-table tbody tr:last-child td {
    border-bottom: none;
}

.p4-line-detail-table tbody tr:hover {
    background: var(--ds-surface-variant);
}

/* ============================================
   PO LIST GRID INTERACTION TUNING
   ============================================ */

.po-grid-shell .e-grid .e-headercell {
    position: relative;
}

.po-grid-shell .e-grid .e-headercell .e-rhandler {
    width: 16px !important;
    min-width: 16px !important;
    height: 100% !important;
    right: -8px !important;
    z-index: 5;
}

.po-grid-shell .e-grid .e-headercell .e-filtermenudiv,
.po-grid-shell .e-grid .e-headercell .e-sortfilterdiv,
.po-grid-shell .e-grid .e-headercell .e-filterbaroperator {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.po-grid-shell .e-grid .e-headercell .e-headercelldiv {
    padding-right: 8px;
}

.po-grid-shell .e-grid .e-headercell .e-filtermenudiv:hover,
.po-grid-shell .e-grid .e-headercell .e-sortfilterdiv:hover {
    background: var(--ds-surface-variant, #f1f5f9);
}

/* ============================================
   SUMMARY ROW
   ============================================ */

.p4-summary-row {
    display: flex;
    gap: 24px;
    padding: 16px 20px;
    background: var(--p4-surface, #FFFFFF);
    border-radius: var(--p4-shape-large, 8px);
    box-shadow: var(--p4-elevation-1, 0 1px 2px rgba(0,0,0,0.12));
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.p4-summary-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--p4-outline, #94A3B8);
    margin-bottom: 4px;
}

.p4-summary-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--p4-on-surface, #1E293B);
}

.p4-summary-item {
    flex: 0 1 auto;
    min-width: auto;
}

.theme-dark .p4-summary-row,
body.e-dark-mode .p4-summary-row {
    background: var(--p4-surface, #0F172A);
}

/* ============================================
   DETAIL FORM SHELL
   ============================================ */

.ds-detail-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    text-align: left;
}

.ds-detail-form-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    text-align: left;
    min-height: 32px;
}

.ds-detail-form-group > .ds-detail-label {
    flex: 0 0 120px;
    width: 120px;
    max-width: 120px;
    text-align: right;
}

.p4-form-field > .ds-detail-label {
    flex: 0 0 var(--p4-form-label-width, 120px);
    width: var(--p4-form-label-width, 120px);
    min-width: var(--p4-form-label-width, 120px);
    max-width: var(--p4-form-label-width, 120px);
}

.ds-detail-form-group > *:not(.ds-detail-label) {
    flex: 1;
    min-width: 0;
}

.p4-form-field__content {
    flex: 1;
    min-width: 0;
}

.p4-form-field__hint {
    margin-top: 4px;
    font-size: 12px;
    color: var(--p4-text-muted, #718096);
}

.p4-form-field.p4-form-field--stacked {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
}

.p4-form-field.p4-form-field--stacked > .ds-detail-label {
    flex: none;
    width: auto;
    min-width: 0;
    max-width: none;
    text-align: left;
}

/* ── Dialog form wrapper ──
   Shared class for all create/edit dialog form content.
   Self-contained — no dependency on parent dialog class. */
.ds-dialog-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
    width: 100%;
}

/* ── Bank adjustment / transfer dialog form ──
   Shared styles for Deposit / Withdraw / Transfer dialogs. */
.bank-dialog-body {
    padding: 12px 8px 8px 8px;
}

.bank-dialog-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.bank-dialog-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bank-dialog-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--ds-text, #1f2933);
    margin-bottom: 2px;
}

.bank-dialog-numeric input {
    text-align: left;
}

.bank-dialog-multiline textarea {
    min-height: 80px;
    resize: vertical;
}

.bank-dialog-hint {
    font-style: italic;
}

/* ── Electronic submission dialog ──
   Shared dialog used by Invoice, Credit Note and Discount detail pages
   to submit a document to the government electronic-invoice service. */
.electronic-submission-dialog .es-dialog-body {
    display: flex;
    flex-direction: column;
    gap: var(--ds-space-3, 12px);
}

.electronic-submission-dialog .es-dialog-summary {
    display: grid;
    grid-template-columns: 120px 1fr;
    row-gap: var(--ds-space-2, 8px);
    column-gap: var(--ds-space-3, 12px);
    padding: var(--ds-space-3, 12px);
    background: var(--ds-surface-muted, #f6f7fb);
    border-radius: var(--ds-radius-md, 6px);
}

.electronic-submission-dialog .es-dialog-row {
    display: grid;
    grid-template-columns: 120px 1fr;
    align-items: center;
    gap: var(--ds-space-3, 12px);
}

.electronic-submission-dialog .es-dialog-summary .es-dialog-row {
    display: contents;
}

.electronic-submission-dialog .es-dialog-label {
    font-weight: 600;
    color: var(--ds-text-muted, #6b7280);
}

.electronic-submission-dialog .es-dialog-alert {
    padding: var(--ds-space-3, 12px);
    border-radius: var(--ds-radius-md, 6px);
}

.electronic-submission-dialog .es-dialog-override {
    margin-top: var(--ds-space-2, 8px);
}

.electronic-submission-dialog .es-dialog-details {
    margin-top: var(--ds-space-2, 8px);
    border: 1px solid var(--ds-border-subtle, #e5e7eb);
    border-radius: var(--ds-radius-md, 6px);
    padding: var(--ds-space-3, 12px);
}

.electronic-submission-dialog .es-dialog-details > summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--ds-text, #111827);
}

.electronic-submission-dialog .es-dialog-json {
    margin-top: var(--ds-space-3, 12px);
    font-family: var(--ds-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
    font-size: 12px;
    min-height: 240px;
}

.electronic-submission-dialog .es-dialog-json textarea {
    min-height: 240px;
    font-family: inherit;
}

.electronic-submission-dialog .es-dialog-loading {
    display: flex;
    align-items: center;
    gap: var(--ds-space-2, 8px);
    margin-top: var(--ds-space-3, 12px);
    color: var(--ds-text-muted, #6b7280);
}

/* ── Dialog loading overlay ──
   Covers the dialog form while lookups load. */
.ds-dialog-overlay {
    position: absolute;
    inset: 0;
    background: var(--ds-surface, #fff);
    opacity: 0.7;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

/* ── Page-level busy overlay ──
   Apply .p4-overlay-host to a positioned container (card, panel),
   then render .p4-busy-overlay inside while a long operation runs.
   Blocks pointer events so the UI underneath can't be clicked. */
.p4-overlay-host {
    position: relative;
}

.p4-busy-overlay {
    position: absolute;
    inset: 0;
    background: var(--ds-surface);
    opacity: 0.6;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: all;
    border-radius: inherit;
}

.p4-cell-text {
    line-height: 1.4;
}

.dn-add-note-dialog .dn-add-note-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

.dn-add-note-dialog .dn-field {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
}

.dn-add-note-dialog .dn-field-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--ds-on-surface-muted, var(--p4-outline, #94A3B8));
    text-align: left;
}

.dn-add-note-dialog .dn-field .e-control-wrapper,
.dn-add-note-dialog .dn-field .e-input-group,
.dn-add-note-dialog .dn-field textarea,
.dn-add-note-dialog .dn-field input {
    width: 100%;
}

.dn-add-note-dialog .dn-note-attachment-row {
    min-width: 0;
}

.dn-add-note-dialog .dn-note-attachment-icon {
    font-size: 14px;
}

.dn-add-note-dialog .dn-note-attachment-name {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dn-add-note-dialog .dn-note-upload-trigger {
    margin: 0;
    width: fit-content;
    cursor: pointer;
}

.dn-add-note-dialog .dn-note-upload-icon {
    font-size: 14px;
    margin-right: 4px;
    vertical-align: middle;
}

.dn-add-note-dialog .dn-hidden-file-input {
    display: none;
}

.po-doc-trail-wrap .p4-doc-trail-card {
    margin-top: 6px;
    margin-bottom: 16px;
}

.ds-detail-form-group > .p4-badge,
.ds-detail-form-group > .e-switch-wrapper,
.ds-detail-form-group > .e-checkbox-wrapper {
    flex: none;
}

.ds-detail-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--p4-outline, #94A3B8);
    text-align: left;
    white-space: normal;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
    min-width: 120px;
    word-wrap: break-word;
}

.ds-detail-form-full {
    grid-column: 1 / -1;
}

.ds-detail-form-group .e-input-group,
.ds-detail-form-group .e-control-wrapper {
    min-height: 32px;
}

.ds-detail-form-group .e-input-group input.e-input,
.ds-detail-form-group .e-control-wrapper input.e-input {
    height: 30px;
    padding: 6px 10px;
}

.ds-detail-form-group:has(.e-multi-line-input) {
    align-items: flex-start;
    padding-top: 4px;
}

.ds-detail-form-group .e-multi-line-input,
.ds-detail-form-group .e-multiline {
    min-height: 60px;
}

.ds-detail-form--stacked .ds-detail-form-group {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
}

.ds-detail-form--stacked .ds-detail-form-group > .ds-detail-label {
    flex: none;
    text-align: left;
}

.p4-detail-sidebar .ds-detail-form {
    grid-template-columns: 1fr;
    gap: 12px;
}

.p4-detail-sidebar .ds-detail-form-group > .ds-detail-label {
    flex: 0 0 110px;
    text-align: right;
}

.theme-dark .ds-detail-label,
body.e-dark-mode .ds-detail-label {
    color: var(--p4-outline, #475569);
}

/* ============================================
   RESPONSIVE SHARED SHELLS
   ============================================ */

@media (max-width: 1024px) {
    .p4-summary-row {
        flex-wrap: wrap;
        gap: 12px;
    }

    .p4-summary-item {
        flex: 1 1 calc(33.333% - 12px);
        min-width: 140px;
    }
}

@media (max-width: 768px) {
    .ds-detail-form {
        grid-template-columns: 1fr;
    }

    .ds-detail-form-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .ds-detail-form-group > .ds-detail-label {
        flex: none;
        text-align: left;
    }

    .p4-page-header {
        padding: 16px 20px;
        flex-wrap: wrap;
        gap: 12px;
    }

    .p4-page-header > .p4-flex:last-child {
        width: 100%;
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .p4-summary-item {
        flex: 1 1 calc(50% - 8px);
    }
}

@media (max-width: 640px) {
    .p4-page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .p4-page-header > .p4-flex:first-child {
        width: 100%;
    }

    .p4-page-header > .p4-flex:last-child {
        width: 100%;
        gap: 8px;
    }

    .p4-page-title {
        font-size: 1.125rem;
    }

    .p4-page-header .e-btn {
        flex: 1 1 auto;
        min-width: 0;
    }

    .p4-summary-item {
        flex-basis: 100%;
    }
}

@media (max-width: 480px) {
    .p4-page-title {
        font-size: 1rem;
    }

    .p4-badge {
        font-size: 10px;
        padding: 2px 6px;
    }

    .p4-page-header .p4-flex {
        flex-wrap: wrap;
        gap: 8px;
    }

    .p4-page-header .e-btn {
        flex: 1 1 auto;
        justify-content: center;
    }
}

/* ============================================
   MIGRATED FROM p4-design-system.css (2026-04-02)
   CSS layer cleanup: each section now lives in its
   correct ownership layer per CLAUDE.md rules.
   ============================================ */
/* ============================================
   14. CARD
   ============================================ */

.p4-card {
    background: var(--p4-surface);
    border: 1px solid var(--p4-outline-variant);
    border-radius: var(--p4-shape-large);
    box-shadow: var(--p4-elevation-1);
    overflow: clip;
    padding: 20px;
}

.p4-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--p4-outline-variant);
}

.p4-card-body {
    padding: 16px;
}

.p4-card-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--p4-outline-variant);
}

/* Shared badge styles moved to p4-components.css */

/* ============================================
   15b. AVATARS
   ============================================ */

.p4-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: var(--p4-label-medium);
    font-weight: 600;
    line-height: 1;
}

.p4-avatar-xs { width: 24px; height: 24px; min-width: 24px; font-size: 10px; }
.p4-avatar-sm { width: 28px; height: 28px; min-width: 28px; font-size: 11px; }
.p4-avatar-md { width: 40px; height: 40px; min-width: 40px; font-size: 14px; }
.p4-avatar-lg { width: 64px; height: 64px; min-width: 64px; font-size: 22px; }

.p4-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.p4-avatar-fallback {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--p4-primary) 12%, transparent);
    color: var(--p4-primary);
}

.p4-avatar-primary {
    background: var(--p4-primary);
    color: #fff;
}

/* ============================================
   16. KPI CARDS
   ============================================ */

.p4-kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

@media (max-width: 1200px) {
    .p4-kpi-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .p4-kpi-row {
        grid-template-columns: 1fr;
    }
}

.p4-kpi-card {
    background: var(--p4-surface);
    border: 1px solid var(--p4-outline-variant);
    border-radius: var(--p4-shape-large);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--p4-elevation-1);
}

.p4-kpi-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.p4-kpi-label {
    font-size: var(--p4-label-medium);
    font-weight: 500;
    color: var(--p4-text-caption, #A0AEC0);
    text-transform: uppercase;
}

.p4-kpi-value {
    font-size: var(--p4-headline-large);
    font-weight: 600;
    color: var(--p4-on-surface);
}

.p4-kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.p4-kpi-icon .e-icons {
    font-size: 24px;
}

.p4-kpi-primary {
    background: var(--p4-primary-container);
    color: var(--p4-on-primary-container);
}

.p4-kpi-success {
    background: var(--p4-success-container);
    color: var(--p4-on-success-container);
}

.p4-kpi-warning {
    background: var(--p4-warning-container);
    color: var(--p4-on-warning-container);
}

.p4-kpi-danger {
    background: var(--p4-error-container);
    color: var(--p4-on-error-container);
}

.p4-kpi-info {
    background: var(--p4-primary-container);
    color: var(--p4-on-primary-container);
}

/* ============================================
   16.5. STATS GRID SYSTEM
   Used for summary statistics at bottom of list pages
   ============================================ */

.p4-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-top: 16px;
}

@media (max-width: 1200px) {
    .p4-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .p4-stats-grid {
        grid-template-columns: 1fr;
    }
}

.p4-stat-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--ds-surface, #FFFFFF);
    border-radius: var(--p4-shape-large);
    box-shadow: var(--p4-elevation-1);
    border: 1px solid var(--ds-border-default, #E2E8F0);
}

.p4-stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--p4-shape-medium);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.p4-stat-icon span,
.p4-stat-icon .e-icons {
    font-size: 24px;
    color: white;
}

.p4-stat-icon-primary { background: var(--p4-primary-blue); }
.p4-stat-icon-success { background: var(--p4-success-green); }
.p4-stat-icon-warning { background: var(--p4-warning-orange); }
.p4-stat-icon-danger { background: var(--p4-error-red); }
.p4-stat-icon-info { background: var(--p4-primary, #1976D2); }
.p4-stat-icon-purple { background: var(--p4-purple); }

.p4-stat-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.p4-stat-value {
    font-size: var(--p4-headline-small);
    font-weight: 600;
    color: var(--p4-on-surface);
    line-height: 1.2;
}

.p4-stat-label {
    font-size: var(--p4-body-small);
    color: var(--p4-outline);
    font-weight: 500;
}

/* ============================================
   16.6. EMPTY STATE
   Used when grids have no data
   ============================================ */

.p4-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}

.p4-empty-state > .e-icons {
    font-size: 64px;
    color: var(--p4-text-caption);
    margin-bottom: 16px;
}

.p4-empty-state h6 {
    font-size: 18px;
    font-weight: 600;
    color: var(--p4-text-secondary);
    margin-bottom: 8px;
}

.p4-empty-state p,
.p4-empty-state-text {
    font-size: 14px;
    color: var(--p4-text-muted);
    max-width: 320px;
    margin-bottom: 24px;
}

/* Class-based empty state selectors (preferred over element selectors) */
.p4-empty-state-icon {
    font-size: 64px;
    color: var(--p4-text-caption);
    margin-bottom: 16px;
}

.p4-empty-state-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--p4-text-secondary);
    margin-bottom: 8px;
}

/* ============================================
   17. ICON BUTTONS
   ============================================ */

.p4-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    transition: all 0.15s ease;
}

.p4-icon-btn .e-icons {
    font-size: 20px;
}

.p4-icon-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.p4-icon-btn-primary {
    color: var(--p4-primary);
}

.p4-icon-btn-primary:hover {
    background: var(--p4-primary-container);
}

.p4-icon-btn-success {
    color: var(--p4-success);
}

.p4-icon-btn-success:hover {
    background: var(--p4-success-container);
}

.p4-icon-btn-warning {
    color: var(--p4-warning);
}

.p4-icon-btn-warning:hover {
    background: var(--p4-warning-container);
}

.p4-icon-btn-danger {
    color: var(--p4-error);
}

.p4-icon-btn-danger:hover {
    background: var(--p4-error-container);
}

/* ============================================
   19. LOADING & EMPTY STATES
   ============================================ */

/* Loading - Inline (for empty states) */
.p4-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 64px 16px;
    gap: 16px;
}

/* Loading - Card Overlay (blocks card content only) */
.p4-loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    gap: 16px;
    border-radius: inherit;
}

/* Loading - Content Area Overlay (blocks content area only) */
.p4-loading-content {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    gap: 16px;
    border-radius: inherit;
    backdrop-filter: blur(2px);
}

/* Dark mode loading overlays */
.theme-dark .p4-loading-overlay,
body.e-dark-mode .p4-loading-overlay {
    background: rgba(31, 31, 31, 0.92);
}

.theme-dark .p4-loading-content,
body.e-dark-mode .p4-loading-content {
    background: rgba(31, 31, 31, 0.92);
}

/* Container for centered loading indicator */
.p4-loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    padding: 48px 24px;
    text-align: center;
}

/* Fullpage loading - centered on viewport */
.p4-loading-fullpage {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 200px);
    padding: 48px 24px;
    text-align: center;
}

.p4-layout-loading-overlay {
    min-height: calc(100vh - 160px);
    background: rgba(244, 246, 248, 0.6);
    pointer-events: none;
}

.p4-layout-loading-pill {
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Dark mode layout loading */
.theme-dark .p4-layout-loading-overlay,
body.e-dark-mode .p4-layout-loading-overlay {
    background: rgba(31, 31, 31, 0.6);
}

.theme-dark .p4-layout-loading-pill,
body.e-dark-mode .p4-layout-loading-pill {
    background: rgba(45, 45, 45, 0.92);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.p4-layout-loading-spinner {
    width: 20px;
    height: 20px;
}

/* Spinner - Modern circular */
.p4-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--p4-border-gray, #E2E8F0);
    border-top-color: var(--p4-primary-blue, #1976D2);
    border-radius: 50%;
    animation: p4-spin 0.8s linear infinite;
}

.p4-spinner-sm {
    width: 24px;
    height: 24px;
    border-width: 3px;
}

.p4-spinner-lg {
    width: 64px;
    height: 64px;
    border-width: 5px;
}

/* Loading text */
.p4-loading-text {
    font-size: 14px;
    color: var(--p4-text-secondary, #4A5568);
    font-weight: 500;
}

/* Legacy spin class */
.p4-spin {
    animation: p4-spin 1s linear infinite;
}

@keyframes p4-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Skeleton loading animations */
.p4-skeleton {
    background: linear-gradient(90deg, #E2E8F0 25%, #EDF2F7 50%, #E2E8F0 75%);
    background-size: 200% 100%;
    animation: p4-skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 4px;
}

@keyframes p4-skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.p4-skeleton-value {
    height: 32px;
    width: 80px;
    margin: 4px 0;
}

.p4-skeleton-text {
    height: 16px;
    width: 120px;
}

.p4-skeleton-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--p4-light-gray, #F7FAFC);
    border-radius: 4px;
}

.p4-skeleton-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
}

.p4-skeleton-line {
    height: 14px;
    width: 100%;
    max-width: 150px;
    margin-bottom: 6px;
}

.p4-skeleton-line-sm {
    height: 12px;
    width: 80%;
    max-width: 100px;
}

/* Placeholder row shown below a line grid while a new line is being added */
.p4-lines-placeholder-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    border-top: 1px solid var(--ds-border, #e2e8f0);
    border-bottom: 1px solid var(--ds-border, #e2e8f0);
    background: var(--ds-surface-variant, #f8fafc);
}

.p4-lines-placeholder-row .p4-skeleton {
    height: 14px;
    border-radius: 4px;
}

/* Account / entity picker dialog hover row */
.p4-picker-row:hover {
    background: var(--ds-surface-variant, #f1f5f9);
}
.p4-picker-row:last-child {
    border-bottom: none !important;
}
.p4-picker-table thead th {
    position: sticky;
    top: 0;
    background: var(--ds-surface, #fff);
    z-index: 1;
}

/* Lines footer totals panel — shared across all document detail pages */
.p4-lines-totals-panel {
    min-width: 280px;
    width: 320px;
    max-width: 100%;
    padding: 16px 20px;
    background: var(--ds-surface, #fff);
    border: 1px solid var(--ds-border, #e2e8f0);
    border-radius: 8px;
    box-shadow: var(--p4-elevation-1, 0 1px 2px rgba(0,0,0,0.12));
}

.p4-lines-totals-grand {
    border-top: 1px solid var(--ds-border, #e2e8f0);
    padding-top: 8px;
    margin-top: 4px;
}

.p4-lines-totals-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--ds-text-muted, #64748b);
}

.p4-lines-totals-value {
    font-size: 18px;
}

/* ============================================
   21. CODE DISPLAY
   ============================================ */

.p4-code {
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    background: var(--p4-surface-variant);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--p4-on-surface-variant);
}

.p4-code-link {
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    background: var(--p4-surface-variant);
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--p4-primary);
    text-decoration: underline;
    cursor: pointer;
}

.p4-code-link:hover {
    background: rgba(49, 130, 206, 0.1);
}

/* ============================================
   22. STATUS COUNTS
   ============================================ */

.p4-error-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    border-radius: 12px;
    background: var(--p4-error-container);
    color: var(--p4-on-error-container);
    font-weight: 600;
    font-size: 12px;
}

.p4-success-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    border-radius: 12px;
    background: var(--p4-success-container);
    color: var(--p4-on-success-container);
    font-weight: 600;
    font-size: 12px;
}

/* ============================================
   25. ICON COLORS
   ============================================ */

.p4-icon-success {
    color: var(--p4-success);
    font-size: 18px;
}

.p4-icon-danger {
    color: var(--p4-error);
    font-size: 18px;
}

.p4-icon-warning {
    color: var(--p4-warning);
    font-size: 18px;
}

.p4-icon-muted {
    color: var(--p4-outline-variant);
    font-size: 18px;
}

.p4-icon-primary {
    color: var(--p4-primary);
    font-size: 18px;
}

/* ============================================
   26. LINK STYLES
   ============================================ */

.p4-link {
    color: var(--p4-primary);
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
}

.p4-link:hover {
    text-decoration: underline;
}

.p4-link-icon {
    color: var(--p4-primary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.p4-link-icon:hover {
    color: var(--p4-primary-hover, #2B6CB0);
}

/* ============================================
   27. GRID CELL STYLES
   ============================================ */

.p4-alias-cell {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.p4-alias-cell .e-icons {
    font-size: 18px;
    line-height: 1;
    vertical-align: middle;
}

.p4-grid-container {
    flex: 1;
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.p4-grid-container .p4-card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ============================================
   28. P4 BUTTON SYSTEM
   ============================================

   P4 Design System Button Styles
   Use these classes on buttons for consistent styling.

   Base: .p4-btn
   Variants: .p4-btn-primary, .p4-btn-secondary, .p4-btn-danger, .p4-btn-outline, .p4-btn-warning
   Sizes: .p4-btn-sm, .p4-btn-lg
*/

/* Base button - common properties */
.p4-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 16px;
    border-radius: var(--p4-shape-medium); /* Fluent 2: 6px */
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    white-space: nowrap;
}

.p4-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* Primary - Blue background, white text */
.p4-btn-primary {
    color: #FFFFFF;
    background-color: var(--p4-primary-blue, #1976D2);
    border-color: var(--p4-primary-blue, #1976D2);
}
.p4-btn-primary:hover:not(:disabled) {
    background-color: var(--p4-primary-blue-hover, #2B6CB0);
    border-color: var(--p4-primary-blue-hover, #2B6CB0);
}

/* Secondary - Gray background, dark text */
.p4-btn-secondary {
    color: var(--p4-text-secondary, #4A5568);
    background-color: var(--p4-light-gray, #F7FAFC);
    border-color: var(--p4-border-gray, #E2E8F0);
}
.p4-btn-secondary:hover:not(:disabled) {
    background-color: #EDF2F7;
    border-color: #CBD5E0;
}

/* Danger - Red background, white text */
.p4-btn-danger {
    color: #FFFFFF;
    background-color: var(--p4-error-red, #E53E3E);
    border-color: var(--p4-error-red, #E53E3E);
}
.p4-btn-danger:hover:not(:disabled) {
    background-color: var(--p4-error-red-hover, #C53030);
    border-color: var(--p4-error-red-hover, #C53030);
}

/* Warning - Orange background, white text */
.p4-btn-warning {
    color: #FFFFFF;
    background-color: var(--p4-warning-orange, #DD6B20);
    border-color: var(--p4-warning-orange, #DD6B20);
}
.p4-btn-warning:hover:not(:disabled) {
    background-color: var(--p4-warning-orange-hover, #C05621);
    border-color: var(--p4-warning-orange-hover, #C05621);
}

/* Success - Green background, white text */
.p4-btn-success {
    color: #FFFFFF;
    background-color: var(--p4-success-green, #38A169);
    border-color: var(--p4-success-green, #38A169);
}
.p4-btn-success:hover:not(:disabled) {
    background-color: var(--p4-success-green-hover, #2F855A);
    border-color: var(--p4-success-green-hover, #2F855A);
}

/* Outline - Transparent background, bordered */
.p4-btn-outline {
    color: var(--p4-text-secondary, #4A5568);
    background-color: var(--p4-surface, #FFFFFF);
    border-color: var(--p4-border-gray, #E2E8F0);
}
.p4-btn-outline:hover:not(:disabled) {
    background-color: var(--p4-light-gray, #F7FAFC);
    color: var(--p4-text-primary, #2D3748);
}

/* Ghost - No background, no border */
.p4-btn-ghost {
    color: var(--p4-text-secondary, #4A5568);
    background-color: transparent;
    border-color: transparent;
}
.p4-btn-ghost:hover:not(:disabled) {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Button Sizes */
.p4-btn-sm {
    font-size: 13px;
    padding: 6px 12px;
}

.p4-btn-lg {
    font-size: 16px;
    padding: 12px 20px;
}

/* ============================================
   30. ALERTS & NOTIFICATIONS
   ============================================ */

.p4-alert {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-radius: var(--p4-shape-extra-small);
    font-size: 14px;
    gap: 8px;
}

.p4-alert-info {
    background: rgba(49, 130, 206, 0.1);
    color: var(--p4-primary-blue, #1976D2);
    border: 1px solid rgba(49, 130, 206, 0.2);
}

.p4-alert-success {
    background: rgba(56, 161, 105, 0.1);
    color: var(--p4-success-green, #38A169);
    border: 1px solid rgba(56, 161, 105, 0.2);
}

.p4-alert-warning {
    background: rgba(221, 107, 32, 0.1);
    color: var(--p4-warning-orange, #DD6B20);
    border: 1px solid rgba(221, 107, 32, 0.2);
}

.p4-alert-danger {
    background: rgba(229, 62, 62, 0.1);
    color: var(--p4-error-red, #E53E3E);
    border: 1px solid rgba(229, 62, 62, 0.2);
}

/* ============================================
   31. TOGGLE ROW (Switch + Label)
   ============================================ */

.p4-toggle-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ============================================
   45. IMPORT PROGRESS DIALOG
   ============================================ */

.p4-import-progress {
    min-height: 150px;
}

.p4-progress-log {
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    background: var(--p4-light-gray, #F7FAFC);
    border: 1px solid var(--p4-border-gray, #E2E8F0);
    border-radius: 4px;
    padding: 16px;
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 200px;
    overflow-y: auto;
    color: var(--p4-text-secondary, #4A5568);
}

.p4-error-list {
    background: rgba(229, 62, 62, 0.05);
    border: 1px solid rgba(229, 62, 62, 0.2);
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
}

.p4-error-item {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--p4-error-red, #E53E3E);
    border-bottom: 1px solid rgba(229, 62, 62, 0.1);
}

.p4-error-item:last-child {
    border-bottom: none;
}

/* ============================================
   46. ACTION BAR (Detail Page Actions)
   ============================================ */

/* Sticky action bar at the bottom of detail pages */
.p4-action-bar {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    background: var(--p4-surface);
    border-top: 1px solid var(--p4-outline-variant);
    box-shadow: var(--p4-elevation-2);
    margin-left: -24px;
    margin-right: -24px;
    margin-bottom: -24px;
    z-index: 100;
}

/* When inside a card, adjust margins */
.p4-card .p4-action-bar {
    margin-left: -16px;
    margin-right: -16px;
    margin-bottom: -16px;
    padding: 16px;
}

/* Action bar inside form */
form > .p4-action-bar,
.p4-form > .p4-action-bar {
    margin-top: 24px;
}

/* Action bar button groups */
.p4-action-bar > div {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Responsive: Stack on mobile */
@media (max-width: 576px) {
    .p4-action-bar {
        flex-direction: column-reverse;
        gap: 12px;
        padding: 12px 16px;
    }

    .p4-action-bar > div {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }
}

/* ============================================
   PROGRESS BAR
   ============================================ */

.p4-progress-container {
    position: relative;
}

.p4-progress-container::before {
    content: '';
    display: block;
    height: 6px;
    background: var(--p4-surface-container-high, #E2E8F0);
    border-radius: var(--p4-shape-full, 9999px);
    overflow: hidden;
}

.p4-progress-container .p4-progress-bar {
    height: 6px;
    background: var(--p4-primary, #1976D2);
    border-radius: var(--p4-shape-full, 9999px);
    transition: width 0.3s;
    position: absolute;
    top: 0;
    left: 0;
}

.p4-progress-container .p4-progress-text {
    font-size: 12px;
    font-weight: 600;
    color: var(--p4-outline, #94A3B8);
    margin-top: 4px;
    display: block;
}

/* ============================================
   PROPERTY LIST (read-only data display)
   ============================================ */

.ds-property-list {
    margin: 0;
    padding: 0;
}

.ds-property-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 10px 0;
    border-bottom: 1px solid var(--p4-outline-variant, #E2E8F0);
    gap: 16px;
}

.ds-property-item:last-child {
    border-bottom: none;
}

.ds-property-item dt {
    font-size: 13px;
    font-weight: 500;
    color: var(--p4-outline, #94A3B8);
    flex-shrink: 0;
    min-width: 90px;
}

.ds-property-item dd {
    margin: 0;
    font-size: 14px;
    color: var(--p4-on-surface, #1E293B);
    text-align: right;
}

/* ============================================
   SKELETON LOADING (design system variant)
   ============================================ */

.ds-skeleton {
    background: linear-gradient(
        90deg,
        var(--p4-surface-container-high, #E2E8F0) 25%,
        var(--p4-surface-variant, #F1F5F9) 50%,
        var(--p4-surface-container-high, #E2E8F0) 75%
    );
    background-size: 200% 100%;
    animation: ds-shimmer 1.5s ease-in-out infinite;
    border-radius: 4px;
}

.ds-skeleton-text {
    height: 14px;
    width: 80%;
    margin-bottom: 8px;
}

.ds-skeleton-value {
    height: 28px;
    width: 50%;
}

.ds-skeleton-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--p4-shape-medium, 6px);
}

@keyframes ds-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================
   DARK MODE — Ported component overrides
   ============================================ */

/* Shared dark-mode document trail styles moved to p4-components.css */

.theme-dark .ds-property-item,
body.e-dark-mode .ds-property-item {
    border-bottom-color: var(--p4-outline-variant, #334155);
}

.theme-dark .ds-property-item dt,
body.e-dark-mode .ds-property-item dt {
    color: var(--p4-outline, #475569);
}

.theme-dark .ds-property-item dd,
body.e-dark-mode .ds-property-item dd {
    color: var(--p4-on-surface, #E2E8F0);
}

.theme-dark .p4-progress-container::before,
body.e-dark-mode .p4-progress-container::before {
    background: var(--p4-surface-container-high, #334155);
}

.theme-dark .p4-filter-bar,
body.e-dark-mode .p4-filter-bar {
    background: var(--p4-surface, #0F172A);
}

/* Shared dark-mode shell overrides moved to p4-components.css */

.theme-dark .ds-skeleton,
body.e-dark-mode .ds-skeleton {
    background: linear-gradient(
        90deg,
        var(--p4-surface-container-high, #334155) 25%,
        var(--p4-surface-variant, #1E293B) 50%,
        var(--p4-surface-container-high, #334155) 75%
    );
    background-size: 200% 100%;
}

/* ── Toggle Switch ───────────────────────── */

.p4-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    font-size: 14px;
    color: var(--p4-on-surface, #1E293B);
}

.p4-toggle input[type="checkbox"] {
    display: none;
}

.p4-toggle-track {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--p4-outline, #94A3B8);
    border-radius: 10px;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.p4-toggle-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.p4-toggle input:checked + .p4-toggle-track {
    background: var(--p4-primary, #0A5FAD);
}

.p4-toggle input:checked + .p4-toggle-track::after {
    transform: translateX(16px);
}

/* ============================================
   NUMERIC INPUT — LINE ITEMS
   ============================================ */

/* Hide spin arrows in raw SfNumericTextBox inside inline-edit grid cells.
   P4NumericTextBox sets ShowSpinButton=false natively, so this only covers
   any remaining raw SfNumericTextBox that hasn't been migrated yet. */
.p4-inline-edit .e-numerictextbox .e-spin-up,
.p4-inline-edit .e-numerictextbox .e-spin-down {
    display: none;
}

/* Fix Syncfusion line-height:0 rendering bug in grid cell templates.
   Apply .p4-numeric-line on the SfNumericTextBox CssClass inside grid templates
   instead of using inline style="line-height:1.4". */
.p4-numeric-line input.e-numerictextbox {
    line-height: 1.4;
}

/* ============================================
   CREATE / ACTION DIALOG (ds-create-dialog)
   Standard dialog styling for action dialogs
   (payment, return, discount, create, etc.).
   SfDialog portals to <body> — scoped .razor.css
   cannot reach it, so styles live here.
   ============================================ */

.ds-create-dialog.e-dialog {
    border-radius: var(--ds-shape-xl, 12px) !important;
    font-family: var(--ds-font, 'Plus Jakarta Sans', sans-serif) !important;
}

.ds-create-dialog .e-dlg-header {
    font-family: var(--ds-font, 'Plus Jakarta Sans', sans-serif) !important;
    font-weight: 600 !important;
    font-size: 18px !important;
}

.ds-create-dialog .e-footer-content {
    padding: 12px 24px !important;
}

.ds-create-dialog .e-dlg-content {
    padding: 20px 24px !important;
}

.ds-create-dialog .p4-form {
    display: flex !important;
    flex-direction: column !important;
    gap: 20px !important;
    text-align: left;
}

.ds-create-dialog .p4-form-row {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0 !important;
    text-align: left;
}

.ds-create-dialog .p4-form-label {
    display: block !important;
    font-size: 12.5px !important;
    font-weight: 600 !important;
    color: var(--ds-on-surface-muted, #5f6368) !important;
    margin-bottom: 6px !important;
    text-align: left !important;
}

/* ============================================
   MATERIAL SYMBOL ICON BRIDGE
   Use with Syncfusion IconCss where e-icons
   lacks the needed glyph (e.g. DropDownMenuItem).
   Usage: IconCss="p4-mi p4-mi-credit-card"
   ============================================ */

.p4-mi {
    font-family: 'Material Symbols Outlined' !important;
    font-weight: normal;
    font-style: normal;
    font-size: 18px;
    line-height: 1;
    font-feature-settings: 'liga';
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 20;
    -webkit-font-smoothing: antialiased;
}

.p4-mi.p4-mi-archive::before { content: "\e149"; }
.p4-mi.p4-mi-credit-card::before { content: "\e870"; }
.p4-mi.p4-mi-wallet::before { content: "\e850"; }
.p4-mi.p4-mi-percent::before { content: "\eb58"; }
.p4-mi.p4-mi-star::before { content: "\e838"; }

/* ============================================
   CREDIT SUGGESTION DIALOG
   SfDialog portals to <body> — scoped .razor.css
   cannot reach it, so styles live here.
   ============================================ */

.p4-credit-suggestion-dialog.e-dialog .credit-suggestion-banner {
    background: var(--ds-info-container);
}

.p4-credit-suggestion-dialog.e-dialog .credit-suggestion-icon {
    color: var(--ds-info);
    font-size: 28px;
}

.p4-credit-suggestion-dialog.e-dialog .credit-suggestion-amount {
    font-size: 20px;
    color: var(--ds-info);
}

/* ── Attachments Upload trigger (canonical — mirrors PO OrderDetails) ──
   Shared so every detail-page Attachments section aligns its upload glyph
   the same way. Chained selector `.p4-icon.p4-upload-trigger-icon` beats
   the base `.p4-icon { font-size: 24px }` rule in p4-design-system.css
   without needing !important. */
.p4-upload-trigger {
    margin: 0;
    cursor: pointer;
    width: fit-content;
}

.p4-icon.p4-upload-trigger-icon {
    font-size: 14px;
    margin-right: 4px;
    vertical-align: middle;
}

/* ==========================================================================
   Grid filter chips — canonical list-page inclusion filters
   Promoted from Purchasing/Orders/OrderList.razor.css (audit decision D-1).
   Canonical reference: ui-canonical-po-grids.md §1.6.
   ========================================================================== */

/* Controls strip — lives inside the grid card, above the grid */
.p4-grid-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--ds-border, rgba(15, 23, 42, 0.08));
}

.p4-filters-label {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ds-on-surface-variant, #64748B);
    margin-right: 4px;
}

.theme-dark .p4-filters-label,
body.e-dark-mode .p4-filters-label {
    color: rgba(255, 255, 255, 0.55);
}

/* Chip toggle — inactive = dashed ghost pill; active = filled pill */
.p4-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 12px;
    border-radius: 15px;
    border: 1px dashed var(--ds-border, rgba(15, 23, 42, 0.18));
    background: transparent;
    color: var(--ds-on-surface-variant, #475569);
    font: inherit;
    font-size: var(--text-base);
    font-weight: var(--font-medium);
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.p4-filter-chip:hover {
    background: rgba(15, 23, 42, 0.04);
    border-color: var(--ds-border, rgba(15, 23, 42, 0.28));
    color: var(--ds-on-surface, #0f172a);
}

.p4-filter-chip.is-active {
    background: rgba(15, 23, 42, 0.08);
    border: 1px solid transparent;
    color: var(--p4-on-primary-container, #1E3A5F);
    font-weight: var(--font-semibold);
}

.p4-filter-chip.is-active:hover {
    background: rgba(15, 23, 42, 0.12);
}

.p4-filter-chip-icon {
    font-size: var(--text-sm);
    line-height: 1;
    color: inherit;
}

.p4-filter-chip:focus-visible {
    outline: 2px solid var(--ds-primary);
    outline-offset: 2px;
}

/* Read-only chip (e.g. "N filtered") — non-toggle, has its own close button */
.p4-filter-chip-readonly {
    cursor: default;
    padding-right: 4px;
}

.p4-filter-chip-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.p4-filter-chip-close:hover {
    background: rgba(15, 23, 42, 0.16);
}

.p4-filter-chip-close .e-icons {
    font-size: var(--text-sm);
}

.theme-dark .p4-filter-chip,
body.e-dark-mode .p4-filter-chip {
    border-color: rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.7);
}

.theme-dark .p4-filter-chip:hover,
body.e-dark-mode .p4-filter-chip:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.95);
}

.theme-dark .p4-filter-chip.is-active,
body.e-dark-mode .p4-filter-chip.is-active {
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
}

.theme-dark .p4-filter-chip.is-active:hover,
body.e-dark-mode .p4-filter-chip.is-active:hover {
    background: rgba(255, 255, 255, 0.20);
}

.theme-dark .p4-filter-chip-close:hover,
body.e-dark-mode .p4-filter-chip-close:hover {
    background: rgba(255, 255, 255, 0.22);
}

/* ==========================================================================
   Line-grid product cell — image thumbnail + stacked product code/description
   Promoted from Purchasing/Orders/OrderDetails.razor.css (audit decision D-5).
   Canonical reference: ui-canonical-po-grids.md §2.3-2.4.
   ========================================================================== */

.p4-line-number {
    color: var(--ds-primary);
}

.p4-line-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ds-surface-variant);
    border-radius: 4px;
    overflow: hidden;
}

.p4-line-thumb-md {
    width: 40px;
    height: 40px;
}

.p4-line-thumb-sm {
    width: 32px;
    height: 32px;
}

.p4-line-thumb-image {
    object-fit: contain;
}

.p4-line-thumb-image-md {
    width: 40px;
    height: 40px;
}

.p4-line-thumb-image-sm {
    width: 32px;
    height: 32px;
}

.p4-line-thumb-fallback-md {
    font-size: 20px;
    color: var(--ds-text-muted);
}

.p4-line-thumb-fallback-sm {
    font-size: 16px;
    color: var(--ds-text-muted);
}

.p4-line-product-stack {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.p4-line-product-stack-md {
    min-height: 40px;
}

.p4-line-product-stack-sm {
    min-height: 32px;
}

.p4-line-product-desc {
    margin-top: 2px;
}

/* Grid cell "default" checkbox toggle (e.g. payment methods) */
.p4-default-toggle-icon {
    font-size: 22px;
}

.p4-default-toggle-on {
    color: var(--ds-primary);
}

.p4-default-toggle-off {
    color: var(--ds-on-surface-variant);
}

/* ── File attachment cards (canonical normalized attachments surface) ──
   150x125 thumbnail-card grid. Replaces the outdated DocumentAttachments
   table. See decisions/ui-normalization-attachments-notes.md. */
.p4-file-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, 150px);
    gap: 12px;
}

.p4-file-card {
    width: 150px;
}

.p4-file-card-thumb {
    position: relative;
    width: 150px;
    height: 125px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ds-surface-alt, var(--ds-surface));
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-card, 8px);
    overflow: hidden;
}

.p4-file-card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.p4-icon.p4-file-card-icon {
    font-size: 44px;
    color: var(--ds-text-muted);
}

.p4-icon.p4-file-card-icon.p4-file--pdf { color: var(--ds-danger); }
.p4-icon.p4-file-card-icon.p4-file--doc { color: var(--ds-info); }
.p4-icon.p4-file-card-icon.p4-file--xls { color: var(--ds-success); }
.p4-icon.p4-file-card-icon.p4-file--ppt { color: var(--ds-warning); }

.p4-file-card-actions {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity var(--duration-fast, 0.15s) var(--ease-standard, ease);
}

.p4-file-card-thumb:hover .p4-file-card-actions,
.p4-file-card-thumb:focus-within .p4-file-card-actions {
    opacity: 1;
}

.p4-file-card-actions .e-btn {
    background: var(--ds-surface);
    box-shadow: var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.2));
}

.p4-file-card-name {
    margin-top: 6px;
    font-size: 12px;
    color: var(--ds-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

/* Completely hidden SfUploader - still functional via the header trigger */
.p4-file-attachments .p4-uploader-hidden {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

.p4-file-attachments .e-upload .e-file-drop,
.p4-file-attachments .e-upload .e-upload-files {
    display: none !important;
}

/* ============================================================
   LogisticaHQ sync progress modal + appbar indicator
   (shared component -- see SyncProgressDialog / SyncProgressIndicator)
   ============================================================ */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.sync-spin { animation: spin 1.5s linear infinite; }

.p4-sync-dialog.e-dialog .e-dlg-content { padding: 0; }
.p4-sync-dialog.e-dialog .e-dlg-header-content { display: none; }

.sync-modal {
    display: flex;
    flex-direction: column;
    font-size: 13px;
    color: var(--ds-on-surface);
}

/* header */
.sync-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--ds-outline-variant);
}
.sync-title-row { display: flex; align-items: center; gap: 8px; }
.sync-title-icon { font-size: 18px; color: var(--ds-info); }
.sync-title { margin: 0; font-size: 15px; font-weight: 600; }
.sync-pair {
    margin-top: 5px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--ds-on-surface-muted);
}
.sync-pair code {
    font-size: 11px;
    background: var(--ds-surface-variant);
    padding: 2px 6px;
    border-radius: 4px;
}
.sync-pair-arrow { font-size: 13px; }

/* status badge */
.sync-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
}
.sync-badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.sync-badge-running { background: var(--ds-info-container); color: var(--ds-info); }
.sync-badge-completed { background: var(--ds-success-container); color: var(--ds-success); }
.sync-badge-failed { background: var(--ds-error-container); color: var(--ds-error); }

/* overall progress */
.sync-overall { padding: 16px 20px; border-bottom: 1px solid var(--ds-outline-variant); }
.sync-overall-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}
.sync-overall-label { font-size: 12px; color: var(--ds-on-surface-muted); }
.sync-overall-pct { font-size: 24px; font-weight: 600; line-height: 1; }
.sync-pct-sign { font-size: 14px; color: var(--ds-on-surface-muted); margin-left: 1px; }
.sync-bar {
    height: 6px;
    background: var(--ds-surface-variant);
    border-radius: 999px;
    overflow: hidden;
}
.sync-bar-fill { height: 100%; border-radius: 999px; transition: width .3s ease; }
.sync-fill-running { background: var(--ds-info); }
.sync-fill-completed, .sync-fill-done { background: var(--ds-success); }
.sync-fill-failed { background: var(--ds-error); }
.sync-fill-pending { background: var(--ds-outline-variant); }
.sync-overall-foot {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
    font-size: 11px;
    color: var(--ds-on-surface-muted);
}
.sync-eta { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.sync-eta .p4-icon { font-size: 13px; }

/* per-entity rows */
.sync-entities { display: flex; flex-direction: column; }
.sync-entity {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 20px;
    border-bottom: 1px solid var(--ds-outline-variant);
}
.sync-entity:last-child { border-bottom: none; }
.sync-entity-active { background: var(--ds-surface-variant); }
.sync-entity-state { font-size: 19px; flex-shrink: 0; }
.sync-state-done { color: var(--ds-success); }
.sync-state-running { color: var(--ds-info); animation: spin 1.5s linear infinite; }
.sync-state-failed { color: var(--ds-error); }
.sync-state-pending { color: var(--ds-on-surface-muted); }
.sync-entity-icon { font-size: 17px; color: var(--ds-on-surface-muted); flex-shrink: 0; }
.sync-entity-body { flex: 1; min-width: 0; }
.sync-entity-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}
.sync-entity-name { font-size: 13px; font-weight: 500; }
.sync-entity-meta { font-size: 11px; color: var(--ds-on-surface-muted); white-space: nowrap; }
.sync-meta-running { color: var(--ds-info); font-weight: 600; }
.sync-meta-failed { color: var(--ds-error); font-weight: 600; }
.sync-mini {
    height: 3px;
    background: var(--ds-surface-variant);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 6px;
}
.sync-entity-active .sync-mini { background: var(--ds-surface); }
.sync-mini-fill { height: 100%; border-radius: 999px; transition: width .3s ease; }
.sync-entity-rate { font-size: 11px; color: var(--ds-on-surface-muted); margin-top: 4px; }
.sync-entity-errline { font-size: 11px; color: var(--ds-error); margin-top: 4px; }

/* activity log */
.sync-log-section {
    padding: 14px 20px;
    background: var(--ds-surface-variant);
    border-top: 1px solid var(--ds-outline-variant);
}
.sync-log-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.sync-log-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--ds-on-surface-muted);
}
.sync-log-export.e-flat {
    font-size: 11px;
    padding: 2px 8px;
    min-height: auto;
    height: auto;
}
.sync-log {
    font-family: var(--font-mono, ui-monospace, "Cascadia Mono", Consolas, monospace);
    font-size: 11px;
    line-height: 1.7;
    max-height: 150px;
    overflow-y: auto;
}
.sync-log-empty { color: var(--ds-on-surface-muted); }
.sync-log-line { display: flex; gap: 6px; }
.sync-log-time { color: var(--ds-on-surface-muted); flex-shrink: 0; }
.sync-log-mark { flex-shrink: 0; font-weight: 700; width: 10px; text-align: center; }
.sync-log-text { color: var(--ds-on-surface); word-break: break-word; }
.sync-log-success { color: var(--ds-success); }
.sync-log-info { color: var(--ds-info); }
.sync-log-warning { color: var(--ds-warning); }
.sync-log-error { color: var(--ds-error); }

/* footer */
.sync-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-top: 1px solid var(--ds-outline-variant);
}
.sync-foot-last { font-size: 11px; color: var(--ds-on-surface-muted); }
.sync-foot-actions { display: flex; gap: 8px; }

/* appbar background indicator */
.p4-sync-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    width: auto;
    padding: 0 8px;
}
.p4-sync-indicator-icon { font-size: 18px; color: var(--ds-info); }
.p4-sync-indicator-pct { font-size: 12px; font-weight: 600; color: var(--ds-info); }

/* ===== Blazor circuit-loss UI (reconnect modal + error bar) =====
   blazor.web.js toggles the components-reconnect-* classes on the modal
   client-side, so this UI works even when the circuit is dead. */

#components-reconnect-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100000;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.55);
}

#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-retrying,
#components-reconnect-modal.components-reconnect-paused,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected {
    display: flex;
}

#components-reconnect-modal .reconnect-dialog {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    min-width: 280px;
    max-width: 420px;
    padding: 32px;
    text-align: center;
    background: var(--ds-surface);
    border: 1px solid var(--ds-border-default);
    border-radius: var(--ds-radius-dialog);
    box-shadow: var(--ds-elevation-3);
}

#components-reconnect-modal .reconnect-spinner-svg {
    width: 36px;
    height: 36px;
    animation: p4-spin 0.8s linear infinite;
}

#components-reconnect-modal .reconnect-spinner-svg circle {
    stroke: var(--ds-primary);
    stroke-linecap: round;
    stroke-dasharray: 90, 150;
}

#components-reconnect-modal .reconnect-message {
    margin: 0;
    font-size: 14px;
    color: var(--ds-on-surface);
}

#components-reconnect-modal .reconnect-reload-btn {
    padding: 8px 24px;
    border: none;
    border-radius: var(--ds-radius-button);
    background: var(--ds-primary);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

#components-reconnect-modal .reconnect-reload-btn:hover {
    background: var(--ds-primary-hover);
}

/* State-driven visibility: "reconnecting" while retrying, "lost" + reload on failure */
#components-reconnect-modal .reconnect-when-lost,
#components-reconnect-modal .reconnect-reload-btn {
    display: none;
}

#components-reconnect-modal.components-reconnect-failed .reconnect-when-active,
#components-reconnect-modal.components-reconnect-rejected .reconnect-when-active,
#components-reconnect-modal.components-reconnect-failed .reconnect-spinner,
#components-reconnect-modal.components-reconnect-rejected .reconnect-spinner {
    display: none;
}

#components-reconnect-modal.components-reconnect-failed .reconnect-when-lost,
#components-reconnect-modal.components-reconnect-rejected .reconnect-when-lost,
#components-reconnect-modal.components-reconnect-failed .reconnect-reload-btn,
#components-reconnect-modal.components-reconnect-rejected .reconnect-reload-btn {
    display: block;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 100001;
    padding: 12px 20px;
    background: var(--ds-error-container);
    color: var(--ds-error);
    border-top: 1px solid var(--ds-error);
    box-shadow: var(--ds-elevation-3);
    font-size: 14px;
}

#blazor-error-ui .reload {
    margin-left: 12px;
    color: var(--ds-error);
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
}

#blazor-error-ui .dismiss {
    float: right;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}

/* ──────────────────────────────────────────────────────────────────────────
   SQL code editor (CodeMirror 5) — used by SqlEditorTab in the Query Builder
   and Scheduled Reports editors. Token colors map to --ds-* tokens so light
   and dark themes both work without swapping CodeMirror theme files.
   ────────────────────────────────────────────────────────────────────────── */
.code-editor-container {
    border: 1px solid var(--ds-outline-variant);
    border-radius: var(--ds-radius-input, 8px);
    overflow: hidden;
    background: var(--ds-surface);
}

.code-editor-container .code-editor-source {
    display: none;
}

.code-editor-container .CodeMirror {
    height: auto;
    min-height: 160px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--ds-on-surface);
    background: var(--ds-surface);
}

.code-editor-container .CodeMirror-gutters {
    background: var(--ds-surface-variant);
    border-right: 1px solid var(--ds-outline-variant);
}

.code-editor-container .CodeMirror-linenumber {
    color: var(--ds-on-surface-muted);
}

.code-editor-container .CodeMirror-cursor {
    border-left: 1.5px solid var(--ds-on-surface);
}

.code-editor-container .CodeMirror-selected {
    background: var(--ds-primary-12);
}

.code-editor-container .CodeMirror-focused .CodeMirror-selected {
    background: var(--ds-primary-12);
}

.code-editor-container .CodeMirror-activeline-background {
    background: var(--ds-surface-container-low);
}

.code-editor-container .CodeMirror-matchingbracket {
    color: var(--ds-primary) !important;
    font-weight: 600;
}

/* Token colors */
.code-editor-container .cm-keyword {
    color: var(--ds-primary);
    font-weight: 600;
}

.code-editor-container .cm-string,
.code-editor-container .cm-string-2 {
    color: var(--ds-warning);
}

.code-editor-container .cm-number {
    color: var(--ds-success);
}

.code-editor-container .cm-comment {
    color: var(--ds-on-surface-muted);
    font-style: italic;
}

.code-editor-container .cm-atom,
.code-editor-container .cm-builtin,
.code-editor-container .cm-type {
    color: var(--ds-tertiary);
}

.code-editor-container .cm-operator,
.code-editor-container .cm-punctuation,
.code-editor-container .cm-bracket,
.code-editor-container .cm-variable,
.code-editor-container .cm-variable-2,
.code-editor-container .cm-property {
    color: var(--ds-on-surface);
}


/* ── Comments rich-text editor (P4CommentsEditor) ── */
/* Read-only render of stored HTML comments: give block elements sane spacing
   since the markup is injected via MarkupString and has no inline styles. */
.p4-comments-readonly {
    line-height: 1.5;
    white-space: normal;
    word-break: break-word;
}
.p4-comments-readonly p {
    margin: 0 0 0.5em;
}
.p4-comments-readonly p:last-child {
    margin-bottom: 0;
}
.p4-comments-readonly ul,
.p4-comments-readonly ol {
    margin: 0 0 0.5em;
    padding-left: 1.25rem;
}
.p4-comments-readonly a {
    color: var(--ds-primary);
    text-decoration: underline;
}
