@import url("tokens.css");

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body.menu-open {
  overflow: hidden;
}

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

a {
  color: inherit;
  text-decoration: none;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* ——— Sidebar ——— */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-current-w);
  background:
    linear-gradient(180deg, rgba(46, 229, 157, 0.03) 0%, transparent 120px),
    var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: width 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  overflow: visible;
}

.sidebar-top {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 12px 8px;
  overflow: hidden;
  transition: padding 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.sidebar-brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px 16px;
  min-height: 40px;
  transition: padding 0.32s cubic-bezier(0.22, 1, 0.36, 1), gap 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.sidebar-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(46, 229, 157, 0.18);
}

.sidebar-logo img {
  width: 28px;
  height: 28px;
  display: block;
}

.sidebar-brand {
  flex: 1;
  min-width: 0;
  max-width: 140px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition:
    opacity 0.18s ease,
    max-width 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    flex-basis 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.sidebar-collapse {
  position: absolute;
  top: 54px;
  right: 0;
  z-index: 110;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  transform: translateX(50%);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.sidebar-collapse:hover {
  background: var(--surface-3);
  border-color: var(--faint);
  color: var(--text);
}

.sidebar-collapse svg {
  position: absolute;
  width: 14px;
  height: 14px;
  transition: opacity 0.2s ease;
}

.sidebar-collapse-collapse {
  opacity: 1;
}

.sidebar-collapse-expand {
  opacity: 0;
}

html[data-sidebar="collapsed"] .sidebar-collapse-collapse {
  opacity: 0;
}

html[data-sidebar="collapsed"] .sidebar-collapse-expand {
  opacity: 1;
}

.sidebar-close,
.sidebar-sheet-handle {
  display: none;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  padding-right: 2px;
}

.nav-item {
  position: relative;
  width: 100%;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 0 10px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 450;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  overflow: hidden;
  transition:
    background 0.15s,
    color 0.15s,
    padding 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    gap 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.22s ease;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.72;
  transition: opacity 0.15s, color 0.15s;
}

.nav-item span {
  display: block;
  min-width: 0;
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 1;
  transition:
    opacity 0.16s ease,
    max-width 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.nav-item:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item:hover:not(:disabled) svg {
  opacity: 1;
}

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 500;
  box-shadow: inset 2px 0 0 var(--accent);
}

.nav-item.is-active svg {
  opacity: 1;
  color: var(--accent);
}

.nav-item.is-disabled,
.nav-item:disabled {
  opacity: 0.35;
  cursor: default;
}

.sidebar-bottom {
  padding: 8px 12px 12px;
  border-top: 1px solid var(--line);
  transition: padding 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.sidebar-profile-wrap {
  position: relative;
}

.sidebar-profile-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  transition:
    background 0.15s,
    border-color 0.15s,
    padding 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    gap 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.sidebar-profile-trigger:hover,
.sidebar-profile-trigger.is-open {
  background: var(--surface-2);
  border-color: var(--line);
}

.sidebar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  object-fit: cover;
  flex-shrink: 0;
}

.sidebar-user-meta {
  flex: 1;
  min-width: 0;
  max-width: 140px;
  opacity: 1;
  overflow: hidden;
  transition:
    opacity 0.16s ease,
    max-width 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.sidebar-user-name {
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-stats {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-profile-chevron {
  width: 8px;
  height: 8px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
  flex-shrink: 0;
  opacity: 1;
  transition: transform 0.15s, opacity 0.16s ease;
}

.sidebar-profile-trigger.is-open .sidebar-profile-chevron {
  transform: rotate(-135deg) translateY(1px);
}

.sidebar-profile-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  z-index: 120;
}

.sidebar-profile-menu:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-profile-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.sidebar-profile-menu-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.8;
}

.sidebar-profile-menu-item:hover {
  color: var(--text);
  background: var(--surface-3);
}

.sidebar-profile-menu-item:hover svg {
  opacity: 1;
}

.sidebar-profile-menu-item.is-danger:hover {
  color: var(--danger);
  background: rgba(255, 107, 107, 0.06);
}

.sidebar-profile-menu-item.is-hidden {
  display: none;
}

.sidebar-profile-menu-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--line);
}

/* Collapsed rail (desktop) — animate opacity/width, no display:none snaps */

@media (min-width: 769px) {
  html[data-sidebar="collapsed"] .sidebar-brand,
  html[data-sidebar="collapsed"] .nav-item > span,
  html[data-sidebar="collapsed"] .sidebar-user-meta {
    opacity: 0;
    max-width: 0;
    pointer-events: none;
  }

  html[data-sidebar="collapsed"] .sidebar-profile-chevron {
    opacity: 0;
    width: 0;
    height: 0;
    border: none;
    margin: 0;
  }

  html[data-sidebar="collapsed"] .sidebar-top {
    padding: 14px 10px 8px;
  }

  html[data-sidebar="collapsed"] .sidebar-brand-row {
    gap: 0;
    padding: 2px 0 14px;
  }

  html[data-sidebar="collapsed"] .nav-item {
    gap: 0;
    padding: 0 13px;
    box-shadow: none;
  }

  html[data-sidebar="collapsed"] .nav-item.is-active {
    box-shadow: none;
    background: var(--accent-soft);
  }

  html[data-sidebar="collapsed"] .sidebar-bottom {
    padding: 8px 10px 12px;
  }

  html[data-sidebar="collapsed"] .sidebar-profile-trigger {
    gap: 0;
    padding: 6px 9px;
  }

  html[data-sidebar="collapsed"] .sidebar-profile-menu {
    left: calc(100% + 12px);
    right: auto;
    bottom: 0;
    min-width: 200px;
  }

  html[data-sidebar="collapsed"] .nav-item[data-tip]::after,
  html[data-sidebar="collapsed"] .sidebar-collapse[data-tip]::after,
  html[data-sidebar="collapsed"] .sidebar-profile-trigger[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    padding: 6px 9px;
    border-radius: 7px;
    background: var(--surface-3);
    border: 1px solid var(--line);
    color: var(--text);
    font-size: 12px;
    font-weight: 450;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
    z-index: 140;
    transition: opacity 0.12s;
  }

  html[data-sidebar="collapsed"] .nav-item[data-tip]:hover::after,
  html[data-sidebar="collapsed"] .sidebar-collapse[data-tip]:hover::after,
  html[data-sidebar="collapsed"] .sidebar-profile-trigger[data-tip]:hover::after {
    opacity: 1;
  }
}

.page-subtitle {
  margin: -12px 0 20px;
  font-size: 12px;
  color: var(--muted);
}

/* ——— Settings page ——— */

.settings-layout {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 56px;
}

.settings-tab {
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 450;
  text-align: left;
  cursor: pointer;
}

.settings-tab:hover {
  background: var(--surface-2);
  color: var(--text);
}

.settings-tab.is-active {
  background: var(--surface-3);
  color: var(--text);
  font-weight: 500;
}

.settings-panels {
  min-width: 0;
}

.settings-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px;
}

