/* Analytics (redesign Phase 6: screens 24-31). Page-specific layout on top of the design-system classes
   (stat, card, an-grid, ch*, hbars, share, issue-row, act-grid, modal, drawer). Tokens only.
   #analyticsView is the page; .an-layer is a modal / drawer / popover appended to <body> (also data-ui="v2"). */

#analyticsView { flex: 1; min-height: 0; overflow: auto; padding: var(--s-6) var(--s-8) var(--s-8); background: var(--bg); color: var(--text); }
#analyticsView .an-root { max-width: 1440px; margin: 0 auto; }
#analyticsClassic { display: none !important; } /* retired: kept in the DOM only because the engine still fills it */
#analyticsView .page-head { flex-wrap: wrap; align-items: flex-end; }
#analyticsView .page-head > div:first-child { flex: 1 1 420px; min-width: 0; }
#analyticsView .page-sub { max-width: 640px; font-size: var(--fs-13); }
#analyticsView .page-actions { flex-wrap: wrap; align-items: center; }
#analyticsView .page-actions .select { width: auto; min-width: 150px; height: 34px; }
#analyticsView .an-tabs { padding: 0; margin: 0 0 var(--s-5); overflow-x: auto; scrollbar-width: none; }
#analyticsView .an-tabs::-webkit-scrollbar { display: none; }
#analyticsView .an-tabs .tab { white-space: nowrap; flex: none; }
#analyticsView .an-tabs .tab .ua-ic, #analyticsView .an-tabs .tab svg { color: var(--text-3); }

/* KPI row */
#analyticsView .kpi-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
#analyticsView .kpi-row.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }
#analyticsView .stat { min-height: 124px; }
#analyticsView .stat .l { min-height: 28px; }
#analyticsView .stat .l .an-stat-i { margin-left: auto; }
#analyticsView .stat .v { font-size: var(--fs-24); display: flex; align-items: center; gap: 8px; }
#analyticsView .stat .s { flex-wrap: wrap; line-height: 1.4; }
#analyticsView .stat .s b { color: var(--text-2); font-weight: 600; }
#analyticsView .stat.bad .v { color: var(--danger); }
#analyticsView .stat.good .v { color: var(--success); }
#analyticsView .stat.hero .an-info { color: var(--text-inverse); opacity: 0.8; }
#analyticsView .stat.hero .s b { color: var(--text-inverse); }

/* Panels */
#analyticsView .an-grid { margin-bottom: var(--s-4); }
#analyticsView .an-grid.even { grid-template-columns: 1fr 1fr; }
#analyticsView .an-grid.one { grid-template-columns: 1fr; }
#analyticsView .an-grid.side { grid-template-columns: 340px 1fr; }
#analyticsView .an-grid .wide { grid-column: 1 / -1; }
#analyticsView .an-grid + .an-card, #analyticsView .an-card + .an-card { margin-top: var(--s-4); }
#analyticsView .an-card .card-head { flex-wrap: wrap; row-gap: 4px; }
#analyticsView .an-card .card-head .hint { margin-left: 4px; }
#analyticsView .an-card .card-head .an-right { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; }
#analyticsView .an-pad { padding-top: var(--s-4); }
#analyticsView .an-note { margin: 0 0 var(--s-4); padding: 10px 14px; border-radius: var(--r-md); background: var(--surface-2); color: var(--text-2); font-size: var(--fs-13); display: flex; gap: 8px; align-items: flex-start; }
#analyticsView .an-note.warn { background: var(--warning-soft); color: var(--text); }
#analyticsView .an-note .ua-ic, #analyticsView .an-note svg { flex: none; margin-top: 2px; }
#analyticsView .an-note.warn svg { color: var(--warning); }
#analyticsView .an-foot { margin: var(--s-3) 0 0; font-size: var(--fs-12); color: var(--text-3); line-height: 1.5; }
#analyticsView .an-foot b { color: var(--text-2); }
#analyticsView .activity-strip { flex-wrap: wrap; row-gap: 10px; }
#analyticsView .activity-strip .an-strip-l { font-size: var(--fs-12); font-weight: 600; color: var(--text-3); }
#analyticsView .activity-strip button { display: flex; align-items: baseline; gap: 8px; padding: 0; border-radius: var(--r-sm); }
#analyticsView .activity-strip button:hover span { color: var(--text); }
#analyticsView .activity-strip button .ua-ic, #analyticsView .activity-strip button svg { align-self: center; color: var(--text-3); }

