:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #f0f4f3;
  --surface-strong: #e7eeec;
  --text: #13231f;
  --muted: #687873;
  --line: #dce5e2;
  --brand: #00a884;
  --brand-deep: #087a65;
  --brand-soft: #dcf7ef;
  --blue: #4188ff;
  --orange: #f59d2a;
  --red: #e1515a;
  --purple: #8567e8;
  --shadow: 0 18px 45px rgba(24, 56, 48, .08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1513;
  --surface: #121f1c;
  --surface-soft: #172824;
  --surface-strong: #20342f;
  --text: #edf8f4;
  --muted: #98aaa4;
  --line: #294039;
  --brand: #28c9a4;
  --brand-deep: #67e0c4;
  --brand-soft: #143e34;
  --shadow: 0 18px 50px rgba(0, 0, 0, .24);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--text); background: var(--bg); }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.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; }

.brand-lockup { display: flex; align-items: center; gap: 11px; font-weight: 800; font-size: 21px; letter-spacing: -.04em; }
.brand-lockup > span:last-child > span { color: var(--brand); }
.brand-lockup--large { font-size: 30px; }
.brand-mark { position: relative; display: inline-flex; align-items: flex-end; gap: 3px; width: 30px; height: 30px; padding: 6px; border-radius: 10px; background: var(--brand); box-shadow: 0 8px 20px rgba(0, 168, 132, .25); }
.brand-mark i { display: block; width: 4px; border-radius: 4px; background: white; transform: skew(-14deg); }
.brand-mark i:nth-child(1) { height: 8px; }
.brand-mark i:nth-child(2) { height: 17px; }
.brand-mark i:nth-child(3) { height: 12px; }

.eyebrow { margin: 0 0 6px; color: var(--brand-deep); font-size: 11px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.icon-button, .ghost-button, .primary-button { border: 0; border-radius: 11px; transition: transform .16s ease, background .16s ease, border-color .16s ease; }
.icon-button:focus-visible, .ghost-button:focus-visible, .primary-button:focus-visible, input:focus-visible, select:focus-visible, .detail-button:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 2px; }
.icon-button { display: grid; place-items: center; width: 40px; height: 40px; color: var(--text); background: var(--surface-soft); }
.ghost-button { padding: 10px 14px; color: var(--text); background: transparent; border: 1px solid var(--line); font-weight: 700; }
.primary-button { display: flex; align-items: center; justify-content: space-between; gap: 24px; width: 100%; padding: 14px 18px; color: white; background: var(--brand); font-weight: 800; box-shadow: 0 10px 22px rgba(0, 168, 132, .18); }
.primary-button.compact { width: auto; padding-inline: 18px; }
.primary-button:hover, .ghost-button:hover, .icon-button:hover { transform: translateY(-1px); }
.primary-button:disabled { opacity: .6; cursor: wait; }

