/* ==========================================================================
   Aivanta page-level patterns used by more than one page (or too specific for
   components.css): heatmaps, rank bars, chat, model and prompt cards.
   ========================================================================== */

/* ---------- Rank rows (label, bar, value) ---------- */
.av-rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.av-rank li { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; gap: 12px; align-items: center; font-size: var(--av-text-base); }
.av-rank__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.av-rank__track { height: 8px; border-radius: var(--av-radius-pill); background: var(--av-neutral-soft); overflow: hidden; }
.av-rank__fill { display: block; height: 100%; border-radius: var(--av-radius-pill); background: var(--av-series-1); }
.av-rank__value { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 3.2em; text-align: right; }

/* ---------- Heatmap table (cohort retention) ---------- */
.av-heat { width: 100%; border-collapse: separate; border-spacing: 3px; font-variant-numeric: tabular-nums; font-size: var(--av-text-sm); }
.av-heat th { font-weight: 600; color: var(--av-text-muted); padding: 6px 8px; text-align: center; white-space: nowrap; }
.av-heat th[scope="row"] { text-align: left; }
.av-heat td { text-align: center; padding: 9px 6px; border-radius: var(--av-radius-sm); min-width: 54px; color: var(--av-text); }
.av-heat td[data-level="0"] { background: var(--av-neutral-soft); color: var(--av-text-subtle); }
.av-heat td[data-level="1"] { background: color-mix(in srgb, var(--av-series-1) 16%, var(--av-surface)); }
.av-heat td[data-level="2"] { background: color-mix(in srgb, var(--av-series-1) 30%, var(--av-surface)); }
.av-heat td[data-level="3"] { background: color-mix(in srgb, var(--av-series-1) 48%, var(--av-surface)); }
.av-heat td[data-level="4"] { background: color-mix(in srgb, var(--av-series-1) 92%, var(--av-surface)); color: #fff; }
[data-bs-theme="dark"] .av-heat td[data-level="3"] { color: #fff; }

/* ---------- Mini report cards ---------- */
.av-report-card { display: flex; flex-direction: column; height: 100%; }
.av-report-card .av-chart { height: 90px; }
.av-report-card__value { font-size: var(--av-text-xl); font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* ---------- Chat (AI chat and Messaging) ---------- */
.av-chat { display: grid; grid-template-columns: 300px minmax(0, 1fr); height: calc(100dvh - var(--av-topbar-height) - 220px); min-height: 520px; overflow: hidden; }
.av-chat__side { border-right: 1px solid var(--av-border); display: flex; flex-direction: column; min-height: 0; background: var(--av-surface-2); }
.av-chat__side-head { padding: var(--av-space-4); border-bottom: 1px solid var(--av-border); display: grid; gap: var(--av-space-3); }
.av-chat__list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.av-chat__item { width: 100%; display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 10px; border: 0; border-radius: var(--av-radius); background: transparent; color: var(--av-text); font: inherit; cursor: pointer; }
.av-chat__item:hover { background: var(--av-surface-hover); }
.av-chat__item[aria-current="true"] { background: var(--av-accent-soft); }
.av-chat__item strong { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.av-chat__item small { color: var(--av-text-subtle); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.av-chat__item > span:last-child { min-width: 0; }
.av-chat__main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.av-chat__head { display: flex; align-items: center; justify-content: space-between; gap: var(--av-space-3); padding: var(--av-space-3) var(--av-space-5); border-bottom: 1px solid var(--av-border); }
.av-chat__thread { flex: 1; overflow-y: auto; padding: var(--av-space-5); display: flex; flex-direction: column; gap: var(--av-space-4); }
.av-msg { display: flex; gap: 12px; max-width: min(720px, 100%); }
.av-msg--me { align-self: flex-end; flex-direction: row-reverse; }
.av-msg__bubble { padding: 10px 14px; border-radius: var(--av-radius-lg); background: var(--av-surface-2); border: 1px solid var(--av-border); white-space: pre-wrap; overflow-wrap: anywhere; }
.av-msg--me .av-msg__bubble { background: var(--av-accent); border-color: var(--av-accent); color: var(--av-accent-contrast); }
.av-msg__meta { display: block; margin-top: 4px; font-size: var(--av-text-xs); color: var(--av-text-subtle); }
.av-msg--me .av-msg__meta { text-align: right; }
.av-typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 0; }
.av-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--av-text-subtle); animation: av-bounce 1s infinite ease-in-out; }
.av-typing i:nth-child(2) { animation-delay: 0.15s; }
.av-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes av-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; } 40% { transform: translateY(-4px); opacity: 1; } }
.av-chat__composer { border-top: 1px solid var(--av-border); padding: var(--av-space-4) var(--av-space-5); display: grid; gap: var(--av-space-2); }
.av-chat__composer-row { display: flex; gap: var(--av-space-2); align-items: flex-end; }
.av-chat__composer textarea { resize: none; max-height: 160px; }
.av-chat__suggestions { display: flex; flex-wrap: wrap; gap: 6px; }
.av-chat__back { display: none; }
@media (max-width: 767.98px) {
  .av-chat { grid-template-columns: 1fr; height: calc(100dvh - var(--av-topbar-height) - 160px); }
  .av-chat[data-view="thread"] .av-chat__side { display: none; }
  .av-chat[data-view="list"] .av-chat__main { display: none; }
  .av-chat__back { display: inline-grid; }
  .av-chat__thread, .av-chat__composer, .av-chat__head { padding-left: var(--av-space-3); padding-right: var(--av-space-3); }
}

