:root {
  color-scheme: dark;
  --bg: #09111d;
  --bg-soft: #0f1a2a;
  --panel: rgba(17, 29, 46, .88);
  --panel-solid: #111d2e;
  --panel-raised: #16263b;
  --line: rgba(165, 188, 212, .14);
  --line-strong: rgba(165, 188, 212, .25);
  --text: #e9f1f8;
  --text-soft: #a8b7c8;
  --text-faint: #71849a;
  --accent: #62d0c3;
  --accent-strong: #8ce7db;
  --accent-blue: #77a9ef;
  --warn: #f3be71;
  --danger: #f38a87;
  --radius: 18px;
  --shadow: 0 20px 60px rgba(0, 0, 0, .25);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; max-width: 100%; overflow-x: hidden; background: var(--bg); }
body { max-width: 100%; margin: 0; min-height: 100vh; overflow-x: hidden; color: var(--text); background: radial-gradient(circle at 15% -10%, rgba(70, 124, 174, .18), transparent 34rem), var(--bg); line-height: 1.45; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(98, 208, 195, .65); outline-offset: 3px; }
a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: .75rem; left: .75rem; z-index: 20; padding: .65rem .85rem; border-radius: 9px; color: var(--bg); background: var(--accent); transform: translateY(-160%); transition: transform .2s ease; }
.skip-link:focus { transform: translateY(0); }
.ambient { position: fixed; z-index: -1; width: 30rem; height: 30rem; pointer-events: none; border-radius: 999px; filter: blur(80px); opacity: .12; }
.ambient-a { top: 18%; right: -18rem; background: var(--accent-blue); }
.ambient-b { bottom: -20rem; left: -12rem; background: var(--accent); }
.login-view { display: grid; min-height: 100vh; place-items: center; padding: 2rem 1rem; }
.login-card { width: min(100%, 440px); padding: clamp(1.5rem, 5vw, 3rem); border: 1px solid var(--line); border-radius: 24px; background: linear-gradient(150deg, rgba(23, 40, 62, .95), rgba(12, 22, 36, .96)); box-shadow: var(--shadow); }
.brand-mark { display: grid; width: 3.35rem; height: 3.35rem; margin-bottom: 2.25rem; place-items: center; border: 1px solid rgba(98, 208, 195, .4); border-radius: 12px; color: var(--accent); background: rgba(98, 208, 195, .08); }
.brand-mark svg { width: 2rem; height: 2rem; }
.eyebrow { margin: 0 0 .55rem; color: var(--accent); font-size: .7rem; font-weight: 750; letter-spacing: .16em; line-height: 1.2; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .7rem; font-size: clamp(1.7rem, 4vw, 2.6rem); letter-spacing: -.04em; line-height: 1.05; }
h2 { margin-bottom: 0; font-size: 1.2rem; letter-spacing: -.025em; }
h3 { margin: 0; font-size: .95rem; }
.login-lead { max-width: 31rem; margin-bottom: 2rem; color: var(--text-soft); }
.login-form { display: grid; gap: .65rem; }
.login-form label, .period-control label { color: var(--text-soft); font-size: .8rem; font-weight: 650; }
.password-wrap { position: relative; }
input, select { min-height: 2.75rem; color: var(--text); border: 1px solid var(--line-strong); border-radius: 10px; background: rgba(5, 13, 24, .55); }
input { width: 100%; padding: .7rem .8rem; }
select { width: 100%; padding: .55rem 2rem .55rem .75rem; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%), linear-gradient(135deg, var(--text-faint) 50%, transparent 50%); background-position: calc(100% - 15px) 1.2rem, calc(100% - 10px) 1.2rem; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
input::placeholder { color: var(--text-faint); }
.password-wrap input { padding-right: 3rem; }
.icon-button { position: absolute; top: 50%; right: .55rem; display: grid; width: 2rem; height: 2rem; place-items: center; color: var(--text-soft); border: 0; border-radius: 8px; background: transparent; transform: translateY(-50%); }
.button { display: inline-flex; min-height: 2.55rem; align-items: center; justify-content: center; gap: .55rem; padding: .55rem .9rem; border: 1px solid transparent; border-radius: 10px; color: var(--text); font-size: .82rem; font-weight: 700; transition: border-color .2s ease, background .2s ease, color .2s ease, transform .2s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { color: #08151d; background: var(--accent); }
.button-primary:hover { background: var(--accent-strong); }
.button-secondary { border-color: var(--line-strong); background: rgba(255,255,255,.035); }
.button-secondary:hover { border-color: rgba(98,208,195,.5); background: rgba(98,208,195,.08); }
.button-quiet { padding-inline: .65rem; color: var(--text-soft); border-color: transparent; background: transparent; }
.button-quiet:hover { color: var(--text); background: rgba(255,255,255,.06); }
.button-full { width: 100%; margin-top: .7rem; }
.form-feedback, .inline-feedback { min-height: 1.2rem; margin: .15rem 0 0; color: var(--danger); font-size: .78rem; }
.security-note { display: flex; align-items: center; gap: .5rem; margin: 2.2rem 0 0; color: var(--text-faint); font-size: .72rem; }
.status-dot { display: inline-block; width: .48rem; height: .48rem; flex: 0 0 auto; border-radius: 999px; background: var(--warn); box-shadow: 0 0 0 .2rem rgba(243, 190, 113, .12); }
.status-dot-ok { background: var(--accent); box-shadow: 0 0 0 .2rem rgba(98,208,195,.12); }
.status-dot-danger { background: var(--danger); box-shadow: 0 0 0 .2rem rgba(243,138,135,.12); }
.app-view { min-width: 0; min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 10; border-bottom: 1px solid var(--line); background: rgba(9,17,29,.84); backdrop-filter: blur(18px); }
.topbar-inner { display: flex; max-width: 1440px; min-height: 4.8rem; align-items: center; justify-content: space-between; gap: 1rem; margin: 0 auto; padding: 0 clamp(1rem, 4vw, 3.5rem); }
.wordmark { display: inline-flex; align-items: center; gap: .65rem; text-decoration: none; }
.wordmark-symbol { display: grid; width: 1.9rem; height: 1.9rem; place-items: center; color: var(--bg); border-radius: 7px; background: var(--accent); font-weight: 900; }
.wordmark strong, .wordmark small { display: block; line-height: 1.05; }
.wordmark strong { font-size: .78rem; letter-spacing: .12em; }
.wordmark small { margin-top: .25rem; color: var(--text-faint); font-size: .52rem; font-weight: 750; letter-spacing: .12em; }
.topbar-actions { display: flex; align-items: center; gap: .6rem; }
.sync-pill { display: inline-flex; max-width: 18rem; align-items: center; gap: .55rem; padding: .5rem .7rem; color: var(--text-soft); border: 1px solid var(--line); border-radius: 99px; font-size: .7rem; white-space: nowrap; }
.main-shell { max-width: 1440px; min-width: 0; margin: 0 auto; padding: clamp(2.2rem, 5vw, 4.5rem) clamp(1rem, 4vw, 3.5rem) 2.5rem; }
.hero-row { display: flex; align-items: end; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
.hero-copy { max-width: 39rem; margin: 0; color: var(--text-soft); }
.period-control { display: grid; gap: .45rem; justify-items: end; }
.date-fields { display: flex; align-items: center; gap: .45rem; color: var(--text-faint); }
.date-fields input { width: 8.8rem; min-height: 2.5rem; padding: .5rem .6rem; font-size: .78rem; }
.stale-banner { display: flex; align-items: flex-start; gap: .85rem; margin-bottom: 1.2rem; padding: .8rem 1rem; border: 1px solid rgba(243,190,113,.28); border-radius: 12px; color: var(--warn); background: rgba(243,190,113,.08); font-size: .78rem; }
.stale-banner strong, .stale-banner span { display: block; }
.stale-banner strong { margin-bottom: .15rem; color: #ffd699; }
.stale-banner span { color: #cbb18d; }
.stale-icon { display: grid; width: 1.35rem; height: 1.35rem; flex: 0 0 auto; place-items: center; border: 1px solid currentColor; border-radius: 999px; font-size: .7rem; font-weight: 800; }
.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .85rem; margin-bottom: 1.25rem; }
.kpi-card, .panel, .ranking-card { border: 1px solid var(--line); background: var(--panel); box-shadow: 0 10px 30px rgba(0,0,0,.08); }
.kpi-card { min-height: 9.2rem; padding: 1.1rem; border-radius: 15px; }
.kpi-featured { border-color: rgba(98,208,195,.35); background: linear-gradient(140deg, rgba(98,208,195,.13), rgba(17,29,46,.92) 60%); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; color: var(--text-soft); font-size: .72rem; font-weight: 650; }
.kpi-icon { color: var(--accent); font-size: 1.25rem; line-height: 1; }
.kpi-icon-warn { color: var(--warn); }
.kpi-value { display: block; margin: 1rem 0 .25rem; font-size: clamp(1.8rem, 3vw, 2.35rem); letter-spacing: -.055em; line-height: 1; }
.kpi-caption { color: var(--text-faint); font-size: .68rem; }
.content-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(18rem, .9fr); gap: 1.25rem; min-width: 0; margin-bottom: 3rem; }
.panel { border-radius: var(--radius); }
.timeline-panel, .status-panel { min-height: 23rem; padding: clamp(1rem, 2vw, 1.4rem); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.timeline-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .7rem; }
.timeline-controls select { width: auto; min-height: 2rem; padding-block: .35rem; font-size: .7rem; }
.legend { display: flex; flex-wrap: wrap; gap: .8rem; color: var(--text-faint); font-size: .68rem; }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend-dot { display: inline-block; width: .45rem; height: .45rem; border-radius: 99px; }
.legend-contacts { background: var(--accent); }.legend-conversations { background: var(--accent-blue); }.legend-messages { background: var(--warn); }
.timeline-wrap { position: relative; min-height: 16.5rem; margin-top: 1.1rem; }
#timeline-chart { width: 100%; height: 16.5rem; overflow: visible; }
#timeline-chart .chart-grid { stroke: rgba(165,188,212,.12); stroke-width: 1; }
#timeline-chart .chart-line { fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 3; }
#timeline-chart .chart-area { opacity: .14; }
#timeline-chart .chart-label { fill: var(--text-faint); font-size: 10px; }
.empty-state { display: grid; min-height: 8rem; place-items: center; align-content: center; gap: .3rem; color: var(--text-faint); text-align: center; font-size: .8rem; }
.empty-state strong { color: var(--text-soft); }
.status-panel { background: linear-gradient(150deg, rgba(20,38,59,.95), rgba(15,26,42,.88)); }
.badge { display: inline-flex; align-items: center; padding: .32rem .55rem; color: var(--accent-strong); border: 1px solid rgba(98,208,195,.25); border-radius: 99px; background: rgba(98,208,195,.08); font-size: .65rem; font-weight: 750; }
.badge-warn { color: #ffd699; border-color: rgba(243,190,113,.25); background: rgba(243,190,113,.08); }
.badge-danger { color: #ffb7b1; border-color: rgba(243,138,135,.25); background: rgba(243,138,135,.08); }
.sync-details { display: grid; gap: 1rem; margin: 2rem 0 1.35rem; }
.sync-detail { display: flex; justify-content: space-between; gap: 1rem; padding-bottom: .75rem; border-bottom: 1px solid var(--line); color: var(--text-faint); font-size: .7rem; }
.sync-detail strong { color: var(--text-soft); font-size: .75rem; font-weight: 650; text-align: right; }
.progress-track { height: .32rem; overflow: hidden; border-radius: 99px; background: rgba(165,188,212,.12); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width .45s ease; }
.panel-note, .panel-subtitle { margin: .9rem 0 0; color: var(--text-faint); font-size: .7rem; }
.rankings-section { min-width: 0; margin-bottom: 3rem; }
.section-heading { display: flex; align-items: center; gap: 1.25rem; margin-bottom: 1.1rem; }
.section-rule { display: block; height: 1px; flex: 1; background: var(--line); }
.rankings-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .85rem; }
.ranking-card { min-height: 12.5rem; padding: 1rem; border-radius: 15px; }
.ranking-heading { display: flex; align-items: center; gap: .6rem; padding-bottom: .8rem; border-bottom: 1px solid var(--line); }
.ranking-number { color: var(--accent); font-size: .65rem; font-weight: 800; letter-spacing: .08em; }
.ranking-list { display: grid; gap: .6rem; margin: .9rem 0 0; padding: 0; list-style: none; counter-reset: ranking; }
.ranking-list li { display: flex; align-items: center; justify-content: space-between; gap: .5rem; color: var(--text-soft); font-size: .75rem; counter-increment: ranking; }
.ranking-list li::before { content: counter(ranking, decimal-leading-zero); width: 1.25rem; color: var(--text-faint); font-size: .62rem; }
.ranking-list .ranking-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-list .ranking-count { color: var(--text); font-weight: 750; }
.contacts-panel { min-width: 0; padding: clamp(1rem, 2.5vw, 1.5rem); }
.contacts-heading { align-items: end; }
.muted-count { color: var(--text-faint); font-size: .7rem; }
.filters-bar { display: grid; grid-template-columns: minmax(13rem, 1.7fr) repeat(4, minmax(8rem, 1fr)) repeat(3, auto) auto; gap: .55rem; align-items: center; margin: 1.5rem 0 .7rem; }
.search-field { position: relative; display: flex; align-items: center; }
.search-field > span:not(.sr-only) { position: absolute; left: .75rem; color: var(--text-faint); font-size: 1.15rem; pointer-events: none; }
.search-field input { padding-left: 2.15rem; }
.check-field { display: inline-flex; min-height: 2.6rem; align-items: center; gap: .4rem; color: var(--text-soft); font-size: .68rem; white-space: nowrap; }
.check-field input { width: 1rem; min-height: 1rem; accent-color: var(--accent); }
.inline-feedback { margin: 0; color: var(--danger); }
.table-wrap { max-width: 100%; min-width: 0; overflow-x: auto; margin: .6rem -1.5rem 0; padding: 0 1.5rem; }
.contacts-table { width: 100%; min-width: 1160px; border-collapse: collapse; }
.contacts-table th { padding: .8rem .55rem; color: var(--text-faint); border-bottom: 1px solid var(--line-strong); font-size: .64rem; font-weight: 750; letter-spacing: .09em; text-align: left; text-transform: uppercase; }
.contacts-table td { padding: .95rem .55rem; border-bottom: 1px solid var(--line); color: var(--text-soft); font-size: .76rem; vertical-align: middle; }
.contacts-table tbody tr:hover { background: rgba(255,255,255,.025); }
.contact-primary { display: block; color: var(--text); font-weight: 700; }
.contact-secondary { display: block; margin-top: .2rem; color: var(--text-faint); font-size: .67rem; }
.label-stack { display: flex; flex-wrap: wrap; gap: .3rem; max-width: 14rem; }
.label-chip { display: inline-flex; padding: .23rem .4rem; color: var(--accent-strong); border: 1px solid rgba(98,208,195,.18); border-radius: 6px; background: rgba(98,208,195,.07); font-size: .64rem; }
.inbox-stack { display: grid; gap: .28rem; min-width: 10rem; max-width: 17rem; }
.inbox-chip { display: block; overflow: hidden; color: var(--text-soft); text-overflow: ellipsis; white-space: nowrap; }
.table-link { color: var(--accent-strong); font-size: .7rem; font-weight: 700; text-decoration: none; }
.table-link:hover { text-decoration: underline; }
.table-footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3.5rem; padding-top: .85rem; }
.footer { display: flex; justify-content: space-between; gap: 1rem; padding: 2rem 0 .5rem; color: var(--text-faint); font-size: .68rem; }
.skeleton { position: relative; overflow: hidden; color: transparent !important; border-radius: 4px; background: rgba(165,188,212,.12); }
.skeleton::after { position: absolute; inset: 0; content: ""; background: linear-gradient(90deg, transparent, rgba(255,255,255,.08), transparent); transform: translateX(-100%); animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-card:last-child { grid-column: span 1; }
  .filters-bar { grid-template-columns: minmax(14rem, 2fr) repeat(3, minmax(8rem, 1fr)); }
  .filters-bar .check-field, .filters-bar .button { justify-self: start; }
}

@media (max-width: 860px) {
  .hero-row { align-items: flex-start; flex-direction: column; }
  .period-control { justify-items: start; }
  .content-grid { grid-template-columns: 1fr; }
  .rankings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-field { grid-column: 1 / -1; }
  .filters-bar .button { justify-self: stretch; }
}

@media (max-width: 680px) {
  .table-wrap { margin: .6rem 0 0; padding: 0; overflow: visible; }
  .contacts-table { display: block; min-width: 0; width: 100%; }
  .contacts-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
  .contacts-table tbody { display: grid; gap: .8rem; }
  .contacts-table tr { display: block; min-width: 0; padding: .8rem .85rem; border: 1px solid var(--line); border-radius: 13px; background: rgba(15,26,42,.52); }
  .contacts-table td { display: grid; grid-template-columns: minmax(5.8rem, 34%) minmax(0, 1fr); gap: .6rem; min-width: 0; padding: .55rem 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
  .contacts-table td::before { content: attr(data-label); color: var(--text-faint); font-size: .61rem; font-weight: 750; letter-spacing: .08em; line-height: 1.35; text-transform: uppercase; }
  .contacts-table td:first-child { display: block; padding-top: 0; }
  .contacts-table td:first-child::before { display: none; }
  .contacts-table td.contact-current { display: block; }
  .contacts-table td.contact-current::before { display: block; margin-bottom: .25rem; }
  .contacts-table td:last-child { padding-bottom: 0; border-bottom: 0; }
  .contacts-table td:empty { display: none; }
  .contacts-table .label-stack, .contacts-table .inbox-stack { min-width: 0; max-width: none; }
  .contacts-table .inbox-chip { overflow: visible; text-overflow: clip; white-space: normal; overflow-wrap: anywhere; }
}

@media (max-width: 560px) {
  h1 { font-size: 1.8rem; }
  .topbar-inner { min-height: 4.2rem; }
  .sync-pill { max-width: 2rem; padding: .55rem; border: 0; background: transparent; }
  .sync-pill #sync-pill-label { display: none; }
  .main-shell { padding-top: 2rem; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-card { min-height: 8.5rem; padding: .9rem; }
  .kpi-card:first-child { grid-column: 1 / -1; }
  .kpi-value { margin-top: .8rem; font-size: 1.8rem; }
  .date-fields { flex-wrap: wrap; }
  .date-fields input { width: 8.3rem; }
  .rankings-grid { grid-template-columns: 1fr; }
  .filters-bar { grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
  .footer { flex-direction: column; gap: .35rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