.auth-shell { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(400px, .95fr); min-height: 100vh; }
.auth-brand { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: center; padding: clamp(42px, 8vw, 120px); color: #eefbf7; background: radial-gradient(circle at 75% 25%, rgba(46, 222, 180, .22), transparent 30%), linear-gradient(145deg, #0b382f 0%, #09241f 58%, #071916 100%); }
.auth-brand::before, .auth-brand::after { content: ""; position: absolute; border: 1px solid rgba(112, 235, 205, .13); border-radius: 50%; }
.auth-brand::before { width: 560px; height: 560px; right: -250px; bottom: -230px; }
.auth-brand::after { width: 360px; height: 360px; right: -90px; bottom: -120px; }
.auth-brand .eyebrow { margin-top: 70px; color: #71e1c5; }
.auth-brand h1 { position: relative; max-width: 650px; margin: 6px 0 20px; font-size: clamp(38px, 5.2vw, 72px); line-height: 1.03; letter-spacing: -.055em; }
.auth-copy { max-width: 500px; color: #aac4bd; font-size: 17px; line-height: 1.7; }
.signal-card { position: relative; z-index: 1; display: flex; align-items: center; gap: 13px; max-width: 390px; margin-top: 56px; padding: 16px 18px; border: 1px solid rgba(150, 236, 215, .16); border-radius: 16px; background: rgba(255, 255, 255, .06); backdrop-filter: blur(8px); }
.signal-card strong, .signal-card small { display: block; }
.signal-card small { margin-top: 3px; color: #91aaa4; }
.signal-dot { width: 10px; height: 10px; border-radius: 50%; background: #41e2ba; box-shadow: 0 0 0 6px rgba(65, 226, 186, .1); }
.signal-wave { margin-left: auto; width: 72px; height: 22px; background: linear-gradient(135deg, transparent 45%, #41e2ba 46% 53%, transparent 54%) 0 0 / 16px 22px; opacity: .6; }
.auth-panel { position: relative; display: grid; place-items: center; padding: 42px; background: var(--surface); }
.auth-panel .theme-toggle { position: absolute; top: 24px; right: 24px; }
.login-card { width: min(100%, 410px); }
.login-card h2 { margin: 0; font-size: 34px; letter-spacing: -.04em; }
.login-card > p:not(.eyebrow):not(.form-error) { margin: 9px 0 34px; color: var(--muted); }
label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 750; }
input, select { min-width: 0; height: 43px; padding: 0 12px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.login-card label { margin-bottom: 18px; color: var(--text); font-size: 13px; }
.login-card input { height: 49px; background: var(--surface-soft); }
.login-card .primary-button { margin-top: 10px; }
.form-error { padding: 11px 13px; border-radius: 9px; color: var(--red); background: color-mix(in srgb, var(--red) 10%, transparent); font-size: 13px; }

.app-shell { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 27px 20px; color: #eaf7f3; background: #0b2923; }
.sidebar .brand-lockup { padding: 0 10px 30px; }
.sidebar nav { display: grid; gap: 8px; padding-top: 22px; border-top: 1px solid rgba(255, 255, 255, .08); }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 11px; color: #92aaa4; text-decoration: none; font-size: 14px; font-weight: 700; }
.nav-item.active { color: white; background: rgba(41, 201, 164, .13); }
.nav-item span { display: grid; place-items: center; width: 26px; height: 26px; color: #64dcc0; font-size: 20px; }
.sidebar-foot { margin-top: auto; padding-top: 18px; border-top: 1px solid rgba(255, 255, 255, .08); }
.organization-badge, .user-menu { display: flex; align-items: center; gap: 10px; min-width: 0; }
.organization-badge > span, .user-menu > span { flex: 0 0 auto; display: grid; place-items: center; width: 35px; height: 35px; border-radius: 10px; color: white; background: var(--brand); font-weight: 800; }
.organization-badge div, .user-menu div { min-width: 0; }
.organization-badge strong, .organization-badge small, .user-menu strong, .user-menu small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.organization-badge strong { max-width: 150px; font-size: 12px; }
.organization-badge small { margin-top: 3px; color: #7f9b94; font-size: 10px; }
.workspace { min-width: 0; }
.topbar { position: sticky; z-index: 20; top: 0; display: flex; align-items: center; justify-content: space-between; min-height: 76px; padding: 14px clamp(20px, 3vw, 42px); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 91%, transparent); backdrop-filter: blur(15px); }
.topbar h1 { margin: 1px 0 0; font-size: 18px; }
.breadcrumb { margin: 0; color: var(--muted); font-size: 10px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.user-menu { padding-left: 6px; }
.user-menu > span { width: 38px; height: 38px; border-radius: 50%; }
.user-menu strong { max-width: 140px; font-size: 12px; }
.user-menu small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.menu-toggle { display: none; }
.content { width: min(1580px, 100%); margin: 0 auto; padding: 34px clamp(18px, 3vw, 42px) 60px; }
.page-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 25px; }
.page-intro h2 { margin: 0; font-size: 30px; letter-spacing: -.04em; }
.page-intro p:last-child { margin: 8px 0 0; color: var(--muted); }
.live-indicator { display: flex; align-items: center; gap: 8px; padding: 9px 12px; color: var(--brand-deep); border: 1px solid var(--line); border-radius: 100px; background: var(--surface); font-size: 11px; font-weight: 750; white-space: nowrap; }
.live-indicator span { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }

.filter-panel, .panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.filter-panel { margin-bottom: 20px; padding: 18px 20px; box-shadow: none; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-heading h3 { margin: 0; font-size: 16px; letter-spacing: -.02em; }
.filter-toggle { display: none; }
.filters-grid { display: grid; grid-template-columns: repeat(5, minmax(140px, 1fr)); gap: 13px; margin-top: 16px; }
.filters-grid .search-field { grid-column: span 2; }
.filter-actions { display: flex; align-items: flex-end; justify-content: flex-end; gap: 9px; }
.notice { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 18px 0; padding: 15px 18px; border-radius: 13px; }
.notice--error { color: color-mix(in srgb, var(--red) 80%, var(--text)); border: 1px solid color-mix(in srgb, var(--red) 30%, var(--line)); background: color-mix(in srgb, var(--red) 8%, var(--surface)); }
.notice strong, .notice p { display: block; margin: 0; }
.notice p { margin-top: 3px; color: var(--muted); font-size: 12px; }

.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 15px; margin: 20px 0; }
.kpi-card { position: relative; overflow: hidden; min-height: 164px; padding: 19px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.kpi-card::after { content: ""; position: absolute; right: -26px; bottom: -34px; width: 100px; height: 100px; border-radius: 50%; background: var(--accent-soft, var(--brand-soft)); }
.kpi-card p { margin: 18px 0 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.kpi-card strong { display: block; font-size: 31px; letter-spacing: -.05em; }
.kpi-card small { position: relative; z-index: 1; display: block; margin-top: 8px; color: var(--muted); font-size: 10px; }
.kpi-icon { display: grid; place-items: center; width: 33px; height: 33px; border-radius: 10px; color: var(--accent, var(--brand)); background: var(--accent-soft, var(--brand-soft)); font-weight: 900; }
.kpi-card--failure { --accent: var(--red); --accent-soft: color-mix(in srgb, var(--red) 11%, var(--surface)); }
.kpi-card--accepted { --accent: var(--blue); --accent-soft: color-mix(in srgb, var(--blue) 11%, var(--surface)); }
.kpi-card--uncertain { --accent: var(--orange); --accent-soft: color-mix(in srgb, var(--orange) 12%, var(--surface)); }
.kpi-card--total { --accent: var(--purple); --accent-soft: color-mix(in srgb, var(--purple) 11%, var(--surface)); }

.charts-grid { display: grid; grid-template-columns: 1.25fr .75fr; gap: 16px; }
.panel { padding: 20px; }
.panel--wide { grid-row: span 2; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 15px; color: var(--muted); font-size: 10px; font-weight: 700; }
.chart-legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: currentColor; }
.legend-conversion { color: var(--brand-deep); }
.legend-telegram { color: var(--blue); }
.legend-whatsapp { color: var(--purple); }
.chart-area { min-height: 330px; margin-top: 20px; }
.chart-area svg { display: block; width: 100%; height: 330px; overflow: visible; }
.chart-grid-line { stroke: var(--line); stroke-width: 1; }
.chart-axis-text { fill: var(--muted); font-size: 10px; }
.chart-empty { display: grid; place-items: center; min-height: 220px; color: var(--muted); font-size: 12px; text-align: center; }
.bar-chart { display: grid; gap: 14px; margin-top: 22px; }
.bar-row { display: grid; grid-template-columns: minmax(85px, .55fr) 1fr auto; align-items: center; gap: 10px; font-size: 11px; }
.bar-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; overflow: hidden; border-radius: 20px; background: var(--surface-strong); }
.bar-fill { height: 100%; min-width: 2px; border-radius: inherit; background: var(--brand); }
.bar-value { color: var(--muted); font-variant-numeric: tabular-nums; }

.history-panel { margin-top: 16px; padding: 0; overflow: hidden; }
.history-heading { padding: 20px; border-bottom: 1px solid var(--line); }
.count-pill { padding: 6px 10px; border-radius: 30px; color: var(--brand-deep); background: var(--brand-soft); font-size: 11px; font-weight: 800; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 15px; color: var(--muted); background: var(--surface-soft); font-size: 9px; text-align: left; text-transform: uppercase; letter-spacing: .08em; }
td { padding: 15px; border-top: 1px solid var(--line); font-size: 12px; vertical-align: middle; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: var(--surface-soft); }
.event-kind { display: flex; align-items: center; gap: 8px; font-weight: 750; }
.event-kind span { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: var(--surface-soft); }
.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 20px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.status-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-succeeded { color: var(--brand-deep); background: var(--brand-soft); }
.status-failed { color: var(--red); background: color-mix(in srgb, var(--red) 11%, var(--surface)); }
.status-accepted { color: var(--blue); background: color-mix(in srgb, var(--blue) 11%, var(--surface)); }
.status-delivery_uncertain { color: var(--orange); background: color-mix(in srgb, var(--orange) 12%, var(--surface)); }
.status-not_applicable { color: var(--muted); background: var(--surface-strong); }
.reason-code { max-width: 220px; overflow: hidden; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.detail-button { padding: 7px 9px; color: var(--brand-deep); border: 0; border-radius: 8px; background: var(--brand-soft); font-weight: 800; }
.pagination { display: flex; justify-content: center; padding: 15px; border-top: 1px solid var(--line); }
.empty-state { padding: 60px 20px; color: var(--muted); text-align: center; }
.empty-state div { margin-bottom: 10px; color: var(--brand); font-size: 36px; }
.empty-state h4 { margin: 0; color: var(--text); }
.empty-state p { margin: 7px 0 0; font-size: 12px; }
.skeleton-list { display: grid; gap: 1px; background: var(--line); }
.skeleton-list i { height: 58px; background: linear-gradient(90deg, var(--surface) 15%, var(--surface-soft) 45%, var(--surface) 75%) 0 0 / 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.detail-dialog { width: min(680px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; color: var(--text); border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: 0 30px 90px rgba(0, 0, 0, .28); }
.detail-dialog::backdrop { background: rgba(4, 16, 13, .58); backdrop-filter: blur(3px); }
.dialog-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--line); background: var(--surface); }
.dialog-head h2 { margin: 0; font-size: 20px; }
.detail-content { display: grid; gap: 20px; padding: 22px; }
.detail-summary { padding: 16px; border-radius: 13px; background: var(--surface-soft); }
.detail-summary h3 { margin: 0 0 6px; font-size: 15px; }
.detail-summary p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.detail-field { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 11px; }
.detail-field dt { margin-bottom: 6px; color: var(--muted); font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.detail-field dd { margin: 0; overflow-wrap: anywhere; font-size: 12px; }
.detail-field--wide { grid-column: 1 / -1; }
.safe-url { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.safe-url code { overflow-wrap: anywhere; color: var(--text); font-size: 11px; }
.copy-button { flex: 0 0 auto; padding: 5px 7px; color: var(--brand-deep); border: 0; border-radius: 7px; background: var(--brand-soft); font-size: 10px; font-weight: 800; }
.toast { position: fixed; z-index: 100; right: 24px; bottom: 24px; max-width: 340px; padding: 12px 15px; color: white; border-radius: 11px; background: #163b32; box-shadow: var(--shadow); font-size: 12px; }

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .filters-grid { grid-template-columns: repeat(3, 1fr); }
  .filters-grid .search-field { grid-column: span 2; }
}

@media (max-width: 900px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; left: 0; transform: translateX(-105%); width: 244px; transition: transform .2s ease; box-shadow: 20px 0 50px rgba(0, 0, 0, .25); }
  .app-shell.menu-open .sidebar { transform: translateX(0); }
  .menu-toggle { display: grid; }
  .topbar { justify-content: flex-start; gap: 14px; }
  .topbar-actions { margin-left: auto; }
  .charts-grid { grid-template-columns: 1fr; }
  .panel--wide { grid-row: auto; }
}

@media (max-width: 700px) {
  .auth-panel { padding: 28px 20px; }
  .topbar { min-height: 67px; padding-inline: 14px; }
  .topbar > div:nth-child(2) { display: none; }
  .user-menu div, .topbar-actions .ghost-button { display: none; }
  .content { padding: 24px 14px 42px; }
  .page-intro { align-items: flex-start; flex-direction: column; }
  .page-intro h2 { font-size: 27px; }
  .filter-toggle { display: inline-block; }
  .filters-grid { display: none; grid-template-columns: 1fr 1fr; }
  .filter-panel.filters-open .filters-grid { display: grid; }
  .filters-grid .search-field { grid-column: 1 / -1; }
  .filter-actions { grid-column: 1 / -1; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-card { min-height: 145px; padding: 15px; }
  .kpi-card:first-child { grid-column: 1 / -1; }
  .kpi-card strong { font-size: 27px; }
  .panel { padding: 16px; }
  .history-panel { padding: 0; }
  .chart-legend { display: none; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr { padding: 14px; border-top: 1px solid var(--line); }
  td { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 6px 0; border: 0; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 9px; font-weight: 800; text-transform: uppercase; }
  td:last-child { justify-content: flex-end; }
  td:last-child::before { display: none; }
  .reason-code { max-width: 60vw; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-field--wide { grid-column: auto; }
}

@media (max-width: 440px) {
  .filters-grid { grid-template-columns: 1fr; }
  .filters-grid .search-field, .filter-actions { grid-column: auto; }
  .filter-actions { justify-content: stretch; }
  .filter-actions button { flex: 1; }
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-card:first-child { grid-column: auto; }
  .kpi-card { min-height: 132px; }
}

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