/* =========================================================
   PLATFORM CONSOLE
   Superadmin home: org cards with "Open workspace" up front, then
   people, AI usage, service health and the audit trail.
========================================================= */

/* every console control is a comfortable touch target */
#page-admin .btn { min-height: 44px; }

/* ---------- tabs and toolbars ---------- */

.ac-tabs { overflow-x: auto; scrollbar-width: none; }
.ac-tabs .tab { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font-size: 12.5px; white-space: nowrap; }
.ac-tab-count { min-width: 20px; padding: 1px 7px; border-radius: 999px; background: var(--surface-soft); color: var(--text-3); font-size: 10.5px; font-weight: 800; }
.ac-tab-count:empty { display: none; }
.tab.active .ac-tab-count { background: var(--primary-soft-2); color: var(--primary-dark); }

.ac-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }

.ac-search { position: relative; flex: 1 1 320px; max-width: 420px; }
.ac-search svg { position: absolute; left: 11px; top: 50%; width: 15px; height: 15px; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.ac-search .lab-input { min-height: 44px; padding-left: 34px; font-size: 13px; }
.ac-toggle { min-height: 44px; padding-bottom: 0; }

.ac-field-inline { display: flex; flex-direction: column; gap: 5px; }
.ac-field-inline > span { font-size: 11.5px; font-weight: 700; color: var(--text-2); }
.ac-field-inline .lab-select, .ac-field-inline .lab-input { min-height: 44px; min-width: 170px; font-size: 13px; }

.ac-note { margin: 0; font-size: 12px; color: var(--text-3); }
.ac-muted { font-size: 11.5px; color: var(--text-3); }

/* ---------- organization cards ---------- */

.ac-org-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }

