:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d8dee8;
  --text: #18202f;
  --muted: #647084;
  --brand: #0b6bcb;
  --brand-dark: #094f96;
  --danger: #b42318;
  --ok: #157f3b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  min-height: 36px;
}

button {
  background: var(--brand);
  color: white;
  cursor: pointer;
  padding: 0 12px;
}

button:hover {
  background: var(--brand-dark);
}

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

button.secondary {
  background: #eef2f7;
  color: var(--text);
}

button.active {
  background: #dbeafe;
  color: var(--brand-dark);
}

button.danger {
  background: var(--danger);
}

input,
select {
  background: white;
  color: var(--text);
  padding: 0 10px;
}

input[type="checkbox"] {
  height: 16px;
  min-height: 0;
  padding: 0;
  width: 16px;
}

.hidden {
  display: none !important;
}

.topbar {
  align-items: center;
  background: #101827;
  color: white;
  display: flex;
  justify-content: space-between;
  min-height: 84px;
  padding: 18px 28px;
}

.topbar h1 {
  font-size: 24px;
  line-height: 1;
  margin: 0 0 8px;
}

.topbar p {
  color: #b9c3d4;
  margin: 0;
}

.token-box {
  display: flex;
  gap: 8px;
}

.token-box input {
  width: 240px;
}

main {
  padding: 22px 28px 40px;
}

.auth-panel,
.bm-form,
.message {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 14px;
  padding: 14px 16px;
}

.auth-panel h2 {
  font-size: 16px;
  margin: 0 0 6px;
}

.auth-panel p {
  color: var(--muted);
  margin: 0;
}

.auth-panel.hidden,
.message.hidden {
  display: none;
}

.message {
  border-color: #f3c25b;
  background: #fff8e6;
  color: #6f4c00;
}

.message.error {
  border-color: #f0a39e;
  background: #fff1f0;
  color: var(--danger);
}

.message.success {
  border-color: #9ad5ad;
  background: #eefbf2;
  color: var(--ok);
}

.toolbar {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px;
}

.form-grid {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  padding: 14px;
}

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

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

.toolbar label {
  align-items: center;
  color: var(--muted);
  display: flex;
  gap: 6px;
}

.toolbar .custom-date.hidden {
  display: none;
}

.summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin: 16px 0;
}

.summary-grid article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

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

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

.layout {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(420px, 34vw) minmax(0, 1fr);
}

aside,
.content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
}

.panel-title {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 56px;
  padding: 12px 14px;
}

.panel-title h2 {
  font-size: 16px;
  margin: 0;
}

.tree-tools {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
}

.tree-tools-row {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.tree-tools-row input {
  width: 100%;
}

.tree-selection-bar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.tree-selection-bar span {
  color: var(--muted);
  font-size: 12px;
  margin-right: auto;
}

.tree-selection-bar button {
  font-size: 12px;
  min-height: 30px;
  padding: 0 9px;
}

.tree-list {
  max-height: 680px;
  overflow: auto;
}

.bm-node {
  border-bottom: 1px solid var(--line);
}

.bm-node.active {
  background: #f1f7ff;
}

.bm-node.disabled {
  background: #fafafa;
}

.bm-header {
  align-items: flex-start;
  display: grid;
  gap: 10px;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  padding: 12px;
}

.bm-header.selecting {
  grid-template-columns: 22px 32px minmax(0, 1fr) auto;
}

.tree-check {
  align-items: center;
  display: inline-flex;
  justify-content: center;
  min-height: 30px;
}

.icon-button {
  align-items: center;
  background: #eef2f7;
  color: var(--text);
  display: inline-flex;
  font-size: 18px;
  font-weight: 700;
  justify-content: center;
  min-height: 30px;
  padding: 0;
  width: 30px;
}

.bm-title {
  min-width: 0;
}

.bm-title strong {
  display: block;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bm-title span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  line-height: 1.45;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  max-width: 176px;
}

.bm-actions button {
  font-size: 12px;
  min-height: 30px;
  padding: 0 9px;
}

.account-children {
  background: #fbfcfe;
  border-top: 1px solid #e7ecf3;
  padding: 6px 0 8px 42px;
}

.account-row {
  align-items: stretch;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.account-row.selecting {
  grid-template-columns: 22px minmax(0, 1fr);
  padding-left: 8px;
}

.account-row.active {
  background: #e9f2ff;
}

.account-node {
  background: transparent;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0;
  color: var(--text);
  display: block;
  min-height: 0;
  padding: 8px 12px;
  text-align: left;
  width: 100%;
}

.account-node:hover,
.account-node.active {
  background: #e9f2ff;
}

.account-node.active {
  border-left-color: var(--brand);
}

.account-node strong {
  display: block;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-node span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  line-height: 1.4;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-node {
  color: var(--muted);
  font-size: 13px;
  padding: 12px 14px;
}

.table-wrap {
  overflow: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
}

td.actions {
  display: flex;
  gap: 6px;
}

.check-cell {
  text-align: center;
  width: 42px;
}

.campaign-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.campaign-tools button {
  font-size: 12px;
  min-height: 32px;
  padding: 0 10px;
}

.status {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  padding: 3px 8px;
}

.status.active {
  background: #dcfce7;
  color: var(--ok);
}

.status.paused {
  background: #fff1f2;
  color: var(--danger);
}

.toast {
  background: #101827;
  border-radius: 6px;
  bottom: 18px;
  color: white;
  display: none;
  left: 50%;
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 14px;
  position: fixed;
  transform: translateX(-50%);
}

.toast.show {
  display: block;
}

@media (max-width: 920px) {
  .topbar,
  .layout {
    display: block;
  }

  .token-box {
    margin-top: 14px;
  }

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

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

  .form-grid .wide {
    grid-column: auto;
  }

  aside {
    margin-bottom: 16px;
  }

  .bm-header {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .bm-header.selecting {
    grid-template-columns: 22px 32px minmax(0, 1fr);
  }

  .bm-actions {
    grid-column: 2;
    justify-content: flex-start;
    max-width: none;
  }

  .bm-header.selecting .bm-actions {
    grid-column: 3;
  }

  .account-children {
    padding-left: 28px;
  }

  .campaign-tools {
    justify-content: flex-start;
    margin-top: 10px;
    width: 100%;
  }
}
