:root {
  --bg: #f7f8fa;
  --bg-dot: #dde1e8;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --surface-soft: #f4f5f7;
  --text: #0b0d12;
  --text-strong: #000000;
  --muted: #5f6772;
  --line: #e6e8ec;
  --line-strong: #d7dae0;
  --accent: #14161b;
  --accent-strong: #000000;
  --accent-soft: #eef0f3;
  --brand-green: #1f5f5b;
  --brand-green-soft: #e4f0ee;
  --danger: #c8372d;
  --danger-soft: #fde7e2;
  --success: #1f7a56;
  --success-soft: #dff6eb;
  --info: #1d4ed8;
  --info-soft: #e3edff;
  --shadow-sm: 0 2px 8px rgba(16, 18, 24, 0.04);
  --shadow-md: 0 8px 24px rgba(16, 18, 24, 0.06);
  --shadow-lg: 0 24px 48px -12px rgba(16, 18, 24, 0.12);
  --radius: 20px;
  --radius-lg: 28px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(var(--bg-dot) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: 0 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.shell {
  width: min(1280px, calc(100% - 24px));
  margin: 0 auto;
  padding: 20px 0 48px;
}

/* Top brand nav — pill-shaped, floating — mirrors landing page header */
.brand-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px 10px 20px;
  margin-bottom: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
}

.brand-nav__logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-strong);
  text-decoration: none;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.brand-nav__logo-image {
  width: 42px;
  height: 42px;
  display: block;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand-nav__logo-text {
  display: inline-block;
  line-height: 1;
}

.brand-nav__links {
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-nav__link {
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

.brand-nav__link:hover,
.brand-nav__link--active {
  background: var(--surface-soft);
  color: var(--text);
}

.brand-nav__cta {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  border: none;
  font: inherit;
  cursor: pointer;
}

.brand-nav__cta:hover {
  background: var(--accent-strong);
}

@media (max-width: 720px) {
  .brand-nav__links {
    display: none;
  }
}

.landing,
.tenant-placeholder,
.auth-page,
.dashboard {
  display: grid;
  gap: 18px;
}

.hero,
.tenant-placeholder,
.auth-card,
.panel,
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.hero,
.tenant-placeholder {
  padding: 40px;
}

.hero h1,
.tenant-placeholder h1,
.auth-card h1,
.dashboard h1 {
  margin: 0;
  font-size: clamp(32px, 4.4vw, 52px);
  line-height: 1.02;
  letter-spacing: -0.035em;
  color: var(--text-strong);
  font-weight: 800;
}

.hero-copy,
.muted,
.tenant-placeholder p {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.hero-actions,
.dashboard-header__actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 18px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease, border-color 120ms ease;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 16px rgba(20, 22, 27, 0.18);
}

.btn-primary:hover {
  background: var(--accent-strong);
  box-shadow: 0 10px 22px rgba(20, 22, 27, 0.22);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.btn-danger {
  background: transparent;
  border-color: rgba(200, 55, 45, 0.28);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-soft);
  border-color: rgba(200, 55, 45, 0.45);
}

.btn-small {
  min-height: 34px;
  padding: 0 14px;
  font-size: 13px;
}

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

.field {
  display: grid;
  gap: 7px;
}

.field span {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--text-strong);
  box-shadow: 0 0 0 3px rgba(16, 18, 24, 0.08);
}

.auth-page {
  place-items: center;
  min-height: calc(100vh - 120px);
}

.auth-card {
  width: min(520px, 100%);
  padding: 36px;
  box-shadow: var(--shadow-lg);
}

.alert {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid transparent;
  font-size: 14px;
}

.alert-error {
  background: var(--danger-soft);
  border-color: rgba(200, 55, 45, 0.22);
  color: var(--danger);
}

.alert-success {
  background: var(--success-soft);
  border-color: rgba(31, 122, 86, 0.16);
  color: var(--success);
}

.dashboard-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.dashboard-header--hero {
  align-items: center;
}

.dashboard-header--panel {
  padding: 28px 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.dashboard-header--panel::after {
  content: "";
  position: absolute;
  right: -40px;
  top: -40px;
  width: 220px;
  height: 220px;
  background: radial-gradient(circle, rgba(31, 95, 91, 0.08), transparent 70%);
  pointer-events: none;
}

.dashboard-hero {
  display: grid;
  gap: 12px;
  max-width: 760px;
  position: relative;
  z-index: 1;
}

.dashboard-hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hero-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: var(--brand-green-soft);
  border: 1px solid rgba(31, 95, 91, 0.16);
  color: var(--brand-green);
  font-size: 12px;
  font-weight: 700;
}

.dashboard-header h1 {
  max-width: none;
  font-size: clamp(28px, 3.8vw, 44px);
}

.admin-pill {
  padding: 9px 12px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--text-strong);
  font-size: 13px;
  font-weight: 700;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.stat-card {
  position: relative;
  overflow: hidden;
  padding: 18px 20px;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, var(--brand-green), rgba(31, 95, 91, 0.28));
}

.stat-card__label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-card strong {
  font-size: 32px;
  line-height: 1;
  color: var(--text-strong);
  font-weight: 800;
}

.stat-card__meta {
  margin-top: 12px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(300px, 340px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  padding: 24px;
}

.panel--sticky {
  position: sticky;
  top: 20px;
}

.panel--danger {
  background: rgba(253, 231, 226, 0.45);
  border-color: rgba(200, 55, 45, 0.18);
}

.panel__header {
  margin-bottom: 16px;
}

.panel__header--spaced {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.panel__header h2 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-strong);
}

.panel-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panel-search {
  min-width: 220px;
  max-width: 300px;
}

.panel-filter {
  min-width: 170px;
}

.panel-counter {
  margin-top: 0;
  padding: 0 4px;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

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

.table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.table-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.table-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.table-code {
  display: inline-flex;
  align-items: center;
  margin-top: 6px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.table-action {
  width: 1%;
  text-align: right;
}

.table-actions {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 6px;
}

.table-actions form {
  margin: 0;
}

.table-actions .btn {
  min-width: 108px;
}

.table-stack {
  display: grid;
  gap: 8px;
}

.btn-copy {
  justify-self: flex-start;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.status-invited {
  background: var(--brand-green-soft);
  color: var(--brand-green);
}

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

.status-pending {
  background: var(--accent-soft);
  color: var(--muted);
}

.status-warning {
  background: #fff2d4;
  color: #b46a00;
}

.status-empty,
.status-disconnected,
.status-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-blocked,
.status-archived {
  background: var(--danger-soft);
  color: var(--danger);
}

.empty-state {
  padding: 28px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  background: var(--surface-soft);
}

.sheet-page {
  display: grid;
  gap: 18px;
}

.dashboard--wide {
  max-width: min(1800px, calc(100vw - 48px));
}

.sheet-page__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.sheet-page__title {
  display: grid;
  gap: 4px;
}

.sheet-page__meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sheet-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sheet-tab {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  background: var(--surface);
}

.sheet-tab:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.sheet-tab--active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.sheet-frame {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.sheet-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-gutter: stable both-edges;
}

.sheet-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.sheet-toolbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.sheet-import-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.sheet-import-form__row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sheet-import-form__row .sheet-field {
  width: 100%;
  max-width: 640px;
}

.sheet-import-form__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.sheet-grid {
  display: inline-table;
  width: auto;
  min-width: calc(var(--sheet-column-count, 1) * 130px);
  border-collapse: collapse;
  table-layout: fixed;
}

.sheet-grid th,
.sheet-grid td {
  width: 130px;
  min-width: 130px;
  padding: 0;
  border: 1px solid var(--line);
  vertical-align: top;
  background: #fff;
}

.sheet-grid th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.sheet-grid td {
  white-space: normal;
  word-break: break-word;
}

.sheet-grid--ads th,
.sheet-grid--ads td {
  width: 180px;
  min-width: 180px;
}

.sheet-grid--ads {
  min-width: calc(var(--sheet-column-count, 1) * 180px);
}

.sheet-grid--matrix th,
.sheet-grid--matrix td {
  width: 90px;
  min-width: 90px;
}

.sheet-grid--matrix {
  min-width: calc(var(--sheet-column-count, 1) * 90px);
}

.sheet-cell {
  padding: 14px;
  background: #ffffff;
}

.sheet-column-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  min-height: 92px;
}

.sheet-column-head__eyebrow {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  font-weight: 700;
}

.sheet-column-head__title {
  font-size: 16px;
  color: var(--text-strong);
  line-height: 1.2;
  font-weight: 700;
}

.sheet-column-head__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sheet-ad-form {
  display: grid;
  gap: 10px;
}

.sheet-cell__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}

.sheet-input,
.sheet-field {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.sheet-input {
  padding: 12px 14px;
  resize: vertical;
  line-height: 1.45;
}

.sheet-field {
  min-height: 44px;
  padding: 10px 12px;
}

.sheet-link {
  display: block;
  margin-top: -2px;
  color: var(--info);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.sheet-image-preview {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
}

.sheet-grid--editable td {
  padding: 10px;
}

.sheet-grid--editable tbody tr:hover td {
  background: rgba(16, 18, 24, 0.02);
}

.sheet-row-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 70px;
}

.sheet-readonly {
  padding: 12px;
  color: var(--muted);
  background: var(--surface-soft);
}

.sheet-row-new td {
  background: rgba(31, 95, 91, 0.04);
}

.tenant-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 28px 0 0;
}

.tenant-meta div {
  padding: 18px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.tenant-meta dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 700;
}

.tenant-meta dd {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-strong);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  gap: 18px;
}

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

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

.entity-card {
  display: grid;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.entity-card__header,
.entity-card__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.stat-card__compact {
  display: block;
  font-size: 20px;
  line-height: 1.2;
  overflow-wrap: anywhere;
  font-weight: 700;
}

code {
  font-family: "JetBrains Mono", "SFMono-Regular", monospace;
  font-size: 0.92em;
}

/* Platform brand icons */
.platform-icon {
  display: inline-block;
  width: 28px;
  height: 28px;
  vertical-align: middle;
  flex-shrink: 0;
}

.platform-icon--sm {
  width: 24px;
  height: 24px;
}

.platform-icon--md {
  width: 40px;
  height: 40px;
}

.platform-icon--lg {
  width: 56px;
  height: 56px;
}

.platform-icon--xl {
  width: 72px;
  height: 72px;
}

.platform-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.platform-badge .platform-icon {
  flex-shrink: 0;
}

@media (max-width: 920px) {
  .dashboard-header,
  .admin-grid,
  .stats-grid,
  .tenant-meta,
  .detail-grid,
  .field-row {
    grid-template-columns: 1fr;
  }

  .dashboard-header {
    display: grid;
  }

  .table-actions,
  .sheet-page__bar,
  .sheet-tabs {
    justify-content: flex-start;
  }

  .table-action {
    text-align: left;
  }

  .table-actions {
    align-items: flex-start;
  }

  .panel__header--spaced,
  .panel-tools,
  .sheet-toolbar__actions,
  .sheet-toolbar,
  .sheet-column-head {
    display: grid;
  }

  .hero,
  .tenant-placeholder,
  .auth-card,
  .panel,
  .dashboard-header--panel {
    padding: 24px;
  }

  .panel--sticky {
    position: static;
  }
}

.admin-tabs {
  display: flex;
  gap: 8px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(214, 220, 228, 0.95);
  border-radius: var(--radius-pill);
  box-shadow: 0 14px 30px rgba(71, 46, 13, 0.06);
  width: fit-content;
}

.admin-tabs__link {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
  transition: background 140ms ease, color 140ms ease;
}

.admin-tabs__link:hover {
  color: var(--text-strong);
  background: rgba(238, 242, 247, 0.8);
}

.admin-tabs__link--active {
  background: var(--brand-green, #1f5f5b);
  color: #fff;
}

.admin-tabs__link--active:hover {
  color: #fff;
  background: var(--brand-green, #1f5f5b);
}

@media (max-width: 720px) {
  body {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  .admin-tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    border-top: 1px solid rgba(214, 220, 228, 0.95);
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 -8px 24px rgba(71, 46, 13, 0.08);
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    gap: 4px;
    z-index: 1000;
  }

  .admin-tabs__link {
    flex: 1 1 0;
    justify-content: center;
    padding: 12px 8px;
    border-radius: 14px;
    font-size: 14px;
    text-align: center;
  }

  .brand-nav {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
  }

  .brand-nav__logo-text {
    font-size: 16px;
  }

  .dashboard-header h1 {
    font-size: 1.5rem;
    line-height: 1.15;
  }

  .dashboard-header--hero {
    padding: 18px;
  }

  .dashboard {
    gap: 14px;
  }

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

  .stat-card {
    padding: 14px 14px;
  }

  .stat-card__label {
    font-size: 11px;
  }

  .stat-card strong {
    font-size: 26px;
  }

  .panel {
    padding: 16px;
  }

  .analytics-section__title {
    font-size: 1rem;
  }

  .analytics-platforms th,
  .analytics-platforms td {
    padding: 10px 12px;
    font-size: 14px;
  }
}
