:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d9e2ec;
  --line-strong: #c6d3e1;
  --text: #172033;
  --muted: #64748b;
  --accent: #1764d8;
  --accent-hover: #0f55bd;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --ok: #0f7a3b;
  --ok-bg: #edfdf4;
  --radius: 8px;
  --control-h: 40px;
  --shadow: 0 10px 30px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  font-family: Arial, "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover { text-decoration: underline; }

.page {
  width: min(100% - 32px, 1360px);
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.topbar strong {
  display: block;
  font-size: 20px;
  line-height: 1.2;
}

.topbar span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar nav a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: #29415f;
  font-weight: 600;
}

.topbar nav a:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.panel {
  margin-bottom: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.panel h2 {
  margin: 0 0 16px;
  font-size: 18px;
  line-height: 1.25;
}

.panel p { margin: 0; }

.auth-card {
  max-width: 560px;
  margin: 44px auto;
}

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

.stat {
  min-height: 76px;
  padding: 14px;
  border: 1px solid #e4ebf3;
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.stat b {
  display: block;
  margin-bottom: 3px;
  font-size: 24px;
  line-height: 1;
}

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

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

label {
  color: #334155;
  font-weight: 600;
}

.form-row {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.form-row > .muted {
  align-self: center;
  font-size: 13px;
}

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

select {
  padding-right: 28px;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 100, 216, .14);
}

input::placeholder { color: #8a97a8; }

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-h);
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.button:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

button:active,
.button:active {
  transform: translateY(1px);
}

button.secondary,
.button.secondary {
  border-color: var(--line-strong);
  background: #fff;
  color: #334155;
}

button.secondary:hover,
.button.secondary:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}

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

.inline-form { margin-bottom: 16px; }

.compact-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.channel-form {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) minmax(180px, 1fr) minmax(150px, .85fr) minmax(120px, .65fr) minmax(130px, .65fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field label {
  font-size: 13px;
  color: #32445a;
}

.field small {
  min-height: 32px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.form-actions,
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.actions form { margin: 0; }

.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.table-actions form { margin: 0; }

.table-actions a,
.table-actions button {
  min-height: 36px;
}

.stacked-control {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stacked-control .muted {
  font-size: 12px;
}

.payment-image-preview {
  width: 160px;
  max-width: 100%;
  height: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
}

.inline-check input,
.check-list input {
  width: auto;
  min-height: auto;
}

.remember-row {
  align-items: center;
}

.remember-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--control-h);
  width: max-content;
  color: #334155;
  font-weight: 600;
}

.remember-control input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 0;
}

.check-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.check-list label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

hr {
  border: 0;
  border-top: 1px solid #e5ebf2;
  margin: 18px 0;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid #e5ebf2;
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
}

.data-table {
  min-width: 760px;
}

.tenant-table {
  min-width: 1940px;
}

.channel-table {
  min-width: 900px;
}

.user-table {
  min-width: 1120px;
}

.order-table,
.deletion-table {
  min-width: 900px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid #e5ebf2;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #506174;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

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

tbody tr:hover td {
  background: #fbfdff;
}

.cell-id { min-width: 116px; }
.cell-name { min-width: 130px; }
.cell-status { width: 144px; min-width: 144px; max-width: 144px; }
.cell-count { width: 62px; min-width: 56px; text-align: center; }
.cell-webhook { min-width: 310px; max-width: 360px; }
.cell-actions { min-width: 330px; }
.cell-expiry { min-width: 360px; }
.cell-payment-image { min-width: 260px; }
.cell-token { min-width: 310px; }

.cell-input,
.cell-select {
  min-width: 96px;
}

.status-select {
  width: 132px !important;
  min-width: 132px !important;
  max-width: none;
}

.image-upload-form {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.image-upload-form input[type="file"] {
  min-height: 36px;
  padding: 5px 8px;
  font-size: 12px;
}

.image-upload-form button {
  min-height: 36px;
}

.token-edit-form {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.token-edit-form input {
  min-height: 36px;
}

.token-edit-form button {
  min-height: 36px;
}

.tenant-table .cell-status,
.tenant-table th.cell-status,
.channel-table .cell-status,
.channel-table th.cell-status {
  width: 144px;
  min-width: 144px;
  max-width: 144px;
}

.expiry-cell {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.expiry-form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  flex-wrap: nowrap;
}

.expiry-form input[type="datetime-local"] {
  width: 190px;
  min-width: 190px;
}

.expiry-form button {
  min-width: 118px;
}

.code {
  display: inline-block;
  max-width: 100%;
  padding: 3px 6px;
  border-radius: 6px;
  background: #f1f5f9;
  color: #0f172a;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.35;
  word-break: break-all;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.badge.active {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge.completed,
.badge.done {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge.pending {
  background: #eef6ff;
  color: #155bb5;
}

.badge.paid {
  margin-left: 6px;
  background: #eef6ff;
  color: #155bb5;
}

.badge.cancelled,
.badge.failed {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge.paused {
  background: #fff7ed;
  color: #9a3412;
}

.flash {
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid;
  border-radius: var(--radius);
  font-weight: 600;
}

.flash.info {
  background: #eef6ff;
  border-color: #bfdcff;
}

.flash.ok {
  background: var(--ok-bg);
  border-color: #b8e7c8;
  color: #14532d;
}

.flash.error {
  background: var(--danger-bg);
  border-color: #ffc9c4;
  color: var(--danger);
}

@media (max-width: 920px) {
  .page {
    width: min(100% - 20px, 1360px);
    padding-top: 12px;
  }

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

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

  .form-row,
  .compact-grid,
  .channel-form {
    grid-template-columns: 1fr;
  }

  .field small {
    min-height: 0;
  }
}

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

  .panel,
  .topbar {
    padding: 14px;
  }

  button,
  .button {
    width: 100%;
  }

  .actions,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

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