:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #171717;
  --muted: #6a6f73;
  --line: #d9d7cf;
  --accent: #0f766e;
  --accent-dark: #0b5b55;
  --danger: #b42318;
  --warning: #a15c07;
  --success: #14753f;
  --shadow: 0 18px 44px rgba(39, 42, 45, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, transform 140ms ease;
}

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

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

.app {
  min-height: 100svh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 32px 18px;
  border-bottom: 1px solid var(--line);
}

.top-status {
  display: flex;
  align-items: center;
  gap: 14px;
}

.top-link {
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.top-link:hover {
  text-decoration: underline;
}

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

.brand-mark {
  width: 46px;
  height: 46px;
  border: 1px solid #1f2a2c;
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: end;
  gap: 4px;
  padding: 9px;
  background: #fefefe;
}

.brand-mark span {
  display: block;
  background: var(--accent);
  border-radius: 3px;
}

.brand-mark span:nth-child(1) { height: 36%; }
.brand-mark span:nth-child(2) { height: 70%; background: #22272a; }
.brand-mark span:nth-child(3) { height: 52%; background: #d08a1d; }

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

h3 {
  font-size: 14px;
  margin-bottom: 12px;
}

.brand p,
.muted,
.policy,
.note {
  color: var(--muted);
}

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

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.status-dot::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--warning);
}

.status-dot.ok::before {
  background: var(--success);
}

.status-dot.bad::before {
  background: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(360px, 1fr) minmax(280px, 360px);
  gap: 18px;
  padding: 24px 32px 32px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel,
.order-panel,
.side-panel {
  padding: 22px;
}

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

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

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field span {
  font-size: 13px;
  font-weight: 700;
}

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

input:focus,
select:focus {
  outline: 2px solid rgba(15, 118, 110, 0.22);
  border-color: var(--accent);
}

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

.primary {
  width: 100%;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

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

.secondary {
  background: #202426;
  color: white;
}

.ghost {
  min-height: 34px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.danger {
  background: #fff3f1;
  color: var(--danger);
  border: 1px solid #f2b8b0;
}

.policy,
.note {
  margin: 14px 0 18px;
  font-size: 13px;
  line-height: 1.6;
}

.compliance-check {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border: 1px solid #d9c9a6;
  background: #fffaf0;
  color: #5f440f;
  border-radius: 8px;
  padding: 12px;
  margin: 12px 0 16px;
  font-size: 13px;
  line-height: 1.5;
}

.compliance-check input {
  width: 18px;
  min-height: 18px;
  margin: 2px 0 0;
}

.empty {
  min-height: 420px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 22px;
  color: var(--muted);
  text-align: center;
}

.empty-visual {
  width: min(320px, 100%);
  height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: end;
  gap: 10px;
  padding: 20px;
  background:
    linear-gradient(#ecebe5 1px, transparent 1px),
    linear-gradient(90deg, #ecebe5 1px, transparent 1px);
  background-size: 28px 28px;
}

.empty-visual i {
  display: block;
  border-radius: 4px 4px 0 0;
  background: #22272a;
}

.empty-visual i:nth-child(1) { height: 32%; }
.empty-visual i:nth-child(2) { height: 76%; background: var(--accent); }
.empty-visual i:nth-child(3) { height: 54%; background: #d08a1d; }
.empty-visual i:nth-child(4) { height: 43%; background: #8a4f9e; }

.hidden {
  display: none !important;
}

.order-detail {
  display: grid;
  gap: 18px;
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.badge {
  display: inline-flex;
  min-width: 80px;
  justify-content: center;
  border-radius: 999px;
  padding: 7px 12px;
  background: #fff8e8;
  color: var(--warning);
  font-size: 13px;
  font-weight: 800;
}

.badge.success {
  background: #eaf7ef;
  color: var(--success);
}

.badge.timeout,
.badge.cancelled,
.badge.error {
  background: #fff3f1;
  color: var(--danger);
}

.number-box,
.code-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.number-box span,
.code-box span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.number-box div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.number-box strong,
.code-box strong {
  font-size: 28px;
  line-height: 1.2;
  word-break: break-all;
}

.code-box strong {
  color: var(--accent-dark);
}

.sms-history {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  background: #fbfaf7;
}

.sms-history > span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.sms-history ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sms-history li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.sms-history time {
  color: var(--muted);
  font-size: 12px;
}

.sms-history strong {
  color: var(--accent-dark);
  word-break: break-all;
}

.order-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.order-meta div {
  padding: 14px;
  border-right: 1px solid var(--line);
}

.order-meta div:last-child {
  border-right: 0;
}

dt {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

dd {
  margin: 0;
  font-weight: 700;
  word-break: break-word;
}

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

.event-list,
.coverage-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.event-list {
  display: grid;
  gap: 12px;
  min-height: 220px;
  max-height: 360px;
  overflow: auto;
}

.event-list li {
  border-left: 3px solid var(--line);
  padding-left: 12px;
}

.event-list time {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.event-list span {
  font-size: 13px;
  line-height: 1.45;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 22px 0;
}

.coverage-list {
  display: grid;
  gap: 10px;
}

.coverage-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #ecebe5;
  padding-bottom: 10px;
  font-size: 13px;
}

.admin-workspace {
  padding: 24px 32px 32px;
}

.admin-login {
  max-width: 720px;
  padding: 22px;
}

.admin-dashboard {
  display: grid;
  gap: 18px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1.35fr) minmax(300px, 0.9fr);
  gap: 18px;
}

.admin-panel {
  padding: 22px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.metric-grid div {
  padding: 16px;
  border-right: 1px solid var(--line);
  background: #fff;
}

.metric-grid div:last-child {
  border-right: 0;
}

.metric-grid span,
.balance-list span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.metric-grid strong {
  font-size: 30px;
  line-height: 1;
}

.balance-list {
  display: grid;
  gap: 12px;
}

.balance-list > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #ecebe5;
}

.balance-row > div {
  display: grid;
  gap: 4px;
  padding: 0;
  border: 0;
}

.balance-row > strong {
  max-width: 150px;
  text-align: right;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.45;
}

.balance-status {
  font-style: normal;
  font-size: 12px;
}

.ok-text {
  color: var(--success);
}

.warn-text {
  color: var(--warning);
}

.balance-policy {
  margin-bottom: 0;
}

.balance-list > div:last-child {
  border-bottom: 0;
}

.danger-text {
  color: var(--danger);
}

.admin-form-row {
  display: grid;
  grid-template-columns: minmax(120px, 160px) minmax(180px, 1fr) minmax(200px, 260px) auto;
  gap: 12px;
  align-items: end;
}

.batch-card-row {
  grid-template-columns: minmax(200px, 1fr) minmax(90px, 110px) minmax(90px, 110px) minmax(160px, 1fr) minmax(190px, 240px) auto;
}

.admin-form-row .field {
  margin-bottom: 0;
}

.admin-create-btn {
  width: auto;
  min-width: 128px;
}

.created-card {
  margin-top: 16px;
  border: 1px solid #b7d8d2;
  background: #eef9f6;
  color: var(--accent-dark);
  border-radius: 8px;
  padding: 14px;
  font-weight: 900;
  word-break: break-all;
}

.created-card-list {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  line-height: 1.55;
  font-family: Consolas, "Courier New", monospace;
}

.card-usage-query {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.card-usage-query .field {
  margin-bottom: 0;
}

.card-usage-result {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.usage-summary-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.usage-summary-grid div {
  padding: 14px;
  border-right: 1px solid var(--line);
}

.usage-summary-grid div:last-child {
  border-right: 0;
}

.usage-summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 7px;
}

.usage-summary-grid strong {
  font-size: 16px;
  line-height: 1.35;
  word-break: break-word;
}

.usage-table-wrap {
  box-shadow: none;
}

.route-price-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) minmax(160px, 220px) auto;
  gap: 12px;
  align-items: end;
}

.route-price-grid .field,
.bulk-toolbar .field {
  margin-bottom: 0;
}

.price-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.price-matrix-wrap {
  margin-top: 16px;
}

.highlight-row td {
  background: #eef9f6;
  font-weight: 800;
}

.price-list > div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid #ecebe5;
}

.price-list .price-title {
  color: var(--muted);
  font-weight: 800;
  border-bottom: 1px solid var(--line);
}

.price-list span {
  color: var(--muted);
  text-align: right;
}

.bulk-toolbar {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(150px, 180px) auto auto auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid #ecebe5;
  text-align: left;
  font-size: 13px;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  background: #fbfaf7;
}

tr:last-child td {
  border-bottom: 0;
}

.tiny {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #202426;
  color: white;
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  max-width: min(520px, calc(100vw - 32px));
  z-index: 10;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 1fr 1fr;
  }
  .side-panel {
    grid-column: 1 / -1;
  }
  .admin-grid,
  .admin-form-row,
  .route-price-grid,
  .bulk-toolbar,
  .card-usage-query {
    grid-template-columns: 1fr;
  }
  .admin-create-btn {
    width: 100%;
  }
  .usage-summary-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .topbar,
  .workspace,
  .admin-workspace {
    padding-left: 16px;
    padding-right: 16px;
  }
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .workspace {
    grid-template-columns: 1fr;
  }
  .inline-input {
    grid-template-columns: 1fr;
  }
  .order-meta {
    grid-template-columns: 1fr;
  }
  .order-meta div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .order-meta div:last-child {
    border-bottom: 0;
  }
  .number-box div,
  .status-line {
    align-items: flex-start;
    flex-direction: column;
  }
  .top-status {
    width: 100%;
    justify-content: space-between;
  }
  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }
  .metric-grid div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