/* ---------- Selectable cards (models, prompts, plans) ---------- */
.av-select-card { position: relative; height: 100%; display: flex; flex-direction: column; }
.av-select-card[aria-selected="true"], .av-select-card.is-selected { border-color: var(--av-accent); box-shadow: 0 0 0 1px var(--av-accent), var(--av-shadow-sm); }
.av-meta-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.av-spec { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--av-space-3); margin: var(--av-space-4) 0 0; }
.av-spec div { min-width: 0; }
.av-spec dt { font-size: var(--av-text-xs); color: var(--av-text-subtle); font-weight: 500; }
.av-spec dd { margin: 2px 0 0; font-weight: 650; font-variant-numeric: tabular-nums; }
.av-fav { color: var(--av-text-subtle); }
.av-fav[aria-pressed="true"] { color: var(--av-warning); }

/* ---------- Editor ---------- */
.av-editor { font-family: var(--av-font-mono); font-size: var(--av-text-sm); line-height: 1.7; min-height: 280px; resize: vertical; }
.av-var-chip { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: var(--av-radius-pill); background: var(--av-accent-soft); color: var(--av-accent-text); font-family: var(--av-font-mono); font-size: var(--av-text-xs); font-weight: 600; }
.av-output { padding: var(--av-space-4); border: 1px solid var(--av-border); border-radius: var(--av-radius); background: var(--av-surface-2); white-space: pre-wrap; overflow-wrap: anywhere; min-height: 120px; }

/* ---------- Status dots for job states (icon + label always present) ---------- */
.av-progress-cell { display: grid; gap: 4px; min-width: 120px; }
.av-progress-cell .progress { --bs-progress-height: 6px; }

.min-w-0 { min-width: 0; }

/* ---------- Invoice document ---------- */
.av-invoice { max-width: 860px; margin-inline: auto; }
.av-invoice__head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--av-space-5); }
.av-invoice__parties { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--av-space-6); margin: var(--av-space-6) 0; }
.av-invoice__parties h2 { font-size: var(--av-text-sm); color: var(--av-text-muted); font-weight: 600; margin-bottom: 6px; }
.av-invoice__parties address { margin: 0; font-style: normal; }
.av-totals { margin-left: auto; width: min(320px, 100%); }
.av-totals .av-stat-row:last-child { font-size: var(--av-text-lg); border-top: 1px solid var(--av-border-strong); padding-top: 12px; margin-top: 4px; }

