:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #65736b;
  --line: #d9e1dc;
  --panel: #ffffff;
  --soft: #f4f7f5;
  --accent: #0f7b66;
  --accent-dark: #095748;
  --warn: #a56a00;
  --bad: #b33a3a;
  --good-bg: #e6f4ef;
  --mid-bg: #fff5df;
  --low-bg: #f7e7e7;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #eef3f0;
  color: var(--ink);
}

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

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

.sidebar {
  background: #fbfcfb;
  border-right: 1px solid var(--line);
  padding: 24px;
  overflow-y: auto;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 24px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #0f7b66, #0b5f50);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  box-shadow: 0 8px 20px rgba(15, 123, 102, 0.18);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
}

.brand p,
.topbar p {
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.45;
}

.control-panel {
  display: grid;
  gap: 16px;
}

label span,
legend {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: #35423a;
  margin-bottom: 7px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 123, 102, 0.13);
}

.source-details,
.status-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.source-details summary,
.status-details summary {
  cursor: pointer;
  padding: 12px;
  font-size: 13px;
  font-weight: 800;
  color: #35423a;
  list-style: none;
}

.source-details summary::-webkit-details-marker,
.status-details summary::-webkit-details-marker {
  display: none;
}

.source-details summary::after,
.status-details summary::after {
  content: "+";
  float: right;
  color: var(--muted);
  font-weight: 800;
}

.source-details[open] summary,
.status-details[open] summary {
  border-bottom: 1px solid var(--line);
}

.source-details[open] summary::after,
.status-details[open] summary::after {
  content: "-";
}

.source-options {
  padding: 4px 12px 10px;
}

.city-options {
  max-height: 185px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 4px 10px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 9px 0;
  color: #324037;
}

.city-check {
  margin: 8px 0;
}

.check-row input {
  width: 16px;
  height: 16px;
}

.primary-button,
.actions button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

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

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

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

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

.plan-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  margin-top: 8px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.plan-badge.premium {
  border-color: rgba(15, 123, 102, 0.35);
  background: var(--good-bg);
  color: var(--accent-dark);
}

.plan-badge.locked {
  border-color: #ead6a7;
  background: var(--mid-bg);
  color: var(--warn);
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.actions button {
  background: #fff;
  border: 1px solid var(--line);
  color: #243229;
}

.source-strip,
.metrics,
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.status-details {
  margin-bottom: 16px;
}

.status-details .source-strip {
  padding: 10px 12px 12px;
  margin-bottom: 0;
}

.source-card,
.metrics div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.source-card {
  min-width: 210px;
}

.source-card strong {
  display: block;
  font-size: 13px;
}

.source-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.source-card.ready {
  border-color: #a7d7c7;
  background: #f2fbf7;
}

.source-card.waiting {
  border-color: #e2c78e;
  background: #fff9ec;
}

.metrics div {
  flex: 1;
  min-width: 160px;
}

.metrics strong {
  display: block;
  font-size: 26px;
  line-height: 1;
}

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

.filter-pill {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 13px;
  color: #34433a;
  cursor: pointer;
}

.filter-pill.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.page-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.page-tab {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #34433a;
  padding: 9px 13px;
  cursor: pointer;
}

.page-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 800;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.panel-head,
.panel-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.panel h3 {
  margin: 0;
  font-size: 18px;
}

.panel p {
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.45;
}

.inline-form,
.settings-grid {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.inline-form {
  grid-template-columns: 220px minmax(260px, 1fr) 150px;
  align-items: end;
}

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

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

.row-actions {
  display: grid;
  gap: 8px;
}

.small-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #243229;
  min-height: 34px;
  padding: 0 10px;
  cursor: pointer;
  white-space: nowrap;
}

.small-button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 800;
}

.small-button.danger {
  border-color: #e4b4b4;
  color: var(--bad);
}

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  user-select: none;
}

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

.col-customer {
  width: 430px;
}

.col-source {
  width: 170px;
}

.col-contact {
  width: 260px;
}

.col-match {
  width: 230px;
}

.col-action {
  width: 190px;
}

.col-message {
  width: 300px;
}

.col-operate {
  width: 120px;
}

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

th {
  font-size: 12px;
  color: var(--muted);
  background: #f8faf8;
  position: sticky;
  top: 0;
  z-index: 1;
  resize: horizontal;
  overflow: auto;
  white-space: nowrap;
}

.company {
  font-weight: 800;
  line-height: 1.3;
}

.subtext {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  line-height: 1.45;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
  margin-right: 4px;
  white-space: nowrap;
}

.grade-a {
  background: var(--good-bg);
  color: #075f4a;
}

.grade-b {
  background: var(--mid-bg);
  color: var(--warn);
}

.grade-c {
  background: var(--low-bg);
  color: var(--bad);
}

.message {
  white-space: pre-wrap;
  line-height: 1.45;
  max-height: 120px;
  overflow: auto;
  word-break: normal;
}

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

.admin-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

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

.brand.compact {
  margin-bottom: 0;
}

.admin-link {
  color: var(--accent-dark);
  font-weight: 800;
  text-decoration: none;
}

.admin-status {
  margin-top: 12px;
  color: var(--muted);
}

.admin-token-grid {
  grid-template-columns: minmax(240px, 420px) 130px;
}

.admin-license-grid {
  grid-template-columns: minmax(220px, 1.5fr) 160px 140px 140px 120px;
}

.admin-metrics {
  margin-top: 16px;
}

.admin-table {
  min-width: 980px;
}

.code-box {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid rgba(15, 123, 102, 0.35);
  border-radius: 8px;
  background: var(--good-bg);
  color: var(--accent-dark);
  font-weight: 900;
  user-select: text;
}

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

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

  .topbar {
    display: block;
  }

  .actions {
    margin-top: 14px;
  }

  .inline-form,
  .settings-grid,
  .admin-token-grid,
  .admin-license-grid {
    grid-template-columns: 1fr;
  }

  .panel-head {
    display: block;
  }
}
