:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  background: #f3f5f8;
  color: #1f2937;
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  margin: 0;
  overflow-x: hidden;
}

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

button,
a {
  border: 0;
  border-radius: 6px;
  background: #1677ff;
  color: #fff;
  cursor: pointer;
  padding: 9px 14px;
  text-decoration: none;
}

button.secondary {
  background: #6b7280;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.danger {
  background: #dc2626;
}

button.warning {
  background: #f59e0b;
}

button.icon {
  background: transparent;
  color: #4b5563;
  padding: 4px 8px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #111827;
  padding: 9px 10px;
}

label {
  display: grid;
  gap: 6px;
  color: #374151;
  font-size: 14px;
}

.shell {
  width: min(1320px, calc(100vw - 32px));
  margin: 24px auto;
}

.app {
  min-width: 0;
}

.hidden {
  display: none !important;
}

.login {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  margin: 90px auto;
  padding: 28px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 36px rgba(15, 23, 42, 0.08);
}

.loading {
  display: grid;
  place-items: center;
  width: min(420px, 100%);
  min-height: 160px;
  margin: 90px auto;
  padding: 28px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  color: #64748b;
  box-shadow: 0 12px 36px rgba(15, 23, 42, 0.08);
}

.loading p {
  margin: 0;
}

.login h1,
.topbar h1 {
  margin: 0;
  font-size: 22px;
}

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

.topbar p {
  margin: 8px 0 0;
  color: #6b7280;
}

.stats-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.stats-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  white-space: nowrap;
}

.stats-item b {
  font-size: 16px;
}

.stats-item.blue {
  background: #dbeafe;
  color: #1e40af;
}

.stats-item.red {
  background: #fee2e2;
  color: #991b1b;
}

.stats-item.orange {
  background: #ffedd5;
  color: #9a3412;
}

.stats-item.gray {
  background: #e5e7eb;
  color: #374151;
}

.stats-item.green {
  background: #dcfce7;
  color: #166534;
}

.stats-item.purple {
  background: #ede9fe;
  color: #5b21b6;
}

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

.toolbar {
  margin-bottom: 12px;
}

.toolbar input {
  max-width: 360px;
}

.settings-strip {
  display: flex;
  align-items: end;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
}

.settings-strip label {
  width: 220px;
}

.settings-strip .sub-url-setting {
  flex: 1;
  min-width: 360px;
}

.settings-strip .message {
  min-height: auto;
  margin: 0;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0;
}

.tab {
  background: #e5e7eb;
  color: #374151;
}

.tab.active {
  background: #1677ff;
  color: #fff;
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
}

.segmented {
  display: inline-flex;
  gap: 0;
  overflow: hidden;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
}

.segmented button {
  border-radius: 0;
  background: #fff;
  color: #374151;
}

.segmented button + button {
  border-left: 1px solid #d1d5db;
}

.segmented button.active {
  background: #1677ff;
  color: #fff;
}

.section {
  display: none;
}

.section.active {
  display: block;
}

.panel {
  overflow: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 22px 0 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 20px;
}

.section-head p {
  margin: 6px 0 0;
  color: #6b7280;
}

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

.user-panel {
  overflow-x: auto;
}

.user-table {
  min-width: 1240px;
  table-layout: fixed;
}

.user-table th:nth-child(1),
.user-table td:nth-child(1) {
  width: 42px;
}

.user-table th:nth-child(2),
.user-table td:nth-child(2) {
  width: 92px;
}

.user-table th:nth-child(3),
.user-table td:nth-child(3) {
  width: 100px;
}

.user-table th:nth-child(4),
.user-table td:nth-child(4) {
  width: 70px;
}

.user-table th:nth-child(5),
.user-table td:nth-child(5) {
  width: 66px;
}

.user-table th:nth-child(6),
.user-table td:nth-child(6) {
  width: 184px;
}

.user-table th:nth-child(7),
.user-table td:nth-child(7) {
  width: 200px;
}

.user-table th:nth-child(8),
.user-table td:nth-child(8) {
  width: 84px;
}

.user-table th:nth-child(9),
.user-table td:nth-child(9) {
  width: 96px;
}

.user-table th:nth-child(10),
.user-table td:nth-child(10) {
  width: 98px;
}

.user-table th:nth-child(11),
.user-table td:nth-child(11) {
  width: 176px;
}

