/* Made by Federico Dionisi */
/* © 2026 – All rights reserved. */
@font-face {
  font-family: "Questrial";
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url("/questrial.ttf") format("truetype");
}

:root {
  color-scheme: light;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top-runtime: var(--safe-top);
  --safe-bottom-runtime: var(--safe-bottom);
  --safe-left: env(safe-area-inset-left, 0px);
  --sidebar-width: clamp(340px, 20.7vw, 408px);
  --bg: #f8fafc;
  --bg-deep: #eef2f7;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-soft: rgba(255, 255, 255, 0.7);
  --panel-item: rgba(255, 255, 255, 0.78);
  --text: #0b0c10;
  --muted: #667085;
  --line: rgba(15, 23, 42, 0.1);
  --line-strong: rgba(15, 23, 42, 0.16);
  --brand: #8ec5ff;
  --brand-2: #60a5fa;
  --brand-strong: #1d4ed8;
  --success: #0d8f6f;
  --danger: #b42318;
  --shadow: 0 22px 60px rgba(3, 9, 23, 0.12);
  --shadow-strong: 0 34px 90px rgba(3, 9, 23, 0.16);
  --control-bg: #eef2f7;
  --field-bg: #ffffff;
  --theme-bg: linear-gradient(135deg, var(--brand), var(--brand-2));
  font-family: "Questrial", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0c10;
  --bg-deep: #06070a;
  --panel: rgba(15, 18, 32, 0.9);
  --panel-soft: rgba(21, 24, 33, 0.78);
  --panel-item: rgba(255, 255, 255, 0.025);
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --brand: #6ee7b7;
  --brand-2: #60a5fa;
  --brand-strong: #2563eb;
  --success: #34d399;
  --danger: #ff7a90;
  --shadow: 0 32px 90px rgba(0, 0, 0, 0.34);
  --shadow-strong: 0 42px 120px rgba(0, 0, 0, 0.48);
  --control-bg: #0f1220;
  --field-bg: rgba(255, 255, 255, 0.045);
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--brand-2) 70%, transparent) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--brand-2) 70%, transparent);
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

html[data-loading] {
  overflow: hidden;
}

html[data-loading] .dashboard-app,
html[data-loading] .theme-footer {
  opacity: 0;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at 14% 0, color-mix(in srgb, var(--brand-2) 20%, transparent) 0, transparent 32%),
    radial-gradient(circle at 84% 8%, color-mix(in srgb, var(--brand) 18%, transparent) 0, transparent 28%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  overflow-x: hidden;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

body.view-scroll-locked {
  overflow: hidden;
}

body.view-scroll-locked .main {
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 84px 84px;
  opacity: 0.42;
  mask-image: radial-gradient(circle at center, black 28%, transparent 78%);
  pointer-events: none;
}

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

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

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

.dashboard-app {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  transition: opacity 150ms ease;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: min(var(--sidebar-width), calc(100vw - 32px));
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 20%), var(--panel);
  box-shadow: 20px 0 60px rgba(3, 9, 23, 0.1), inset -1px 0 0 rgba(255, 255, 255, 0.04);
  overflow-y: auto;
  overscroll-behavior: contain;
}

html[data-theme="dark"] .sidebar {
  box-shadow: 20px 0 60px rgba(0, 0, 0, 0.28), inset -1px 0 0 rgba(255, 255, 255, 0.025);
}

@media (max-width: 860px) {
  html[data-theme="dark"] .sidebar {
    background: #0f1220;
  }
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  gap: clamp(24px, 0.9vw + 10px, 34px);
  min-height: 100%;
  padding: calc(32px + var(--safe-top)) clamp(18px, 0.64vw + 8px, 28px) calc(28px + var(--safe-bottom));
}

.sidebar-top,
.account-tools {
  display: grid;
  gap: clamp(20px, 0.7vw + 8px, 30px);
}

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

.app-logo {
  width: clamp(58px, 1.5vw + 38px, 76px);
  height: clamp(58px, 1.5vw + 38px, 76px);
  flex: 0 0 auto;
}

