:root {
  color-scheme: light;
  --page: #eef3f5;
  --sidebar: #101415;
  --sidebar-2: #1a2020;
  --card: #ffffff;
  --field: #ffffff;
  --ink: #111716;
  --muted: #647083;
  --soft: #eef2f6;
  --line: #dce3ea;
  --line-strong: #c8d1dc;
  --accent: #00a889;
  --accent-dark: #087563;
  --blue: #2563eb;
  --lime: #a3e635;
  --coral: #f97352;
  --amber: #b7791f;
  --red: #b42318;
  --green: #067647;
  --shadow: 0 18px 44px rgba(21, 31, 43, 0.12);
  --shadow-soft: 0 10px 24px rgba(21, 31, 43, 0.07);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0b1118;
  --sidebar: #060a10;
  --sidebar-2: #0e1620;
  --card: #121b26;
  --field: #0c141e;
  --ink: #eef4fa;
  --muted: #9aa8b8;
  --soft: #172231;
  --line: rgba(203, 213, 225, 0.15);
  --line-strong: rgba(203, 213, 225, 0.24);
  --accent: #14b8a6;
  --accent-dark: #0f9488;
  --blue: #60a5fa;
  --amber: #f2b84b;
  --red: #ff7a75;
  --green: #3ddc97;
  --shadow: 0 20px 48px rgba(0, 0, 0, 0.36);
  --shadow-soft: 0 12px 28px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(0, 168, 137, 0.08), transparent 26%),
    linear-gradient(315deg, rgba(249, 115, 82, 0.08), transparent 28%),
    var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
.primaryLink,
.secondaryLink {
  cursor: pointer;
}

h1,
h2,
p {
  margin: 0;
}

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

.sidebar {
  position: sticky;
  top: 0;
  min-height: 100vh;
  padding: 18px 14px;
  background:
    linear-gradient(180deg, rgba(0, 168, 137, 0.24), transparent 28%),
    linear-gradient(180deg, var(--sidebar-2), var(--sidebar));
  color: #e8eef5;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 22px;
}

.brand {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 4px 6px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brandMark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--lime);
  color: #111716;
  font-size: 20px;
  font-weight: 950;
}

.brand strong {
  display: block;
  font-size: 20px;
  line-height: 1.05;
  letter-spacing: 0;
}

.brand span {
  display: block;
  margin-top: 4px;
  color: #9ee8df;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

nav {
  display: grid;
  align-content: start;
  gap: 6px;
}

.navItem {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  color: #b9c6d5;
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 800;
}

.navItem span {
  width: 24px;
  color: #6f8399;
  font-size: 11px;
  font-weight: 900;
}

.navItem:hover,
.navItem.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.navItem.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.authPanel {
  display: grid;
  gap: 9px;
  padding: 16px 6px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.authPanel label,
label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.authPanel label {
  color: #d9e5f1;
}

.tokenRow,
.fieldBlock,
.groupTools {
  display: grid;
  gap: 8px;
}

input,
textarea,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  outline: 0;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  padding: 12px;
  resize: vertical;
  line-height: 1.45;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.14);
}

.authPanel input {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(6, 10, 16, 0.5);
  color: white;
}

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

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 20px;
  align-items: center;
  margin-bottom: 16px;
  min-height: 176px;
  padding: 26px;
  border-radius: 8px;
  color: #ffffff;
  background:
    linear-gradient(135deg, rgba(163, 230, 53, 0.18), transparent 34%),
    linear-gradient(315deg, rgba(0, 168, 137, 0.32), transparent 42%),
    #111716;
  box-shadow: 0 24px 58px rgba(17, 23, 22, 0.24);
}

.eyebrow,
.sectionKicker {
  display: block;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

:root[data-theme="dark"] .eyebrow,
:root[data-theme="dark"] .sectionKicker {
  color: #7ddbd1;
}

.topbar h1 {
  margin-top: 6px;
  font-size: 38px;
  line-height: 1.08;
}

.panelHeader p,
.metrics small {
  color: var(--muted);
}

.topbar .eyebrow {
  color: var(--lime);
}

.topbar p {
  margin-top: 6px;
  max-width: 650px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 16px;
}

.topActions,
.adsActions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

button,
.primaryLink,
.secondaryLink {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  background: var(--accent);
  font-weight: 850;
  text-decoration: none;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

button:hover,
.primaryLink:hover {
  background: var(--accent-dark);
}

button:active,
.primaryLink:active,
.secondaryLink:active {
  transform: translateY(1px);
}

.secondaryLink,
.smallButton {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.18);
}

.secondaryLink:hover,
.smallButton:hover {
  background: rgba(255, 255, 255, 0.16);
}

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

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

.metrics article,
.statusStrip,
.adsPanel,
.panel,
.batchPanel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: var(--shadow-soft);
}