/* ---------- Print: invoices and reports print without the app shell ---------- */
@media print {
  .av-sidebar, .av-topbar, .av-footer, .av-overlay, .av-page-actions, .av-breadcrumb, .av-skip-link, .av-toast-region, .av-demo-note, .no-print { display: none !important; }
  .av-main-col { margin-left: 0 !important; }
  .av-content { padding: 0; max-width: none; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; }
}

/* ==========================================================================
   Phase 4: CRM, team and application pages
   ========================================================================== */

/* ---------- Board (pipeline and kanban) ---------- */
.av-board { position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: var(--av-space-4); overflow-x: auto; padding-bottom: var(--av-space-3); align-items: start; }
.av-board__col { background: var(--av-surface-2); border: 1px solid var(--av-border); border-radius: var(--av-radius-lg, 12px); padding: var(--av-space-3); min-width: 0; }
.av-board__col.is-over { border-color: var(--av-accent); box-shadow: 0 0 0 1px var(--av-accent); }
.av-board__head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 4px 10px; }
.av-board__list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--av-space-3); min-height: 48px; }
.av-board__card { background: var(--av-surface); border: 1px solid var(--av-border); border-radius: var(--av-radius); padding: var(--av-space-3); display: grid; gap: 6px; box-shadow: var(--av-shadow-xs); }
.av-board__card[draggable="true"] { cursor: grab; }
.av-board__card.is-dragging { opacity: 0.5; }
.av-board__empty { padding: 12px 4px; font-size: var(--av-text-sm); }

/* ---------- Task list ---------- */
.av-task { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 8px var(--av-space-4); padding: var(--av-space-3) var(--av-space-5); border-top: 1px solid var(--av-border); }
.av-task:first-child { border-top: 0; }
.av-task.is-done .form-check-label { text-decoration: line-through; color: var(--av-text-muted); }
.av-task__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--av-text-muted); font-size: var(--av-text-sm); }

/* ---------- Workspace cards ---------- */
.av-ws-dot { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--av-accent-soft); color: var(--av-accent-text); font-size: 1.1rem; flex: none; }

/* ---------- Calendar ---------- */
.av-cal { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 4px; }
.av-cal th { text-align: center; font-size: var(--av-text-xs); color: var(--av-text-subtle); font-weight: 600; padding: 4px 0; }
.av-cal td { padding: 0; vertical-align: top; }
.av-cal__day { width: 100%; min-height: 84px; display: flex; flex-direction: column; align-items: stretch; gap: 3px; text-align: left; padding: 6px; border: 1px solid var(--av-border); border-radius: var(--av-radius); background: var(--av-surface); color: var(--av-text); font: inherit; cursor: pointer; }
.av-cal__day:hover { background: var(--av-surface-hover); }
.av-cal__day[aria-pressed="true"] { border-color: var(--av-accent); box-shadow: 0 0 0 1px var(--av-accent); background: var(--av-accent-soft); }
.av-cal__day.is-other { background: var(--av-surface-2); color: var(--av-text-subtle); }
.av-cal__num { font-weight: 600; font-variant-numeric: tabular-nums; }
.av-cal__day.is-today .av-cal__num { display: inline-grid; place-items: center; min-width: 24px; height: 24px; border-radius: 999px; background: var(--av-accent); color: var(--av-accent-contrast); padding: 0 4px; align-self: flex-start; }
.av-cal__chip { display: block; font-size: 0.72rem; line-height: 1.3; padding: 1px 5px; border-radius: 4px; background: var(--av-accent-soft); color: var(--av-accent-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid var(--av-accent); }
.av-cal__chip--meeting { background: var(--av-info-soft); color: var(--av-info); border-left-color: var(--av-info); }
.av-cal__chip--deadline { background: var(--av-warning-soft); color: var(--av-warning); border-left-color: var(--av-warning); }
.av-cal__more { font-size: 0.72rem; color: var(--av-text-muted); }
@media (max-width: 767.98px) { .av-cal__day { min-height: 52px; padding: 4px; } .av-cal__chip { display: none; } .av-cal__dots { display: flex; gap: 3px; } }
@media (min-width: 768px) { .av-cal__dots { display: none; } }
.av-cal__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--av-accent); }