.settings-panel-head {
  margin-bottom: 14px;
}

.settings-panel-title {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
}

.settings-panel-desc {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 480px;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.settings-field .settings-label {
  font-size: 11px;
  color: var(--muted);
}

.settings-hint {
  margin: 0;
  font-size: 11px;
  color: var(--faint);
  line-height: 1.45;
}

.settings-segments {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: var(--surface-2);
}

.settings-segment {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  padding: 7px 8px;
  cursor: pointer;
  white-space: nowrap;
}

.settings-segment.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

.settings-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.settings-toggle-label {
  font-size: 12px;
  font-weight: 500;
}

.settings-avatar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.settings-avatar-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}

.settings-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  object-fit: cover;
  background: var(--surface-2);
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
}

.settings-status {
  font-size: 11px;
  color: var(--muted);
}

.settings-status.is-ok {
  color: var(--green);
}

.settings-status.is-error {
  color: var(--danger);
}

.settings-soon-card {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.settings-status-row {
  margin-bottom: 4px;
}

.badge-soon,
.badge-off {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 500;
}

.badge-soon {
  background: rgba(130, 177, 255, 0.12);
  color: #82b1ff;
}

.badge-off {
  background: rgba(255, 107, 107, 0.1);
  color: var(--danger);
}

.textarea {
  width: 100%;
  min-height: 72px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  resize: vertical;
}

.textarea:focus {
  outline: none;
  border-color: var(--faint);
}

.toggle {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.15s;
  position: relative;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.15s;
}

.toggle input:checked + .toggle-track {
  background: rgba(130, 177, 255, 0.45);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(16px);
}

.settings-panel .custom-select {
  width: 100%;
  min-width: 0;
}

.settings-panel .custom-select-trigger {
  border-color: var(--line);
}

/* ——— Shell ——— */

.shell {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-current-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  transition: margin-left 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  overflow-x: clip;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  background: var(--topnav-bg);
  border-bottom: 1px solid var(--line);
}

.menu-toggle {
  display: none;
}

@media (min-width: 901px) {
  .topbar {
    display: none;
  }

  .menu-toggle {
    display: none;
  }
}

.topbar-spacer {
  flex: 1;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pref-btn {
  height: 28px;
  min-width: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}

.pref-btn:hover {
  color: var(--text);
  border-color: var(--faint);
}

.pref-btn.is-active {
  color: var(--green);
  border-color: var(--green);
}

.main {
  flex: 1;
  width: 100%;
  max-width: calc(var(--content-max) + var(--page-gutter) * 2);
  margin: 0 auto;
  padding: 28px var(--page-gutter) 40px;
  box-sizing: border-box;
  min-width: 0;
}

/* ——— Dashboard ——— */

.page-greeting {
  margin: 0 0 20px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.page-greeting em {
  font-style: normal;
  color: var(--muted);
}

.section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 12px;
}

.section-head {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
}

.section-title {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.period-select,
.custom-select-host {
  position: relative;
  min-width: 168px;
}

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

.custom-select-trigger {
  width: 100%;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 10px 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 450;
  cursor: pointer;
  text-align: left;
}

[data-theme="light"] .custom-select-trigger {
  border-color: var(--line);
}

.custom-select-trigger:hover {
  background: var(--surface-3);
}

.custom-select-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-select-chevron {
  width: 8px;
  height: 8px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
  flex-shrink: 0;
  transition: transform 0.15s;
}

.custom-select.is-open .custom-select-chevron {
  transform: rotate(-135deg) translateY(1px);
}

table.data tr.empty-row td {
  padding: 28px 16px;
  text-align: center;
  color: var(--faint);
  font-size: 12px;
  border-bottom: none;
}

table.data th.col-num,
table.data td.td-num {
  text-align: right;
}

table.data th.col-num .th-sort {
  justify-content: flex-end;
}

.custom-select-menu {
  position: fixed;
  min-width: 168px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  z-index: 2000;
}

.custom-select-menu:not([hidden]) {
  display: block;
}

.sites-dialog,
.sites-dialog-body,
.link-create-body,
.link-create-panel,
.link-field {
  overflow: visible;
}

.sites-dialog .custom-select-trigger {
  border-color: var(--line);
  border-radius: var(--radius);
}

.link-field .custom-select {
  width: 100%;
  min-width: 0;
}

.custom-select-host-sm {
  min-width: 132px;
}

.custom-select-host-sm .custom-select {
  min-width: 132px;
}

.custom-select-option {
  width: 100%;
  display: block;
  padding: 8px 10px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.custom-select-option:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.custom-select-option.is-selected {
  background: #82b1ff;
  color: #111111;
}

[data-theme="light"] .custom-select-option.is-selected {
  background: #6ea8fe;
  color: #111111;
}

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

.kpi-cell {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  min-height: 0;
  overflow: hidden;
}

.kpi-cell:nth-child(odd) {
  border-right: 1px solid var(--line-soft);
}

.kpi-cell:nth-child(-n + 2) {
  border-bottom: 1px solid var(--line-soft);
}

.kpi-cell-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.kpi-icon {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  flex-shrink: 0;
  color: var(--muted);
  background: var(--surface-2);
}

.kpi-icon svg {
  width: 13px;
  height: 13px;
  display: block;
}

.kpi-icon-profit {
  color: var(--accent);
  background: var(--accent-soft);
}

.kpi-icon-period {
  color: var(--muted);
  background: var(--surface-2);
}

.kpi-icon-logs {
  color: #b0b0b0;
}

.kpi-icon-mafile {
  color: #d4a017;
  background: rgba(212, 160, 23, 0.12);
}

.kpi-label {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.25;
  padding: 0;
}

.kpi-hint {
  font-size: 10px;
  color: var(--faint);
  font-weight: 400;
}

.kpi-cell-main {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.kpi-cell-nums {
  flex: 1;
  min-width: 0;
}

.kpi-value {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.kpi-delta {
  margin-top: 3px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--faint);
}

.kpi-delta-pct {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.kpi-delta.neutral .kpi-delta-pct {
  color: var(--muted);
}

.kpi-delta.up .kpi-delta-pct {
  color: var(--success);
}

.kpi-delta.down .kpi-delta-pct {
  color: var(--danger);
}

.kpi-delta-suffix {
  color: var(--faint);
}

.kpi-spark {
  width: 38%;
  max-width: 120px;
  height: 24px;
  margin: 0 0 2px;
  flex-shrink: 0;
  opacity: 0.85;
}

.kpi-spark.is-empty {
  opacity: 0.35;
}

.kpi-spark svg {
  display: block;
  width: 100%;
  height: 24px;
  overflow: visible;
}

.kpi-spark polyline,
.kpi-spark path {
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.kpi-spark-profit polyline,
.kpi-spark-profit path,
.kpi-spark-period polyline,
.kpi-spark-period path {
  stroke: var(--accent);
}

.kpi-spark-logs polyline,
.kpi-spark-logs path {
  stroke: #9a9a9a;
}

.kpi-spark-mafile polyline,
.kpi-spark-mafile path {
  stroke: #d4a017;
}

.kpi-foot {
  margin-top: 8px;
  font-size: 10.5px;
  color: var(--faint);
}

@media (max-width: 640px) {
  .kpi-cell-main {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .kpi-spark {
    width: 100%;
    max-width: none;
  }
}

.chart-area {
  padding: 4px 8px 10px;
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
}

.chart-legend-item:hover {
  color: var(--text);
  border-color: var(--line);
}

.chart-legend-item.is-off {
  opacity: 0.4;
}

.chart-legend-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chart-legend-dot-logs,
.chart-legend-dot-count {
  background: #8a8a8a;
}

.chart-legend-dot-mafile {
  background: #d4a017;
}

.chart-legend-dot-profit,
.chart-legend-dot-amount {
  background: #f2f2f2;
}

[data-theme="light"] .chart-legend-dot-logs,
[data-theme="light"] .chart-legend-dot-count {
  background: #999;
}

[data-theme="light"] .chart-legend-dot-mafile {
  background: #b8860b;
}

[data-theme="light"] .chart-legend-dot-profit,
[data-theme="light"] .chart-legend-dot-amount {
  background: #222;
}

/* ——— Dynamics line chart ——— */

.section-dynamics .section-head {
  border-bottom: none;
  padding-bottom: 4px;
}

.dynamics-chart {
  position: relative;
  width: 100%;
  min-height: 240px;
}

.dynamics-chart-inner {
  position: relative;
  width: 100%;
  height: 240px;
  overflow: hidden;
}

.dynamics-svg {
  display: block;
  width: 100%;
  height: 240px;
}

.dynamics-grid line {
  stroke: var(--chart-grid);
  stroke-width: 1;
  stroke-dasharray: 3 5;
}

.dynamics-axis-line {
  stroke: var(--line);
  stroke-width: 1;
}

.dynamics-axis text {
  fill: var(--faint);
  font-size: 10px;
  font-family: var(--font);
}

.dynamics-x-labels text {
  fill: var(--muted);
  font-size: 10px;
  font-family: var(--font);
}

.dynamics-area {
  pointer-events: none;
}

.dynamics-area-profit {
  fill: url(#dynamicsProfitFill);
}

.dynamics-area-logs {
  fill: url(#dynamicsLogsFill);
}

[data-theme="light"] .dynamics-area-profit {
  fill: url(#dynamicsProfitFillLight);
}

.dynamics-line {
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.dynamics-line-logs,
.dynamics-line-count {
  stroke: #8a8a8a;
}

.dynamics-line-mafile {
  stroke: #d4a017;
}

.dynamics-line-profit,
.dynamics-line-amount {
  stroke: #f0f0f0;
}

[data-theme="light"] .dynamics-line-logs,
[data-theme="light"] .dynamics-line-count {
  stroke: #888;
}

[data-theme="light"] .dynamics-line-mafile {
  stroke: #b8860b;
}

[data-theme="light"] .dynamics-line-profit,
[data-theme="light"] .dynamics-line-amount {
  stroke: #222;
}

.dynamics-guide {
  stroke: var(--line);
  stroke-width: 1;
  stroke-dasharray: 2 4;
  opacity: 0;
  pointer-events: none;
}

.dynamics-dot-group:hover .dynamics-guide {
  opacity: 1;
}

.dynamics-dot {
  fill: var(--surface);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  opacity: 0;
  transition: opacity 0.12s;
}

.dynamics-dot-group:hover .dynamics-dot {
  opacity: 1;
}

.dynamics-dot-logs,
.dynamics-dot-count {
  stroke: #8a8a8a;
}

.dynamics-dot-mafile {
  stroke: #d4a017;
}

.dynamics-dot-profit,
.dynamics-dot-amount {
  stroke: #f0f0f0;
}

[data-theme="light"] .dynamics-dot-logs,
[data-theme="light"] .dynamics-dot-count {
  stroke: #888;
}

[data-theme="light"] .dynamics-dot-mafile {
  stroke: #b8860b;
}

[data-theme="light"] .dynamics-dot-profit,
[data-theme="light"] .dynamics-dot-amount {
  stroke: #222;
}

.dynamics-hit {
  fill: transparent;
  cursor: crosshair;
}

.dynamics-tooltip {
  position: absolute;
  transform: translateX(-50%);
  min-width: 148px;
  padding: 10px 12px;
  background: var(--chart-tooltip-bg);
  border: 1px solid var(--chart-tooltip-border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  pointer-events: none;
  z-index: 5;
}

.dynamics-tooltip[hidden] {
  display: none !important;
}

.dynamics-tooltip-date {
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 8px;
}

.dynamics-tooltip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.55;
}

.dynamics-tooltip-swatch {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dynamics-tooltip-logs .dynamics-tooltip-swatch,
.dynamics-tooltip-count .dynamics-tooltip-swatch {
  background: #8a8a8a;
}

.dynamics-tooltip-mafile .dynamics-tooltip-swatch {
  background: #d4a017;
}

.dynamics-tooltip-profit .dynamics-tooltip-swatch,
.dynamics-tooltip-amount .dynamics-tooltip-swatch {
  background: #f0f0f0;
}

.dynamics-empty {
  display: grid;
  place-items: center;
  min-height: 240px;
  color: var(--faint);
  font-size: 12px;
}

.dynamics-chart.is-empty .dynamics-chart-inner {
  display: none;
}

/* ——— Events feed ——— */

.events-sort-host {
  min-width: 168px;
}

.events-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--faint);
  font-size: 12.5px;
}

.events-feed {
  display: flex;
  flex-direction: column;
  padding: 4px 8px 10px;
}

.event-row {
  position: relative;
  width: 100%;
  display: flex;
  align-items: stretch;
  gap: 0;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: background 0.15s;
}

.event-row:hover {
  background: var(--surface-2);
}

.event-row-accent {
  width: 3px;
  margin: 10px 0 10px 8px;
  border-radius: 999px;
  background: #6b6b6b;
  flex-shrink: 0;
}

.event-row.is-log .event-row-accent {
  background: #8a8a8a;
}

.event-row.is-mafile .event-row-accent {
  background: #d4a017;
}

.event-row-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 12px 12px 12px;
}

.event-row-top {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.event-row-account {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-row-price {
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  flex-shrink: 0;
}

.event-row-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--muted);
}

.event-row-id {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11px;
}

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

table.data th,
table.data td {
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}

table.data th {
  font-size: 11px;
  font-weight: 500;
  color: var(--faint);
  background: var(--surface-2);
}

table.data th.sortable {
  cursor: pointer;
  user-select: none;
}

table.data th.sortable:hover {
  color: var(--text);
}

.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.th-sort-icon {
  font-size: 9px;
  line-height: 1;
  color: var(--faint);
}

table.data th.is-sorted .th-sort-icon {
  color: var(--blue);
}

table.data tbody tr:hover td {
  background: var(--surface-2);
}

table.data tbody tr.is-clickable {
  cursor: pointer;
}

table.data tbody tr.is-clickable:focus-visible td {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

.event-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  margin: 4px 0 0;
}

.event-detail-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.event-detail-item dt {
  margin: 0;
  font-size: 10.5px;
  color: var(--muted);
}

.event-detail-item dd {
  margin: 0;
  font-size: 12px;
  color: var(--text);
  word-break: break-word;
}

.event-detail-item code {
  font-family: var(--mono);
  font-size: 11.5px;
}

.event-card-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(94dvh, calc(var(--tg-viewport-stable-height, 100dvh) - 12px));
}

.event-card-body {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.event-card-scroll {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 14px 10px;
  min-height: 0;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.event-card-sticky {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line-soft);
  background: var(--surface);
}

.event-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.event-card-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.badge-vac {
  border-color: rgba(255, 107, 107, 0.35);
  background: rgba(255, 107, 107, 0.12);
  color: #ff8a8a;
}

.event-card-head-text {
  min-width: 0;
}

.event-card-head .sites-dialog-title {
  margin-bottom: 4px;
}

.event-money-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.event-money-card {
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--surface-2);
}

.event-money-card.is-total {
  border-color: rgba(46, 229, 157, 0.25);
  background: var(--accent-soft);
}

.event-money-label {
  font-size: 10.5px;
  color: var(--muted);
  margin-bottom: 4px;
}

.event-money-value {
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.event-block {
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--surface-2);
}

.event-block-title {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
}

.event-games-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.event-games-stage {
  position: relative;
  overflow: hidden;
  min-height: 96px;
}

.event-games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}

.event-game-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 6px 4px 4px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  min-width: 0;
}

.event-game-tile:hover,
.event-game-tile:focus-visible {
  background: var(--surface-3);
  border-color: var(--line);
}

.event-game-tile-art {
  position: relative;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.event-game-tile-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
}

.event-game-tile-icon.is-fallback {
  background: linear-gradient(135deg, #2a2a2a, #3a3a3a);
}

.event-game-vac {
  position: absolute;
  top: -5px;
  right: -6px;
  padding: 1px 4px;
  border-radius: 4px;
  background: #c23b3b;
  color: #fff;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.3;
  box-shadow: 0 0 0 2px var(--surface-2);
}

.event-game-tile-name {
  width: 100%;
  font-size: 10.5px;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-game-tile-hours {
  font-size: 10px;
  color: var(--faint);
}

.event-game-inv-panel {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: var(--surface-2);
  transform: translateX(100%);
  transition: transform 0.22s ease;
  overflow: auto;
}

.event-games-stage.is-inv-open .event-game-inv-panel {
  transform: translateX(0);
}

.event-game-inv-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 4px 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.event-game-inv-back svg {
  width: 16px;
  height: 16px;
}

.event-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 8px 0 4px;
}

.event-game-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 5px 8px 5px 5px;
  border-radius: 8px;
  background: var(--surface-3);
  border: 1px solid var(--line);
}

.event-game-icon {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface);
}

.event-game-icon.is-fallback {
  display: inline-block;
  background: linear-gradient(135deg, #2a2a2a, #3a3a3a);
}

.event-game-name {
  min-width: 0;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-game-meta {
  flex-shrink: 0;
  font-size: 10.5px;
  color: var(--faint);
}

.event-items-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.event-item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.event-item-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--line);
}

.event-item-icon.is-fallback {
  display: inline-block;
  background: linear-gradient(135deg, #2a2a2a, #3a3a3a);
}

.event-item-name {
  flex: 1;
  min-width: 0;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-item-price {
  flex-shrink: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.event-card-tools {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.event-tool-btn {
  width: 100%;
  justify-content: center;
  text-align: center;
}

.event-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 0;
  border-top: none;
}

.event-card-footer .btn-primary {
  min-width: 120px;
}

.event-card-body .kpi-hint {
  min-height: 16px;
}

@media (max-width: 520px) {
  .event-detail-grid,
  .event-money-grid,
  .event-card-tools {
    grid-template-columns: 1fr;
  }

  .event-card-footer {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .event-card-footer .btn-primary {
    width: 100%;
  }
}

table.data tr:last-child td {
  border-bottom: none;
}

.muted {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 500;
}

.badge.ok {
  background: rgba(62, 207, 142, 0.12);
  color: var(--success);
}

.badge.warn {
  background: rgba(201, 162, 39, 0.12);
  color: var(--warn);
}

.badge.bad {
  background: rgba(255, 107, 107, 0.1);
  color: var(--danger);
}

.badge.type {
  background: var(--surface-3);
  color: var(--muted);
}

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
}

.inline-alert {
  padding: 8px 16px;
  font-size: 12px;
  color: var(--warn);
  border-bottom: 1px solid var(--line-soft);
  background: rgba(201, 162, 39, 0.06);
}

.page-head h1 {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.sidebar-backdrop {
  display: none;
}

/* ——— Login ——— */

.login-body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

.login-page {
  position: relative;
  isolation: isolate;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.login-atmosphere {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.login-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.9;
  animation: loginGlowDrift 14s ease-in-out infinite alternate;
}

.login-glow-a {
  width: min(70vw, 520px);
  height: min(70vw, 520px);
  top: -12%;
  left: calc(50% - min(35vw, 260px));
  background: radial-gradient(circle, var(--login-gradient-1) 0%, transparent 68%);
}

.login-glow-b {
  width: min(55vw, 420px);
  height: min(55vw, 420px);
  right: -8%;
  bottom: 8%;
  background: radial-gradient(circle, var(--login-gradient-2) 0%, transparent 70%);
  animation-delay: -4s;
}

.login-grid {
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 38%, #000 20%, transparent 75%);
}

.login-topbar {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 0;
}

.login-controls {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin: 0;
}

.login-stage {
  position: relative;
  z-index: 1;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px 20px calc(40px + env(safe-area-inset-bottom, 0px));
}

.login-hero {
  width: min(100%, 400px);
  text-align: center;
  animation: loginRise 0.55s ease-out both;
}

.login-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  display: grid;
  place-items: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  animation: loginMarkIn 0.7s ease-out both;
}

.login-mark img {
  width: 40px;
  height: 40px;
  display: block;
}

.login-brand {
  margin: 0 0 6px;
  font-size: clamp(32px, 8vw, 42px);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1.05;
  color: var(--text);
}

.login-kicker {
  margin: 0 0 18px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.login-subtitle {
  margin: 0 auto 22px;
  max-width: 32ch;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.55;
}

.login-error {
  display: none;
  padding: 10px 12px;
  margin: 0 0 14px;
  border-radius: 10px;
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.22);
  color: var(--danger);
  font-size: 12.5px;
  line-height: 1.4;
  text-align: left;
}

.login-error.is-visible {
  display: block;
  animation: loginRise 0.25s ease-out both;
}

.btn-telegram {
  width: 100%;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: none;
  border-radius: 12px;
  background: #229ed9;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
}

.btn-telegram-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn-telegram:hover {
  filter: brightness(1.06);
}

.btn-telegram:active {
  transform: translateY(1px);
}

.btn-telegram:disabled {
  opacity: 0.65;
  cursor: wait;
}

.login-footnote {
  margin: 16px 0 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--faint);
}

@keyframes loginRise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes loginMarkIn {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes loginGlowDrift {
  from {
    transform: translate3d(0, 0, 0) scale(1);
  }
  to {
    transform: translate3d(2%, 3%, 0) scale(1.06);
  }
}

@media (prefers-reduced-motion: reduce) {
  .login-hero,
  .login-mark,
  .login-glow,
  .login-error.is-visible {
    animation: none;
  }
}

@media (max-width: 480px) {
  .login-stage {
    padding-top: 12px;
  }

  .login-brand {
    font-size: 34px;
  }

  .login-mark {
    width: 58px;
    height: 58px;
    border-radius: 16px;
  }

  .login-mark img {
    width: 34px;
    height: 34px;
  }
}

/* ——— Shared controls ——— */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--faint);
}

.btn-primary {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.btn-primary:hover {
  opacity: 0.92;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-danger {
  background: rgba(255, 107, 107, 0.08);
  border-color: rgba(255, 107, 107, 0.35);
  color: var(--danger);
}

.input {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
}

.input:focus {
  outline: none;
  border-color: var(--faint);
}

.input::placeholder {
  color: var(--faint);
}

/* ——— Sites ——— */

.sites-page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.sites-page-heading {
  min-width: 0;
}

.sites-page-heading .page-greeting {
  margin-bottom: 5px;
}

.sites-page-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.sites-page-head .sites-add-btn {
  height: 38px;
  padding: 0 15px;
}

.sites-add-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.sites-overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.sites-overview-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.sites-overview-icon {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-3);
}

.sites-overview-icon svg {
  width: 15px;
  height: 15px;
}

.sites-overview-item.is-active .sites-overview-icon {
  color: var(--accent);
  background: var(--accent-soft);
}

.sites-overview-item.is-paused .sites-overview-icon {
  color: #ff9b9b;
  background: rgba(207, 70, 70, 0.12);
}

.sites-overview-item.is-links .sites-overview-icon {
  color: var(--blue);
  background: rgba(59, 158, 255, 0.12);
}

.sites-overview-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
}

.sites-overview-copy strong {
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.sites-overview-copy span {
  color: var(--faint);
  font-size: 10px;
  line-height: 1.25;
}

.sites-list-section {
  min-width: 0;
}

.sites-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.sites-toolbar .sites-filter-select,
.sites-toolbar .custom-select-host {
  flex: 0 0 148px;
  width: 148px;
}

.sites-links-paused-note {
  margin: 0;
  padding: 0 16px 12px;
  font-size: 11px;
}

.sites-search {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.sites-search-compact {
  flex: none;
  width: 100%;
  margin-bottom: 10px;
}

.sites-search svg {
  width: 14px;
  height: 14px;
  color: var(--faint);
  flex-shrink: 0;
}

.sites-search input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 12px;
}

.sites-search input:focus {
  outline: none;
}

.sites-search:focus-within {
  border-color: var(--faint);
  background: var(--surface-3);
  box-shadow: 0 0 0 3px rgba(127, 127, 127, 0.07);
}

.sites-filter-select {
  width: 128px;
  flex-shrink: 0;
}

.sites-filter-select .custom-select-trigger {
  height: 36px;
}

.sites-add-btn {
  height: 36px;
  padding: 0 14px;
  flex-shrink: 0;
  font-size: 12px;
}

.sites-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.sites-empty {
  grid-column: 1 / -1;
  padding: 40px 16px;
  text-align: center;
  color: var(--faint);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  font-size: 12px;
}

.site-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  overflow: visible;
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s, transform 0.18s;
}

.site-card:hover,
.site-card:focus-visible {
  border-color: var(--faint);
  background: var(--surface-2);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.16);
  transform: translateY(-1px);
  outline: none;
}

.site-card.is-paused {
  background: color-mix(in srgb, var(--surface) 94%, #cf4646 6%);
}

.site-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 16px 12px;
}

.site-card-id {
  min-width: 0;
  flex: 1;
}

.site-card-title-row {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  margin-bottom: 4px;
}

.site-card-status {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.site-card-status.is-on {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.site-card-status.is-off {
  background: #ff7a7a;
  box-shadow: 0 0 0 3px rgba(207, 70, 70, 0.16);
}

.site-card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-card-created {
  display: block;
  color: var(--faint);
  font-size: 10.5px;
  line-height: 1.25;
}

.site-health {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 16px 12px;
  padding: 9px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.015);
}

.site-health-label {
  color: var(--faint);
  font-size: 10.5px;
  white-space: nowrap;
}

.site-card-kpi {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  margin: 0 16px;
  padding: 0;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-2);
}

.site-mini-stat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px;
  text-align: left;
  min-width: 0;
}

.site-mini-stat + .site-mini-stat {
  border-left: 1px solid var(--line-soft);
}

.site-mini-stat-icon {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  flex-shrink: 0;
  color: var(--muted);
  background: var(--surface-3);
}

.site-mini-stat-icon svg {
  width: 13px;
  height: 13px;
  display: block;
}

.site-mini-stat:nth-child(1) .site-mini-stat-icon {
  color: var(--blue);
  background: rgba(59, 158, 255, 0.12);
}

.site-mini-stat:nth-child(2) .site-mini-stat-icon {
  color: #c9a227;
  background: rgba(201, 162, 39, 0.12);
}

.site-mini-stat:nth-child(3) .site-mini-stat-icon {
  color: var(--accent);
  background: var(--accent-soft);
}

.site-mini-stat:nth-child(4) .site-mini-stat-icon {
  color: #b0b0b0;
  background: rgba(255, 255, 255, 0.05);
}

.site-mini-stat-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.site-mini-stat-val {
  display: block;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.site-mini-stat-lbl {
  display: block;
  font-size: 10px;
  color: var(--faint);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 13px;
  padding: 11px 16px 13px;
  border-top: 1px solid var(--line-soft);
  font-size: 11px;
}

.site-card-links {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.site-card-links svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.site-card-go {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, gap 0.15s;
}

.site-card-go svg {
  width: 14px;
  height: 14px;
}

.site-card:hover .site-card-go {
  color: var(--accent);
  gap: 4px;
}

.site-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.site-badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 500;
  line-height: 1;
}

.site-badge-paused {
  background: rgba(207, 70, 70, 0.14);
  color: #ff9b9b;
}

.site-badge-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.site-badge-team {
  background: rgba(45, 122, 77, 0.18);
  color: #7ddea3;
}

.site-badge-own {
  background: rgba(147, 197, 253, 0.12);
  color: #93c5fd;
}

.site-card-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.site-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.site-tool-count {
  cursor: default;
  padding: 0 8px;
}

.site-tool-check {
  position: relative;
  width: auto;
  padding: 0 9px;
  gap: 5px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.site-tool-check:hover,
.site-tool-check:focus-visible {
  color: var(--text);
  border-color: var(--faint);
  background: var(--surface-3);
  outline: none;
}

.site-tool-check.is-ok {
  color: var(--muted);
}

.site-tool-check.is-banned {
  border-color: rgba(207, 70, 70, 0.45);
  background: rgba(207, 70, 70, 0.12);
  color: #ff9b9b;
}

.site-tool svg {
  width: 13px;
  height: 13px;
  display: block;
}

.site-tool-google.is-banned {
  background: rgba(207, 70, 70, 0.16);
}

.site-check-tip {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  min-width: 248px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0b0b0b;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.48);
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  pointer-events: none;
}

.site-tool-check:hover .site-check-tip,
.site-tool-check:focus-visible .site-check-tip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.site-check-tip-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.site-check-tip-row + .site-check-tip-row {
  margin-top: 8px;
}

.site-check-tip-row svg {
  width: 14px;
  height: 14px;
  margin-top: 1px;
  color: var(--faint);
  flex-shrink: 0;
}

.site-check-tip-body {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  line-height: 1.35;
}

.site-check-tip-label {
  color: var(--muted);
  white-space: nowrap;
}

.site-check-tip-value {
  color: var(--text);
  font-weight: 500;
  text-align: right;
}

.sites-dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: min(92dvh, calc(var(--tg-viewport-stable-height, 100dvh) - 24px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sites-dialog:not([open]) {
  display: none;
}

.sites-dialog[open] {
  display: flex;
}

.sites-dialog-wide {
  width: min(520px, calc(100vw - 32px));
}

.sites-dialog-templates {
  width: min(720px, calc(100vw - 24px));
  max-height: min(860px, calc(100vh - 24px));
}

.template-pick-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}

.template-pick-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-height: min(520px, calc(100vh - 260px));
  overflow: auto;
  padding: 2px;
}

.template-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.template-card:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(130, 177, 255, 0.35);
}

.template-card.is-selected {
  border-color: rgba(130, 177, 255, 0.75);
  background: rgba(130, 177, 255, 0.12);
  box-shadow: 0 0 0 1px rgba(130, 177, 255, 0.2);
}

.template-card-preview {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent),
    #0d0f14;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.template-card-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}

.template-card-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 11px;
  color: var(--faint);
  text-align: center;
  padding: 10px;
}

.template-card-add {
  border-style: dashed;
  background: transparent;
}

.template-card-add:hover,
.template-card-add.is-selected {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.28);
  box-shadow: none;
}

.template-card-preview-add {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
}

.template-card-preview-add svg {
  width: 28px;
  height: 28px;
}

.template-html-input {
  height: auto;
  min-height: 140px;
  padding: 10px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.45;
  resize: vertical;
}

.template-file-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.template-file-btn {
  height: 32px;
  padding: 0 12px;
  flex-shrink: 0;
}

.template-file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--muted);
}

.template-file-name[hidden] {
  display: none !important;
}

.sites-links-empty {
  padding: 48px 20px;
}

.template-card-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.template-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 12px;
}

.template-row:last-child {
  border-bottom: none;
}

.template-row:hover {
  background: rgba(255, 255, 255, 0.03);
}

.template-row.is-selected {
  background: rgba(130, 177, 255, 0.12);
}

.template-row-id {
  flex-shrink: 0;
  min-width: 42px;
  font-size: 10px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.template-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 550;
}

@media (max-width: 640px) {
  .template-pick-grid {
    grid-template-columns: 1fr;
    max-height: min(460px, calc(100vh - 240px));
  }
}

.sites-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.sites-dialog-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  min-height: 0;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.sites-add-body {
  gap: 12px;
}

.sites-dialog-sub {
  margin: -4px 0 0;
  font-size: 11px;
}

.sites-dialog-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.sites-dialog-hint {
  margin: -2px 0 0;
  font-size: 11px;
  line-height: 1.4;
}

.sites-dialog-hint[hidden] {
  display: none !important;
}

.sites-dialog-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 2px;
}