.ac-org {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.ac-org { position: relative; }
.ac-org:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.ac-org.is-archived { background: var(--surface-soft); box-shadow: none; }
.ac-org.is-archived .ac-mark { background: var(--border-strong); color: var(--text-2); }

.ac-org-top { display: flex; align-items: flex-start; gap: 12px; }

.ac-mark {
    flex: 0 0 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: var(--primary-gradient);
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: .02em;
}

.ac-org-title { flex: 1; min-width: 0; }
.ac-org-title h3 { margin: 0; font-size: 15px; font-weight: 800; color: var(--text); overflow-wrap: anywhere; }
.ac-org-title p { margin: 2px 0 0; font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ac-chip { display: inline-flex; align-items: center; gap: 5px; flex: none; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.ac-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.ac-chip.is-active { background: var(--success-soft); color: var(--success); }
.ac-chip.is-inactive { background: var(--warning-soft); color: var(--warning); }
.ac-chip.is-banned { background: var(--danger-soft); color: var(--danger); }
.ac-chip.is-archived { background: var(--surface); border: 1px solid var(--border-strong); color: var(--text-2); }

.ac-org-meta { display: grid; grid-template-columns: 1fr 1.5fr 1fr; gap: 10px; margin: 0; padding: 12px 0 0; border-top: 1px solid var(--border); }
.ac-org-meta div { min-width: 0; }
.ac-org-meta dt { font-size: 11px; font-weight: 700; color: var(--text-3); }
.ac-org-meta dd { margin: 3px 0 0; font-size: 12px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-org code, .ac-table code { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 11.5px; color: var(--text-2); }

.ac-org-link { padding: 0; margin: 0; border: 0; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.ac-org-link::after { content: ""; position: absolute; inset: 0; border-radius: 16px; }
.ac-org-link:focus-visible { outline: none; }
.ac-org-link:focus-visible::after { outline: 2px solid var(--primary); outline-offset: 2px; }
.ac-org:has(.ac-org-link) { cursor: pointer; }
.ac-org-actions { position: relative; z-index: 1; display: flex; gap: 8px; margin-top: auto; }
.ac-org-actions .btn { min-height: 44px; padding: 0 16px; font-size: 12.5px; }
.ac-org-actions .btn-primary { flex: 1; }
.ac-archive { color: var(--text-2); }
.ac-archive:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- tables ---------- */

.ac-card { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; }
.ac-table { min-width: 720px; }
.ac-table th { font-size: 12px; font-weight: 700; text-transform: none; letter-spacing: 0; padding: 11px 14px; }
.ac-table td { padding: 12px 14px; font-size: 12.5px; color: var(--text-2); }
.ac-table tbody tr { cursor: default; }
.ac-table .is-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ac-table .is-action { text-align: right; }
.ac-table .is-action .btn { min-height: 44px; padding: 0 14px; font-size: 12px; }
.ac-table tr.is-skeleton:hover { background: transparent; }
.ac-strong { display: block; color: var(--text); font-weight: 700; }
.ac-sub { display: block; margin-top: 2px; }

.ac-person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ac-person b { display: block; color: var(--text); font-weight: 700; }
.ac-person-text { display: block; min-width: 0; text-align: left; }
.ac-person-text span { display: block; font-size: 11.5px; font-weight: 400; color: var(--text-3); overflow-wrap: anywhere; }
.ac-person-btn { width: 100%; min-height: 44px; padding: 4px 8px; margin: 0 -8px; border: 0; border-radius: 10px; background: none; font: inherit; cursor: pointer; }
.ac-person-btn:hover { background: var(--surface-soft); }
.ac-person-btn:focus-visible, .ac-link:focus-visible, .ac-dcard :focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.ac-avatar { flex: 0 0 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: var(--primary-soft-2); color: var(--primary-dark); font-size: 11.5px; font-weight: 800; }

.ac-role { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; text-transform: capitalize; background: var(--surface-soft); color: var(--text-2); }
.ac-role.is-admin { background: var(--primary-soft-2); color: var(--primary-dark); }
.ac-role.is-superadmin { background: var(--purple-soft); color: var(--purple); }

.ac-share { display: flex; align-items: center; gap: 8px; min-width: 140px; font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ac-share-bar { flex: 1; height: 6px; border-radius: 999px; background: var(--surface-soft); overflow: hidden; }
.ac-share-bar i { display: block; height: 100%; border-radius: inherit; background: var(--primary); }

/* audit */
.ac-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-bottom: 14px; }
.ac-filters .ac-field-inline .lab-input, .ac-filters .ac-field-inline .lab-select { min-width: 140px; }
.ac-filter-actions { display: flex; gap: 6px; margin-left: auto; }
.ac-filter-actions .btn { min-height: 44px; padding: 0 16px; font-size: 12px; }
.ac-time { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text-3); }
.ac-route { overflow-wrap: anywhere; }

.ac-method { display: inline-block; min-width: 52px; padding: 2px 6px; margin-right: 4px; border-radius: 5px; text-align: center; font-size: 10.5px; font-weight: 800; background: var(--surface-soft); color: var(--text-2); }
.ac-method.is-post, .ac-method.is-put, .ac-method.is-patch { background: var(--primary-soft-2); color: var(--primary-dark); }
.ac-method.is-delete { background: var(--danger-soft); color: var(--danger); }

.ac-status { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ac-status.is-ok { background: var(--success-soft); color: var(--success); }
.ac-status.is-warn { background: var(--warning-soft); color: var(--warning); }
.ac-status.is-bad { background: var(--danger-soft); color: var(--danger); }

.ac-pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ac-pager:empty { display: none; }
.ac-pager-buttons { display: flex; gap: 6px; }
.ac-pager .btn { min-height: 44px; padding: 0 14px; font-size: 12px; }

/* ---------- health ---------- */

.ac-health-summary { display: flex; align-items: center; gap: 14px; padding: 16px 18px; margin-bottom: 12px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface); }
.ac-health-summary b { font-size: 15px; color: var(--text); }
.ac-health-summary p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-2); }
.ac-health-summary.is-ok { border-color: var(--success-soft); background: var(--success-soft); }
.ac-health-summary.is-bad { border-color: var(--danger-soft); background: var(--danger-soft); }

.ac-pulse { position: relative; flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--success); }
.is-bad .ac-pulse { background: var(--danger); }
.ac-pulse::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid currentColor; color: inherit; opacity: 0; animation: ac-pulse 2.4s ease-out infinite; }
.is-ok .ac-pulse::after { color: var(--success); }
.is-bad .ac-pulse::after { color: var(--danger); }
@keyframes ac-pulse { 0% { opacity: .6; transform: scale(.6); } 100% { opacity: 0; transform: scale(1.4); } }

