:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #121826;
  --text: #1f2937;
  --muted: #667085;
  --line: #d9e2ef;
  --line-strong: #aebbd0;
  --teal: #0f766e;
  --teal-dark: #0b5751;
  --mint: #dff3ed;
  --gold: #b7791f;
  --gold-soft: #fff7df;
  --amber: #c77700;
  --red: #b42318;
  --green: #16803d;
  --blue: #2563eb;
  --indigo: #3843a8;
  --shadow: 0 18px 45px rgba(18, 24, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Segoe UI",
    Arial,
    sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), transparent 32%),
    linear-gradient(225deg, rgba(183, 121, 31, 0.1), transparent 34%),
    linear-gradient(180deg, #f8fbff 0%, #eef3f8 100%);
}

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

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

.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 78px;
  padding: 12px 22px;
  border-bottom: 1px solid rgba(174, 187, 208, 0.55);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 280px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: linear-gradient(135deg, #0f766e, #3843a8);
  color: #fff;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 21px;
  line-height: 1.25;
}

.top-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.9);
}

.tab-button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 7px 12px;
  cursor: pointer;
}

.tab-button.active {
  background: var(--ink);
  color: #fff;
}

.admin-only {
  display: none !important;
}

body.admin-mode .admin-only {
  display: inline-flex !important;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

.brand p,
.actionbar p,
.dialog-head p,
.hint,
#resultMeta {
  color: var(--muted);
  line-height: 1.5;
}

