* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  background: #f4f1ea;
  color: #1b1b1b;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
h1 {
  margin: 0 0 20px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
}
input, button {
  width: 100%;
  font: inherit;
  border-radius: 6px;
}
input {
  border: 1px solid #c9c2b4;
  padding: 12px 14px;
  margin-bottom: 10px;
  letter-spacing: 0.4px;
  text-align: center;
}
input:focus {
  outline: 2px solid #1b1b1b;
  border-color: #1b1b1b;
}
button {
  border: 1px solid #1b1b1b;
  background: #fff;
  padding: 11px 14px;
  cursor: pointer;
}
button.primary {
  background: #1b1b1b;
  color: #fff;
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
body.store {
  padding: 28px 16px;
  background:
    radial-gradient(circle at 12% 18%, rgba(47, 138, 92, .16), transparent 28%),
    radial-gradient(circle at 88% 8%, rgba(196, 154, 86, .18), transparent 26%),
    linear-gradient(180deg, #f7f3ea 0%, #efe7d8 100%);
}
.box {
  width: min(560px, 100%);
  background: rgba(255, 255, 255, .94);
  border: 1px solid rgba(196, 184, 162, .55);
  border-radius: 22px;
  padding: 36px 32px 28px;
  text-align: center;
  box-shadow:
    0 24px 50px rgba(68, 52, 24, .08),
    0 2px 0 rgba(255, 255, 255, .7) inset;
  backdrop-filter: blur(10px);
}
.store-head {
  margin-bottom: 22px;
}
.store-kicker {
  margin: 0 0 8px;
  color: #2f8a5c;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
}
.box h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 750;
  letter-spacing: 0.02em;
  text-align: center;
}
.store-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  align-items: stretch;
  gap: 10px;
}
.box input,
.box button {
  width: 100%;
  font: inherit;
  border-radius: 12px;
}
.box input {
  border: 1px solid #d7ccb8;
  background: #fffdf8;
  padding: 14px 16px;
  margin-bottom: 0;
  letter-spacing: 0.4px;
  text-align: center;
}
.box input:focus {
  outline: none;
  border-color: #2f8a5c;
  box-shadow: 0 0 0 4px rgba(47, 138, 92, .12);
}
.box button {
  border: 1px solid #1d3b2c;
  background: #fff;
  color: #1d3b2c;
  padding: 13px 14px;
  cursor: pointer;
  font-weight: 650;
}
.box button.primary {
  background: #163528;
  border-color: #163528;
  color: #fff;
}
.box button.primary:hover:not(:disabled) {
  background: #1d4634;
}
.box button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}
.panel {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}
.result-card {
  padding: 16px 16px 14px;
  border: 1px solid #eadfcd;
  border-radius: 16px;
  background: #fffaf2;
  text-align: center;
}
.result-card-code {
  background: #f3faf5;
  border-color: #d7eadc;
}
.label {
  margin: 0 0 8px;
  color: #857b6b;
  font-size: 12px;
  letter-spacing: 0.08em;
}
.phone, .code {
  margin: 0;
  font-size: 30px;
  font-weight: 750;
  letter-spacing: 0.6px;
  word-break: break-all;
  min-height: 40px;
  text-align: center;
}
.phone-tip {
  display: grid;
  grid-template-columns: minmax(120px, .75fr) minmax(0, 1.4fr);
  align-items: center;
  gap: 12px;
  margin: 10px 0 0;
  padding: 10px;
  border-radius: 10px;
  background: rgba(47, 138, 92, .08);
  color: #3d6f54;
  font-size: 13px;
  line-height: 1.55;
  text-align: left;
}
.phone-tip p {
  margin: 0;
}
.phone-tip-image {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 0;
  border-radius: 12px;
  border: 1px solid #d7eadc;
  background: #fff;
}
.phone {
  cursor: text;
  user-select: text;
}
.phone.placeholder {
  color: #b2aa9d;
}
.code { color: #0a7a3e; }
.result-card-timer {
  background: #fff7ec;
  border-color: #ead3b0;
}
.switch-countdown {
  margin: 0;
  font-size: 36px;
  font-weight: 750;
  letter-spacing: 0.08em;
  color: #b25a12;
  min-height: 44px;
}
.switch-countdown.urgent {
  color: #b42318;
}
.switch-tip {
  margin: 8px 0 0;
  color: #8a6a45;
  font-size: 13px;
  line-height: 1.5;
}
.store-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.refresh-state {
  margin: 2px 0 0;
  color: #3d6f54;
  font-size: 12px;
  text-align: center;
}
.hint {
  margin: 0;
  color: #8a8479;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

body.admin {
  align-items: flex-start;
  padding: 32px 16px;
}
.admin-box {
  width: min(860px, 100%);
  text-align: left;
}
.admin-box h1 { text-align: left; }
.toolbar {
  display: grid;
  grid-template-columns: 1fr 120px 120px;
  gap: 10px;
  margin-bottom: 16px;
}
.toolbar input, .toolbar button { margin: 0; text-align: center; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid #ece7dd; }
th { color: #6f6a62; font-weight: 600; }
.tag { font-size: 12px; }
.tag.ok { color: #0a7a3e; }
.tag.busy { color: #b45309; }
.tag.used { color: #9a3b3b; }
.small { width: auto; padding: 6px 10px; }
.msg { color: #6f6a62; font-size: 13px; margin: 0 0 12px; }

/* Commercial administration */
body.admin-v3 {
  display: block;
  min-height: 100vh;
  padding: 0;
  background: #f5f6f8;
  color: #18202b;
}
.hidden { display: none !important; }
.admin-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 10%, rgba(226, 150, 42, .12), transparent 34%),
    #f5f6f8;
}
.login-card {
  width: min(390px, 100%);
  padding: 36px;
  border: 1px solid #e0e4e9;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 20px 50px rgba(24, 32, 43, .09);
}
.login-card h1 {
  margin: 18px 0 6px;
  text-align: left;
  font-size: 24px;
}
.login-card p {
  margin: 0 0 26px;
  color: #798291;
}
.login-card label {
  display: block;
  margin-bottom: 7px;
  color: #4c5665;
  font-size: 13px;
  font-weight: 600;
}
.login-card input {
  margin: 0 0 12px;
  text-align: left;
}
.admin-logo {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  background: #1e2735;
  color: #fff;
  font-weight: 800;
}
.form-message {
  min-height: 20px;
  display: block;
  margin-top: 12px;
  color: #b33b3b;
  font-size: 13px;
}
.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 226px minmax(0, 1fr);
}
.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  background: #17202d;
  color: #fff;
}
.sidebar-backdrop,
.sidebar-toggle {
  display: none;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 8px 25px;
}
.sidebar-brand strong,
.sidebar-brand small {
  display: block;
}
.sidebar-brand strong { font-size: 15px; }
.sidebar-brand small {
  margin-top: 3px;
  color: #8e9aab;
  font-size: 11px;
}
.admin-sidebar nav {
  display: grid;
  gap: 5px;
}
.nav-item,
.nav-logout {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #aab4c3;
  text-align: left;
  font-size: 14px;
}
.nav-item:hover,
.nav-item.active {
  background: #263245;
  color: #fff;
}
.nav-logout {
  margin-top: auto;
  color: #8e9aab;
}
.nav-logout:hover { color: #fff; }
.admin-content {
  min-width: 0;
  padding: 28px 32px 44px;
}
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.admin-heading {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}
.admin-header h1 {
  margin: 0 0 4px;
  text-align: left;
  font-size: 25px;
}
.admin-header p {
  margin: 0;
  color: #7d8795;
  font-size: 13px;
}
button.secondary {
  border-color: #d8dde5;
  background: #fff;
  color: #364152;
}
button.compact {
  width: auto;
  padding: 8px 13px;
  font-size: 13px;
}
.admin-notice {
  margin-bottom: 18px;
  padding: 11px 14px;
  border: 1px solid #f0d6a7;
  border-radius: 8px;
  background: #fff8e9;
  color: #805b19;
  font-size: 13px;
}
.admin-tab { display: none; }
.admin-tab.active { display: block; }
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.metric-card,
.admin-panel {
  border: 1px solid #e0e4e9;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(24, 32, 43, .035);
}
.metric-card {
  min-height: 130px;
  padding: 19px;
}
.metric-card span {
  color: #788392;
  font-size: 13px;
}
.metric-card strong {
  display: block;
  margin: 16px 0 6px;
  font-size: 25px;
}
.metric-card small { color: #a0a7b1; }
.metric-card.profit strong { color: #128357; }
.metric-card.risk strong { color: #bd6a1d; }
.admin-grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.admin-panel {
  padding: 20px;
  margin-bottom: 16px;
}
.panel-title {
  display: flex;
  align-items: center;
  margin-bottom: 17px;
}
.panel-title.split { justify-content: space-between; gap: 16px; }
.panel-title h2 {
  margin: 0 0 4px;
  font-size: 16px;
}
.panel-title p {
  margin: 0;
  color: #8a93a0;
  font-size: 12px;
}
.stat-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 22px;
}
.stat-list div,
.order-summary div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #edf0f3;
  padding: 9px 0;
}
.stat-list span,
.order-summary span {
  color: #707b89;
  font-size: 13px;
}
.upstream-status {
  min-height: 90px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #a9b0ba;
  box-shadow: 0 0 0 6px rgba(169, 176, 186, .15);
}
.status-dot.online {
  background: #1aae72;
  box-shadow: 0 0 0 6px rgba(26, 174, 114, .13);
}
.status-dot.offline {
  background: #d34d4d;
  box-shadow: 0 0 0 6px rgba(211, 77, 77, .13);
}
.upstream-status p {
  margin: 6px 0 0;
  color: #7c8693;
  font-size: 13px;
}
.order-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 24px;
}
.generate-form {
  display: grid;
  grid-template-columns: 180px 130px;
  align-items: end;
  gap: 12px;
}
.generate-form label,
.form-grid label {
  color: #566171;
  font-size: 12px;
  font-weight: 600;
}
.generate-form input,
.form-grid input,
.form-grid select {
  margin: 7px 0 0;
  text-align: left;
}
.form-grid select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #c9cfd8;
  border-radius: 6px;
  background: #fff;
}
.form-grid .inline-help {
  display: block;
  margin-top: 6px;
  color: #88929f;
  font-weight: 400;
  line-height: 1.45;
}
.form-grid > button {
  align-self: center;
}
.live-price-panel {
  margin-top: 15px;
  padding: 14px;
  border: 1px solid #d8e6dd;
  border-radius: 9px;
  background: #f7fbf8;
}
.live-price-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.live-price-heading span {
  display: block;
  margin-bottom: 5px;
  color: #69766d;
  font-size: 12px;
}
.live-price-heading strong {
  color: #15734b;
  font-size: 20px;
}
.live-price-panel > p {
  margin: 9px 0;
  color: #7b887f;
  font-size: 12px;
}
.live-price-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}
.live-price-details div {
  padding: 9px 10px;
  border-radius: 7px;
  background: #fff;
}
.live-price-details span {
  display: block;
  margin-bottom: 4px;
  color: #7d8881;
  font-size: 11px;
}
.live-price-details b { font-size: 13px; }
.price-cap-advice.good { color: #15734b; }
.price-cap-advice.warning { color: #b6631d; }
.generated-output {
  width: 100%;
  min-height: 120px;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid #dbe0e6;
  border-radius: 8px;
  resize: vertical;
  font: 13px/1.65 Consolas, monospace;
}
.compact-select {
  width: auto;
  min-width: 130px;
  padding: 8px 10px;
  border: 1px solid #d8dde5;
  border-radius: 7px;
  background: #fff;
}
.card-list-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-search {
  width: 220px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid #d8dde5;
  border-radius: 7px;
  background: #fff;
  text-align: left;
  letter-spacing: 0;
}
.data-table-wrap {
  width: 100%;
  overflow: auto;
}
.data-table {
  min-width: 820px;
  font-size: 12px;
}
.data-table th {
  padding: 9px 8px;
  border-bottom: 1px solid #dfe4ea;
  color: #737e8c;
  white-space: nowrap;
}
.data-table td {
  padding: 11px 8px;
  border-bottom: 1px solid #eef1f4;
  vertical-align: top;
}
.data-table code {
  color: #26344a;
  font-size: 12px;
}
.data-table small {
  color: #9099a5;
  font-size: 10px;
}
.empty-row {
  height: 100px;
  color: #929aa5;
  text-align: center !important;
}
.status-badge {
  display: inline-block;
  padding: 4px 7px;
  border-radius: 999px;
  background: #eef1f4;
  color: #66717f;
  font-size: 11px;
  white-space: nowrap;
}
.status-badge.unused,
.status-badge.success {
  background: #e9f7f0;
  color: #14704c;
}
.status-badge.locked,
.status-badge.active {
  background: #edf3ff;
  color: #315fa7;
}
.status-badge.cancel_pending {
  background: #fff5df;
  color: #94610b;
}
.status-badge.used,
.status-badge.canceled {
  background: #f1f2f4;
  color: #6e7782;
}
.status-badge.orphan_code,
.status-badge.duplicate_code,
.status-badge.revoked {
  background: #feecec;
  color: #a33434;
}
.error-detail {
  display: block;
  max-width: 200px;
  margin-top: 5px;
  color: #a8702c !important;
}
.row-actions { white-space: nowrap; }
.link-button {
  width: auto;
  padding: 3px 5px;
  border: 0;
  background: transparent;
  color: #315f9f;
  font-size: 12px;
}
.link-button.danger { color: #ad3e3e; }
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.settings-grid .admin-panel:last-child { grid-column: 1 / -1; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.margin-preview {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f7f8fa;
  color: #626d7c;
  font-size: 13px;
}
.margin-preview div + div { margin-top: 7px; }
.positive { color: #138154; }
.negative { color: #bb3b3b; }
.security-status {
  margin-bottom: 13px;
  padding: 12px;
  border-radius: 8px;
  background: #f7f8fa;
}
.security-status div {
  display: flex;
  justify-content: space-between;
}
.security-status small {
  display: block;
  margin-top: 7px;
  color: #88929f;
}
.webhook-config {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
}
.webhook-config label {
  color: #566171;
  font-size: 12px;
  font-weight: 600;
}
.webhook-config input {
  margin: 7px 0 0;
  text-align: left;
  font-family: Consolas, monospace;
}
.webhook-config .field-help {
  grid-column: 1 / -1;
  margin: 0;
  color: #88929f;
  font-size: 12px;
  line-height: 1.5;
}
.text-success { color: #138154; }
.text-danger { color: #bb3b3b; }
.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 11px 0;
  color: #536071;
  font-size: 13px;
}
.toggle-row input {
  width: auto;
  margin: 0;
}
.toggle-row.warning { color: #a6671d; }
.settings-actions {
  position: sticky;
  bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid #dfe3e8;
  border-radius: 10px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 8px 30px rgba(26, 35, 48, .1);
}
.settings-actions span {
  color: #66717f;
  font-size: 13px;
}
.settings-actions button { width: auto; }
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: 360px;
  padding: 11px 15px;
  border-radius: 8px;
  background: #1d2837;
  color: #fff;
  box-shadow: 0 10px 28px rgba(22, 31, 43, .24);
  font-size: 13px;
}
.toast.success { background: #2f7d54; }
.toast.error { background: #a93e3e; }
.store-toast {
  top: 24px;
  right: auto;
  bottom: auto;
  left: 50%;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 14px 20px;
  transform: translateX(-50%);
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
}

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-grid .admin-panel:last-child { grid-column: auto; }
}
@media (max-width: 760px) {
  body.admin-menu-open { overflow: hidden; }
  .admin-shell { display: block; }
  .admin-sidebar {
    position: fixed;
    z-index: 60;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(260px, 84vw);
    height: 100dvh;
    transform: translateX(-102%);
    box-shadow: 18px 0 38px rgba(9, 15, 24, .25);
    transition: transform .2s ease;
  }
  .admin-sidebar nav {
    grid-template-columns: 1fr;
  }
  .nav-item { text-align: left; padding: 11px 14px; }
  .nav-logout { display: block; }
  .sidebar-toggle {
    width: auto;
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border: 1px solid #d8dde5;
    border-radius: 8px;
    background: #fff;
    color: #263245;
    font-size: 13px;
    font-weight: 650;
  }
  .sidebar-toggle span:first-child {
    font-size: 18px;
    line-height: 1;
  }
  .sidebar-backdrop {
    position: fixed;
    z-index: 55;
    inset: 0;
    display: block;
    background: rgba(10, 16, 25, .48);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  .admin-shell.sidebar-open .admin-sidebar { transform: translateX(0); }
  .admin-shell.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .admin-content { padding: 20px 14px 36px; }
  .card-list-title {
    align-items: flex-start;
    flex-direction: column;
  }
  .card-list-controls { width: 100%; }
  .card-search {
    min-width: 0;
    flex: 1;
  }
  .metric-grid,
  .admin-grid.two,
  .order-summary,
  .form-grid { grid-template-columns: 1fr 1fr; }
  .generate-form { grid-template-columns: 1fr; }
}
@media (max-width: 500px) {
  .phone-tip {
    grid-template-columns: 1fr;
    text-align: center;
  }
  .phone-tip-image {
    max-width: 420px;
    margin: 0 auto;
  }
  .metric-grid,
  .admin-grid.two,
  .order-summary,
  .form-grid,
  .live-price-details { grid-template-columns: 1fr; }
  .admin-header { align-items: flex-start; }
}