.logo-bubble {
  fill: #00aff0;
  stroke: #000000;
  stroke-width: 38;
  stroke-linejoin: round;
}

.logo-robot {
  fill: #000000;
}

.sidebar-brand span {
  font-size: clamp(1.34rem, 1.04rem + 0.36vw, 1.8rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-section-head h2 {
  font-size: clamp(1.04rem, 0.95rem + 0.12vw, 1.16rem);
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.add-account {
  width: clamp(38px, 0.6vw + 28px, 48px);
  height: clamp(38px, 0.6vw + 28px, 48px);
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-item);
  color: var(--text);
  cursor: pointer;
  transition: border-color 140ms ease, transform 140ms ease, background 140ms ease;
}

.add-account svg {
  width: 22px;
  height: 22px;
}

.add-account:hover {
  border-color: color-mix(in srgb, var(--brand-2) 40%, var(--line-strong));
  transform: translateY(-1px);
}

.account-search {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: clamp(58px, 0.95vw + 42px, 74px);
  padding: 0 clamp(18px, 0.8vw + 10px, 28px);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--panel-item);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.account-search:focus-within {
  border-color: color-mix(in srgb, var(--brand-2) 68%, var(--line-strong));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 20%, transparent);
}

.account-search svg {
  width: 22px;
  height: 22px;
  color: var(--muted);
  flex: 0 0 auto;
}

.account-search input {
  width: 100%;
  border: 0;
  outline: 0;
  box-shadow: none;
  background: transparent;
  color: var(--text);
  font-size: clamp(1.04rem, 0.95rem + 0.12vw, 1.16rem);
  appearance: none;
}

.account-search input:focus {
  border-color: transparent;
  box-shadow: none;
}

.account-search input::placeholder {
  color: color-mix(in srgb, var(--muted) 70%, transparent);
}

.account-list {
  display: grid;
  gap: 10px;
}

.account-item {
  width: 100%;
  min-height: clamp(60px, 0.95vw + 42px, 78px);
  display: flex;
  align-items: center;
  gap: clamp(12px, 0.6vw + 8px, 18px);
  padding: 0 clamp(18px, 0.8vw + 10px, 28px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-item);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms ease, transform 140ms ease, background 140ms ease;
}

.account-item:hover,
.account-item[data-active="true"] {
  border-color: color-mix(in srgb, var(--brand-2) 34%, var(--line-strong));
  background: color-mix(in srgb, var(--panel-item) 86%, var(--brand-2) 14%);
  transform: translateY(-1px);
}

.account-item[data-oauth-status="invalid"] {
  border-color: color-mix(in srgb, #f59e0b 58%, var(--line-strong));
  background: color-mix(in srgb, var(--panel-item) 78%, #f59e0b 22%);
}

.account-item[data-oauth-status="invalid"]:hover,
.account-item[data-oauth-status="invalid"][data-active="true"] {
  border-color: color-mix(in srgb, #f59e0b 82%, var(--line-strong));
  background: color-mix(in srgb, var(--panel-item) 66%, #f59e0b 34%);
}

.account-item:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--brand-2) 58%, transparent);
  outline-offset: 2px;
}

.account-avatar,
.account-hero-avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand-2) 16%, var(--panel-item));
  border: 1px solid var(--line-strong);
  color: var(--text);
  text-transform: uppercase;
}

.account-avatar {
  width: clamp(42px, 0.85vw + 28px, 58px);
  height: clamp(42px, 0.85vw + 28px, 58px);
  font-size: 0.9rem;
}

.account-hero-avatar {
  width: clamp(68px, 4vw, 96px);
  height: clamp(68px, 4vw, 96px);
  font-size: 1.18rem;
}

.account-avatar img,
.account-hero-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.account-copy {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 5px;
}

