:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #eef4f8;
  --ink: #17212b;
  --muted: #667587;
  --line: #dce5ee;
  --blue: #2477f2;
  --green: #1a9d72;
  --amber: #c77a12;
  --red: #d84a4a;
  --teal: #0f8f9f;
  --shadow: 0 18px 45px rgba(23, 33, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #101820;
  color: #f8fbff;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f5c542;
  color: #111820;
  font-weight: 800;
}

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

.brand span {
  margin-top: 3px;
  color: #aebbc8;
  font-size: 13px;
}

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

.nav-item {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  color: #cfd9e4;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.nav-item:hover,
.nav-item.is-active {
  background: #22303d;
  color: #ffffff;
}

.icon {
  width: 22px;
  display: inline-grid;
  place-items: center;
  color: #75d0df;
}

.sidebar-card {
  margin-top: auto;
  padding: 14px;
  border-radius: 8px;
  background: #1b2835;
  display: flex;
  gap: 10px;
}

.sidebar-card p {
  margin: 5px 0 0;
  color: #aebbc8;
  font-size: 13px;
  line-height: 1.45;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  background: var(--green);
  flex: 0 0 auto;
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar,
.section-head,
.panel-head,
.source-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 24px;
}

.topbar h1,
.section-head h2,
.panel h2,
.health-band h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 30px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.select-wrap {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.account-select select {
  width: 230px;
}

select,
input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

select:focus,
input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(36, 119, 242, 0.14);
}

.primary-btn,
.secondary-btn {
  min-height: 42px;
  border-radius: 8px;
  border: 0;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
}

.primary-btn {
  color: #ffffff;
  background: var(--blue);
}

.secondary-btn {
  color: var(--ink);
  background: var(--surface-soft);
}

.logout-link {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
}

.full {
  width: 100%;
}

.view {
  display: none;
}

.view.is-visible {
  display: block;
}

.health-band {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 24px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.health-band p:last-child {
  max-width: 760px;
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.health-score {
  width: 112px;
  height: 112px;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: 50%;
  background: conic-gradient(var(--green) 82%, #e5edf4 0);
  flex: 0 0 auto;
}

.health-score strong,
.health-score span {
  display: block;
  width: 84px;
  text-align: center;
  background: #ffffff;
}

.health-score strong {
  padding-top: 17px;
  border-radius: 50% 50% 0 0;
  font-size: 28px;
}

.health-score span {
  padding-bottom: 17px;
  border-radius: 0 0 50% 50%;
  color: var(--muted);
  font-size: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.metric-card,
.panel,
.source-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 25px rgba(23, 33, 43, 0.04);
}

.metric-card {
  padding: 18px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

.metric-card small {
  display: inline-flex;
  margin-top: 10px;
  color: var(--green);
  font-weight: 700;
}

.metric-card small.is-bad {
  color: var(--red);
}

.workspace-grid,
.admin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.75fr);
  gap: 18px;
}

.panel {
  padding: 20px;
}

.panel-badge,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chart {
  height: 300px;
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(10, minmax(18px, 1fr));
  gap: 12px;
  align-items: end;
  border-bottom: 1px solid var(--line);
}

.bar {
  position: relative;
  min-height: 24px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, #2477f2, #0f8f9f);
}

.bar::after {
  content: attr(data-label);
  position: absolute;
  left: 50%;
  bottom: -26px;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 12px;
}

.conversion-dot {
  position: absolute;
  left: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transform: translate(-50%, 50%);
  background: #f5c542;
  box-shadow: 0 0 0 4px rgba(245, 197, 66, 0.24);
}

.priority-list,
.recommendation-grid,
.marketer-list,
.billing-preview {
  display: grid;
  gap: 12px;
}

.priority-item,
.recommendation-card,
.marketer-row,
.billing-preview div {
  padding: 14px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.priority-item strong,
.recommendation-card strong,
.billing-preview strong {
  display: block;
}

.priority-item p,
.recommendation-card p,
.source-card p,
.billing-preview span {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.section-head {
  margin-bottom: 16px;
}

.search-input {
  width: min(320px, 100%);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

th,
td {
  padding: 15px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

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

.status-good {
  color: var(--green);
}

.status-warn {
  color: var(--amber);
}

.status-bad {
  color: var(--red);
}

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

.recommendation-card {
  background: #ffffff;
  border: 1px solid var(--line);
}

.recommendation-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

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

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

.source-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.source-note span {
  color: var(--muted);
  line-height: 1.45;
}

.source-card {
  padding: 18px;
}

.source-card label {
  display: block;
  margin: 20px 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.source-card input {
  width: 100%;
  margin-bottom: 12px;
}

.source-logo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-weight: 900;
  flex: 0 0 auto;
}

.yandex {
  background: #e83b3b;
}

.metric {
  background: var(--teal);
}

.openai {
  background: #101820;
}

.connection-status {
  display: block;
  min-height: 20px;
  color: var(--green);
  font-size: 13px;
}

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

.marketer-row span {
  color: var(--muted);
  font-size: 13px;
}

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

.account-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 25px rgba(23, 33, 43, 0.04);
}

.account-card.is-active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(36, 119, 242, 0.12);
}

.account-card-head,
.account-stats {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.account-card-head {
  align-items: flex-start;
}

.account-card-head strong,
.account-card-head span,
.account-stats span,
.account-stats strong {
  display: block;
}

.account-card-head span,
.account-stats span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.account-stats {
  margin: 18px 0;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.account-stats strong {
  margin-top: 5px;
}

.account-card p,
.admin-source p {
  color: var(--muted);
  line-height: 1.45;
}

.admin-source label {
  display: block;
  margin: 14px 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.admin-source input {
  width: 100%;
  margin-bottom: 12px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 14px 16px;
  border-radius: 8px;
  color: #ffffff;
  background: #101820;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(36, 119, 242, 0.12), rgba(15, 143, 159, 0.12)),
    var(--bg);
}

.login-shell {
  width: min(440px, 100%);
}

.login-panel {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

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

.login-panel h1 {
  margin: 0;
  font-size: 30px;
}

.login-panel p {
  margin: 10px 0 22px;
  color: var(--muted);
  line-height: 1.5;
}

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

.login-form label,
.login-form span {
  display: grid;
  gap: 8px;
}

.login-form span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-error {
  margin-bottom: 14px;
  padding: 12px;
  border-radius: 8px;
  color: var(--red);
  background: rgba(216, 74, 74, 0.1);
  font-weight: 700;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .brand div:last-child,
  .nav-item:not(.is-active) {
    font-size: 0;
  }

  .nav-item {
    justify-content: center;
  }

  .sidebar-card {
    display: none;
  }

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

  .workspace-grid,
  .admin-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

  .nav-list {
    grid-template-columns: repeat(6, minmax(44px, 1fr));
  }

  .nav-item {
    min-height: 46px;
    padding: 0;
    font-size: 0;
  }

  .main {
    padding: 18px;
  }

  .topbar,
  .section-head,
  .health-band {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-grid,
  .source-grid,
  .source-grid.compact,
  .account-grid,
  .recommendation-grid {
    grid-template-columns: 1fr;
  }

  .source-note {
    align-items: flex-start;
    flex-direction: column;
  }

  .account-select select {
    width: 100%;
  }

  .health-score {
    align-self: center;
  }
}
