/* ==========================================================================
   CraftX ERP — Miscellaneous secondary surfaces
   Surface-specific layout rules for surfaces that don't warrant their own
   dedicated stylesheet (Documents browser, Analytics dashboards, Workflow
   editor, Public document viewer, Chat, error/auth landing pages, generic
   loose top-level pages).

   Token-only: every value resolves to a custom property defined upstream
   in app.css / cx-widgets.css. Layered classes are namespaced per surface
   to avoid collisions: .cx-docs-*, .cx-analytics-*, .cx-workflow-*,
   .cx-public-*, .cx-chat-*, .cx-error-*, .cx-auth-*.
   ========================================================================== */

/* ── Documents browser (Angebote / Rechnungen list) ──────────────────── */

.cx-docs-page {
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.cx-docs-page__header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 4px;
}

.cx-docs-page__title {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: var(--fw-bold);
    color: var(--cx-text-primary);
    margin: 0 0 4px;
    letter-spacing: -0.01em;
}

.cx-docs-page__subtitle {
    font-size: 13px;
    color: var(--cx-text-muted);
    margin: 0;
}

.cx-docs-page__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.cx-docs-kpis {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    padding: 14px 14px 0;
}

.cx-docs-kpi {
    display: grid;
    /* Pack rows at the top: when a sibling card carries a sparkline and stretches the
       row, cards without one keep their label/value/meta spacing instead of spreading. */
    align-content: start;
    gap: 3px;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--cx-border);
    border-radius: var(--radius-sm);
    background: var(--cx-surface);
    color: var(--cx-text-primary);
    text-align: left;
    cursor: pointer;
}

.cx-docs-kpi:hover,
.cx-docs-kpi.active {
    border-color: var(--cx-primary);
    background: var(--cx-primary-soft);
}

.cx-docs-kpi--passive {
    cursor: default;
}

.cx-docs-kpi--passive:hover {
    border-color: var(--cx-border);
    background: var(--cx-surface);
}

.cx-docs-kpi__label {
    font-size: 11px;
    font-weight: var(--fw-semibold);
    color: var(--cx-text-muted);
    text-transform: uppercase;
}

.cx-docs-kpi__value {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: var(--fw-bold);
    line-height: 1;
}

.cx-docs-kpi__meta {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--cx-text-muted);
    white-space: nowrap;
}

/* A plain-language note under a figure (e.g. payments without a day that are not in it): may wrap. */
.cx-docs-kpi__meta--note {
    font-family: inherit;
    color: var(--cx-warning);
    white-space: normal;
}

/* Slim "Verlauf" sparkline under a KPI card's meta line. The card is a <button>; the svg accepts
   pointer input for its per-week hover tooltip but never calls stopPropagation, so clicks still
   bubble to the button and filter the list. Rendered only on some cards; the KPI grid stretches all
   cards to a common height, so a card without a spark keeps its natural bottom padding
   instead of jumping. */
.cx-docs-kpi__spark {
    margin-top: 6px;
    height: 22px;
}

.cx-docs-kpi__spark .cx-sparkline {
    display: block;
    width: 100%;
    height: 100%;
}

.cx-docs-table-header {
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
}

.cx-docs-table-summary {
    margin: 4px 0 0;
    color: var(--cx-text-muted);
    font-size: 12px;
}

.cx-docs-table-tools {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.cx-docs-search {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 260px;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--cx-border);
    border-radius: var(--radius-sm);
    background: var(--cx-surface);
    color: var(--cx-text-muted);
}

.cx-docs-search input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--cx-text-primary);
    font-size: 13px;
}

.cx-docs-title-cell {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.cx-docs-row-note {
    flex-basis: 100%;
    color: var(--cx-text-muted);
    font-size: 11px;
}

.cx-sort-button {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    max-width: 100%;
    border: 0;
    padding: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: var(--fw-semibold);
    text-transform: inherit;
    letter-spacing: inherit;
    cursor: pointer;
}

.cx-sort-button--num {
    justify-content: flex-end;
}

.cx-docs-empty,
.cx-docs-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px;
    color: var(--cx-text-muted);
    font-size: 13px;
}

/* Guided first-run empty state: instead of a bare "nothing here" line, explain
   the flow and offer the next step (used by QuoteList/InvoiceList). */
