:root {
  --bg: #0a0a0b;
  --sidebar: #17181b;
  --surface: #111214;
  --surface-2: #181a1f;
  --surface-3: #24262d;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f2f4f7;
  --muted: #a0a6b2;
  --muted-2: #737a86;
  --accent: #f1f1ee;
  --accent-text: #101114;
  --success: #6bc58b;
  --danger: #ff8b8b;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
  --radius-xl: 18px;
  --radius-lg: 14px;
  --radius-md: 12px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Roboto", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.04), transparent 18%),
    linear-gradient(180deg, #09090a 0%, #0c0d10 100%);
}

::selection {
  background: rgba(255, 255, 255, 0.14);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

h1,
h2,
h3,
p {
  margin: 0;
}

strong {
  font-weight: 500;
}

code {
  padding: 0.16rem 0.42rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.84em;
}

.hidden {
  display: none !important;
}

.app-layout {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.app-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  height: 100vh;
  padding: 14px 10px;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(24, 25, 28, 0.98), rgba(18, 19, 22, 0.98));
}

.sidebar-brand {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  color: var(--text);
  text-decoration: none;
}

.sidebar-brand span {
  font-size: 1.02rem;
  font-weight: 500;
  letter-spacing: -0.03em;
}

.sidebar-nav {
  display: grid;
  gap: 18px;
}

.sidebar-nav__group {
  display: grid;
  gap: 4px;
}

.sidebar-nav__label {
  padding: 0 10px 6px;
  color: var(--muted-2);
  font-size: 0.74rem;
  font-weight: 400;
}

.sidebar-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.94rem;
  font-weight: 400;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.sidebar-link:hover,
.sidebar-link:focus-visible {
  outline: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.sidebar-link__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  color: #8f95a0;
  flex: 0 0 auto;
}

.sidebar-link__icon svg {
  display: block;
  width: 16px;
  height: 16px;
}

body[data-page="dashboard"] .sidebar-link--dashboard,
body[data-page="admin"] .sidebar-link--admin {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.05);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.05));
}

body[data-page="dashboard"] .sidebar-link--dashboard .sidebar-link__icon,
body[data-page="admin"] .sidebar-link--admin .sidebar-link__icon {
  color: var(--text);
}

.app-main {
  min-width: 0;
  transition: opacity 180ms ease, transform 180ms ease;
}

body.is-soft-loading .app-main {
  opacity: 0.7;
  transform: translateY(4px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 54px;
  padding: 0 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 11, 0.84);
  backdrop-filter: blur(18px);
}

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

.ghost-badge,
.ghost-button,
.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.ghost-badge {
  max-width: 280px;
  overflow: hidden;
  justify-content: flex-start;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 0.83rem;
  cursor: default;
}

.ghost-button,
.action-button {
  cursor: pointer;
  font-weight: 400;
}

.ghost-button:hover,
.ghost-button:focus-visible,
.action-button:hover,
.action-button:focus-visible {
  outline: none;
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-strong);
}

.page-shell {
  padding: 20px;
}

.page-frame {
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(16, 17, 20, 0.92), rgba(11, 12, 14, 0.96));
  box-shadow: var(--shadow);
}

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-kicker,
.section-label,
.filter-field span {
  display: inline-flex;
  color: var(--muted-2);
  font-size: 0.73rem;
  font-weight: 400;
}

.page-title {
  font-size: clamp(1.6rem, 2.1vw, 2rem);
  line-height: 1;
  letter-spacing: -0.04em;
  font-weight: 500;
}

.page-description {
  max-width: 640px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.page-tabs,
.auth-tab-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.header-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 400;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
  white-space: nowrap;
}

.header-tab:hover,
.header-tab:focus-visible {
  outline: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.header-tab.active,
.header-tab--static {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.05);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
}

.page-content,
.stack-layout {
  display: grid;
  gap: 16px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(19, 20, 23, 0.98), rgba(14, 15, 18, 0.98));
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.24);
}

.panel-card--stack {
  display: grid;
  gap: 14px;
}