/* ---------- Email ---------- */
.av-mail { display: grid; grid-template-columns: 200px 340px minmax(0, 1fr); height: calc(100dvh - var(--av-topbar-height) - 220px); min-height: 520px; overflow: hidden; }
.av-mail__folders { border-right: 1px solid var(--av-border); background: var(--av-surface-2); padding: var(--av-space-3); display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.av-mail__folder { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; border-radius: var(--av-radius); background: transparent; color: var(--av-text); font: inherit; text-align: left; cursor: pointer; }
.av-mail__folder:hover { background: var(--av-surface-hover); }
.av-mail__folder[aria-current="true"] { background: var(--av-accent-soft); font-weight: 600; }
.av-mail__list { list-style: none; margin: 0; padding: 0; border-right: 1px solid var(--av-border); overflow-y: auto; min-height: 0; }
.av-mail__item { display: block; width: 100%; text-align: left; padding: 12px var(--av-space-4); border: 0; border-bottom: 1px solid var(--av-border); background: transparent; color: var(--av-text); font: inherit; cursor: pointer; }
.av-mail__item:hover { background: var(--av-surface-hover); }
.av-mail__item[aria-current="true"] { background: var(--av-accent-soft); }
.av-mail__item .av-mail__from { display: flex; justify-content: space-between; gap: 8px; }
.av-mail__item.is-unread .av-mail__from strong, .av-mail__item.is-unread .av-mail__subject { font-weight: 700; }
.av-mail__item small { display: block; color: var(--av-text-subtle); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.av-mail__subject { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.av-mail__reader { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow-y: auto; }
.av-mail__body { padding: var(--av-space-5); white-space: pre-line; max-width: 70ch; }
.av-mail__back { display: none; }
@media (max-width: 1199.98px) {
  .av-mail { grid-template-columns: 180px minmax(0, 1fr); }
  .av-mail[data-view="list"] .av-mail__reader { display: none; }
  .av-mail[data-view="read"] .av-mail__list { display: none; }
  .av-mail__back { display: inline-grid; }
}
@media (max-width: 767.98px) {
  .av-mail { grid-template-columns: 1fr; height: auto; min-height: 520px; }
  .av-mail__folders { flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--av-border); }
  .av-mail__folder { width: auto; }
  .av-mail[data-view="read"] .av-mail__folders { display: none; }
}

/* ---------- Notifications ---------- */
.av-notice { display: flex; gap: var(--av-space-3); align-items: flex-start; padding: var(--av-space-4) var(--av-space-5); border-top: 1px solid var(--av-border); }
.av-notice:first-child { border-top: 0; }
.av-notice.is-unread { background: var(--av-accent-soft); }
.av-notice__icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--av-neutral-soft); color: var(--av-neutral); flex: none; }
.av-notice__body { flex: 1; min-width: 0; }
.av-notice__body p { margin: 0 0 2px; }
.av-notice.is-unread .av-notice__body p { font-weight: 600; }
.av-notice__actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* ---------- Team chat (reuses .av-chat) ---------- */
.av-chat__item .av-presence { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--av-surface-2); background: var(--av-text-subtle); display: inline-block; margin-right: 4px; }
.av-chat__item .av-presence.is-on { background: var(--av-success); }

/* ==========================================================================
   Phase 5: authentication and utility layouts (standalone, no app shell)
   ========================================================================== */