.account-actions {
  margin-left: auto;
  margin-right: -10px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.account-oauth-alert {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  color: #b45309;
}

:root[data-theme="dark"] .account-oauth-alert {
  color: #fbbf24;
}

.account-oauth-alert svg {
  width: 19px;
  height: 19px;
}

.deeplink-group-actions {
  gap: 10px;
  align-items: center;
}

.deeplink-group-action {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: transparent;
  transition: background 0.16s ease, filter 0.16s ease;
  line-height: 1;
}

.deeplink-group-action svg {
  width: 20px;
  height: 20px;
}

.deeplink-group-action:hover,
.deeplink-group-action:focus-visible {
  filter: brightness(1.05);
}

.deeplink-group-action:focus-visible {
  outline: none;
}

.deeplink-group-action--delete:hover,
.deeplink-group-action--delete:focus-visible {
  background: color-mix(in srgb, var(--danger, #ef4444) 18%, transparent);
}

.account-analytics {
  color: var(--text);
}

.account-analytics:hover,
.account-analytics:focus-visible {
  background: color-mix(in srgb, var(--brand-2) 16%, transparent);
}

.account-copy strong,
.account-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-copy strong {
  font-size: clamp(1.04rem, 0.95rem + 0.12vw, 1.16rem);
  font-weight: 400;
}

.account-copy small,
.accounts-empty {
  color: var(--muted);
  font-size: clamp(0.86rem, 0.78rem + 0.08vw, 0.94rem);
}

.accounts-empty {
  margin: 0;
  padding: 18px 4px 0;
  line-height: 1.5;
}

.main {
  position: relative;
  min-height: 0;
  margin-left: min(var(--sidebar-width), calc(100vw - 32px));
  padding: clamp(28px, 2.4vw, 48px);
}

.welcome-view {
  min-height: calc(100vh - clamp(56px, 4.8vw, 96px));
  min-height: calc(100dvh - clamp(56px, 4.8vw, 96px));
  display: grid;
  place-items: center;
  align-content: center;
  gap: clamp(24px, 2vw, 34px);
  text-align: center;
}

.welcome-logo {
  width: min(360px, 46vw);
  height: auto;
  filter: drop-shadow(0 30px 70px rgba(3, 9, 23, 0.18));
}

.welcome-view h1 {
  font-size: clamp(2.4rem, 5.4vw, 5.8rem);
  font-weight: 400;
  line-height: 0.96;
}

.page-shell {
  display: grid;
  gap: 18px;
  width: min(1180px, 100%);
  margin: 0 auto;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: clamp(18px, 1.6vw, 28px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.page-head h1 {
  font-size: clamp(2rem, 3.2vw, 4rem);
  font-weight: 400;
  line-height: 0.96;
}

.page-head p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 1rem;
}

.add-view .page-head {
  box-shadow: none;
}

.account-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 18px;
}

.page-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.page-head-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

.primary,
.secondary {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 160ms ease, transform 140ms ease, border-color 160ms ease;
}

.oauth-reconnect {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  color: #0b0c10;
  background: linear-gradient(135deg, #fde68a, #f59e0b);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: filter 160ms ease, transform 140ms ease;
}

.oauth-reconnect svg {
  width: 19px;
  height: 19px;
}

.oauth-reconnect:hover,
.oauth-reconnect.is-long-press-ready,
#oauthConnectButton.is-long-press-ready {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.oauth-reconnect:disabled {
  cursor: not-allowed;
  opacity: 0.72;
  transform: none;
}

.oauth-reconnect.is-loading {
  color: transparent;
  pointer-events: none;
  position: relative;
}

.oauth-reconnect.is-loading svg,
.oauth-reconnect.is-loading span {
  opacity: 0;
}

.oauth-reconnect.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin-left: -9px;
  margin-top: -9px;
  border-radius: 50%;
  border: 2px solid rgba(11, 12, 16, 0.32);
  border-top-color: #0b0c10;
  animation: connect-btn-spin 0.8s linear infinite;
}

.oauth-copy-tooltip {
  position: fixed;
  z-index: 120;
  left: 0;
  top: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 0.86rem;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, calc(-100% - 8px)) scale(0.96);
  transition: opacity 120ms ease, transform 120ms ease;
}

.oauth-copy-tooltip.show {
  opacity: 1;
  transform: translate(-50%, calc(-100% - 8px)) scale(1);
}

.primary {
  color: #0b0c10;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
}

#oauthConnectButton {
  user-select: none;
  touch-action: manipulation;
}