.compact-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.compact-form-head h2,
.table-toolbar h2 {
  font-size: 1.14rem;
  line-height: 1.1;
  letter-spacing: -0.03em;
  font-weight: 500;
}

.compact-form-head p,
.channel-subline,
.metric-total span,
.metric-delta small,
.empty-state p,
.added-cell span,
.auth-feature-item span,
.table-muted,
.summary-card__sub {
  color: var(--muted);
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.inline-form .primary-button,
.stack-form .primary-button {
  min-width: 132px;
}

.stack-form {
  display: grid;
  gap: 14px;
}

.stack-form label,
.filter-field {
  display: grid;
  gap: 8px;
}

.stack-form label span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 400;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
  color: var(--text);
}

input::placeholder {
  color: var(--muted-2);
}

input:focus,
select:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04);
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease;
}

.primary-button:hover,
.primary-button:focus-visible {
  outline: none;
  transform: translateY(-1px);
  filter: brightness(1.02);
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.table-toolbar--end {
  justify-content: flex-end;
}

.table-toolbar__group {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.custom-select {
  position: relative;
  width: 206px;
  min-width: 206px;
}

.custom-select__trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: #15171b;
  color: var(--text);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.custom-select__trigger:hover,
.custom-select.is-open .custom-select__trigger {
  border-color: rgba(255, 255, 255, 0.18);
  background: #191b20;
}

.custom-select__trigger:focus-visible {
  outline: none;
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04);
}

.custom-select__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
  font-weight: 400;
}

.custom-select__chevron {
  position: relative;
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
}

.custom-select__chevron::before,
.custom-select__chevron::after {
  content: "";
  position: absolute;
  top: 4px;
  width: 6px;
  height: 1.5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  transition: transform 140ms ease;
}

.custom-select__chevron::before {
  left: 0;
  transform: rotate(45deg);
}

.custom-select__chevron::after {
  right: 0;
  transform: rotate(-45deg);
}

.custom-select.is-open .custom-select__chevron::before {
  transform: rotate(-45deg);
}

.custom-select.is-open .custom-select__chevron::after {
  transform: rotate(45deg);
}

.custom-select__menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 100%;
  z-index: 40;
  display: grid;
  gap: 4px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: #33353c;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.42);
}

.custom-select__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 140ms ease;
}

.custom-select__option:hover,
.custom-select__option:focus-visible {
  outline: none;
  background: rgba(255, 255, 255, 0.04);
}

.custom-select__option.is-active {
  background: rgba(255, 255, 255, 0.12);
}

.custom-select__option-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
  font-weight: 400;
}

.custom-select__option-check {
  flex: 0 0 auto;
  opacity: 0;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1;
}

.custom-select__option.is-active .custom-select__option-check {
  opacity: 1;
}

.table-summary {
  display: grid;
  grid-template-columns: minmax(180px, 1.1fr) repeat(4, minmax(120px, 1fr));
  gap: 10px;
}

.summary-card {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
}

.summary-card__label {
  display: block;
  color: var(--muted-2);
  font-size: 0.72rem;
}

.summary-card__value {
  display: block;
  margin-top: 8px;
  font-size: 1rem;
  line-height: 1.1;
  font-weight: 500;
}

.summary-card__sub {
  display: block;
  margin-top: 4px;
  font-size: 0.76rem;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.015);
}

.analytics-table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
}

.analytics-table thead {
  background: rgba(255, 255, 255, 0.02);
}

.analytics-table th,
.analytics-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.analytics-table th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 400;
}

.analytics-table tbody tr {
  transition: background 140ms ease;
}

.analytics-table tbody tr:hover,
.analytics-table tbody tr.context-open {
  background: rgba(255, 255, 255, 0.025);
}

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

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 0.88rem;
  font-weight: 400;
  cursor: pointer;
}

.sort-button.is-active {
  color: var(--text);
}

.sort-indicator {
  color: var(--muted-2);
  font-size: 0.76rem;
}

.channel-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 208px;
}

.channel-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.05);
}

.channel-title {
  display: inline-block;
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.15;
}

.channel-title:hover {
  opacity: 0.88;
}