.metrics article {
  min-height: 108px;
  padding: 16px;
  display: grid;
  align-content: space-between;
  border-top: 4px solid var(--accent);
}

.metrics article:nth-child(2) {
  border-top-color: var(--blue);
}

.metrics article:nth-child(3) {
  border-top-color: var(--coral);
}

.metrics article:nth-child(4) {
  border-top-color: var(--lime);
}

.metrics span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 850;
}

.metrics strong {
  display: block;
  margin: 9px 0 5px;
  font-size: 32px;
  line-height: 1;
}

.metrics small {
  font-size: 12px;
}

.statusStrip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  margin-bottom: 14px;
}

.statusItem {
  min-height: 70px;
  padding: 14px 16px;
  border-right: 1px solid var(--line);
  background: var(--card);
}

.statusItem:last-child {
  border-right: 0;
}

.statusItem span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.statusItem strong {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  font-size: 14px;
}

.statusItem strong::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
}

.ok {
  color: var(--green);
}

.fail {
  color: var(--red);
}

.adsPanel,
.panel {
  overflow: hidden;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.adsPanel {
  border-color: rgba(0, 168, 137, 0.34);
}

.panelHeader {
  min-height: 68px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background:
    linear-gradient(90deg, rgba(0, 168, 137, 0.08), transparent 48%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0));
}

:root[data-theme="dark"] .panelHeader {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0));
}

.panelHeader.compact {
  min-height: 62px;
}

.panelHeader h2 {
  margin-top: 3px;
  font-size: 18px;
}

.panelHeader p {
  margin-top: 4px;
  font-size: 13px;
}

.adsGrid {
  display: grid;
  grid-template-columns: minmax(300px, 0.92fr) minmax(360px, 1fr);
  gap: 16px;
  padding: 16px;
}

.inputPanel,
.previewPanel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.inputPanel {
  grid-template-rows: auto 1fr;
}

.grow {
  min-height: 100%;
}

.grow textarea {
  min-height: 290px;
}

.previewToolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(210px, 0.72fr);
  gap: 12px;
}

.groupSearchRow,
.savedFieldRow {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

pre {
  min-height: 238px;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 13px;
  color: var(--ink);
  font: 13px/1.5 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.batchPanel {
  margin: 0 16px 16px;
  box-shadow: none;
}

.adsBatchList {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  max-height: 520px;
  overflow: auto;
  padding: 16px;
}

.adsBatchItem {
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--card);
}

.adsBatchItem label {
  color: var(--ink);
  font-size: 14px;
}

.adsBatchItem pre {
  min-height: 118px;
}

.workArea {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(340px, 0.76fr);
  gap: 18px;
}

.messageList {
  max-height: 560px;
  overflow: auto;
}

.message {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.message:last-child {
  border-bottom: 0;
}

.badge {
  width: 82px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
  background: rgba(6, 118, 71, 0.1);
  color: var(--green);
}

.badge.outbound {
  background: rgba(183, 121, 31, 0.13);
  color: var(--amber);
}

.messageBody {
  min-width: 0;
}

.messageMeta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.messageText {
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.testPanel {
  padding-bottom: 16px;
}

.testPanel textarea,
.testPanel button,
.replyBox {
  width: calc(100% - 32px);
  margin-left: 16px;
  margin-right: 16px;
}

.testPanel textarea {
  min-height: 148px;
}

.testPanel button {
  margin-top: 10px;
}

.replyBox {
  min-height: 132px;
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

@media (max-width: 1240px) {
  .adsBatchList,
  .workArea {
    grid-template-columns: 1fr;
  }

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

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

  .sidebar {
    position: static;
    min-height: auto;
    grid-template-rows: auto;
  }

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

  .topbar,
  .adsGrid,
  .metrics,
  .statusStrip,
  .groupSearchRow {
    grid-template-columns: 1fr;
  }

  .statusItem {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .statusItem:last-child {
    border-bottom: 0;
  }

  .topActions,
  .adsActions {
    justify-content: stretch;
  }

  .topActions > *,
  .adsActions > * {
    flex: 1 1 160px;
  }

  .workspace {
    padding: 16px;
  }

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

@media (max-width: 560px) {
  .workspace {
    padding: 12px;
  }

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

  .metrics strong {
    font-size: 28px;
  }

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

  .adsActions {
    width: 100%;
  }

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