.cx-docs-empty-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;
    padding: 48px 24px;
}

.cx-docs-empty-hero > i {
    font-size: 34px;
    color: var(--cx-text-muted);
    opacity: 0.6;
    margin-bottom: 4px;
}

.cx-docs-empty-hero__title {
    font-size: 16px;
    font-weight: 600;
}

.cx-docs-empty-hero__text {
    max-width: 440px;
    color: var(--cx-text-muted);
    font-size: 13px;
    margin: 0 0 10px;
}

.cx-docs-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Document tables: on narrow viewports the table scrolls inside its card
   instead of being clipped; dates, amounts and the action buttons never wrap,
   while the chip columns (status, due) stack their chips. */
.cx-docs-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.cx-docs-table .num,
.cx-docs-date-cell,
.cx-docs-actions-cell {
    white-space: nowrap;
}

.cx-docs-chip-cell {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    max-width: 260px;
}

.cx-docs-due--overdue {
    color: var(--cx-danger);
    font-weight: var(--fw-semibold);
}

.cx-docs-due--soon {
    color: var(--cx-warning);
    font-weight: var(--fw-semibold);
}

.cx-docs-due-note {
    margin-left: 6px;
    color: var(--cx-text-muted);
    font-size: 11px;
}

/* ⋯ menu trigger: looks like .btn.outline.sm, but styled via the .e-dropdown-btn hook only —
   SfDropDownButton copies CssClass onto the popup too, so .btn classes must not be used there. */
.cx-docs-actions .cx-docs-menu-btn.e-dropdown-btn {
    display: inline-flex;
    align-items: center;
    height: 28px;
    padding: 0 8px;
    min-width: 0;
    border: 1px solid var(--cx-hairline);
    border-radius: var(--radius-md);
    background: white;
    color: var(--cx-text-primary);
    font-size: 12px;
    line-height: 1;
    box-shadow: none;
}

.cx-docs-actions .cx-docs-menu-btn.e-dropdown-btn:hover {
    border-color: var(--cx-text-muted);
    background: white;
}

.cx-docs-actions .cx-docs-menu-btn.e-dropdown-btn .e-caret {
    display: none;
}

@media (max-width: 1440px) {
    .cx-docs-table thead th,
    .cx-docs-table tbody td {
        padding-left: 10px;
        padding-right: 10px;
    }

    .cx-docs-chip-cell {
        max-width: 200px;
    }
}

@media (max-width: 900px) {
    .cx-docs-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .cx-docs-table-tools,
    .cx-docs-search {
        width: 100%;
    }
}

/* ── Analytics dashboards ────────────────────────────────────────────── */