.channel-subline,
.table-muted {
  display: block;
  margin-top: 2px;
  font-size: 0.73rem;
  line-height: 1.2;
}

.owner-cell {
  min-width: 150px;
}

.added-cell {
  display: grid;
  gap: 3px;
  min-width: 126px;
}

.added-cell strong,
.metric-total strong,
.metric-delta strong {
  font-size: 0.93rem;
  line-height: 1.12;
  font-weight: 500;
}

.metric-total,
.metric-delta {
  display: grid;
  gap: 3px;
}

.metric-total span,
.metric-delta small,
.added-cell span {
  font-size: 0.72rem;
  line-height: 1.2;
}

.metric-delta--empty strong,
.delta-empty {
  color: var(--muted);
}

.delta-positive {
  color: var(--success);
}

.delta-negative {
  color: var(--danger);
}

.row-actions {
  display: flex;
  justify-content: flex-end;
}

.row-actions .action-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.empty-state {
  padding: 20px;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.015);
  text-align: center;
}

.empty-state h3 {
  font-size: 1rem;
  font-weight: 500;
}

.empty-state p {
  margin-top: 8px;
}

.invite-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.75rem;
  font-weight: 400;
}

.invite-status.active {
  color: var(--success);
}

.invite-status.used {
  color: var(--muted);
}

.auth-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(360px, 0.82fr);
  gap: 18px;
}

.auth-hero,
.auth-panel {
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(18, 19, 22, 0.98), rgba(13, 14, 17, 0.98));
  box-shadow: var(--shadow);
}

.auth-hero h1 {
  margin-top: 10px;
  font-size: clamp(1.8rem, 2.7vw, 2.6rem);
  line-height: 1;
  letter-spacing: -0.05em;
  font-weight: 500;
}

.auth-hero p {
  max-width: 560px;
  margin-top: 14px;
  color: var(--muted);
  line-height: 1.6;
}

.auth-feature-list {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.auth-feature-item {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
}

.auth-feature-item strong {
  font-size: 0.95rem;
  font-weight: 500;
}

.screen-loader {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 9, 11, 0.62);
  backdrop-filter: blur(8px);
}

.screen-loader__box {
  display: grid;
  justify-items: center;
  gap: 12px;
  min-width: 180px;
  padding: 18px 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: rgba(20, 21, 24, 0.96);
  box-shadow: var(--shadow);
}

.screen-loader__spinner {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: rgba(255, 255, 255, 0.88);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100% - 24px));
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(24, 25, 29, 0.96);
  color: var(--text);
  box-shadow: var(--shadow);
  z-index: 90;
}

.toast.success {
  border-color: rgba(107, 197, 139, 0.3);
}

.toast.error {
  border-color: rgba(255, 139, 139, 0.28);
}

body[data-page="login"] .app-layout {
  grid-template-columns: 1fr;
}

body[data-page="login"] .app-sidebar,
body[data-page="login"] .topbar {
  display: none;
}

body[data-page="login"] .page-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

body[data-page="login"] .page-frame {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

body[data-page="login"] .page-heading,
body[data-page="login"] .page-tabs {
  display: none;
}

@media (max-width: 1180px) {
  .auth-shell {
    grid-template-columns: 1fr;
  }
}

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

  .app-sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .topbar {
    padding: 0 18px;
  }

  .page-shell {
    padding: 18px;
  }

  .page-frame {
    padding: 18px;
  }

  .table-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .compact-form-head,
  .table-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .page-tabs,
  .auth-tab-strip,
  .topbar-actions,
  .table-summary {
    width: 100%;
    flex-wrap: wrap;
  }

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

  .inline-form {
    grid-template-columns: 1fr;
  }

  .inline-form .primary-button,
  .custom-select,
  .filter-field,
  .ghost-button,
  .primary-button {
    width: 100%;
    min-width: 0;
  }

  .page-shell {
    padding: 12px;
  }

  .page-frame,
  .panel-card,
  .auth-hero,
  .auth-panel {
    padding: 18px;
  }

  .analytics-table th,
  .analytics-table td {
    padding: 12px 10px;
  }
}

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