.sites-dialog-actions .btn {
  width: 100%;
  min-width: 0;
}

.sites-add-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}

.sites-add-actions .btn {
  min-width: 0;
  width: 100%;
}

.sites-add-actions .btn-primary {
  grid-column: 1 / -1;
}

.sites-dialog-actions-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.sites-dialog-actions-stack .btn {
  width: 100%;
  min-width: 0;
}

.sites-confirm-dialog {
  width: min(380px, calc(100vw - 32px));
}

.sites-confirm-body {
  gap: 12px;
  padding: 16px;
}

.sites-confirm-body .sites-dialog-title {
  font-size: 15px;
}

.sites-confirm-body .sites-dialog-sub {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
}

.sites-confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}

.sites-confirm-actions .btn {
  width: 100%;
}

.sites-back-link {
  display: inline-flex;
  margin: 0 0 10px;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.sites-back-link:hover {
  color: var(--text);
}

/* ——— Sites breadcrumb ——— */

.sites-breadcrumb-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--muted);
}

.sites-crumb-btn {
  border: none;
  background: none;
  padding: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}

.sites-crumb-btn:hover {
  color: var(--text);
}

.sites-crumb-sep {
  opacity: 0.65;
}

.sites-crumb-current {
  color: var(--text);
  font-weight: 600;
}

