/* page-patterns.css — the one page frame and the shared patterns every dashboard
 * page composes. Spec: docs/product/page-patterns/README.md. A page adopts it by
 * loading this file and using the vp- classes; it does not restyle them.
 * Self-contained: every --ai-* token has a fallback (the dashboard's own value), so a
 * page that doesn't load css/ai-dashboard.css still renders correctly. */

:root {
    /* Spacing scale: every margin, padding and gap uses one of these. */
    --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
    --sp-5: 24px; --sp-6: 32px; --sp-7: 40px; --sp-8: 48px;

    /* Type scale */
    --fs-title: 28px;
    --fs-subtitle: 15px;
    --fs-section: 18px;
    --fs-body: 14px;
    --fs-label: 12px;
    --fs-kpi: 28px;

    --radius-card: 12px;
    --vp-width: 1280px;
    --vp-width-narrow: 960px;
}

/* ---------- Page frame ---------- */
.vp-page {
    padding: var(--sp-6) var(--sp-7);
    width: 100%;   /* in a flex column (pages with no scroll wrapper), auto margins would shrink it */
    max-width: var(--vp-width);
    margin: 0 auto;
    box-sizing: border-box;
    font-family: var(--ai-font, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
}
.vp-page--narrow { max-width: var(--vp-width-narrow); }
.vp-page--full { max-width: none; }

/* ---------- 1. Page header: title left, actions top right ---------- */
.vp-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: var(--sp-5);
}
.vp-header-text { flex: 1; min-width: 0; }
.vp-title {
    font-size: var(--fs-title);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.01em;
    color: var(--ai-text-dark, #101828);
    margin: 0 0 var(--sp-1);
}
.vp-subtitle {
    font-size: var(--fs-subtitle);
    line-height: 1.5;
    color: var(--ai-text-muted, #6A7282);
    margin: 0;
}
.vp-header-actions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    margin-left: var(--sp-4);
}
.vp-header-actions > * + * { margin-left: var(--sp-2); }
.vp-header-actions[hidden], .vp-btn[hidden] { display: none; }   /* `hidden` must beat the flex display */

/* Back link above the title — only on a sub-page (one the nav files under a parent). */
.vp-back {
    display: flex;          /* its own line, whatever the title element is */
    width: max-content;
    align-items: center;
    margin-bottom: var(--sp-2);
    font: 500 13px/1.4 var(--ai-font, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
    color: var(--ai-text-muted, #6A7282);
    text-decoration: none;
}
.vp-back svg { margin-right: 6px; }
.vp-back:hover { color: var(--ai-text-dark, #101828); }

/* ---------- Buttons ---------- */
.vp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    padding: 0 var(--sp-4);
    border-radius: 8px;
    border: 1px solid transparent;
    font: 500 var(--fs-body)/1 var(--ai-font, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.vp-btn svg { margin-right: 6px; }
.vp-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.vp-btn--primary { background: var(--ai-primary, #8200DB); color: #fff; }
.vp-btn--primary:hover:not(:disabled) { background: #6d00b8; }
.vp-btn--secondary { background: var(--ai-bg-white, #FFFFFF); color: var(--ai-text-dark, #101828); border-color: var(--ai-border, #E5E7EB); }
.vp-btn--secondary:hover:not(:disabled) { background: var(--ai-bg-main, #F9FAFB); }
.vp-btn--ghost { background: transparent; color: var(--ai-text-medium, #364153); }
.vp-btn--ghost:hover:not(:disabled) { background: var(--ai-bg-main, #F9FAFB); }
.vp-btn--danger { background: #DC2626; color: #fff; }
.vp-btn--danger:hover:not(:disabled) { background: #B91C1C; }
.vp-btn--sm { height: 32px; padding: 0 var(--sp-3); font-size: 13px; }

/* ---------- 2. Secondary nav: underline tabs (which view of this page) ---------- */
/* The active state accepts .active, .is-active and aria-selected so a page's existing
   tab script keeps working when its tabs take these classes. */
.vp-tabs {
    display: flex;
    border-bottom: 1px solid var(--ai-border, #E5E7EB);
    margin-bottom: var(--sp-5);
    overflow-x: auto;
    scrollbar-width: none;
}
.vp-tabs::-webkit-scrollbar { display: none; }
.vp-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 2px;
    margin: 0 var(--sp-5) -1px 0;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    font: 500 var(--fs-body)/1.2 var(--ai-font, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
    color: var(--ai-text-muted, #6A7282);
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}
.vp-tab:hover { color: var(--ai-text-dark, #101828); }
.vp-tab svg { width: 16px; height: 16px; flex-shrink: 0; }
.vp-tab.active, .vp-tab.is-active, .vp-tab[aria-selected="true"] {
    color: var(--ai-primary, #8200DB);
    border-bottom-color: var(--ai-primary, #8200DB);
}
.vp-tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #F2F4F7;
    font: 600 11px/1 var(--ai-font, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
    color: var(--ai-text-medium, #364153);
}
.vp-tab.active .vp-tab-count, .vp-tab.is-active .vp-tab-count, .vp-tab[aria-selected="true"] .vp-tab-count {
    background: var(--ai-primary-light, #FAF5FF);
    color: var(--ai-primary, #8200DB);
}
.vp-tab:focus-visible { outline: 2px solid var(--ai-primary, #8200DB); outline-offset: 2px; }
.vp-tab-count[hidden] { display: none; }

/* ---------- Tertiary: segmented control (how to look at the same data) ---------- */
.vp-seg {
    display: inline-flex;
    padding: 3px;
    margin-bottom: var(--sp-4);
    border-radius: 8px;
    background: #F2F4F7;
}
.vp-seg-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 0;
    border-radius: 6px;
    background: none;
    font: 500 13px/1.2 var(--ai-font, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
    color: var(--ai-text-medium, #364153);
    white-space: nowrap;
    cursor: pointer;
}
.vp-seg-btn.active, .vp-seg-btn.is-active, .vp-seg-btn[aria-selected="true"], .vp-seg-btn[aria-pressed="true"] {
    background: var(--ai-bg-white, #FFFFFF);
    color: var(--ai-text-dark, #101828);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}
.vp-seg-btn:focus-visible { outline: 2px solid var(--ai-primary, #8200DB); outline-offset: 2px; }

/* ---------- 3. Headline numbers: 2–6 cards, label then value, optional delta ---------- */
.vp-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--sp-4);
    margin-bottom: var(--sp-5);
}
.vp-kpi {
    display: block;
    min-width: 0;
    padding: var(--sp-4) var(--sp-5);
    border: 1px solid var(--ai-border, #E5E7EB);
    border-radius: var(--radius-card);
    background: var(--ai-bg-white, #FFFFFF);
    color: inherit;
    text-align: left;
    text-decoration: none;
}
a.vp-kpi, button.vp-kpi { cursor: pointer; font: inherit; }
a.vp-kpi:hover, button.vp-kpi:hover { border-color: #D0D5DD; }
.vp-kpi-label {
    display: block;
    margin: 0 0 var(--sp-1);
    font: 600 var(--fs-label)/1.3 var(--ai-font, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ai-text-muted, #6A7282);
}
.vp-kpi-value {
    display: block;
    margin: 0;
    font: 700 var(--fs-kpi)/1.15 var(--ai-font, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
    font-variant-numeric: tabular-nums;
    color: var(--ai-text-dark, #101828);
    overflow-wrap: anywhere;
}
.vp-kpi-sub, .vp-kpi-delta {
    display: block;
    margin: var(--sp-1) 0 0;
    font: 400 13px/1.4 var(--ai-font, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
    color: var(--ai-text-muted, #6A7282);
}
.vp-kpi-sub:empty { display: none; }
/* Colour follows good/bad, not the arrow: more unsubscribes is --bad. */
.vp-kpi-delta--good { color: #067647; }
.vp-kpi-delta--bad { color: #B42318; }

/* ---------- Filter pills: narrow the rows (filters are never tabs) ---------- */
.vp-pills { display: flex; flex-wrap: wrap; margin-bottom: var(--sp-4); }
.vp-pills > * { margin: 0 var(--sp-2) var(--sp-2) 0; }
.vp-pill {
    display: inline-flex;
    align-items: center;
    height: 32px;
    padding: 0 var(--sp-3);
    border-radius: 999px;
    border: 1px solid var(--ai-border, #E5E7EB);
    background: var(--ai-bg-white, #FFFFFF);
    color: var(--ai-text-medium, #364153);
    font: 500 13px/1 var(--ai-font, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
    white-space: nowrap;
    cursor: pointer;
    gap: 6px;   /* spaces icon, text node and count alike */
}
.vp-pill:hover { border-color: #D0D5DD; }
.vp-pill.is-on, .vp-pill.active, .vp-pill.is-active, .vp-pill[aria-pressed="true"], .vp-pill[aria-selected="true"] { background: var(--ai-primary-light, #FAF5FF); border-color: var(--ai-primary, #8200DB); color: var(--ai-primary, #8200DB); }
.vp-pill.is-on .vp-tab-count, .vp-pill.active .vp-tab-count, .vp-pill.is-active .vp-tab-count,
.vp-pill[aria-pressed="true"] .vp-tab-count, .vp-pill[aria-selected="true"] .vp-tab-count {
    background: var(--ai-bg-white, #FFFFFF);
    color: var(--ai-primary, #8200DB);
}

.vp-btn:focus-visible, .vp-pill:focus-visible { outline: 2px solid var(--ai-primary, #8200DB); outline-offset: 2px; }
@media (pointer: coarse) { .vp-pill { height: 44px; } .vp-tab { padding: 14px 2px; } .vp-seg-btn { padding: 10px 14px; } }

/* A record's edit page (/x/new, /x/:id) shares the list's HTML: while it shows, its
   .vp-back link is the trail, and the breadcrumb (aligned to the hidden list) steps aside. */
.ai-main-content-scroll:has(> .vp-page--record:not([hidden])) > .ai-breadcrumb,
.ai-main-content:has(> .vp-page--record:not([hidden])) > .ai-breadcrumb { display: none; }

/* ---------- Section card (also the frame of a record's edit page) ---------- */
.vp-card {
    margin-bottom: var(--sp-6);
    border: 1px solid var(--ai-border, #E5E7EB);
    border-radius: var(--radius-card);
    background: var(--ai-bg-white, #FFFFFF);
    overflow: hidden;
}

/* ---------- 4. Record drawer: a row opens here (modals are for create/confirm) ---------- */
.vp-drawer-scrim {
    position: fixed;
    inset: 0;
    z-index: 900;
    background: rgba(16, 24, 40, 0.32);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}
.vp-drawer-scrim.open { opacity: 1; pointer-events: auto; }
.vp-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 901;
    display: flex;
    flex-direction: column;
    width: 480px;
    max-width: 100vw;
    background: var(--ai-bg-white, #FFFFFF);
    box-shadow: -8px 0 24px rgba(16, 24, 40, 0.12);
    font-family: var(--ai-font, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
    transform: translateX(100%);
    transition: transform 0.2s ease;
}
.vp-drawer.open { transform: none; }
.vp-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--ai-border, #E5E7EB);
}
.vp-drawer-title {
    margin: 0;
    font: 600 var(--fs-section)/1.3 var(--ai-font, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
    color: var(--ai-text-dark, #101828);
}
.vp-drawer-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--ai-text-muted, #6A7282);
    cursor: pointer;
}
.vp-drawer-close:hover { background: var(--ai-bg-main, #F9FAFB); color: var(--ai-text-dark, #101828); }
.vp-drawer-close:focus-visible { outline: 2px solid var(--ai-primary, #8200DB); outline-offset: 2px; }
.vp-drawer-body { flex: 1; overflow-y: auto; padding: var(--sp-5); }
.vp-drawer-body--flush { padding: 0; }
.vp-drawer-footer {
    display: flex;
    align-items: center;
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--ai-border, #E5E7EB);
}
.vp-drawer-footer > * + * { margin-left: var(--sp-2); }
.vp-drawer-footer-spacer { flex: 1; }

/* A record's summary: labelled sections of label/value pairs (drawer body, record page) */
.vp-section { margin-bottom: var(--sp-5); }
.vp-section:last-child { margin-bottom: 0; }
.vp-section-title {
    margin: 0 0 var(--sp-2);
    font-size: var(--fs-label);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ai-text-muted, #6A7282);
}
.vp-dl {
    display: grid;
    grid-template-columns: minmax(96px, 128px) 1fr;
    gap: var(--sp-2) var(--sp-3);
    margin: 0;
    font-size: var(--fs-body);
}
.vp-dl dt { color: var(--ai-text-muted, #6A7282); }
.vp-dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; color: var(--ai-text-dark, #101828); }
.vp-dl a, .vp-prose a { color: var(--ai-primary, #8200DB); }
.vp-prose { margin: 0; font-size: var(--fs-body); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ai-text-dark, #101828); }
.vp-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: var(--fs-label);
    font-weight: 600;
    background: var(--ai-bg-main, #F3F4F6);
    color: var(--ai-text-dark, #101828);
}
/* Cancel / Save under a record page's form */
.vp-form-actions {
    display: flex;
    justify-content: flex-end;
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--ai-border, #E5E7EB);
}
.vp-form-actions > * + * { margin-left: var(--sp-2); }
@media (prefers-reduced-motion: reduce) {
    .vp-drawer, .vp-drawer-scrim { transition: none; }
}

@media (max-width: 768px) {
    .vp-page { padding: var(--sp-5) var(--sp-4); }
    .vp-title { font-size: 24px; }
    .vp-header { flex-direction: column; align-items: stretch; }
    .vp-header-actions { margin: var(--sp-3) 0 0; flex-wrap: wrap; }
    /* Primary first and full width; the rest wrap below it. */
    .vp-header-actions > * { margin: 0 var(--sp-2) var(--sp-2) 0; }
    .vp-header-actions > .vp-btn--primary { order: -1; flex: 1 0 100%; margin-right: 0; }
    .vp-btn { height: 44px; }
    .vp-drawer { width: 100vw; }
}

/* ---------- Overflow menu (⋯) for header actions past the third ---------- */
.vp-more { position: relative; }
.vp-more > summary { list-style: none; }
.vp-more > summary::-webkit-details-marker { display: none; }
.vp-more-menu {
    position: absolute;
    right: 0;
    top: calc(100% + var(--sp-1));
    z-index: 50;
    min-width: 180px;
    padding: var(--sp-1);
    background: var(--ai-bg-white, #FFFFFF);
    border: 1px solid var(--ai-border, #E5E7EB);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12);
}
.vp-more-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: var(--sp-2) var(--sp-3);
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--ai-text-dark, #101828);
    font: 400 var(--fs-body)/1.4 var(--ai-font, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.vp-more-item svg { margin-right: var(--sp-2); }
.vp-more-item:hover:not(:disabled) { background: var(--ai-bg-main, #F9FAFB); }
.vp-more-item:disabled { opacity: 0.5; cursor: not-allowed; }