.cx-analytics-page {
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.cx-analytics-page__header {
    margin-bottom: 4px;
}

.cx-analytics-page__title {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: var(--fw-bold);
    color: var(--cx-text-primary);
    margin: 0;
    letter-spacing: -0.01em;
}

.cx-analytics-tabs-host {
    /* Tabs sit in their own card so the SfTab header strip respects card chrome */
    overflow: hidden;
}

.cx-analytics-tabs-host .tab-content {
    min-height: 600px;
    padding: 16px;
}

.cx-analytics-chart-card {
    /* Internal padding for chart panels — .card alone provides only the surface */
    padding: 20px;
    margin-bottom: 16px;
}

.cx-analytics-chart-title {
    font-size: 13px;
    font-weight: var(--fw-semibold);
    color: var(--cx-text-secondary);
    margin: 0 0 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* SfTab content area inherits min-height so charts don't compress */
.cx-analytics-tabs-host ::deep .e-content {
    min-height: 600px;
}

/* ── Workflow management / editor / steps / approvals ────────────────── */

.cx-workflow-page {
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.cx-workflow-step-card {
    background: var(--cx-card-bg);
    border: 1px solid var(--cx-card-border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    transition: box-shadow 0.15s var(--ease), border-color 0.15s var(--ease);
}

.cx-workflow-step-card:hover {
    box-shadow: var(--shadow-sm);
}

.cx-workflow-step-card.is-selected {
    border-color: var(--cx-primary);
    box-shadow: inset 3px 0 0 var(--cx-primary);
}

.cx-workflow-connector {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 28px;
    color: var(--cx-text-muted);
    font-size: 14px;
}

.cx-workflow-info-box {
    background: rgba(31, 74, 130, 0.06);
    border: 1px solid rgba(31, 74, 130, 0.18);
    border-radius: var(--radius-lg);
    padding: 14px 18px;
    color: var(--cx-text-secondary);
    font-size: 13px;
    line-height: 1.5;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.cx-workflow-info-box .cx-workflow-info-icon {
    flex-shrink: 0;
    color: var(--cx-info);
    font-size: 18px;
    margin-top: 2px;
}

.cx-workflow-info-box strong {
    color: var(--cx-text-primary);
    display: block;
    margin-bottom: 4px;
}

/* ── Public document viewer (anonymous landing) ──────────────────────── */

.cx-public-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 64px 20px;
    gap: 14px;
}

.cx-public-state__icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--cx-primary-soft);
    color: var(--cx-primary);
    font-size: 28px;
}

.cx-public-state__icon.is-muted {
    background: rgba(28, 25, 21, 0.06);
    color: var(--cx-text-muted);
}

.cx-public-state__icon.is-danger {
    background: color-mix(in srgb, var(--cx-danger) 14%, white);
    color: var(--cx-danger);
}

.cx-public-state__title {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: var(--fw-bold);
    color: var(--cx-text-primary);
    margin: 0;
}

.cx-public-state__message {
    font-size: 14px;
    color: var(--cx-text-muted);
    margin: 0;
    max-width: 480px;
    line-height: 1.5;
}

/* ── Chat surface (overrides for ad-hoc rules) ───────────────────────── */

.cx-chat-divider-line {
    /* Replaces the hard-coded #ebebeb that previously sat in scoped CSS */
    border-bottom: 1px solid var(--cx-hairline);
}

/* ── Error landing page ──────────────────────────────────────────────── */

.cx-error-page {
    min-height: calc(var(--cx-app-h) - var(--cx-topbar-h, 60px));
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 20px;
    background: var(--paper);
}

.cx-error-card {
    width: 100%;
    max-width: 560px;
    background: var(--cx-card-bg);
    border: 1px solid var(--cx-card-border);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-md);
    padding: 32px 36px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.cx-error-card__icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: color-mix(in srgb, var(--cx-danger) 12%, white);
    color: var(--cx-danger);
    font-size: 26px;
    margin-bottom: 4px;
}

.cx-error-card__title {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: var(--fw-bold);
    color: var(--cx-text-primary);
    margin: 0;
    letter-spacing: -0.01em;
}

.cx-error-card__message {
    font-size: 14px;
    color: var(--cx-text-secondary);
    margin: 0;
    line-height: 1.55;
}

.cx-error-card__request-id {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--cx-text-muted);
    background: var(--paper-2);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--cx-hairline-soft);
    word-break: break-all;
}

.cx-error-card__hint {
    font-size: 12.5px;
    color: var(--cx-text-muted);
    line-height: 1.5;
    border-top: 1px solid var(--cx-hairline-soft);
    padding-top: 14px;
    margin-top: 4px;
}

.cx-error-card__actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 6px;
}

/* ── Auth confirmation landing ───────────────────────────────────────── */

.cx-auth-confirm {
    padding: 48px 24px;
    text-align: center;
    color: var(--cx-text-secondary);
    font-size: 14px;
}

.cx-auth-confirm__title {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: var(--fw-bold);
    color: var(--cx-text-primary);
    margin: 0 0 8px;
}

/* ── User management page (loose top-level) ──────────────────────────── */

.cx-user-mgmt-page {
    padding: 20px;
}

.cx-user-mgmt-page .header-section {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 20px;
    gap: 16px;
}

.cx-user-mgmt-page .page-title {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: var(--fw-bold);
    color: var(--cx-text-primary);
    margin: 0 0 4px;
    letter-spacing: -0.01em;
}

.cx-user-mgmt-page .page-subtitle {
    font-size: 13px;
    color: var(--cx-text-muted);
    margin: 0;
}

.cx-user-mgmt-page .action-buttons {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

/* ── Demo-only helper tokens (Demo Variant A/D fixtures) ───────────────
   Demo pages occasionally need a deeper info shade that isn't part of
   the canonical palette. Scoped here so the demo surfaces can reference
   a single token instead of inlining a hex literal. */

:root {
    --demo-info-deep: #1A365D; /* navy/info-dark for demo gradients only */
}