.secondary {
  color: var(--text);
  background: var(--control-bg);
  border-color: var(--line);
}

.danger {
  color: #ffffff;
  background: color-mix(in srgb, var(--danger) 82%, #8c151f 18%);
  border-color: color-mix(in srgb, var(--danger) 70%, transparent);
}

.primary:hover,
.secondary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.account-form,
.account-label-card,
.add-form {
  padding: clamp(18px, 1.6vw, 28px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.analytics-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.5fr) minmax(0, 0.5fr);
  gap: 14px;
  align-items: end;
}

.period-field {
  position: relative;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.2;
}

.period-field h2 {
  margin: 0;
  color: var(--text);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.2;
}

.analytics-controls > label,
.period-field {
  min-width: 0;
}

.period-dropdown {
  position: relative;
}

.period-trigger {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  background: var(--field-bg);
  font-size: 1.05rem;
  cursor: pointer;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.period-trigger:focus-visible,
.period-dropdown.is-open .period-trigger {
  outline: 0;
  border-color: color-mix(in srgb, var(--brand-2) 68%, var(--line-strong));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 20%, transparent);
}

.period-trigger svg {
  flex: 0 0 auto;
  transition: transform 160ms ease;
}

.period-dropdown.is-open .period-trigger svg {
  transform: rotate(180deg);
}

.period-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 282px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: var(--shadow);
  backdrop-filter: none;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 140ms ease, transform 140ms ease;
}

html[data-theme="dark"] .period-menu {
  background: #0f1220;
}

.period-dropdown.is-open .period-menu {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.period-separator {
  display: block;
  height: 1px;
  margin: 6px 4px;
  background: var(--line);
}

.period-option {
  width: 100%;
  min-height: 38px;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  color: var(--text);
  background: transparent;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
}

.period-option:hover,
.period-option:focus-visible,
.period-option[aria-selected="true"] {
  outline: 0;
  background: color-mix(in srgb, var(--brand-2) 14%, transparent);
}

.analytics-controls .is-hidden {
  display: none;
}

.analytics-controls input[type="date"] {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-inline-size: 0;
  max-inline-size: 100%;
  padding-right: 44px;
  display: block;
  color-scheme: light;
  -webkit-appearance: none;
  appearance: none;
}

html[data-theme="dark"] .analytics-controls input[type="date"] {
  color-scheme: dark;
}

.analytics-controls input[type="date"]::-webkit-calendar-picker-indicator {
  opacity: 0;
  cursor: pointer;
}

.date-input-wrap {
  position: relative;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  display: block;
}

.date-calendar-icon {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text);
  pointer-events: none;
}

html[data-theme="dark"] .date-calendar-icon {
  color: #ffffff;
}

.analytics-grid {
  display: grid;
  gap: 18px;
}

.analytics-card {
  display: grid;
  gap: 18px;
}

.analytics-card-head {
  margin-bottom: 0;
}

.analytics-tone-note {
  max-width: 720px;
}

.analytics-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.analytics-metric {
  min-height: 104px;
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-item);
}

.analytics-metric.is-featured {
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--brand-2) 16%, transparent), transparent 62%),
    var(--panel-item);
}

.analytics-metric span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.analytics-metric strong {
  color: var(--text);
  font-size: clamp(1.65rem, 3vw, 2.5rem);
  font-weight: 400;
  line-height: 0.9;
}

.analytics-metric em {
  width: 54px;
  padding: 4px 7px;
  border-radius: 999px;
  color: var(--brand-strong);
  background: color-mix(in srgb, var(--brand-2) 14%, transparent);
  font-size: 0.78rem;
  font-style: normal;
  line-height: 1;
  text-align: center;
}

.analytics-metric em.is-good {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 13%, transparent);
}

.analytics-metric em.is-bad {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.analytics-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.analytics-group {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--panel-item) 80%, transparent);
}

.analytics-group h3 {
  margin: 0 0 12px;
  color: var(--text);
  font-size: 0.98rem;
  font-weight: 400;
  line-height: 1.2;
}