.site-head-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.site-head-tools {
  margin-left: 0;
}

.site-domain-kpi {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 0 16px 4px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.015);
}

.site-domain-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 16px 12px;
  font-size: 11px;
}

.site-domain-meta-sep {
  color: var(--faint);
}

.site-bind-chip {
  font-size: 11px;
}

.inline-alert-danger {
  color: var(--danger);
  background: rgba(255, 107, 107, 0.06);
}

.sites-detail-danger {
  margin-top: 4px;
}

.site-link-url {
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
  word-break: break-all;
}

.site-link-url:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.site-link-sub {
  margin-top: 3px;
  font-size: 11px;
}

.site-link-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.site-flag {
  display: inline-flex;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}

.site-flag-warn {
  background: rgba(255, 107, 107, 0.1);
  color: #ffb4b4;
}

.site-empty-add {
  margin-top: 10px;
}

.site-link-actions {
  width: 36px;
  text-align: right;
  vertical-align: middle;
}

.link-actions-btn {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.link-actions-btn:hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
}

.link-actions-btn svg {
  width: 14px;
  height: 14px;
}

.link-actions-menu {
  position: fixed;
  z-index: 2100;
  min-width: 160px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.link-actions-menu button {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.link-actions-menu button:hover {
  background: rgba(255, 255, 255, 0.04);
}

.link-actions-menu button.is-danger {
  color: var(--danger);
}

table.data th.col-actions {
  width: 36px;
  padding-right: 12px;
}

.link-segments {
  display: flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.link-segment {
  flex: 1;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  padding: 6px 8px;
  cursor: pointer;
}

.link-segment.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.link-field + .link-field {
  margin-top: 10px;
}

.link-field-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  margin-bottom: 5px;
  color: var(--muted);
}

.link-path-input {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
  background: var(--surface-2);
  height: 32px;
}

.link-path-prefix {
  font-size: 12px;
  color: var(--faint);
  white-space: nowrap;
  margin-right: 2px;
}

.link-path-field {
  flex: 1;
  min-width: 0;
  border: none !important;
  background: transparent !important;
  padding: 0 !important;
  height: 30px !important;
  box-shadow: none !important;
}

.link-template-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  padding: 0 10px;
  height: 32px;
  font-size: 12px;
  cursor: pointer;
}

.link-template-btn svg {
  width: 13px;
  height: 13px;
  color: var(--faint);
}

.link-advanced-block {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 8px;
  background: var(--surface-2);
}

.link-advanced-title {
  font-size: 11px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--muted);
}

