:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef4f3;
  --surface-muted: #f8fafb;
  --text: #142029;
  --muted: #61717d;
  --muted-strong: #44535d;
  --line: #d9e2e7;
  --line-strong: #c6d1d8;
  --primary: #2264e5;
  --primary-dark: #184eb8;
  --primary-soft: #e8f0ff;
  --accent: #0f8766;
  --accent-soft: #e6f6f1;
  --warning: #b86b00;
  --warning-soft: #fff4de;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --shadow: 0 18px 48px rgb(27 43 54 / 10%);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, #e9f2f1 0, var(--bg) 310px),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

code {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted-strong);
  padding: 1px 5px;
  font-size: 13px;
}

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

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 48px;
}

.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
  margin-bottom: 22px;
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 80%);
  border-radius: 8px;
  background: #15313b;
  color: #fff;
  font-size: 19px;
  font-weight: 760;
  box-shadow: 0 14px 28px rgb(21 49 59 / 20%);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 720;
}

h1 {
  max-width: 680px;
  margin: 0;
  font-size: 32px;
  line-height: 1.12;
  font-weight: 760;
}

.lede {
  max-width: 660px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.sync-card {
  min-width: 266px;
  border: 1px solid rgb(255 255 255 / 78%);
  border-radius: 8px;
  background: rgb(255 255 255 / 82%);
  padding: 14px 15px;
  box-shadow: 0 12px 32px rgb(36 58 70 / 9%);
  backdrop-filter: blur(16px);
}

.sync-label {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 24px;
  color: var(--muted-strong);
  font-size: 14px;
  line-height: 1.35;
}

.status-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--warning);
  box-shadow: 0 0 0 4px var(--warning-soft);
}

.sync-card[data-state="ready"] .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.sync-card[data-state="error"] .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px var(--danger-soft);
}

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

.section-nav {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 10px;
}

.tab {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  width: 100%;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(255 255 255 / 72%);
  color: var(--text);
  padding: 12px;
  text-align: left;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

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

.tab[aria-selected="true"] {
  border-color: rgb(34 100 229 / 32%);
  background: var(--surface);
  box-shadow: 0 10px 28px rgb(34 100 229 / 11%);
}

.tab-index {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 760;
}

.tab[aria-selected="true"] .tab-index {
  background: var(--primary);
  color: #fff;
}

.tab-title {
  display: block;
  margin-bottom: 3px;
  font-size: 15px;
  font-weight: 760;
  line-height: 1.2;
}

.tab-copy {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.content-area {
  min-width: 0;
}

.workspace.auth-required {
  grid-template-columns: minmax(0, 620px);
  justify-content: center;
}

.workspace.auth-required .section-nav,
.workspace.auth-required .panel,
.workspace.auth-required .actionbar {
  display: none;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.auth-panel {
  display: block;
}

.auth-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 8px;
}

.auth-message {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
}

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

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-muted);
  padding: 18px 18px 16px;
}

.panel-kicker {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 760;
}

.panel-title {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 760;
}

.panel-copy {
  max-width: 660px;
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.counter {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted-strong);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.editor-body {
  padding: 18px;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.field-label {
  display: block;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 740;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  line-height: 1.48;
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

input {
  height: 42px;
  padding: 0 12px;
}

textarea {
  display: block;
  min-height: 540px;
  padding: 14px;
  resize: vertical;
  font-size: 14px;
}

input::placeholder,
textarea::placeholder {
  color: #8b98a2;
}

input:focus,
textarea:focus {
  border-color: rgb(34 100 229 / 82%);
  box-shadow: 0 0 0 4px rgb(34 100 229 / 13%);
}

.audience-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.agent {
  display: grid;
  min-width: 0;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: 0 12px 34px rgb(27 43 54 / 8%);
}

.agent-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.agent-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
  font-weight: 760;
}

.agent-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 760;
}

.agent textarea {
  min-height: 440px;
}

.style-editor textarea {
  min-height: 560px;
}

.actionbar {
  grid-column: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(255 255 255 / 88%);
  padding: 12px;
  box-shadow: 0 12px 36px rgb(27 43 54 / 8%);
  backdrop-filter: blur(18px);
}

.message {
  min-width: 0;
  color: var(--muted-strong);
  line-height: 1.4;
}

.message.ok {
  color: var(--accent);
  font-weight: 700;
}

.message.error {
  color: var(--danger);
  font-weight: 700;
}

.message.warning {
  color: var(--warning);
  font-weight: 700;
}

.primary {
  flex: 0 0 auto;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  padding: 0 18px;
  font-weight: 760;
  cursor: pointer;
  box-shadow: 0 12px 24px rgb(34 100 229 / 20%);
  transition:
    background 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease,
    opacity 160ms ease;
}

.secondary {
  flex: 0 0 auto;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  padding: 0 16px;
  font-weight: 760;
  cursor: pointer;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

.primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 14px 28px rgb(34 100 229 / 24%);
}

.primary:active,
.secondary:active,
.tab:active {
  transform: translateY(1px);
}

.secondary:hover {
  background: #20333d;
}

.primary:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
}

:focus-visible {
  outline: 3px solid rgb(34 100 229 / 28%);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .workspace.auth-required {
    grid-template-columns: 1fr;
  }

  .section-nav {
    position: static;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .actionbar {
    grid-column: 1;
  }

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

  .agent textarea {
    min-height: 340px;
  }

  .style-editor textarea {
    min-height: 430px;
  }
}

@media (max-width: 740px) {
  body {
    background:
      linear-gradient(180deg, #e9f2f1 0, var(--bg) 250px),
      var(--bg);
  }

  .app-shell {
    width: min(100% - 20px, 680px);
    padding: 18px 0 34px;
  }

  .masthead {
    grid-template-columns: 1fr;
    align-items: start;
  }

  h1 {
    font-size: 28px;
  }

  .sync-card {
    width: 100%;
    min-width: 0;
  }

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

  .tab {
    min-height: 64px;
    align-items: center;
    grid-template-columns: 30px minmax(0, 1fr);
    padding: 10px;
  }

  .tab[data-tab="gamma-style"] {
    grid-column: 1 / -1;
  }

  .tab > span:last-child {
    min-width: 0;
  }

  .tab-index {
    width: 30px;
    height: 30px;
  }

  .tab-title {
    margin-bottom: 0;
    font-size: 14px;
    line-height: 1.15;
    overflow-wrap: break-word;
  }

  .tab-copy {
    display: none;
  }

  .panel-header,
  .editor-body,
  .audience-grid {
    padding: 14px;
  }

  .panel-header {
    display: grid;
  }

  textarea {
    min-height: 390px;
  }

  .style-editor textarea {
    min-height: 390px;
  }

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

  .auth-actions {
    grid-template-columns: 1fr;
  }

  .secondary {
    width: 100%;
  }

  .primary {
    width: 100%;
  }
}

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