.analytics-group-list {
  display: grid;
  gap: 8px;
}

.analytics-row {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--field-bg) 74%, transparent);
}

.analytics-row span {
  min-width: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.25;
}

.analytics-value {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 54px minmax(38px, max-content);
  align-items: center;
  gap: 8px;
  justify-content: end;
}

.analytics-value.no-percent {
  grid-template-columns: minmax(38px, max-content);
}

.analytics-value strong {
  min-width: 3.5ch;
  color: var(--text);
  font-size: 1.18rem;
  font-weight: 400;
  line-height: 1;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.analytics-value em {
  width: 54px;
  padding: 3px 6px;
  border-radius: 999px;
  color: var(--brand-strong);
  background: color-mix(in srgb, var(--brand-2) 12%, transparent);
  font-size: 0.72rem;
  font-style: normal;
  line-height: 1;
  text-align: center;
}

.analytics-value em.is-good {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 13%, transparent);
}

.analytics-value em.is-bad {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

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

.account-label-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  align-items: end;
  gap: 12px;
}

.account-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.account-card-head h2 {
  font-size: 1.18rem;
  font-weight: 400;
}

.function-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.title-copy p,
.field-help {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
  text-transform: none;
}

.option-copy {
  gap: 3px;
}

.custom-check {
  position: relative;
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  color: var(--text);
  cursor: pointer;
}

.custom-check input {
  position: absolute;
  inset: 0;
  width: 100%;
  min-height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.custom-check span {
  width: 22px;
  height: 22px;
  display: block;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--field-bg);
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.custom-check span::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 5px;
  width: 6px;
  height: 10px;
  border: solid #0b0c10;
  border-width: 0 2px 2px 0;
  opacity: 0;
  transform: rotate(42deg) scale(0.8);
  transition: opacity 120ms ease, transform 120ms ease;
}

.custom-check input:checked + span {
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 8px 18px color-mix(in srgb, var(--brand-2) 26%, transparent);
}

.custom-check input:checked + span::after {
  opacity: 1;
  transform: rotate(42deg) scale(1);
}

.custom-check input:focus-visible + span {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 24%, transparent);
}

.icon-save {
  width: 46px;
  height: 46px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #0b0c10;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(3, 9, 23, 0.12);
  transition: filter 160ms ease, transform 140ms ease;
}

.icon-save:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

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

.function-body[hidden] {
  display: none;
}

.button-toggle-row {
  display: flex;
  align-items: center;
}

.words-toggle-row {
  display: flex;
  align-items: center;
}

.option-title {
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.25;
  text-transform: none;
}

.button-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.button-fields[hidden],
.trigger-words-fields[hidden] {
  display: none;
}

.trigger-words-fields textarea {
  min-height: 84px;
}

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

.compact-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.manual-token {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.manual-token summary {
  width: fit-content;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.86rem;
}

.manual-token .form-grid {
  margin-top: 14px;
}

.oauth-status {
  min-height: 22px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.oauth-status[data-error="true"] {
  color: var(--danger);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

input,
textarea,
select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: 0;
  font-size: 16px;
  line-height: 1.35;
  color: var(--text);
  background: var(--field-bg);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.number-stepper {
  position: relative;
  min-width: 0;
}

.number-stepper input {
  padding-right: 46px;
}

.number-stepper-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  bottom: 6px;
  width: 32px;
  display: grid;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 4px;
}

.number-stepper-actions button {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  background: color-mix(in srgb, var(--brand-2) 13%, var(--control-bg));
  cursor: pointer;
  transition: background 140ms ease, transform 120ms ease;
}

.number-stepper-actions button:hover,
.number-stepper-actions button:focus-visible {
  outline: 0;
  background: color-mix(in srgb, var(--brand-2) 24%, var(--control-bg));
}

.number-stepper-actions button:active {
  transform: scale(0.94);
}

.token-input {
  appearance: none;
  -webkit-appearance: none;
}

.token-input::-ms-clear,
.token-input::-ms-reveal {
  display: none;
}

.token-input::-webkit-contacts-auto-fill-button,
.token-input::-webkit-credentials-auto-fill-button {
  display: none !important;
  visibility: hidden;
  pointer-events: none;
}

textarea {
  min-height: 118px;
  resize: vertical;
  line-height: 1.42;
}

select {
  appearance: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: color-mix(in srgb, var(--brand-2) 68%, var(--line-strong));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 20%, transparent);
}

.toggle-line {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field-bg);
  color: var(--text);
  text-transform: none;
}