.fixed-text {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.account-text,
.email-text,
.ip-text {
  width: 100%;
}

.location-text {
  width: 100%;
}

.copy-link {
  display: inline-block;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #0f172a;
  padding: 0;
  text-align: left;
}

.copy-link:hover {
  color: #1677ff;
  text-decoration: underline;
}

.data-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 28px;
  border-radius: 6px;
  padding: 4px 7px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.expire-pill {
  width: 168px;
  min-width: 168px;
  background: #e0f2fe;
  color: #075985;
}

.expire-pill.expired {
  background: #fee2e2;
  color: #991b1b;
}

.traffic-pill {
  width: max-content;
  min-width: 100%;
  background: #dcfce7;
  color: #166534;
}

.balance-pill {
  background: #ffedd5;
  color: #9a3412;
}

.announcement-table {
  min-width: 860px;
}

.plan-table {
  min-width: 960px;
}

.redeem-table {
  min-width: 1100px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 2px 0;
  color: #4b5563;
}

.pager div {
  display: flex;
  gap: 8px;
}

th,
td {
  border-bottom: 1px solid #eef2f7;
  padding: 11px 10px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.user-table th,
.user-table td {
  padding-inline: 8px;
}

th {
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
}

td .row-actions {
  display: flex;
  gap: 5px;
}

.row-actions button {
  padding-inline: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 1000;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 9px 16px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
}

.announcement-content {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code {
  color: #111827;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
}

.status.enabled {
  background: #dcfce7;
  color: #166534;
}

.status.disabled {
  background: #fee2e2;
  color: #991b1b;
}

.message {
  min-height: 20px;
  margin: 0;
  color: #dc2626;
}

dialog {
  width: min(760px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

dialog form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

dialog header,
dialog footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

dialog h2 {
  margin: 0;
  font-size: 20px;
}

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

@media (max-width: 760px) {
  button,
  a {
    min-height: 42px;
  }

  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 16px;
  }

  .shell {
    width: calc(100% - 24px);
    margin: 12px auto 24px;
  }

  .login,
  .loading {
    width: 100%;
    margin: max(24px, 8vh) auto;
    padding: 20px;
  }

  .topbar,
  .section-head,
  .code-toolbar,
  dialog header,
  dialog footer {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    gap: 14px;
    margin-bottom: 14px;
  }

  .topbar .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .topbar .actions > * {
    width: 100%;
    text-align: center;
  }

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

  .stats-item {
    min-width: 0;
    white-space: normal;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin: 12px 0 18px;
  }

  .tab {
    min-width: 0;
    padding-inline: 6px;
    white-space: nowrap;
  }

  .section-head {
    margin-top: 18px;
  }

  .section-head > button {
    width: 100%;
  }

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

  .toolbar input {
    grid-column: 1 / -1;
    max-width: none;
  }

  .settings-strip {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .settings-strip label,
  .settings-strip .sub-url-setting {
    width: 100%;
    min-width: 0;
  }

  .settings-strip > button {
    width: 100%;
  }

  .code-toolbar {
    align-items: stretch;
  }

  .segmented {
    display: flex;
    width: 100%;
  }

  .segmented button {
    flex: 1;
    min-width: 0;
    padding-inline: 6px;
  }

  .panel,
  .user-panel {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  table,
  .user-table,
  .plan-table,
  .announcement-table,
  .redeem-table {
    display: block;
    width: 100%;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tbody tr {
    display: grid;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
  }

  th,
  td,
  .user-table th,
  .user-table td {
    width: auto !important;
    min-width: 0 !important;
  }

  td,
  .user-table td {
    display: grid;
    grid-template-columns: minmax(84px, 34%) minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    text-align: right;
    white-space: normal;
  }

  td::before {
    content: attr(data-label);
    color: #64748b;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
  }

  td > * {
    min-width: 0;
    max-width: 100%;
    justify-self: end;
  }

  .fixed-text,
  .account-text,
  .email-text,
  .ip-text,
  .location-text,
  .announcement-content {
    width: auto;
    max-width: 100%;
  }

  .copy-link {
    text-align: right;
  }

  .data-pill,
  .expire-pill,
  .traffic-pill,
  .balance-pill {
    width: max-content;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .announcement-content {
    white-space: normal;
  }

  .code {
    overflow-wrap: anywhere;
  }

  td .row-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

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

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

  dialog {
    width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
  }

  dialog form {
    padding: 18px;
  }

  dialog footer button:not(.icon) {
    width: 100%;
  }

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