.ac-health-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.ac-dep { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 16px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-sm); }
.ac-dep h3 { margin: 0; font-size: 13.5px; font-weight: 800; color: var(--text); }
.ac-dep p { flex-basis: 100%; margin: 0; font-size: 12px; color: var(--danger); overflow-wrap: anywhere; }
.ac-dep.is-bad { border-color: var(--danger-soft); }

/* ---------- states ---------- */

.ac-empty { grid-column: 1 / -1; padding: 40px 20px; text-align: center; border: 1px dashed var(--border-strong); border-radius: 16px; }
.ac-table .ac-empty { border: 0; }
.ac-empty-mark { display: grid; place-items: center; width: 40px; height: 40px; margin: 0 auto; border-radius: 12px; background: var(--surface-soft); border: 1px solid var(--border); color: var(--text-3); }
.ac-empty-mark svg { width: 18px; height: 18px; }
.ac-empty h3 { margin: 10px 0 0; font-size: 14px; color: var(--text); }
.ac-empty p { max-width: 380px; margin: 4px auto 0; font-size: 12.5px; color: var(--text-3); }

.ac-error { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 14px; border-radius: 12px; background: var(--danger-soft); color: var(--danger); font-size: 12.5px; font-weight: 700; }
.ac-error .btn { min-height: 44px; }

.ac-skeleton {
    display: block;
    border-radius: 16px;
    background: linear-gradient(90deg, var(--surface-soft) 0%, var(--surface-hover) 50%, var(--surface-soft) 100%);
    background-size: 200% 100%;
    animation: ac-shimmer 1.4s ease-in-out infinite;
}
.ac-skeleton.is-card { height: 188px; }
.ac-skeleton.is-tall { height: 260px; }
.ac-skeleton.is-line { height: 12px; border-radius: 6px; }
.ac-skeleton.is-value { width: 64px; height: 24px; border-radius: 6px; }
@keyframes ac-shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
    .ac-skeleton, .ac-pulse::after { animation: none; }
}

/* ---------- organization detail ---------- */

#acMain[hidden], #acDetail[hidden] { display: none; }
#acDetail .ac-toolbar { align-items: flex-end; }

.ac-dhead { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; padding: 20px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-sm); }
.ac-mark-lg { flex: 0 0 56px; height: 56px; font-size: 18px; border-radius: 16px; }
.ac-dhead-main { flex: 1 1 280px; min-width: 0; }
.ac-dhead-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ac-dhead-title h2 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -.02em; color: var(--text); overflow-wrap: anywhere; }
.ac-dhead-title h2:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; border-radius: 6px; }
.ac-dhead-meta { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 10px 0 0; }
.ac-dhead-meta dt { font-size: 11px; font-weight: 700; color: var(--text-3); }
.ac-dhead-meta dd { margin: 2px 0 0; font-size: 12.5px; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.ac-dhead-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ac-dhead-actions .btn { min-height: 44px; padding: 0 16px; font-size: 12.5px; }

.ac-dgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 12px; align-items: start; }
.ac-dcard { padding: 18px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-sm); min-width: 0; }
.ac-dcard-wide { grid-column: 1 / -1; }
.ac-dcard h3 { margin: 0 0 10px; font-size: 14px; font-weight: 800; color: var(--text); }
.ac-dsub, .ac-pgroup h4 { margin: 16px 0 8px; font-size: 12.5px; font-weight: 800; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.ac-big { margin: 0; font-size: 40px; line-height: 1.1; font-weight: 800; letter-spacing: -.04em; color: var(--text); font-variant-numeric: tabular-nums; }
.ac-dnote { margin: 4px 0 0; font-size: 12px; color: var(--text-3); }
.ac-dempty { margin: 0; font-size: 12.5px; color: var(--text-3); }
.ac-share-wide { margin-top: 14px; }
.ac-dstats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--border); }
.ac-dstats dt { font-size: 11px; font-weight: 700; color: var(--text-3); }
.ac-dstats dd { margin: 3px 0 0; font-size: 15px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }

.ac-bars, .ac-plist, .ac-events { margin: 0; padding: 0; list-style: none; }
.ac-bars li { padding: 8px 0; }
.ac-bar-top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 5px; font-size: 12.5px; color: var(--text-2); }
.ac-bar-top b { color: var(--text); }
.ac-bars .ac-share-bar { display: block; }