.toggle-line.compact {
  min-width: 124px;
}

.toggle-line input {
  width: 18px;
  min-height: 18px;
  flex: 0 0 auto;
  accent-color: var(--brand-2);
}

.trigger-fields {
  display: grid;
  gap: 14px;
}

.trigger-block {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.account-form > .trigger-block:first-child,
.account-form > .trigger-fields:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.trigger-top {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.trigger-top h3 {
  font-size: 1.02rem;
  font-weight: 400;
}

.span-2 {
  grid-column: span 2;
}

.form-actions {
  margin-top: 18px;
}

#oauthConnectButton.is-loading {
  position: relative;
  min-width: 130px;
  color: transparent;
  pointer-events: none;
}

#oauthConnectButton.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin-left: -9px;
  margin-top: -9px;
  border-radius: 50%;
  border: 2px solid rgba(11, 12, 16, 0.35);
  border-top-color: rgba(11, 12, 16, 1);
  animation: connect-btn-spin 0.8s linear infinite;
}

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

.mobile-menu {
  width: 46px;
  height: 46px;
  display: none;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--text);
  flex-shrink: 0;
  position: relative;
}

.mobile-menu span {
  position: absolute;
  width: 20px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transition: transform 220ms ease, opacity 220ms ease;
}

.mobile-menu span:nth-child(1) { transform: translateY(-6px); }
.mobile-menu span:nth-child(3) { transform: translateY(6px); }

body.sidebar-open .mobile-menu span:nth-child(1) { transform: rotate(45deg); }
body.sidebar-open .mobile-menu span:nth-child(2) { opacity: 0; }
body.sidebar-open .mobile-menu span:nth-child(3) { transform: rotate(-45deg); }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 180ms ease;
}

.sidebar-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-close {
  display: none;
  width: 38px;
  height: 38px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: transparent;
  color: var(--text-2);
  flex-shrink: 0;
  transition: color 120ms ease, background 120ms ease;
}

.sidebar-close:hover {
  color: var(--text);
  background: var(--hover);
}

.theme-footer {
  position: fixed;
  right: clamp(14px, 3vw, 24px);
  bottom: calc(20px + var(--safe-bottom-runtime));
  z-index: 18;
  margin: 0;
  padding: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
}

.theme-toggle {
  appearance: none;
  border: 0;
  background: var(--theme-bg);
  color: #0b0c10;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  line-height: 1;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.theme-toggle:hover {
  filter: brightness(1.15);
}

.theme-toggle .i {
  display: none;
  color: currentColor;
}

.theme-toggle[data-mode="auto"] .i-auto,
.theme-toggle[data-mode="light"] .i-sun,
.theme-toggle[data-mode="dark"] .i-moon {
  display: inline;
}

body.view-account .dashboard-app {
  min-height: 0;
  min-height: initial;
}

body.view-account .theme-footer {
  position: relative;
  right: auto;
  bottom: auto;
  z-index: 1;
  display: flex;
  justify-content: flex-end;
  margin-left: min(var(--sidebar-width), calc(100vw - 32px));
  padding: 0 clamp(28px, 2.4vw, 48px) calc(32px + var(--safe-bottom-runtime));
  pointer-events: auto;
}

.deeplink-delete-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2350;
}

.deeplink-delete-modal.is-open {
  display: flex;
}

.deeplink-delete-modal::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.deeplink-delete-dialog {
  position: relative;
  background: var(--panel);
  color: var(--text);
  border-radius: 16px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  width: min(420px, 92vw);
  padding: 24px 24px 20px;
  box-shadow: var(--shadow-strong);
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

:root[data-theme="dark"] .deeplink-delete-dialog {
  border-color: rgba(255, 255, 255, 0.12);
}

.delete-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.delete-dialog-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.delete-dialog-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, background 0.2s ease;
  cursor: pointer;
}