.link-check,
.link-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-top: 5px;
  cursor: pointer;
}

.link-redirect-wrap {
  margin-top: 8px;
}

.link-redirect-input {
  width: 100%;
  font-size: 12px;
}

@media (max-width: 768px) {
  .sites-page-head {
    align-items: stretch;
    margin-bottom: 14px;
  }

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

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

  .site-card-kpi,
  .site-domain-kpi {
    grid-template-columns: repeat(2, 1fr);
  }

  .site-card-kpi {
    margin: 0 10px;
  }

  .site-mini-stat:nth-child(odd) {
    border-left: none;
  }

  .site-mini-stat:nth-child(2n) {
    border-left: 1px solid var(--line-soft);
  }

  .site-mini-stat:nth-child(n + 3) {
    border-top: 1px solid var(--line-soft);
  }

  .site-card-tools {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .site-head-badges {
    width: 100%;
    justify-content: space-between;
  }
}

/* ——— Wallet / Team ——— */

.wallet-balance-body {
  padding: 14px 16px 18px;
}

.wallet-history-section {
  padding-bottom: 6px;
}

.team-card {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 14px 16px;
  margin-top: 10px;
}

.team-card:hover {
  background: var(--surface-2);
}

.team-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

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

td.col-actions,
th.col-actions {
  width: 36px;
  padding-right: 12px;
}

/* ——— Responsive ——— */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    width: min(85vw, 280px);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-collapse {
    display: none;
  }

  .sidebar-close {
    display: grid;
    place-items: center;
    margin-left: auto;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
  }

  .sidebar-sheet-handle {
    display: block;
    width: 32px;
    height: 3px;
    border-radius: 999px;
    background: var(--line);
    margin: 0 auto 10px;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s;
  }

  .sidebar-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .shell {
    margin-left: 0;
  }

  .menu-toggle {
    display: inline-flex;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--muted);
    cursor: pointer;
    align-items: center;
    justify-content: center;
  }

  .menu-toggle-bars {
    width: 14px;
    height: 1.5px;
    background: currentColor;
    position: relative;
    display: block;
  }

  .menu-toggle-bars::before,
  .menu-toggle-bars::after {
    content: "";
    position: absolute;
    left: 0;
    width: 14px;
    height: 1.5px;
    background: currentColor;
  }

  .menu-toggle-bars::before {
    top: -4px;
  }

  .menu-toggle-bars::after {
    top: 4px;
  }

  .main {
    max-width: none;
    padding: 14px 16px 24px;
  }

  .kpi-value {
    font-size: 17px;
  }

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

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

  .sites-toolbar {
    flex-wrap: wrap;
  }

  .sites-add-btn {
    width: auto;
  }

  .settings-layout {
    grid-template-columns: 1fr;
  }

  .settings-nav {
    position: static;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 6px;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    touch-action: pan-x;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .settings-tab {
    width: auto;
    flex: 0 0 auto;
    min-width: max-content;
    white-space: nowrap;
  }
}