/* Info buttons + popover */
#analyticsView .an-info { width: 22px; height: 22px; color: var(--text-3); flex: none; }
#analyticsView .an-info:hover { color: var(--text); }
.an-layer.an-pop { position: fixed; z-index: 130; padding: var(--s-3) var(--s-4); background: var(--surface-3); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-3); font-size: var(--fs-13); line-height: 1.5; }
.an-layer.an-pop .an-pop-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.an-layer.an-pop .an-pop-head b { font-size: var(--fs-14); font-weight: 600; }
.an-layer.an-pop .an-pop-x { margin-left: auto; }
.an-layer.an-pop .an-pop-sec { color: var(--text-2); margin-top: 8px; }
.an-layer.an-pop .an-pop-sec span { display: block; font-size: var(--fs-11); font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 2px; }

/* Tables */
#analyticsView .an-tw, .an-layer .an-tw { overflow-x: auto; margin: 0 -2px; }
#analyticsView .an-tw .table { min-width: 100%; }
#analyticsView .an-tw.wide-table .table { min-width: 1180px; }
#analyticsView .table td, .an-layer .table td { font-variant-numeric: tabular-nums; }
#analyticsView .table tbody tr:not([data-lead]), .an-layer .table tbody tr:not([data-lead]) { cursor: default; }
#analyticsView .table tbody tr:not([data-lead]):hover, .an-layer .table tbody tr:not([data-lead]):hover { background: transparent; }
#analyticsView .table th.an-sortable { cursor: pointer; }
#analyticsView .table th.an-sortable:hover { color: var(--text); }
#analyticsView .table th[data-dir="asc"]::after { content: " \2191"; }
#analyticsView .table th[data-dir="desc"]::after { content: " \2193"; }
#analyticsView .table td.an-wrap, .an-layer .table td.an-wrap { white-space: normal; min-width: 220px; line-height: 1.45; padding-top: 8px; padding-bottom: 8px; color: var(--text-2); font-size: var(--fs-12); }
#analyticsView .table td.empty-row, .an-layer .table td.empty-row { text-align: center; color: var(--text-3); white-space: normal; }
#analyticsView .an-who, #analyticsView .an-stage, #analyticsView .cell-deal, .an-layer .an-who { display: inline-flex; align-items: center; gap: 8px; }
#analyticsView .cell-deal { max-width: 280px; }
#analyticsView .cell-deal > span:last-child { overflow: hidden; text-overflow: ellipsis; }
#analyticsView .t-good { color: var(--success); }
#analyticsView .t-bad { color: var(--danger); }
#analyticsView .t-warn { color: var(--warning); }
#analyticsView .an-trend { display: inline-flex; align-items: center; gap: 4px; }
#analyticsView .an-score { display: flex; align-items: center; gap: 10px; min-width: 160px; }
#analyticsView .an-score .prog { height: 8px; }
#analyticsView .an-score b { width: 40px; font-size: var(--fs-12); text-align: right; }
#analyticsView .an-row-actions { display: flex; gap: 4px; justify-content: flex-end; }
#analyticsView .an-inp { width: 120px; height: 32px; }
#analyticsView .an-inp.invalid, .an-layer .an-inp.invalid { border-color: var(--danger); }
#analyticsView .an-inp.saved { border-color: var(--success); }

/* Toolbars inside a tab (targets, activity log) */
#analyticsView .sec-tools .select, #analyticsView .sec-tools .input { width: auto; height: 34px; }
#analyticsView .sec-tools .an-lbl { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-12); color: var(--text-3); font-weight: 600; }
#analyticsView .an-switch { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-12); color: var(--text-2); cursor: pointer; }
#analyticsView .an-switch .switch { margin-left: 0; }