.delete-dialog-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.delete-dialog-close:focus-visible {
  outline: 2px solid var(--brand-2);
  outline-offset: 3px;
}

.delete-dialog-message {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.5;
}

.delete-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.delete-dialog-actions .btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.delete-dialog-actions .btn.danger {
  background: #ef4444;
  color: #ffffff;
  border: 0;
}

.delete-dialog-actions .btn.danger:hover,
.delete-dialog-actions .btn.danger:focus-visible {
  filter: brightness(1.1);
}

.delete-dialog-actions .btn.danger:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: none;
}

.delete-dialog-actions .btn.danger.is-loading {
  position: relative;
  min-width: 110px;
  color: transparent;
  opacity: 1;
}

.delete-dialog-actions .btn.danger.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  margin-left: -8px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #ffffff;
  animation: delete-btn-spin 0.8s linear infinite;
}

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

.toast {
  position: fixed;
  left: calc(min(var(--sidebar-width), calc(100vw - 32px)) + (100vw - min(var(--sidebar-width), calc(100vw - 32px))) / 2);
  bottom: calc(70px + var(--safe-bottom));
  z-index: 80;
  max-width: min(520px, calc(100vw - 28px));
  padding: 12px 14px;
  border-radius: 12px;
  color: #ffffff;
  background: #0b0c10;
  box-shadow: var(--shadow-strong);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-50%) translateY(160%);
  transition: transform 180ms ease, opacity 180ms ease, visibility 0s linear 180ms;
}

.toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
  transition-delay: 0s;
}

.toast.error {
  background: #891235;
}

