:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef4f2;
  --ink: #1e2423;
  --muted: #68706d;
  --line: #dfe5e2;
  --teal: #0f766e;
  --green: #18824a;
  --blue: #2563eb;
  --amber: #b7791f;
  --red: #c24138;
  --violet: #7048a8;
  --shadow: 0 18px 45px rgba(21, 30, 28, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(246, 247, 244, 0.92)),
    repeating-linear-gradient(
      135deg,
      rgba(15, 118, 110, 0.05) 0,
      rgba(15, 118, 110, 0.05) 1px,
      transparent 1px,
      transparent 14px
    );
  color: var(--ink);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid #c8ddd8;
  border-radius: 8px;
  background: #e8f4f1;
  color: var(--teal);
  flex: 0 0 auto;
}

.brand-mark svg,
.button svg,
.metric-icon svg,
.file-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark svg {
  width: 34px;
  height: 34px;
  stroke-width: 3;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.55rem;
  line-height: 1.15;
}

h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.brand p,
.panel-header p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 3px;
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
  white-space: nowrap;
  transition:
    transform 0.16s ease,
    border-color 0.16s ease,
    background 0.16s ease;
}

.button:hover,
.file-button:hover {
  transform: translateY(-1px);
}

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

.button.secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.button.full {
  width: 100%;
}

.dashboard {
  display: grid;
  gap: 16px;
}

.filters,
.summary-grid,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.filters {
  display: grid;
  grid-template-columns: minmax(140px, 0.8fr) minmax(140px, 0.8fr) minmax(220px, 1.4fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #36413f;
  font-size: 0.82rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

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

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

.file-button {
  position: relative;
  overflow: hidden;
  min-width: 142px;
  border-color: var(--line);
  background: var(--surface-2);
  color: #24403d;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  background: var(--line);
}

.metric-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 6px 10px;
  min-height: 118px;
  padding: 18px;
  background: #fff;
}

.metric-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  grid-row: span 2;
}

.metric-icon.teal {
  background: #dff4ef;
  color: var(--teal);
}

.metric-icon.green {
  background: #e2f5e9;
  color: var(--green);
}

.metric-icon.blue {
  background: #e7efff;
  color: var(--blue);
}

.metric-icon.amber {
  background: #fff1d9;
  color: var(--amber);
}

.metric-icon.red {
  background: #ffe7e4;
  color: var(--red);
}

.metric-icon.violet {
  background: #eee7f8;
  color: var(--violet);
}

.metric-card span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.metric-card strong {
  font-size: 1.45rem;
  line-height: 1.15;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.85fr);
  gap: 16px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.chart-panel {
  min-height: 386px;
}

#trendCanvas {
  display: block;
  width: 100%;
  height: 300px;
  border: 1px solid #e8eeeb;
  border-radius: 8px;
  background: #fbfcfb;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #c8ddd8;
  border-radius: 999px;
  background: #e8f4f1;
  color: #0d5f58;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #a0a9a6;
  box-shadow: 0 0 0 4px rgba(160, 169, 166, 0.18);
  flex: 0 0 auto;
  margin-top: 4px;
}

.status-dot.active {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(24, 130, 74, 0.15);
}

.ranking-list,
.campaign-bars {
  display: grid;
  gap: 12px;
}

.ranking-item,
.campaign-item {
  display: grid;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid #edf1ef;
}

.ranking-item:last-child,
.campaign-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.item-title {
  min-width: 0;
  font-weight: 850;
}

.item-title small {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-rate {
  font-weight: 900;
  white-space: nowrap;
}

.progress {
  height: 10px;
  border-radius: 999px;
  background: #edf1ef;
  overflow: hidden;
}

.progress > i {
  display: block;
  height: 100%;
  min-width: 4px;
  max-width: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.campaign-item .progress > i {
  background: var(--blue);
}

.connector-panel {
  grid-row: span 2;
}

.connector-form {
  display: grid;
  gap: 12px;
}

.table-panel {
  padding-bottom: 0;
}

.table-wrap {
  overflow: auto;
  margin: 0 -18px;
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 13px 18px;
  text-align: left;
  border-bottom: 1px solid #edf1ef;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #f9fbfa;
  color: #4e5855;
  font-size: 0.78rem;
  text-transform: uppercase;
  z-index: 1;
}

td {
  font-size: 0.92rem;
}

.campaign-cell {
  max-width: 360px;
  white-space: normal;
}

.campaign-cell b,
.admin-name {
  display: block;
  font-weight: 850;
}

.campaign-cell small {
  color: var(--muted);
}

.rate-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 30px;
  border-radius: 999px;
  background: #eef4f2;
  color: #23413d;
  font-weight: 900;
}

.rate-badge.good {
  background: #e2f5e9;
  color: #137040;
}

.rate-badge.warn {
  background: #fff1d9;
  color: #89570d;
}

.rate-badge.low {
  background: #ffe7e4;
  color: #a3372f;
}

.empty-state {
  padding: 26px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

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

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

  .connector-panel {
    grid-row: auto;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1480px);
    padding-top: 14px;
  }

  .topbar,
  .filters {
    grid-template-columns: 1fr;
  }

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

  .top-actions {
    justify-content: stretch;
  }

  .top-actions .button {
    flex: 1 1 0;
  }

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

  .metric-card {
    min-height: 108px;
    padding: 14px;
  }

  .metric-card strong {
    font-size: 1.18rem;
  }
}

@media (max-width: 480px) {
  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  h1 {
    font-size: 1.25rem;
  }

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

  .panel {
    padding: 14px;
  }

  .table-wrap {
    margin: 0 -14px;
  }
}