/* Charts */
#analyticsView .ch .ch-hit { fill: transparent; }
#analyticsView .ch .ch-cross { display: none; }
#analyticsView .ch.on .ch-cross { display: inline; }
#analyticsView .hb-row { grid-template-columns: var(--lw, 150px) 1fr; }
#analyticsView .hb-row .hb-label em { margin-left: 2px; }
#analyticsView .an-empty-chart { display: grid; place-items: center; gap: 8px; min-height: 180px; text-align: center; color: var(--text-3); font-size: var(--fs-13); padding: var(--s-4); }
#analyticsView .an-sub-title { margin: var(--s-6) 0 var(--s-3); }
#analyticsView .share-legend { grid-template-columns: 1fr; }

/* Empty, locked, loading */
#analyticsView .empty { gap: 10px; padding: var(--s-10) var(--s-6); }
#analyticsView .empty .ua-ic, #analyticsView .empty svg { color: var(--text-3); }
#analyticsView .empty b { color: var(--text); font-size: var(--fs-14); }
#analyticsView .empty p { margin: 0; max-width: 460px; line-height: 1.5; }

/* Issues list */
#analyticsView .issue-row.clean svg { color: var(--success); }
#analyticsView .issue-row .chip { margin-left: 4px; }

/* Activity log */
#analyticsView .act-wrap { overflow: auto; max-height: calc(100dvh - 330px); min-height: 240px; }
#analyticsView .act-grid { min-width: 100%; }
#analyticsView .act-grid th { position: sticky; top: 0; z-index: 2; background: var(--surface); text-align: center; }
#analyticsView .act-grid th:first-child, #analyticsView .act-grid tbody th, #analyticsView .act-grid tfoot th { position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; font-weight: 500; color: var(--text-2); white-space: nowrap; padding-right: 12px !important; }
#analyticsView .act-grid thead th:first-child { z-index: 3; }
#analyticsView .act-grid td { text-align: center; }
#analyticsView .act-grid tfoot td, #analyticsView .act-grid tfoot th { border-top: 1px solid var(--border); font-weight: 600; height: 40px; }
#analyticsView .act-grid tr.we th, #analyticsView .act-grid tr.we td { color: var(--text-3); }
#analyticsView .act-grid tr.we td .act-cell { opacity: 0.75; }
#analyticsView .act-person { display: inline-flex; flex-direction: column; align-items: center; gap: 4px; font-size: var(--fs-11); font-weight: 600; color: var(--text-2); padding: 4px; border-radius: var(--r-sm); max-width: 76px; }
#analyticsView .act-person:hover { color: var(--text); background: var(--surface-hover); }
#analyticsView .act-person span:last-child { max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#analyticsView .act-cell { color: var(--text); background: var(--surface-2); }
#analyticsView .act-cell.zero { background: transparent; color: var(--text-3); font-weight: 400; }
#analyticsView .act-cell.s1 { background: var(--seq-1); color: var(--text); }
#analyticsView .act-cell.s2 { background: var(--seq-2); color: var(--text); }
#analyticsView .act-cell.s3 { background: var(--seq-3); color: var(--text-inverse); }
#analyticsView .act-cell.s4 { background: var(--seq-4); color: var(--text-inverse); }
:root:not([data-theme='light']) #analyticsView .act-cell.s3 { color: var(--text); }
#analyticsView .act-key { display: inline-block; width: 14px; height: 14px; border-radius: 4px; }
#analyticsView .act-totlink { font-weight: 600; color: var(--text); padding: 2px 6px; border-radius: var(--r-sm); }
#analyticsView .act-totlink:hover { background: var(--surface-hover); }