.av-auth { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); background: var(--av-bg); }
.av-auth__aside { background: linear-gradient(160deg, #3d40b8 0%, #5457d6 55%, #6a4fd0 100%); color: #fff; padding: clamp(24px, 5vw, 64px); display: flex; flex-direction: column; justify-content: space-between; gap: 32px; }
.av-auth__aside a, .av-auth__aside h2, .av-auth__aside p { color: #fff; }
.av-auth__brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.25rem; text-decoration: none; }
.av-auth__brand img { width: 36px; height: 36px; border-radius: 10px; }
.av-auth__points { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.av-auth__points li { display: flex; gap: 10px; align-items: flex-start; }
.av-auth__main { display: flex; flex-direction: column; padding: clamp(20px, 4vw, 48px); min-width: 0; }
.av-auth__top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 24px; }
.av-auth__panel { margin: auto; width: 100%; max-width: 440px; }
.av-auth__panel h1 { font-size: var(--av-text-2xl, 1.6rem); margin-bottom: 4px; }
.av-auth__panel > p { color: var(--av-text-muted); }
.av-code { display: flex; gap: 8px; }
.av-code input { width: 100%; min-width: 0; text-align: center; font-size: 1.4rem; font-family: var(--av-font-mono, monospace); padding: 10px 0; }
@media (max-width: 991.98px) { .av-auth { grid-template-columns: 1fr; } .av-auth__aside { padding: 20px 24px; gap: 12px; } .av-auth__points, .av-auth__aside .av-auth__lead { display: none; } }

.av-util { min-height: 100dvh; display: flex; flex-direction: column; background: var(--av-bg); }
.av-util__bar { display: flex; justify-content: space-between; align-items: center; padding: 16px clamp(16px, 4vw, 40px); }
.av-util__main { flex: 1; display: grid; place-items: center; padding: 24px clamp(16px, 4vw, 40px) 56px; }
.av-util__box { width: 100%; max-width: 560px; text-align: center; display: grid; gap: 16px; justify-items: center; }
.av-util__box--wide { max-width: 760px; }
.av-util__code { font-size: clamp(4.5rem, 18vw, 9rem); line-height: 1; font-weight: 800; letter-spacing: -0.04em; color: var(--av-accent-text); font-variant-numeric: tabular-nums; margin: 0; }
.av-util__icon { width: 72px; height: 72px; border-radius: 20px; display: grid; place-items: center; font-size: 2rem; background: var(--av-accent-soft); color: var(--av-accent-text); }
.av-util__icon--danger { background: var(--av-danger-soft); color: var(--av-danger); }
.av-util__icon--warning { background: var(--av-warning-soft); color: var(--av-warning); }
.av-countdown { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; width: 100%; margin: 0; padding: 0; list-style: none; }
.av-countdown li { background: var(--av-surface); border: 1px solid var(--av-border); border-radius: var(--av-radius); padding: 14px 6px; }
.av-countdown strong { display: block; font-size: clamp(1.6rem, 6vw, 2.6rem); font-variant-numeric: tabular-nums; line-height: 1.1; }
.av-countdown span { color: var(--av-text-muted); font-size: var(--av-text-sm); }
.av-steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; text-align: left; width: 100%; }
.av-steps li { display: flex; gap: 10px; align-items: center; background: var(--av-surface); border: 1px solid var(--av-border); border-radius: var(--av-radius); padding: 10px 14px; }
[data-bs-theme="dark"] .av-heat td[data-level="4"] { color: #101116; }
.av-auth__aside a.av-auth__brand, .av-auth__aside a.av-auth__brand:hover { color: #fff !important; }
.av-cal__chip[data-text]::before, .av-cal__more[data-text]::before { content: attr(data-text); }

/* Static layout helpers (replace former inline styles) */
.av-min-240 { min-width: 240px; }
.av-col-check { width: 44px; }
.progress--thin { height: 6px; }
.av-spec--2 { grid-template-columns: repeat(2, 1fr); }
.av-util__bar .av-auth__brand { color: var(--av-text); }