@media (max-width: 1100px) {
  .compact-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .mobile-menu {
    display: grid;
  }

  .sidebar {
    background: #ffffff;
    transform: translateX(calc(-100% - 18px));
    transition: transform 220ms cubic-bezier(.2, .8, .2, 1);
  }

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

  .sidebar-close {
    display: grid;
  }

  .page-head .mobile-menu {
    display: grid;
  }

  .welcome-view .mobile-menu {
    position: absolute;
    top: clamp(18px, 1.6vw, 28px);
    right: clamp(14px, 3vw, 24px);
    display: grid;
  }

  .welcome-view {
    position: relative;
  }

  .page-head {
    position: relative;
  }

  .sidebar-backdrop {
    display: none;
    pointer-events: none;
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .main {
    margin-left: 0;
    padding: calc(24px + var(--safe-top-runtime)) max(14px, var(--safe-right)) calc(94px + var(--safe-bottom-runtime)) max(14px, var(--safe-left));
  }

  .theme-footer {
    bottom: calc(14px + var(--safe-bottom-runtime));
    right: calc(max(14px, var(--safe-right)) + clamp(14px, 3vw, 24px));
  }

  body.view-account .theme-footer {
    position: relative;
    right: auto;
    bottom: auto;
    margin-left: 0;
    padding: 0 max(14px, var(--safe-right)) calc(28px + var(--safe-bottom-runtime)) max(14px, var(--safe-left));
  }

  .toast {
    left: 50%;
  }

  .welcome-logo {
    width: min(260px, 70vw);
  }

  .welcome-view h1 {
    font-size: clamp(2.2rem, 11vw, 4rem);
  }

  .page-head,
  .account-title {
    align-items: flex-start;
  }

  .page-head {
    flex-direction: column;
  }

  .add-view .page-head {
    flex-direction: row;
    align-items: center;
  }

  .account-view .page-head {
    flex-direction: row;
    align-items: center;
  }

  .account-view .page-head-actions,
  .analytics-view .page-head-actions {
    gap: 8px;
  }

  .account-view .oauth-reconnect,
  .analytics-view .oauth-reconnect {
    width: 46px;
    height: 46px;
    min-height: 46px;
    padding: 0;
    flex: 0 0 46px;
  }

  .account-view .oauth-reconnect span,
  .analytics-view .oauth-reconnect span {
    display: none;
  }

  .account-view .account-title {
    flex: 1 1 auto;
    min-width: 0;
    align-items: center;
    gap: 12px;
  }

  .account-view .account-title > div {
    min-width: 0;
  }

  .account-view .account-hero-avatar {
    width: 58px;
    height: 58px;
  }

  .account-view .page-head h1,
  .account-view .page-head p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .account-view .page-head h1 {
    font-size: clamp(1.55rem, 7vw, 2.1rem);
  }

  .add-view .page-head h1 {
    font-size: 1.55rem;
  }

  .add-view .page-head p {
    font-size: 0.9rem;
    margin-top: 4px;
  }

  .page-actions,
  .page-actions .primary,
  .page-actions .secondary {
    width: 100%;
  }

  .form-grid,
  .add-account-grid,
  .compact-form,
  .analytics-controls,
  .analytics-summary,
  .analytics-groups {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .theme-toggle {
    width: 40px;
    height: 40px;
  }
}

@supports (-webkit-touch-callout: none) {
  @media (max-width: 860px) {
    .main {
      padding-top: calc(24px + max(var(--safe-top-runtime), 10px));
      padding-bottom: calc(102px + max(var(--safe-bottom-runtime), 14px));
    }

    body.ios-standalone .dashboard-app {
      min-height: 100dvh;
      max-height: 100dvh;
      overflow: hidden;
      padding-bottom: 0;
    }

    body.ios-standalone .main {
      padding-top: 0;
      padding-bottom: 96px;
      max-height: 100%;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior-y: contain;
      scroll-padding-top: max(var(--safe-top-runtime), 14px);
      scroll-padding-bottom: 24px;
    }

    body.ios-standalone .sidebar {
      inset: 0 auto 0 0;
      max-height: 100dvh;
      -webkit-overflow-scrolling: touch;
      padding-bottom: calc(20px + max(var(--safe-bottom-runtime), 8px));
    }

    body.ios-standalone .sidebar-inner {
      padding-top: calc(14px + max(var(--safe-top-runtime), 12px));
    }

    body.ios-standalone {
      overflow: hidden;
      padding-top: env(safe-area-inset-top);
      padding-bottom: env(safe-area-inset-bottom);
      padding-left: env(safe-area-inset-left);
      padding-right: env(safe-area-inset-right);
    }

    body.ios-standalone.view-account {
      overflow-y: auto;
    }

    body.ios-standalone.view-account .dashboard-app {
      min-height: 0;
      max-height: none;
      overflow: visible;
    }

    body.ios-standalone.view-account .main {
      max-height: none;
      overflow: visible;
      padding-bottom: 28px;
    }

    body.ios-standalone.view-scroll-locked .main {
      overflow: hidden;
    }

    .welcome-view .mobile-menu {
      top: calc(max(var(--safe-top-runtime), 12px) + 10px);
    }

    body.ios-standalone .welcome-view .mobile-menu {
      top: 8px;
    }

    body.ios-standalone .theme-footer {
      bottom: calc(20px + max(var(--safe-bottom-runtime), 8px));
      right: calc(max(14px, var(--safe-right)) + clamp(14px, 3vw, 24px));
    }

    body.ios-standalone.view-account .theme-footer {
      position: relative;
      right: auto;
      bottom: auto;
      margin-left: 0;
      padding: 0 max(14px, var(--safe-right)) calc(28px + max(var(--safe-bottom-runtime), 8px)) max(14px, var(--safe-left));
    }
  }
}

@media (max-width: 520px) {
  .sidebar {
    width: min(360px, calc(100vw - 26px));
  }

  .sidebar-inner {
    padding-left: 16px;
    padding-right: 16px;
  }

  .account-title {
    flex-direction: row;
  }

  .page-head h1 {
    font-size: 2.1rem;
  }

  .account-view .account-hero-avatar {
    width: 48px;
    height: 48px;
  }

  .account-view .page-head h1 {
    font-size: 1.45rem;
  }

  .account-view .page-head p {
    margin-top: 3px;
    font-size: 0.86rem;
  }
}