/* Activity day-log drawer */
.an-layer.an-drawer .drawer { width: min(640px, 100vw); }
.an-layer.an-drawer .dw-sub { margin-top: 6px; }
.an-layer.an-drawer .an-dw-tools { display: flex; flex-direction: column; gap: 10px; padding: var(--s-4) 24px 0; }
.an-layer.an-drawer .an-dw-tools .sec-tools { margin: 0; }
.an-layer.an-drawer .an-dw-tools .select, .an-layer.an-drawer .an-dw-tools .input { width: auto; height: 32px; font-size: var(--fs-12); }
.an-layer.an-drawer .an-dw-tools .input[type=search] { flex: 1; min-width: 180px; }
.an-layer.an-drawer .kpi-mini { grid-template-columns: repeat(4, 1fr); margin: 0; }
.an-layer.an-drawer .kpi-mini b { font-size: var(--fs-16); }
.an-layer.an-drawer .act-day-h { display: flex; align-items: baseline; gap: 8px; margin: var(--s-5) 0 var(--s-2); font-size: var(--fs-12); font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
.an-layer.an-drawer .act-day-h:first-child { margin-top: 0; }
.an-layer.an-drawer .act-entries { list-style: none; margin: 0; padding: 0; }
.an-layer.an-drawer .act-entry { border-bottom: 1px solid var(--divider); }
.an-layer.an-drawer .act-entry-row { display: grid; grid-template-columns: 48px 108px 1fr 16px; gap: 10px; align-items: flex-start; padding: 10px 0; font-size: var(--fs-13); cursor: pointer; }
.an-layer.an-drawer .act-entry-row.static { cursor: default; }
.an-layer.an-drawer .act-entry-row:hover .act-entity { color: var(--brand-text); }
.an-layer.an-drawer .act-entry-row:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--r-sm); }
.an-layer.an-drawer .act-time { color: var(--text-3); font-size: var(--fs-12); padding-top: 2px; font-variant-numeric: tabular-nums; }
.an-layer.an-drawer .act-entry-row .chip { justify-content: center; max-width: 108px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-layer.an-drawer .act-main { min-width: 0; color: var(--text-2); line-height: 1.5; }
.an-layer.an-drawer .act-main .act-entity { font-weight: 600; color: var(--text); }
.an-layer.an-drawer .act-main .act-entity a { color: inherit; }
.an-layer.an-drawer .act-main .act-sum { display: block; font-size: var(--fs-12); color: var(--text-3); overflow-wrap: anywhere; }
.an-layer.an-drawer .act-main .act-sum b { color: var(--text-2); font-weight: 600; }
.an-layer.an-drawer .act-caret { color: var(--text-3); padding-top: 2px; }
.an-layer.an-drawer .act-detail { padding: 0 0 12px 58px; display: flex; flex-direction: column; gap: 10px; font-size: var(--fs-12); }
.an-layer.an-drawer .act-text { white-space: pre-wrap; color: var(--text); background: var(--surface-2); border-radius: var(--r-md); padding: 10px 12px; font-size: var(--fs-13); }
.an-layer.an-drawer .act-detail table { width: 100%; border-collapse: collapse; }
.an-layer.an-drawer .act-detail td, .an-layer.an-drawer .act-detail th { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--divider); vertical-align: top; overflow-wrap: anywhere; }
.an-layer.an-drawer .act-detail th { color: var(--text-3); font-weight: 600; }
.an-layer.an-drawer .act-detail .act-before { color: var(--text-3); text-decoration: line-through; }
.an-layer.an-drawer .act-detail .act-after { color: var(--text); }
.an-layer.an-drawer .act-detail summary { cursor: pointer; color: var(--text-2); font-weight: 600; }
.an-layer.an-drawer .act-meta { color: var(--text-3); }
.an-layer.an-drawer .act-via { margin-left: 4px; }
.an-layer.an-drawer .act-more { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: var(--s-4) 0; font-size: var(--fs-12); color: var(--text-3); }