.ac-pgroup h4 { margin-top: 12px; }
.ac-plist .ac-person-btn { margin: 0; }

.ac-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 14px 0; }
.ac-tiles div { display: flex; flex-direction: column; gap: 4px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-soft); }
.ac-tiles dt { order: 2; font-size: 11.5px; font-weight: 700; color: var(--text-2); }
.ac-tiles dd { order: 1; margin: 0; font-size: 22px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.ac-events li { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; padding: 10px 0; border-top: 1px solid var(--border); font-size: 12px; }
.ac-events .ac-route { flex: 1 1 160px; min-width: 0; font-size: 11.5px; color: var(--text-2); }

.ac-link { padding: 0; min-height: 44px; border: 0; background: none; font: inherit; font-weight: 700; color: var(--primary-dark); text-decoration: underline; cursor: pointer; }
.ac-avatar-lg { flex-basis: 48px; width: 48px; height: 48px; font-size: 15px; }
.ac-pdetail-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.ac-pdetail-top .ac-muted { display: block; }
.ac-pdetail { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 0; }
.ac-pdetail dt { font-size: 11px; font-weight: 700; color: var(--text-3); }
.ac-pdetail dd { margin: 3px 0 0; font-size: 13px; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }

/* ---------- dialogs ---------- */

.modal-overlay .ac-modal { width: min(520px, 100%); }
.ac-modal-sub { margin-top: 3px; font-size: 12px; color: var(--text-3); }
.ac-modal .modal-header { align-items: center; }
.ac-close { width: 44px; height: 44px; }
.ac-fieldset { margin: 0 0 16px; padding: 0; border: 0; }
.ac-fieldset legend { margin-bottom: 10px; font-size: 13px; font-weight: 800; color: var(--text); }
.ac-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.ac-field > span { font-size: 12px; font-weight: 700; color: var(--text); }
.ac-field small { font-size: 11px; color: var(--text-3); }
.ac-field .lab-input, .ac-field .lab-select { min-height: 44px; font-size: 13px; }
.ac-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ac-form-error { margin: 4px 0 0; padding: 9px 11px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 12px; font-weight: 700; }
.ac-modal .modal-footer .btn { min-height: 44px; padding: 0 16px; font-size: 12.5px; }

/* ---------- small screens ---------- */

@media (max-width: 640px) {
    #page-admin .page-header { flex-direction: column; }
    #page-admin .page-actions { width: 100%; }
    #page-admin .page-actions .btn { flex: 1; min-height: 44px; }
    .ac-pager { flex-direction: column; align-items: stretch; }
    .ac-pager-pages { justify-content: center; }
    .ac-modal-wide .modal-header { flex-wrap: wrap; gap: 8px; }
    .ac-org-grid { grid-template-columns: 1fr; }
    .ac-org-meta { grid-template-columns: 1fr 1fr; }
    .ac-search { max-width: none; }
    .ac-filters .ac-field-inline { flex: 1 1 calc(50% - 10px); }
    .ac-filters .ac-field-inline .lab-input, .ac-filters .ac-field-inline .lab-select { min-width: 0; width: 100%; }
    .ac-filter-actions { width: 100%; }
    .ac-filter-actions .btn { flex: 1; min-height: 44px; }
    .ac-field-row, .ac-pdetail { grid-template-columns: 1fr; }
    .ac-dhead { padding: 16px; }
    .ac-dhead-actions { width: 100%; }
    .ac-dhead-actions .btn { flex: 1 1 auto; }
    .ac-dstats { grid-template-columns: 1fr 1fr; }
    #acDetail .ac-toolbar > * { flex: 1 1 100%; }
    #acDetail .ac-field-inline .lab-select { width: 100%; }
}


/* ---------- overview, spend charts, pager ---------- */

#page-admin :focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

:root {
    --mix-1: #0071db; --mix-2: #12855f; --mix-3: #c2410c;
    --mix-4: #7c3aed; --mix-5: #0e7490; --mix-6: #be185d;
}

.ac-ov-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.ac-usage-charts { display: grid; gap: 12px; margin-bottom: 14px; }
.ac-usage-charts:empty { display: none; }
.ac-span { grid-column: 1 / -1; }
.ac-mix-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 12px; }
.ac-pad { padding: 16px 18px; }
.ac-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px 16px; flex-wrap: wrap; margin-bottom: 10px; }
.ac-card-head h3 { margin: 0; font-size: 14px; font-weight: 800; color: var(--text); }
.ac-card-head .ac-dnote { margin: 0; }
.ac-chart-card { padding: 16px 18px 12px; }
.ac-chart { position: relative; min-height: 240px; }
.ac-chart .chart-svg:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
.ac-chart-table { margin-top: 8px; font-size: 12px; color: var(--text-2); }
.ac-chart-table summary { min-height: 32px; display: flex; align-items: center; cursor: pointer; font-weight: 700; }
.ac-chart-table .table-wrap { max-height: 240px; overflow: auto; }
.ac-chart-table .ac-table { min-width: 0; }
.ac-skeleton.is-chart { grid-column: 1 / -1; height: 320px; }