@media (max-width: 768px) {
  html,
  body {
    -webkit-tap-highlight-color: transparent;
  }

  .app,
  .shell,
  .main,
  .settings-layout,
  .settings-panels,
  .section,
  .section-flush,
  .table-wrap,
  .analytics-table-wrap {
    min-width: 0;
    max-width: 100%;
  }

  .app {
    min-height: var(--tg-viewport-stable-height, 100dvh);
    height: var(--tg-viewport-stable-height, 100dvh);
    overflow: hidden;
  }

  .shell {
    min-height: 0;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .topbar {
    height: calc(48px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 14px 0;
    gap: 10px;
    flex-shrink: 0;
  }

  .menu-toggle {
    display: inline-flex;
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  .main {
    max-width: none;
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding: 14px 14px calc(28px + env(safe-area-inset-bottom, 0px) + var(--tg-safe-bottom, 0px));
  }

  .page-greeting {
    font-size: 18px;
    margin-bottom: 14px;
    line-height: 1.25;
  }

  .page-sub {
    font-size: 12px;
    line-height: 1.4;
  }

  .section-head {
    padding: 12px 12px;
    gap: 10px;
    flex-wrap: wrap;
  }

  .section-head .link-segments {
    width: 100%;
  }

  .section-head .btn {
    width: 100%;
  }

  .settings-panel .btn-primary,
  .wallet-balance-card .btn-primary {
    width: 100%;
  }

  .section-title {
    font-size: 13px;
  }

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

  .kpi-cell {
    padding: 12px;
    gap: 6px;
  }

  .kpi-value {
    font-size: 16px;
  }

  .kpi-label {
    font-size: 10.5px;
  }

  .sites-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 8px;
  }

  .sites-toolbar .sites-filter-select,
  .sites-toolbar .custom-select-host,
  .sites-toolbar .sites-add-btn,
  .sites-toolbar .btn,
  .sites-toolbar .custom-select {
    width: 100%;
    flex: none;
  }

  .sites-search {
    width: 100%;
    height: 40px;
  }

  .sites-toolbar .custom-select-trigger {
    width: 100%;
  }

  .link-segments {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-wrap,
  .analytics-table-wrap {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    touch-action: pan-x pan-y;
    scrollbar-width: thin;
  }

  table.data {
    min-width: 640px;
    width: max-content;
    max-width: none;
  }

  table.data th,
  table.data td {
    padding: 10px 10px;
    font-size: 11.5px;
  }

  .sites-dialog {
    width: min(100vw - 16px, 420px);
    max-width: none;
    max-height: min(94dvh, calc(var(--tg-viewport-stable-height, 100dvh) - 8px));
    margin: auto;
    border-radius: 14px;
  }

  .sites-dialog-body {
    padding: 16px;
  }

  .event-card-dialog {
    width: calc(100vw - 16px);
    max-height: min(96dvh, calc(var(--tg-viewport-stable-height, 100dvh) - 4px));
  }

  .event-card-scroll {
    padding: 14px 14px 8px;
  }

  .event-card-sticky {
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .sites-dialog-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .sites-dialog-actions .btn {
    width: 100%;
    min-width: 0;
    height: 40px;
  }

  .sites-dialog-actions .btn-primary {
    grid-column: auto;
  }

  .sites-add-actions {
    grid-template-columns: 1fr 1fr;
    margin-top: 2px;
  }

  .sites-add-actions .btn-primary {
    grid-column: 1 / -1;
  }

  .btn {
    min-height: 36px;
  }

  .sidebar {
    width: min(88vw, 300px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .sidebar-top {
    padding: 12px 12px 8px;
  }

  .nav-item {
    min-height: 42px;
    padding: 10px 12px;
    font-size: 13.5px;
  }

  .sidebar-profile-trigger {
    min-height: 48px;
    padding: 10px;
  }

  .sidebar-notif-btn {
    min-height: 44px;
  }

  .event-card {
    border-radius: 12px;
  }

  .wallet-balance-card .kpi-grid {
    max-width: none !important;
  }
}

@media (max-width: 520px) {
  .sites-page-head {
    flex-direction: column;
    gap: 12px;
  }

  .sites-page-head .sites-add-btn {
    width: 100%;
  }

  .sites-overview-item {
    padding: 10px;
  }

  .site-card-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .site-card-badges {
    width: 100%;
  }

  .site-health {
    align-items: flex-start;
    flex-direction: column;
  }

  .site-health .site-card-tools {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .site-health .site-tool-check {
    min-width: 0;
    padding: 0 6px;
  }
}

@media (max-width: 480px) {
  .main {
    padding: 12px 12px calc(24px + env(safe-area-inset-bottom, 0px));
  }

  .page-greeting {
    font-size: 17px;
  }

  .kpi-cell:nth-child(odd) {
    border-right: 1px solid var(--line-soft);
  }

  .site-card-head {
    gap: 8px;
  }

  .site-card-tools .site-tool {
    height: 34px;
  }

  .site-health .site-card-tools .site-tool {
    width: 100%;
    justify-self: stretch;
  }

  .settings-nav {
    gap: 6px;
  }

  .empty-state {
    min-height: 0;
    padding: 28px 16px;
  }

  .empty-state-title {
    font-size: 17px;
  }

  .empty-state-actions {
    width: 100%;
    flex-direction: column;
  }

  .empty-state-actions .btn {
    width: 100%;
  }
}
