:root {
  --ink: #17202a;
  --muted: #6f7b88;
  --line: #e7e9ec;
  --canvas: #f4f5f6;
  --surface: #ffffff;
  --charcoal: #1d252b;
  --coral: #e86f51;
  --coral-dark: #cf583e;
  --coral-soft: #fce9e4;
  --blue: #4976d1;
  --blue-soft: #e8eefb;
  --shadow: 0 16px 45px rgba(27, 35, 41, 0.08);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.is-hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--coral-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.button {
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  font-weight: 750;
  transition: 150ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:focus-visible,
button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(73, 118, 209, 0.3);
  outline-offset: 2px;
}

.button-primary {
  background: var(--coral);
  color: #fff;
  box-shadow: 0 8px 20px rgba(232, 111, 81, 0.23);
}

.button-primary:hover {
  background: var(--coral-dark);
}

.button-secondary {
  background: var(--charcoal);
  color: #fff;
}

.button-quiet {
  min-height: 36px;
  background: #f1f2f3;
  color: #3b454d;
}

.button-wide {
  width: 100%;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 16px;
  background: var(--coral);
  color: #fff;
  font-size: 26px;
  font-weight: 900;
  box-shadow: 0 12px 24px rgba(232, 111, 81, 0.25);
}

.brand-mark-small {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 20px;
  box-shadow: none;
}

.login-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 10%, rgba(232, 111, 81, 0.16), transparent 28%),
    radial-gradient(circle at 86% 82%, rgba(73, 118, 209, 0.13), transparent 30%),
    #1c242a;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  padding: 32px 20px;
  place-items: center;
}

.login-card {
  width: min(100%, 430px);
  padding: 42px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.28);
}

.login-card .brand-mark {
  margin-bottom: 28px;
}

.login-card h1 {
  margin: 0;
  font-size: clamp(30px, 6vw, 42px);
  letter-spacing: -0.04em;
}

.login-lead {
  margin: 12px 0 28px;
  color: var(--muted);
  line-height: 1.6;
}

.login-form {
  display: grid;
  gap: 18px;
}

.login-form label,
.date-fields label {
  display: grid;
  gap: 7px;
  color: #505a63;
  font-size: 13px;
  font-weight: 750;
}