/* bars: top organizations */
.ac-bars li { padding: 7px 0; }
.ac-bar-detail { display: block; margin-top: 4px; font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ac-link-row { padding: 0; min-height: 28px; border: 0; background: none; font: inherit; font-weight: 700; color: var(--text); text-align: left; cursor: pointer; }
.ac-link-row:hover { color: var(--primary-dark); text-decoration: underline; }
.ac-table .ac-link-row { display: block; min-height: 0; }

/* feature mix: one stacked bar, wrapped legend */
.ac-mix-bar { display: flex; gap: 2px; height: 14px; margin: 4px 0 16px; border-radius: 7px; overflow: hidden; }
.ac-mix-bar i { min-width: 3px; }
.ac-mix-legend, .ac-mix-all { margin: 0; padding: 0; list-style: none; }
.ac-mix-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 18px; }
.ac-mix-legend li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; column-gap: 8px; align-items: baseline; font-size: 12.5px; }
.ac-mix-legend .ac-mix-calls { grid-column: 2; grid-row: 2; }
.ac-mix-legend .ac-mix-pct { grid-column: 3; text-align: right; }
.ac-swatch { width: 10px; height: 10px; border-radius: 3px; align-self: center; grid-row: 1; }
.ac-mix-name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-mix b { color: var(--text); font-variant-numeric: tabular-nums; }
.ac-mix-calls { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ac-mix-more { margin-top: 12px; font-size: 12px; }
.ac-mix-more summary { min-height: 32px; display: flex; align-items: center; cursor: pointer; font-weight: 700; color: var(--primary-dark); }
.ac-mix-all { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 4px 18px; padding-top: 6px; }
.ac-mix-all li { display: flex; align-items: baseline; gap: 8px; padding: 4px 0; border-top: 1px solid var(--border); color: var(--text-2); }
.ac-mix-all li > span:first-child { flex: 1; min-width: 0; }

/* pager */
.ac-pager { flex-wrap: wrap; }
.ac-pager-flat { margin-top: 12px; padding: 0; border-top: 0; }
.ac-pager-pages { display: flex; align-items: center; gap: 4px; }
.ac-pg { min-width: 36px; min-height: 36px; padding: 0 8px; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--text-2); font: inherit; font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer; }
.ac-pg:hover:not(:disabled) { background: var(--surface-soft); border-color: var(--border); }
.ac-pg.is-current { background: var(--primary-soft-2); border-color: var(--primary-soft); color: var(--primary-dark); }
.ac-pg:disabled { opacity: .4; cursor: default; }
.ac-pg-gap { min-width: 20px; text-align: center; color: var(--text-3); }
.ac-pager-size { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.ac-pager-size .lab-select { min-height: 36px; width: auto; }

/* reloading behind old data */
.is-busy { opacity: .55; transition: opacity var(--transition); pointer-events: none; }

/* sticky headers inside the scrolling table card */
.ac-card .table-wrap { max-height: 70vh; overflow: auto; }
.ac-table thead th { position: sticky; top: 0; z-index: 1; }

/* small helpers */
.ac-copy { display: inline-grid; place-items: center; width: 26px; height: 26px; margin-left: 4px; vertical-align: middle; border: 0; border-radius: 6px; background: none; color: var(--text-3); cursor: pointer; }
.ac-copy:hover { background: var(--surface-soft); color: var(--text); }
.ac-copy svg { width: 14px; height: 14px; }
.ac-org-meta dd { display: flex; align-items: center; }
.ac-org-meta dd code { overflow: hidden; text-overflow: ellipsis; }
.ac-org-actions, .ac-copy { position: relative; z-index: 1; }
.ac-dhead-meta dd { display: flex; align-items: center; }

/* organization popup */
.modal-overlay .ac-modal-wide { width: min(920px, 100%); }
.ac-modal-titlerow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ac-modal-tools { display: flex; align-items: center; gap: 8px; }
.ac-modal-tools .lab-select { min-height: 44px; min-width: 150px; }
.ac-modal-wide .modal-body { display: grid; gap: 12px; }
.ac-modal-wide .modal-body > .ac-skeleton { grid-column: 1 / -1; }

@media (max-width: 800px) {
    .ac-tilegrid-modal { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .is-busy { transition: none; }
    .modal { animation: none; }
}
.ac-modal-wide .modal-header, .ac-modal-wide .modal-footer { position: sticky; z-index: 2; background: var(--surface); }
.ac-modal-wide .modal-header { top: 0; }
.ac-modal-wide .modal-footer { bottom: 0; }

/* =========================================================
   TILE SYSTEM
   One set of tiles, headers and controls for every tab, the
   organization view and the usage popup. Flat and hairline-bordered;
   the AI spend hero is the one element that carries color.
========================================================= */

#page-admin, #page-organization { --ac-radius: 14px; --ac-gap: 12px; --ac-seg-1: var(--primary-dark); --ac-seg-2: #5aa0ea; --ac-seg-3: var(--text-3); }
.ac-org, .ac-card, .ac-dcard, .ac-dhead, .ac-empty, .ac-dep, .ac-health-summary { border-radius: var(--ac-radius); }
.ac-org-link::after { border-radius: var(--ac-radius); }

/* page header */
.ac-phead { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; margin-bottom: 16px; }
.ac-phead-main { min-width: 0; }
.ac-phead-title { margin: 0; font-size: 22px; line-height: 1.15; font-weight: 800; letter-spacing: -.025em; color: var(--text); }
.ac-phead-status { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 4px; margin: 5px 0 0; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.ac-phead-status:empty { display: none; }
.ac-phead-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.ac-updated { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.ac-refresh { width: 44px; height: 44px; }
.ac-refresh svg { width: 18px; height: 18px; }

.ac-health-pill { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; margin-left: 8px; padding: 0 11px; border: 0; border-radius: 999px; font: inherit; font-size: 12px; font-weight: 800; cursor: pointer; }
.ac-health-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.ac-health-pill.is-ok { background: var(--success-soft); color: var(--success); }
.ac-health-pill.is-bad { background: var(--danger-soft); color: var(--danger); }
.ac-health-pill[hidden] { display: none; }

/* segmented period control */
.ac-seg { display: inline-flex; padding: 3px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-soft); }
.ac-seg-btn { min-width: 48px; min-height: 40px; padding: 0 12px; border: 0; border-radius: 9px; background: none; font: inherit; font-size: 12.5px; font-weight: 700; color: var(--text-2); cursor: pointer; transition: background var(--transition), color var(--transition); }
.ac-seg-btn:hover { color: var(--text); }
.ac-seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 800; box-shadow: 0 1px 2px rgba(13, 27, 42, .12); }

/* sort select, filter chips, sortable headers */
.ac-sort { display: flex; align-items: center; gap: 8px; }
.ac-sort > span { font-size: 12px; font-weight: 700; color: var(--text-2); white-space: nowrap; }
.ac-sort .lab-select { min-height: 44px; min-width: 160px; font-size: 13px; }
.ac-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ac-fchip { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 13px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font: inherit; font-size: 12.5px; font-weight: 700; color: var(--text-2); cursor: pointer; transition: background var(--transition), border-color var(--transition), color var(--transition); }
.ac-fchip:hover { border-color: var(--border-strong); color: var(--text); }
.ac-fchip span { font-size: 11px; font-weight: 800; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ac-fchip span:empty { display: none; }
.ac-fchip[aria-pressed="true"] { background: var(--primary-soft-2); border-color: var(--primary-soft); color: var(--primary-dark); }
.ac-fchip[aria-pressed="true"] span { color: var(--primary-dark); }
.ac-sort-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0; border: 0; background: none; font: inherit; font-weight: 700; color: inherit; cursor: pointer; }
.ac-sort-btn::after { content: "\2195"; font-size: 11px; color: var(--text-3); opacity: .6; }
th[aria-sort="ascending"] .ac-sort-btn::after { content: "\2191"; opacity: 1; color: var(--primary-dark); }
th[aria-sort="descending"] .ac-sort-btn::after { content: "\2193"; opacity: 1; color: var(--primary-dark); }
th[aria-sort="ascending"], th[aria-sort="descending"] { color: var(--text); }

/* tiles */
.ac-tile { position: relative; display: flex; flex-direction: column; gap: 6px; min-width: 0; padding: 16px; border: 1px solid var(--border); border-radius: var(--ac-radius); background: var(--surface); overflow: hidden; }
.ac-tile-label { font-size: 12px; font-weight: 700; color: var(--text-2); }
.ac-tile-value { min-height: 30px; font-size: 28px; line-height: 1.1; font-weight: 800; letter-spacing: -.035em; color: var(--text); font-variant-numeric: tabular-nums; }
.ac-tile-note { margin: 0; font-size: 12px; line-height: 1.45; color: var(--text-3); }
.ac-tile.is-key { box-shadow: inset 0 2px 0 var(--primary); }
.ac-tile > .ac-split, .ac-tile > .ac-minibars { margin-top: auto; }
.ac-vs { color: var(--text-3); }

.ac-delta { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px 2px 6px; border-radius: 999px; background: var(--surface-soft); font-size: 12px; font-weight: 800; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ac-delta svg { width: 12px; height: 12px; }
.ac-delta.is-up { background: var(--warning-soft); color: var(--warning); }
.ac-delta.is-down { background: var(--success-soft); color: var(--success); }
.ac-delta.is-new { padding-left: 8px; background: var(--primary-soft-2); color: var(--primary-dark); }

.ac-tilegrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--ac-gap); margin-bottom: var(--ac-gap); }
.ac-tilegrid:empty { display: none; }
.ac-tilegrid-modal { margin-bottom: 0; }
.ac-tile-value:has(.ac-skeleton) { display: flex; align-items: center; }

/* overview bento: the hero takes the left half, four small tiles fill the right */
.ac-bento { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--ac-gap); margin-bottom: var(--ac-gap); }
.ac-bento > .ac-tile { grid-column: span 3; }
.ac-bento > .ac-hero { grid-column: span 6; grid-row: span 2; }