.operator {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.operator label {
  color: var(--muted);
}

.operator input {
  width: 140px;
}

.save-state {
  min-width: 82px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #edf7f3;
  color: var(--teal-dark);
  text-align: center;
}

.save-state.error {
  background: #fee4e2;
  color: var(--red);
}

.admin-toggle {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 5px 10px;
  cursor: pointer;
}

body.admin-mode .admin-toggle {
  border-color: var(--teal);
  background: #eef8f5;
  color: var(--teal-dark);
}

.layout {
  display: block;
  padding: 18px;
}

.panel,
.actionbar,
.table-shell,
.summary-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel,
.actionbar,
.table-shell,
.summary-tile,
.hero-strip,
.settings-hero,
.insight-item {
  border-color: rgba(217, 226, 239, 0.95);
}

.panel {
  padding: 16px;
}

.panel-title,
.actionbar,
.dialog-head,
.dialog-actions,
.button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

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

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-button,
.ghost-button,
.ghost-link,
.icon-button {
  min-height: 36px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 8px 12px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.primary-button {
  background: linear-gradient(135deg, var(--teal), var(--indigo));
  color: #fff;
}

.primary-button:hover {
  background: var(--teal-dark);
}

.ghost-button,
.ghost-link {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.ghost-button:hover,
.ghost-link:hover {
  border-color: var(--line-strong);
  background: #f9f8f5;
}

.icon-button {
  width: 36px;
  padding: 0;
  border-color: var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: flex;
}

.tools-panel.active {
  display: flex;
  max-width: none;
}

.sync-hero .button-row {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.sync-hero .ghost-button {
  color: var(--text);
}

.sync-grid {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(360px, 1fr);
  gap: 14px;
  align-items: stretch;
}

.wide-tool-card {
  grid-column: 1 / -1;
}

.hero-strip,
.settings-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 126px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(18, 24, 38, 0.96), rgba(15, 118, 110, 0.9)),
    #121826;
  color: #fff;
  box-shadow: var(--shadow);
}

.hero-strip span,
.settings-hero span {
  display: inline-block;
  margin-bottom: 8px;
  color: #b7efe0;
  font-size: 12px;
  font-weight: 700;
}

.hero-strip h2,
.settings-hero h2 {
  font-size: 24px;
}

.hero-strip p,
.settings-hero p {
  max-width: 680px;
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.6;
}

.hero-meter {
  display: grid;
  place-items: center;
  width: 112px;
  height: 86px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
}

.hero-meter span {
  margin: 0;
  color: rgba(255, 255, 255, 0.7);
}

.hero-meter strong {
  font-size: 34px;
  line-height: 1;
}

.summary {
  display: grid;
  grid-template-columns: repeat(8, minmax(112px, 1fr));
  gap: 10px;
}

.manager-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.manager-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.manager-tabs button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.manager-tabs button.active {
  border-color: var(--teal);
  background: #eef8f5;
  color: var(--teal-dark);
  font-weight: 700;
}

.quick-search {
  display: grid;
  grid-template-columns: auto minmax(220px, 320px);
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.quick-search input {
  min-width: 240px;
}

.summary-tile {
  min-height: 88px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.94);
}

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

.summary-tile strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
  line-height: 1.15;
}

.summary-tile.good strong {
  color: var(--green);
}

.summary-tile.warn strong {
  color: var(--amber);
}

.summary-tile.money strong {
  color: var(--blue);
}

.actionbar {
  padding: 14px 16px;
}

.table-shell {
  overflow: auto;
  max-height: calc(100vh - 260px);
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #edf2f8;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

tbody tr:hover {
  background: #fbfaf6;
}

td input,
td select,
td textarea {
  min-width: 110px;
  min-height: 32px;
  padding: 6px 8px;
  border-color: transparent;
  background: transparent;
}

td input:focus,
td select:focus,
td textarea:focus {
  border-color: var(--teal);
  background: #fff;
}

.compact {
  width: 88px;
  min-width: 88px;
}

.money-input {
  width: 92px;
  min-width: 92px;
}

.long-input {
  width: 220px;
  min-width: 220px;
}

.note-input {
  width: 180px;
  min-width: 180px;
}

.case-input {
  width: 280px;
  min-width: 280px;
}

.ad-info {
  display: grid;
  gap: 4px;
  width: 260px;
}

.ad-info strong {
  color: var(--text);
  font-weight: 600;
}

.ad-info span,
.customer span {
  color: var(--muted);
  line-height: 1.35;
}

.customer {
  display: grid;
  gap: 4px;
  width: 150px;
}

.account-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #eef8f5;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 700;
}

.rating {
  font-weight: 800;
  text-align: center;
}

.sync-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.sync-row strong {
  color: var(--gold);
}

.sync-status-card {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.sync-status-card strong {
  color: var(--text);
}

.sync-status-card span {
  color: var(--muted);
  line-height: 1.5;
}

.sync-overview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.sync-overview-card {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.sync-overview-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.sync-overview-card strong {
  display: block;
  margin-top: 7px;
  color: var(--text);
  font-size: 18px;
  line-height: 1.2;
}

.sync-overview-card.warning {
  border-color: #f0c36a;
  background: #fff8e7;
}

.sync-overview-card.warning strong {
  color: #9a5b00;
}

.compact-table-shell {
  margin-top: 12px;
  overflow: auto;
  max-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.spend-table,
.sync-account-table {
  min-width: 980px;
  font-size: 13px;
}

.spend-table th,
.sync-account-table th {
  background: #e8f0f7;
}

.spend-table td,
.sync-account-table td {
  background: rgba(255, 255, 255, 0.88);
  white-space: nowrap;
}

.sync-account-table td:last-child {
  min-width: 180px;
}

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

.config-card {
  min-height: 280px;
}

.wide-card {
  grid-column: 1 / -1;
}

.mini-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
}

.toggle-line {
  display: flex !important;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px !important;
  color: var(--text) !important;
}

.toggle-line input {
  width: 18px;
  min-height: 18px;
}

.account-config-table {
  margin-top: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.account-config-table table {
  min-width: 780px;
}

.account-config-table td input {
  border-color: var(--line);
  background: #fff;
}

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

.copy-line input {
  font-family:
    "Segoe UI",
    Arial,
    sans-serif;
}

.crm-field-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.crm-field-grid span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--text);
  padding: 6px 12px;
  font-size: 13px;
}

.config-save-bar {
  position: sticky;
  bottom: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid rgba(174, 187, 208, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 18px 45px rgba(18, 24, 38, 0.14);
  backdrop-filter: blur(14px);
}

.config-save-bar div {
  display: grid;
  gap: 4px;
}

.config-save-bar strong {
  color: var(--text);
}

.config-save-bar span {
  color: var(--muted);
  font-size: 13px;
}

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

.dashboard-controls {
  display: grid;
  grid-template-columns: 170px 170px 220px minmax(260px, 1fr);
  gap: 12px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

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

.dashboard-note {
  min-height: 36px;
  display: flex;
  align-items: center;
  color: var(--muted);
  line-height: 1.5;
}

.dashboard-kpis {
  display: grid;
  grid-template-columns: repeat(15, minmax(86px, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid #0f5b7e;
  border-radius: 8px;
  background: #0f5b7e;
  box-shadow: var(--shadow);
}

.dashboard-kpi {
  min-height: 70px;
  padding: 11px 8px;
  background: #eef7fb;
  text-align: center;
}

.dashboard-kpi span {
  display: block;
  color: #17445d;
  font-size: 12px;
  font-weight: 700;
}

.dashboard-kpi strong {
  display: block;
  margin-top: 8px;
  color: #123047;
  font-size: 18px;
  line-height: 1.15;
}

.dashboard-shell {
  max-height: calc(100vh - 330px);
}

.dashboard-table {
  min-width: 1580px;
  font-size: 13px;
}

.dashboard-table th {
  background: #0f4f6d;
  color: #fff;
  text-align: center;
}

.dashboard-table td {
  text-align: center;
  vertical-align: middle;
}

.dashboard-table tbody tr:nth-child(even) td,
.spend-table tbody tr:nth-child(even) td {
  background: #f4f9fc;
}

.good-cell {
  color: var(--green);
  font-weight: 800;
}

.risk-cell {
  background: #fde8e7 !important;
  color: var(--red);
  font-weight: 800;
}

.advice-cell {
  min-width: 190px;
  text-align: left !important;
  color: #1b4b63;
}

.manager-cost-shell {
  max-height: 420px;
}

.manager-cost-table {
  min-width: 980px;
  font-size: 13px;
}

.manager-cost-table th {
  background: #e8f0f7;
  color: #244154;
  text-align: center;
}

.manager-cost-table td {
  text-align: center;
  vertical-align: middle;
}

.manager-cost-table td:first-child {
  text-align: left;
  font-weight: 700;
}

.manager-cost-table tbody tr:nth-child(even) td {
  background: #f4f9fc;
}

.insight-item {
  display: grid;
  gap: 10px;
  min-height: 102px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.insight-item span {
  color: var(--muted);
  font-size: 12px;
}

.insight-item strong {
  color: var(--text);
  line-height: 1.55;
}

.hint {
  margin-top: 12px;
  font-size: 13px;
}

dialog {
  width: min(900px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(36, 35, 31, 0.26);
  padding: 0;
}

dialog::backdrop {
  background: rgba(36, 35, 31, 0.36);
}

#leadForm,
#adminForm {
  padding: 18px;
}

.admin-code-line {
  display: grid;
  gap: 6px;
  margin-top: 16px;
  color: var(--muted);
}

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

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

.dialog-actions {
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.empty {
  padding: 36px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1180px) {
  .summary {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
  }

  .top-tabs {
    order: 3;
    width: 100%;
  }

  .settings-grid,
  .insight-list,
  .sync-grid {
    grid-template-columns: 1fr;
  }

  .wide-tool-card {
    grid-column: auto;
  }

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

  .dashboard-kpis {
    grid-template-columns: repeat(5, minmax(96px, 1fr));
  }

  .crm-field-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 780px) {
  .appbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .operator {
    width: 100%;
  }

  .top-tabs {
    overflow-x: auto;
  }

  .hero-strip,
  .settings-hero {
    align-items: flex-start;
    flex-direction: column;
  }

  .operator input {
    flex: 1;
  }

  .layout {
    padding: 10px;
  }

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

  .dashboard-controls,
  .dashboard-kpis {
    grid-template-columns: 1fr;
  }

  .manager-bar,
  .quick-search {
    align-items: stretch;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .quick-search input {
    min-width: 0;
  }

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

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

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