:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-muted: #f0f4f2;
  --text: #1f2933;
  --muted: #65717d;
  --line: #d8ded9;
  --green: #226f54;
  --blue: #2f6fed;
  --amber: #d97706;
  --red: #b42318;
  --purple: #7c3aed;
  --shadow: 0 18px 45px rgba(31, 41, 51, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

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

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #17211d;
}

.auth-panel {
  width: min(430px, 100%);
  padding: 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-brand {
  margin-bottom: 22px;
  color: var(--text);
}

.auth-brand span:last-child {
  color: var(--muted);
}

.auth-panel h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

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

.brand-mark {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-symbol {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: #dbeafe;
  color: #15345f;
  font-weight: 800;
}

.brand-mark strong,
.side-panel strong {
  display: block;
}

.brand-mark span:last-child,
.side-panel small {
  color: #b8c6be;
}

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

.nav-list a {
  color: #d6ded9;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
}

.nav-list a:hover,
.nav-list a.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.side-panel {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.workspace-select {
  width: 100%;
  margin: 0.35rem 0 0.5rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.2);
  color: inherit;
}

.workspace-actions {
  display: flex;
  gap: 0.35rem;
}

.workspace-actions .small {
  flex: 1;
  font-size: 0.75rem;
  padding: 0.35rem 0.5rem;
}

.agency-metrics {
  margin-bottom: 1rem;
}

.list-stack .list-item,
.agency-workspace-list .list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.list-meta {
  display: flex;
  gap: 0.75rem;
  font-size: 0.8rem;
  opacity: 0.85;
}

.hidden-section {
  display: block;
}
  margin-top: auto;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

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

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

.topbar {
  margin-bottom: 22px;
}

.topbar h1,
.panel h2,
.section-header h2 {
  margin: 3px 0 0;
  line-height: 1.1;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(28px, 4vw, 46px);
}

.panel h2,
.section-header h2 {
  font-size: 22px;
}

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

.topbar-actions,
.segmented {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-chip {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.live-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.live-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
}

.live-chip.connected::before {
  background: #16a34a;
  box-shadow: 0 0 0 5px rgba(22, 163, 74, 0.12);
}

.live-chip.connecting::before {
  background: #d97706;
  animation: pulseDot 1.1s ease-in-out infinite;
}

.primary-button,
.ghost-button,
.icon-button,
.segmented button,
.mini-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

.primary-button {
  padding: 0 16px;
  background: var(--green);
  color: #ffffff;
  font-weight: 700;
}

.primary-button:hover {
  background: #1a5a44;
}

.ghost-button,
.mini-button,
.segmented button {
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.ghost-button:hover,
.mini-button:hover,
.segmented button:hover {
  border-color: #aab6ae;
}

.icon-button {
  width: 40px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
  font-size: 20px;
}

.full-width {
  width: 100%;
}

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

.chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 18px;
  align-items: start;
  margin-bottom: 20px;
}

.chat-panel {
  min-height: 520px;
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto;
}

.chat-messages {
  display: grid;
  gap: 10px;
  max-height: 360px;
  overflow: auto;
  padding: 14px 0;
}

.chat-message {
  max-width: 86%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
  animation: riseIn 180ms ease both;
}

.chat-message.user {
  justify-self: end;
  background: #dff5ea;
  border-color: #b7e3ce;
}

.chat-message strong,
.chat-message span {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.chat-message p {
  margin: 5px 0;
  line-height: 1.45;
}

.chat-message.typing p {
  display: flex;
  align-items: center;
  gap: 6px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: typingBounce 1s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 120ms;
}

.typing-dot:nth-child(3) {
  animation-delay: 240ms;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.chat-form textarea {
  min-height: 86px;
}

.metric,
.panel,
.agent-card,
.draft-card,
.integration-card,
.model-card,
.job-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

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

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

.main-grid,
.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.panel {
  padding: 20px;
}

.compact-panel,
.config-panel {
  margin-top: 14px;
}

.section-block {
  margin-top: 24px;
}

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

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

.stacked-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.checkbox-label input {
  width: auto;
}

.profile-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto auto;
  gap: 14px;
  align-items: end;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.12);
}

.status-chip,
.source-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.status-chip.connected {
  background: #dff5ea;
  color: #176348;
}

.status-chip.sandbox,
.status-chip.paused {
  background: #eef2f7;
  color: #475569;
}

.status-chip.needs_key {
  background: #fff0d7;
  color: #92400e;
}

.status-chip.published {
  background: #dbeafe;
  color: #1d4ed8;
}

.status-chip.approved {
  background: #dff5ea;
  color: #176348;
}

.status-chip.draft {
  background: #fff7ed;
  color: #9a3412;
}

.status-chip.error {
  background: #fee2e2;
  color: #991b1b;
}

.agent-grid,
.integration-grid,
.model-grid,
.security-grid,
.planned-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.agent-card,
.integration-card,
.draft-card,
.model-card,
.job-card,
.planned-card {
  padding: 16px;
}

.planned-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  animation: riseIn 220ms ease both;
}

.planned-image,
.draft-image {
  width: 100%;
  display: block;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
}

.planned-image {
  aspect-ratio: 16 / 9;
  object-fit: contain;
}

.draft-image {
  margin-top: 12px;
  max-height: 220px;
  object-fit: contain;
}

.planned-body {
  display: grid;
  gap: 8px;
}

.planned-body h3 {
  margin: 0;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.planned-body p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.agent-card {
  min-height: 170px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.agent-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.agent-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.agent-card h3,
.draft-card h3,
.integration-card h3 {
  margin: 0;
  font-size: 18px;
}

.agent-card p,
.integration-card p,
.draft-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.channel-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
}

.tag {
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tag-ok {
  background: #dff5ea;
  color: #176348;
}

.tag-error {
  background: #fee2e2;
  color: #991b1b;
}

.small-text {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.field-help,
.field-source {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}

.field-source {
  color: #475569;
}

.connector-guide {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
}

.connector-guide h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.connector-guide p {
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.45;
}

.connector-guide ol {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.5;
}

.segmented {
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.segmented button {
  min-height: 32px;
  border: 0;
  background: transparent;
}

.segmented button.active {
  background: #17211d;
  color: #ffffff;
}

.draft-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.job-list,
.call-log {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.draft-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
}

.draft-meta,
.draft-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.draft-meta {
  margin: 10px 0;
}

.draft-actions {
  justify-content: flex-end;
}

.draft-preview {
  white-space: pre-wrap;
  background: #f8faf9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  max-height: 170px;
  overflow: auto;
  font-size: 14px;
}

.two-column {
  margin-top: 24px;
}

.seo-result {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.score-ring {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 8px solid var(--green);
  font-size: 20px;
  font-weight: 800;
}

.check-row,
.task-row,
.activity-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.check-row:last-child,
.task-row:last-child,
.activity-row:last-child {
  border-bottom: 0;
}

.check-mark {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e7ece9;
  color: var(--muted);
  font-weight: 800;
}

.check-mark.ok {
  background: #dff5ea;
  color: #176348;
}

.task-list,
.activity-list {
  margin-top: 12px;
}

.task-row button {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #ffffff;
}

.task-row.done strong {
  text-decoration: line-through;
  color: var(--muted);
}

.integration-card {
  display: grid;
  gap: 12px;
}

.integration-card.selected {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(34, 111, 84, 0.12), var(--shadow);
}

.integration-card header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.model-card {
  display: grid;
  gap: 10px;
  align-content: start;
}

.model-card h3,
.job-card h3 {
  margin: 0;
  font-size: 17px;
}

.job-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}

.security-card strong {
  font-size: 18px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #17211d;
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

@keyframes typingBounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@keyframes pulseDot {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}

.empty-state {
  padding: 26px;
  border: 1px dashed #b7c2bc;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.45);
  color: var(--muted);
  text-align: center;
}

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

  .sidebar {
    position: relative;
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .main-grid,
  .two-column,
  .chat-layout,
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .agent-grid,
  .integration-grid,
  .model-grid,
  .security-grid,
  .planned-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .workspace,
  .sidebar {
    padding: 18px;
  }

  .topbar,
  .panel-header,
  .section-header,
  .draft-card,
  .job-card {
    align-items: stretch;
    flex-direction: column;
  }

  .draft-card,
  .job-card {
    display: flex;
  }

  .topbar-actions,
  .draft-actions,
  .segmented {
    justify-content: stretch;
  }

  .primary-button,
  .ghost-button,
  .segmented button {
    flex: 1;
  }

  .metrics-grid,
  .main-grid,
  .two-column,
  .chat-layout,
  .agent-grid,
  .integration-grid,
  .model-grid,
  .security-grid,
  .planned-grid,
  .form-grid,
  .profile-toolbar {
    grid-template-columns: 1fr;
  }

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

  .chat-message {
    max-width: 100%;
  }

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

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