.ac-hero { gap: 4px; padding-bottom: 0; background: linear-gradient(180deg, var(--surface) 35%, var(--primary-soft-2) 100%); }
.ac-hero-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ac-hero-period { font-size: 12px; color: var(--text-3); }
.ac-hero-figure { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; margin-top: 4px; }
.ac-hero-value { font-size: 46px; line-height: 1.05; font-weight: 800; letter-spacing: -.045em; color: var(--text); font-variant-numeric: tabular-nums; }
.ac-hero-chart { display: flex; flex-direction: column; flex: 1; min-height: 130px; margin: 6px -16px 0; }
.ac-spark { flex: 1; display: flex; min-height: 96px; padding: 10px 14px 0; }
.ac-spark-plot { position: relative; flex: 1; }
.ac-spark-plot svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.ac-spark-stop-a { stop-color: var(--primary); stop-opacity: .34; }
.ac-spark-stop-b { stop-color: var(--primary); stop-opacity: 0; }
.ac-spark-line { fill: none; stroke: var(--primary); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.ac-spark-prev { fill: none; stroke: var(--text-3); stroke-width: 1.5; stroke-dasharray: 4 4; opacity: .85; }
.ac-spark-dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; box-sizing: border-box; }
.ac-spark-dot.is-today { background: var(--surface); border: 2.5px solid var(--primary); }
.ac-spark-dot.is-peak { width: 8px; height: 8px; margin: -4px 0 0 -4px; background: var(--primary); border: 2px solid var(--surface); }
.ac-spark-key { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 16px; margin: 0; padding: 8px 16px 10px; border-top: 1px solid var(--border); background: rgba(255, 255, 255, .7); font-size: 11.5px; color: var(--text-2); }
.ac-spark-key span { display: inline-flex; align-items: center; gap: 6px; }
.ac-spark-peak { margin-left: auto; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ac-key { width: 16px; height: 0; border-top: 2.2px solid var(--primary); }
.ac-key.is-prev { border-top: 1.5px dashed var(--text-3); }

.ac-minibars { display: flex; align-items: flex-end; gap: 2px; height: 30px; }
.ac-minibars i { flex: 1; min-width: 2px; border-radius: 2px 2px 0 0; background: var(--primary-soft); }
.ac-minibars i.is-last { background: var(--primary); }

.ac-split { display: flex; gap: 2px; height: 8px; border-radius: 4px; overflow: hidden; background: var(--surface-soft); }
.ac-split i { min-width: 3px; }
.ac-split i.is-1, .ac-swatch.is-1 { background: var(--ac-seg-1); }
.ac-split i.is-2, .ac-swatch.is-2 { background: var(--ac-seg-2); }
.ac-split i.is-3, .ac-swatch.is-3 { background: var(--ac-seg-3); }
.ac-split-legend { display: flex; flex-wrap: wrap; gap: 2px 12px; margin: 6px 0 0; padding: 0; list-style: none; font-size: 11.5px; color: var(--text-2); }
.ac-split-legend li { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.ac-split-legend b { color: var(--text); font-variant-numeric: tabular-nums; }
.ac-split-legend .ac-swatch { width: 8px; height: 8px; border-radius: 2px; align-self: auto; }

/* lower overview grid: daily cost beside the ranking, the feature mix underneath */
.ac-ov-grid > .ac-chart-card { grid-column: span 8; }
.ac-ov-grid > .ac-card-orgs { grid-column: span 4; }
.ac-ov-grid > .ac-card-mix, .ac-ov-grid > .ac-skeleton { grid-column: 1 / -1; }
.ac-chart .chart-line { stroke-width: 2; }

/* ranked bars */
.ac-bars li { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 10px; padding: 9px 0; }
.ac-rank { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 8px; background: var(--surface-soft); font-size: 11.5px; font-weight: 800; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ac-bars li:first-child .ac-rank { background: var(--primary-soft-2); color: var(--primary-dark); }
.ac-bar-top { margin-bottom: 6px; }
.ac-bars .ac-share-bar { height: 8px; }
.ac-bars li:not(:first-child) .ac-share-bar i { opacity: .62; }
.ac-bar-detail b { color: var(--text-2); }

/* organization view */
.ac-dcard .ac-split-legend { margin-top: 8px; }
.ac-dstats { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 14px; }
.ac-dstats dd { font-size: 20px; letter-spacing: -.02em; }
.ac-dstats .ac-dstat-note { margin: 2px 0 0; font-size: 11.5px; font-weight: 400; letter-spacing: 0; color: var(--text-3); }
.ac-tiles div { background: var(--surface); border-radius: 12px; }
.ac-tiles dd { font-size: 24px; letter-spacing: -.03em; }

@media (max-width: 1100px) {
    .ac-bento > .ac-tile { grid-column: span 6; }
    .ac-bento > .ac-hero { grid-column: 1 / -1; grid-row: auto; }
    .ac-tilegrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ac-ov-grid > .ac-chart-card, .ac-ov-grid > .ac-card-orgs { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
    .ac-phead { align-items: stretch; }
    .ac-phead-tools { width: 100%; justify-content: space-between; }
    .ac-seg { flex: 1; }
    .ac-seg-btn { flex: 1; }
    .ac-hero-value { font-size: 38px; }
    .ac-tile-value { font-size: 24px; }
    .ac-bento > .ac-tile { padding: 14px; }
    .ac-sort, .ac-sort .lab-select { width: 100%; }
    .ac-sort { flex-direction: column; align-items: stretch; gap: 5px; }
    .ac-chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -2px; padding: 2px; scrollbar-width: none; }
    .ac-fchip { flex: none; }
}

@media (prefers-reduced-motion: reduce) {
    .ac-seg-btn, .ac-fchip { transition: none; }
}