/* Modals: summary, plan editor, account detail */
.an-layer.an-modal .modal { width: min(880px, calc(100vw - 32px)); top: 6vh; max-height: 88vh; }
.an-layer.an-modal .modal.md { width: min(720px, calc(100vw - 32px)); }
.an-layer.an-modal .modal-head .an-x { margin-left: auto; }
.an-layer.an-modal .an-mic { width: 34px; height: 34px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--violet-soft); color: var(--violet); flex: none; }
.an-layer.an-modal .an-mic.ok { background: var(--success-soft); color: var(--success); }
.an-layer.an-modal .modal-head .hint { display: block; margin-top: 2px; }
.an-layer.an-modal .modal-foot .hint { margin-right: auto; }
.an-layer.an-modal .an-sec { font-size: var(--fs-12); font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.07em; margin: var(--s-5) 0 var(--s-3); }
.an-layer.an-modal .an-sec:first-child { margin-top: 0; }
.an-layer.an-modal .glance li { font-size: var(--fs-13); }
.an-layer.an-modal ol.glance { counter-reset: none; }
.an-layer.an-modal .an-rep { border: 1px solid var(--border); border-radius: var(--r-xl); padding: var(--s-4) var(--s-5); margin-bottom: var(--s-3); background: var(--surface); }
.an-layer.an-modal .an-rep-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.an-layer.an-modal .an-rep-head b { font-size: var(--fs-14); font-weight: 600; }
.an-layer.an-modal .an-rep-stats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.an-layer.an-modal .an-rep-cols { display: grid; grid-template-columns: 1fr 1.4fr; gap: var(--s-5); margin-top: var(--s-4); }
.an-layer.an-modal .an-col-l { font-size: var(--fs-12); font-weight: 600; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.an-layer.an-modal .an-col-l.good { color: var(--success); }
.an-layer.an-modal .an-col-l.next { color: var(--warning); }
.an-layer.an-modal .an-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; font-size: var(--fs-13); color: var(--text-2); line-height: 1.5; }
.an-layer.an-modal .an-list .chip { margin-right: 6px; height: 20px; font-size: var(--fs-11); }
.an-layer.an-modal .an-list a, .an-layer.an-modal .glance a { color: var(--text); text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
.an-layer.an-modal .an-list a:hover, .an-layer.an-modal .glance a:hover { color: var(--brand-text); }
.an-layer.an-modal .an-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 20px; margin: 0 0 var(--s-4); font-size: var(--fs-13); }
.an-layer.an-modal .an-facts div { display: flex; flex-direction: column; gap: 2px; }
.an-layer.an-modal .an-facts span { font-size: var(--fs-12); color: var(--text-3); }
.an-layer.an-modal .an-form { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }
.an-layer.an-modal .an-form .span-2 { grid-column: 1 / -1; }
.an-layer.an-modal .an-form .field small { font-size: var(--fs-12); color: var(--text-3); line-height: 1.4; }
.an-layer.an-modal .an-form-err { color: var(--danger); font-size: var(--fs-13); }
.an-layer.an-modal .an-form-err:empty { display: none; }
.an-layer.an-modal .table { min-width: 720px; }
.an-layer.an-modal .table td { height: 42px; }
.an-layer.an-modal .table .an-inp { width: 110px; height: 30px; }
.an-layer.an-modal .an-total { margin: var(--s-3) 0 0; font-size: var(--fs-13); color: var(--text-2); }

@media (max-width: 1200px) {
    #analyticsView .kpi-row.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
    #analyticsView .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #analyticsView .an-grid, #analyticsView .an-grid.even, #analyticsView .an-grid.side { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    #analyticsView { padding: var(--s-4); }
    #analyticsView .page-title { font-size: var(--fs-24); }
    #analyticsView .page-actions { margin-left: 0; width: 100%; }
    #analyticsView .page-actions .select { flex: 1 1 140px; min-width: 0; }
    #analyticsView .kpi-row, #analyticsView .kpi-row.six { grid-template-columns: 1fr 1fr; gap: var(--s-2); }
    #analyticsView .stat { min-height: 104px; padding: 14px; }
    #analyticsView .stat .v { font-size: var(--fs-20); }
    #analyticsView .activity-strip { gap: 14px 20px; }
    #analyticsView .hb-row { grid-template-columns: 110px 1fr !important; }
    #analyticsView .dv-row { grid-template-columns: 1fr 96px 1fr; }
    #analyticsView .dv-label { white-space: normal; font-size: var(--fs-12); line-height: 1.2; }
    #analyticsView .act-wrap { max-height: none; }
    .an-layer.an-modal .an-rep-cols, .an-layer.an-modal .an-form, .an-layer.an-modal .an-facts { grid-template-columns: 1fr; }
    .an-layer.an-drawer .kpi-mini { grid-template-columns: 1fr 1fr; }
    .an-layer.an-drawer .act-entry-row { grid-template-columns: 44px 1fr 14px; }
    .an-layer.an-drawer .act-entry-row .chip { display: none; }
    .an-layer.an-drawer .act-detail { padding-left: 0; }
}
#analyticsView .sec-tools .chip { white-space: normal; height: auto; min-height: 22px; padding-top: 3px; padding-bottom: 3px; line-height: 1.35; max-width: 100%; }