.login-form input,
.date-fields input {
  width: 100%;
  height: 46px;
  padding: 0 13px;
  border: 1px solid #d9dde1;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}

.secure-note {
  margin: 22px 0 0;
  color: #9098a0;
  font-size: 12px;
  text-align: center;
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 0 max(24px, calc((100vw - 1280px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.status-dot {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.status-dot i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #36a66f;
  box-shadow: 0 0 0 4px rgba(54, 166, 111, 0.12);
}

.status-dot.is-warning i {
  background: #d9911e;
  box-shadow: 0 0 0 4px rgba(217, 145, 30, 0.14);
}

.dashboard-shell {
  width: min(calc(100% - 40px), 1480px);
  margin: 0 auto;
  padding: 42px 0 70px;
}

.page-heading,
.card-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.page-heading {
  margin-bottom: 28px;
}

.page-heading > div,
.card-heading > div {
  min-width: 0;
}

.page-heading h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 52px);
  letter-spacing: -0.045em;
}

.connections-page .page-heading h1 {
  max-width: 100%;
  font-size: clamp(32px, 4vw, 48px);
  overflow-wrap: anywhere;
}

.page-heading > div > p:last-child {
  margin: 10px 0 0;
  color: var(--muted);
}

.filter-panel {
  display: grid;
  grid-template-columns: minmax(350px, auto) 190px 190px minmax(520px, 1fr);
  align-items: end;
  gap: 16px;
  margin-bottom: 24px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(27, 35, 41, 0.04);
}

.department-filter {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.department-filter > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.department-filter select {
  width: 100%;
  min-height: 44px;
  padding: 0 38px 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 650;
}

.quick-filters {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
}

.quick-filters button {
  min-height: 38px;
  padding: 0 11px;
  border: 1px solid #dde0e3;
  border-radius: 10px;
  background: #fff;
  color: #4f5962;
  cursor: pointer;
  font-weight: 700;
}

.quick-filters button.is-active {
  border-color: var(--coral);
  background: var(--coral-soft);
  color: var(--coral-dark);
}

.manager-filter {
  position: relative;
  width: 100%;
  min-width: 0;
}

.manager-filter-field {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.manager-filter-field > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.manager-filter summary {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 13px;
  border: 1px solid #dde0e3;
  border-radius: 10px;
  background: #fff;
  color: #4f5962;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  list-style: none;
}

.manager-filter summary::-webkit-details-marker {
  display: none;
}

.manager-filter summary::after {
  color: #8c969e;
  content: "⌄";
  font-size: 18px;
}

.manager-filter[open] summary {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(73, 118, 209, 0.12);
}

.manager-filter-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  width: min(320px, 80vw);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 44px rgba(24, 34, 42, 0.16);
}

.manager-filter-menu > button {
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: #f3f5f6;
  color: #46515a;
  cursor: pointer;
  text-align: left;
  font-weight: 750;
}

.manager-filter-options {
  display: grid;
  max-height: 260px;
  gap: 4px;
  margin-top: 7px;
  overflow-y: auto;
}

.manager-filter-options label {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}

.manager-filter-options label:hover {
  background: var(--blue-soft);
}

.manager-filter-options input {
  width: 17px;
  height: 17px;
  accent-color: var(--blue);
}

.date-fields {
  display: flex;
  align-items: end;
  gap: 10px;
}

.date-fields input {
  width: 132px;
  height: 40px;
}

.date-separator {
  padding-bottom: 10px;
  color: #9ca3a9;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 18px;
  margin: 24px 0;
}

.metric-card {
  display: flex;
  min-height: 188px;
  align-items: flex-start;
  gap: 18px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(27, 35, 41, 0.045);
}

.metric-card > div:last-child {
  display: grid;
  grid-template-rows: 40px 50px 1fr;
  min-width: 0;
  height: 100%;
  flex: 1;
  align-self: stretch;
}

.metric-card-accent {
  border-color: #f0b7a8;
  background: linear-gradient(135deg, #fff 45%, #fef1ed);
}

.metric-card-warning {
  border-color: #f2d9a8;
  background: linear-gradient(135deg, #fff 45%, #fff8e8);
}

.metric-card-action {
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.metric-card-action:hover,
.metric-card-action:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 14px 32px rgba(35, 43, 50, 0.1);
  outline: none;
}

.metric-card-action.is-active {
  border-color: #d9911e;
  box-shadow: 0 0 0 3px rgba(217, 145, 30, 0.12);
}

.metric-icon {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 13px;
  background: var(--coral-soft);
  color: var(--coral-dark);
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.metric-icon-blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.metric-icon-slate {
  background: #edf0f2;
  color: #57636c;
}

.metric-icon-warning {
  background: #fff0cf;
  color: #b56a00;
}

.metric-card p {
  display: flex;
  min-height: 40px;
  align-items: flex-start;
  margin: 1px 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.metric-card strong {
  display: block;
  margin: 0;
  font-size: 38px;
  letter-spacing: -0.04em;
}

.metric-card small {
  display: block;
  align-self: end;
  color: #8b949b;
  font-size: 11px;
  line-height: 1.4;
}

.content-card {
  margin-top: 18px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 10px 32px rgba(27, 35, 41, 0.05);
}

.connection-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.connection-progress {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 22px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(27, 35, 41, 0.04);
}

.connection-progress span {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #8b949b;
  font-size: 13px;
  font-weight: 750;
}

.connection-progress span:not(:last-child)::after {
  height: 1px;
  flex: 1;
  margin: 0 18px;
  background: #e2e5e7;
  content: "";
}

.connection-progress i {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: #edf0f2;
  color: #69747c;
  font-size: 12px;
  font-style: normal;
}

.connection-progress .is-current {
  color: var(--ink);
}

.connection-progress .is-current i {
  background: var(--coral);
  color: #fff;
}

.connection-progress .is-complete i {
  background: #e7f5ed;
  color: #24764a;
}

.connection-progress .is-complete i::after {
  content: "✓";
}

.connection-progress .is-complete i {
  font-size: 0;
}

.connection-progress .is-complete i::after {
  font-size: 13px;
}

.connection-layout .content-card {
  margin-top: 0;
}

.connection-form {
  display: grid;
  gap: 18px;
}

.connection-form label {
  display: grid;
  gap: 7px;
  color: #505a63;
  font-size: 13px;
  font-weight: 750;
}

.connection-form input {
  width: 100%;
  height: 46px;
  padding: 0 13px;
  border: 1px solid #d9dde1;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}

.connection-form select,
.connection-table-tools select {
  width: 100%;
  height: 46px;
  padding: 0 13px;
  border: 1px solid #d9dde1;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}

.manager-picker input[type="search"] {
  margin-bottom: 2px;
}

.sync-state {
  min-height: 20px;
  margin: -12px 0 20px;
  color: var(--muted);
  font-size: 12px;
}

.sync-state.has-warning {
  color: #986000;
}

.button-small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.connection-note {
  margin-top: 20px;
  padding: 15px;
  border-radius: 12px;
  background: #f4f6f7;
  color: #55616a;
  font-size: 12px;
  line-height: 1.5;
}

.connection-note p {
  margin: 5px 0 0;
}

.username-input {
  display: flex;
  align-items: center;
  border: 1px solid #d9dde1;
  border-radius: 10px;
  background: #fff;
}

.username-input:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(73, 118, 209, 0.12);
}

.username-input span {
  padding-left: 13px;
  color: var(--muted);
}

.username-input input {
  border: 0;
  outline: 0;
}

.bot-badge,
.connection-status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef0f2;
  color: #4d5861;
  font-size: 12px;
  font-weight: 750;
}

.qr-card {
  display: grid;
  min-height: 430px;
  align-content: center;
  text-align: center;
}

.qr-placeholder {
  max-width: 360px;
  margin: auto;
  color: var(--muted);
}

.qr-placeholder h2 {
  color: var(--ink);
}

.qr-placeholder-icon {
  display: grid;
  width: 86px;
  height: 86px;
  margin: 0 auto 22px;
  place-items: center;
  border: 1px dashed #cfd5d9;
  border-radius: 22px;
  background: #f7f8f9;
  color: #8c969e;
  font-size: 48px;
}

#qr-live-status {
  margin: 0 auto 14px;
}

.qr-card h2 {
  margin: 0 0 18px;
}

.qr-card img {
  display: block;
  width: min(100%, 260px);
  margin: 0 auto 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
}

.qr-card > strong {
  display: block;
  margin: 4px 0;
}

.muted-copy {
  color: var(--muted);
  font-size: 13px;
}

.connection-steps {
  display: grid;
  gap: 8px;
  margin: 22px 0 0;
  padding-left: 22px;
  color: #59646d;
  font-size: 13px;
  line-height: 1.5;
  text-align: left;
}

.connection-status.is-connected {
  background: #e7f5ed;
  color: #24764a;
}

.connection-status.is-waiting {
  background: #fff2d8;
  color: #986000;
}

.connection-status.is-error {
  background: #fff0ed;
  color: #9a382b;
}

.connection-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: -4px 0 18px;
}

.connection-summary span {
  padding: 14px 16px;
  border-radius: 12px;
  background: #f5f6f7;
  color: #68737b;
  font-size: 12px;
}

.connection-summary strong {
  display: block;
  margin-bottom: 3px;
  color: var(--ink);
  font-size: 22px;
}

.connection-table-tools {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 210px;
  gap: 10px;
  margin-bottom: 12px;
}

.connection-table-tools input {
  height: 42px;
  padding: 0 13px;
  border: 1px solid #d9dde1;
  border-radius: 10px;
}

.connection-table-tools select {
  height: 42px;
}

.connections-table td:first-child strong,
.connections-table td:first-child small {
  display: block;
}

.connections-table td:first-child small {
  margin-top: 4px;
  color: #929aa1;
  font-size: 10px;
}

.qr-card .connection-form {
  margin-top: 20px;
  text-align: left;
}

.card-heading {
  align-items: center;
  margin-bottom: 24px;
}

.card-heading h2 {
  margin: 0;
  font-size: 23px;
  letter-spacing: -0.025em;
}

.chart-legend {
  display: flex;
  gap: 18px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chart-legend span {
  display: flex;
  align-items: center;
  gap: 7px;
}

.chart-legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.legend-dialogs {
  background: var(--coral);
}

.legend-unanswered {
  background: #d9911e;
}

.chart-wrap {
  position: relative;
  min-height: 310px;
  overflow-x: auto;
}

#activity-chart {
  display: block;
  width: 100%;
  height: 310px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: #7d8790;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  vertical-align: bottom;
}

td {
  padding: 17px 14px;
  border-bottom: 1px solid #eff0f2;
  color: #3e4850;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.manager-row {
  cursor: pointer;
  transition: background 120ms ease;
}

.manager-row:hover {
  background: #faf6f4;
}

.manager-name {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font-weight: 800;
}

.avatar {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--charcoal);
  color: #fff;
  font-size: 12px;
}

.number-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.managers-table {
  min-width: 900px;
  table-layout: fixed;
}

.managers-table th:first-child,
.managers-table td:first-child {
  width: 34%;
}

.managers-table th:last-child,
.managers-table td:last-child {
  width: 14%;
  white-space: nowrap;
}

.managers-table th:not(:first-child):not(:last-child),
.managers-table td:not(:first-child):not(:last-child) {
  width: 13%;
}

.row-action {
  border: 0;
  background: transparent;
  color: var(--coral-dark);
  cursor: pointer;
  font-weight: 800;
}

.loading-cell,
.empty-state {
  padding: 36px 20px;
  color: var(--muted);
  text-align: center;
}

.updated-at {
  color: #91999f;
  font-size: 12px;
}

.alert {
  margin: 16px 0;
  padding: 13px 15px;
  border-radius: 11px;
  font-size: 13px;
  line-height: 1.5;
}

.alert-error {
  border: 1px solid #f0b8ae;
  background: #fff0ed;
  color: #9a382b;
}

.alert-warning {
  border: 1px solid #ead49b;
  background: #fff9e9;
  color: #755d1d;
}

.alert-success {
  border: 1px solid #b8dfc9;
  background: #edf8f2;
  color: #24764a;
}

.dialog-modal {
  width: min(calc(100% - 32px), 1120px);
  max-height: min(86vh, 850px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.3);
}

.dialog-modal::backdrop {
  background: rgba(18, 24, 28, 0.68);
  backdrop-filter: blur(4px);
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 26px;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin: 0;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: #56616a;
  cursor: pointer;
  font-size: 24px;
}

.dialog-table-wrap {
  max-height: 62vh;
  padding: 10px 26px 26px;
}

.crm-links {
  display: flex;
  gap: 8px;
}

.crm-links a {
  color: var(--blue);
  font-weight: 750;
  text-decoration: none;
}

@media (max-width: 900px) {
  .connection-layout {
    grid-template-columns: 1fr;
  }

  .connection-progress span:not(:last-child)::after {
    margin: 0 8px;
  }

  .filter-panel,
  .date-fields {
    align-items: stretch;
    flex-direction: column;
  }

  .manager-filter {
    width: 100%;
  }

  .date-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .date-fields input {
    width: 100%;
  }

  .date-separator {
    display: none;
  }

  .date-fields .button {
    grid-column: 1 / -1;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .metric-card {
    min-height: auto;
  }
}

@media (max-width: 620px) {
  .topbar {
    padding: 0 16px;
  }

  .connections-page .brand small {
    display: none;
  }

  .connections-page .topbar-actions {
    gap: 6px;
  }

  .connections-page .topbar-actions .button {
    min-height: 36px;
    padding: 0 9px;
    font-size: 12px;
  }

  .status-dot {
    display: none;
  }

  .dashboard-shell {
    width: min(calc(100% - 24px), 1480px);
    padding-top: 28px;
  }

  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .connection-progress {
    gap: 8px;
  }

  .connection-progress span {
    justify-content: center;
    font-size: 0;
  }

  .connection-progress span:not(:last-child)::after {
    display: none;
  }

  .connection-progress i {
    font-size: 12px;
  }

  .connection-summary,
  .connection-table-tools {
    grid-template-columns: 1fr;
  }

  .page-heading,
  .card-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-heading .button {
    width: 100%;
  }

  .date-fields {
    grid-template-columns: 1fr;
  }

  .date-fields .button {
    grid-column: auto;
  }

  .content-card,
  .metric-card {
    padding: 20px;
  }

  .chart-legend {
    flex-wrap: wrap;
  }

  .login-card {
    padding: 30px 24px;
  }
}
