:root {
  color-scheme: light;
  --ink: #202534;
  --muted: #7f8591;
  --line: #ecefeb;
  --surface: #ffffff;
  --canvas: #f2f3f2;
  --workspace: #fafbfa;
  --accent: #16bf83;
  --accent-dark: #0fa66f;
  --green: #0bbb78;
  --blue: #149bd7;
  --purple: #9b45ee;
  --coral: #fa4b18;
  --page-gutter: clamp(18px, 1.5vw, 56px);
  font-family: "Segoe UI Variable", "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; padding: var(--page-gutter); color: var(--ink); background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid rgba(22, 191, 131, .22); outline-offset: 2px; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }

.app-shell {
  width: 100%;
  max-width: 2560px;
  min-height: calc(100vh - var(--page-gutter) - var(--page-gutter));
  margin: 0 auto;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid rgba(30, 43, 38, .035);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(39, 55, 48, .08);
}

.sidebar {
  position: sticky;
  top: var(--page-gutter);
  height: calc(100vh - var(--page-gutter) - var(--page-gutter));
  padding: 30px 24px 24px;
  display: flex;
  flex-direction: column;
  color: #5f6670;
  background: #fff;
  border-right: 1px solid #f0f2ef;
}
.brand { margin: 0 12px 38px; display: grid; gap: 4px; width: fit-content; }
.brand-word { color: #242a39; font-size: 25px; font-weight: 800; letter-spacing: -.07em; line-height: 1; }
.brand-word span { color: var(--accent); }
.brand > small { color: #a2a7ae; font-size: 8px; font-weight: 700; letter-spacing: .22em; }
.nav-list { display: grid; gap: 7px; }
.nav-item {
  position: relative;
  height: 46px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 11px;
  color: #69707a;
  font-size: 13px;
  font-weight: 600;
  transition: color .18s ease, background .18s ease, transform .18s ease;
}
.nav-item i { width: 20px; color: #878d95; font-size: 20px; text-align: center; }
.nav-item:hover { color: #26332f; background: #f4faf7; transform: translateX(2px); }
.nav-item.active { color: var(--accent); background: #f0fbf6; }
.nav-item.active i { color: var(--accent); }
.nav-item.active::before { content: ""; position: absolute; left: -24px; width: 4px; height: 30px; border-radius: 0 5px 5px 0; background: var(--accent); }
.sidebar-note { margin-top: auto; padding: 14px 12px; display: flex; gap: 10px; align-items: flex-start; border-radius: 12px; color: #626a73; background: #f6faf8; }
.sidebar-note > i { margin-top: 1px; color: var(--accent); font-size: 20px; }
.sidebar-note strong, .sidebar-note small { display: block; }
.sidebar-note strong { font-size: 11px; }
.sidebar-note small { margin-top: 5px; color: #989ea6; font-size: 9px; line-height: 1.5; }
.profile-button { width: 100%; margin-top: 12px; padding: 9px 8px; display: flex; align-items: center; gap: 10px; color: #444b55; border: 0; border-radius: 12px; background: transparent; cursor: pointer; text-align: left; }
.profile-button:hover { background: #f7f9f7; }
.profile-button strong, .profile-button small { display: block; }
.profile-button strong { max-width: 105px; overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.profile-button small { margin-top: 3px; color: #a0a5ac; font-size: 9px; }
.avatar { width: 34px; height: 34px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; color: #fff; background: #27332f; font-size: 11px; font-weight: 700; }
.chevron { margin-left: auto; color: #a0a5ac; font-size: 18px; }

.main-content { min-width: 0; padding: 30px 32px 64px; background: var(--workspace); }
.topbar { min-height: 70px; margin-bottom: 22px; display: flex; align-items: center; justify-content: space-between; gap: 22px; }
.eyebrow { margin: 0 0 7px; color: #9aa0a8; font-size: 10px; font-weight: 600; }
h1 { margin-bottom: 0; font-size: 23px; font-weight: 750; letter-spacing: -.025em; }
h2 { margin: 4px 0 0; font-size: 18px; letter-spacing: -.015em; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.dashboard-search { width: min(250px, 24vw); height: 40px; padding: 0 13px; display: flex; align-items: center; gap: 8px; border: 1px solid #eef0ed; border-radius: 10px; color: #9ca2a9; background: #fff; box-shadow: 0 5px 18px rgba(34, 48, 42, .025); }
.dashboard-search i { font-size: 17px; }
.dashboard-search input { min-width: 0; width: 100%; border: 0; outline: 0; color: #3e454f; background: transparent; font-size: 10px; }
.dashboard-search input::placeholder { color: #bbc0c5; }
.sync-state { display: inline-flex; align-items: center; gap: 5px; color: #8e959d; font-size: 10px; }
.sync-state i { color: var(--accent); font-size: 17px; }
.primary-button, .secondary-button, .outline-button { border: 0; border-radius: 10px; font-weight: 700; cursor: pointer; transition: .18s ease; }
.primary-button { height: 40px; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; color: white; background: var(--accent); box-shadow: 0 9px 20px rgba(22, 191, 131, .16); font-size: 11px; }
.primary-button:hover { background: var(--accent-dark); transform: translateY(-1px); }
.primary-button i, .outline-button i, .secondary-button i { font-size: 16px; }

.hero-grid, .admin-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.quota-card, .metric-card, .order-builder, .orders-section { border-radius: 17px; background: var(--surface); box-shadow: 0 6px 24px rgba(37, 52, 46, .035); }
.stat-card { position: relative; min-height: 155px; padding: 20px; overflow: hidden; color: #fff; box-shadow: 0 13px 28px rgba(39, 53, 48, .09); }
.stat-green { background: var(--green); }
.stat-blue { background: var(--blue); }
.stat-purple { background: var(--purple); }
.stat-coral { background: var(--coral); }
.stat-icon { position: absolute; top: 30px; right: 20px; color: rgba(255,255,255,.68); font-size: 34px; }
.quota-card { display: flex; flex-direction: column; }
.card-topline { padding-right: 32px; display: flex; align-items: center; justify-content: space-between; gap: 8px; color: rgba(255,255,255,.82); font-size: 10px; font-weight: 600; }
.card-chip { overflow: hidden; color: rgba(255,255,255,.82); font-size: 8px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.quota-number { margin-top: 8px; font-size: 29px; font-weight: 800; letter-spacing: -.035em; }
.quota-number small { color: rgba(255,255,255,.72); font-size: 9px; font-weight: 600; letter-spacing: 0; }
.quota-progress { height: 3px; margin: 11px 0 10px; overflow: hidden; border-radius: 20px; background: rgba(255,255,255,.24); }
.quota-progress span { display: block; height: 100%; border-radius: inherit; background: #fff; }
.quota-meta { display: flex; gap: 12px; color: rgba(255,255,255,.74); font-size: 8px; }
.quota-meta strong { margin-left: 2px; color: #fff; }
.secondary-button { width: fit-content; margin-top: auto; padding: 6px 9px; display: inline-flex; align-items: center; gap: 4px; color: #fff; background: rgba(255,255,255,.17); font-size: 8px; }
.secondary-button:hover { background: rgba(255,255,255,.26); }
.metric-card { display: flex; flex-direction: column; justify-content: center; }
.metric-label { color: rgba(255,255,255,.8); font-size: 10px; font-weight: 600; }
.metric-value { margin: 9px 0 14px; color: #fff; font-size: 29px; letter-spacing: -.035em; }
.metric-value.metric-state { max-width: 75%; overflow: hidden; font-size: 20px; text-overflow: ellipsis; white-space: nowrap; }
.metric-foot { width: fit-content; color: rgba(255,255,255,.78); font-size: 8px; font-weight: 600; }
.metric-foot.waiting, .metric-foot.good { color: rgba(255,255,255,.78); background: transparent; }

.order-builder, .orders-section { padding: 23px 24px; }
.order-builder, .quota-ledger { margin-bottom: 20px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.section-heading p { margin: 7px 0 0; color: var(--muted); font-size: 10px; line-height: 1.55; }
.section-kicker { color: var(--accent); font-size: 8px; font-weight: 800; letter-spacing: .16em; }
.safe-badge { padding: 7px 10px; border-radius: 9px; color: #16845e; background: #edf9f4; font-size: 9px; font-weight: 700; }
.safe-badge span { margin-right: 3px; }
.outline-button { margin-left: auto; padding: 8px 13px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: #12865f; border: 1px solid #cfeadf; background: #fff; font-size: 9px; }
.outline-button:hover { background: #f1faf6; border-color: #a9ddc8; }
.outline-button.standalone { width: 100%; height: 40px; margin: 0; }
.order-form { margin-top: 21px; display: grid; gap: 16px; }
.form-grid { display: grid; gap: 14px; }
.form-grid.two-columns { grid-template-columns: minmax(0, 1fr) 200px; }
.form-grid.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: 7px; color: #59616b; font-size: 10px; font-weight: 650; }
.field input, .field select, .field textarea { width: 100%; color: var(--ink); border: 1px solid #e1e5e1; border-radius: 9px; outline: none; background: #fff; transition: border-color .18s, box-shadow .18s; }
.field input, .field select { height: 40px; padding: 0 11px; }
.field textarea { min-height: 90px; padding: 11px; resize: vertical; line-height: 1.6; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #7bd4b2; box-shadow: 0 0 0 3px rgba(22,191,131,.1); }
.field small { color: #9ba1a8; font-size: 8px; font-weight: 500; }
.action-field { align-content: end; }
.config-panel { border: 1px solid #e8ebe8; border-radius: 11px; background: #fbfcfb; }
.config-panel summary { padding: 13px 15px; color: #4f5861; cursor: pointer; font-size: 10px; font-weight: 750; }
.config-panel[open] summary { border-bottom: 1px solid #e8ebe8; }
.config-panel .form-grid { padding: 15px 15px 7px; }
.checkbox-row { padding: 8px 15px 15px; display: flex; flex-wrap: wrap; gap: 17px; color: #626a73; font-size: 9px; }
.checkbox-row label { display: flex; align-items: center; gap: 6px; }
.checkbox-row input, .product-table input { accent-color: var(--accent); }
.submit-bar { padding-top: 2px; display: flex; align-items: center; justify-content: space-between; gap: 15px; color: #8e959d; font-size: 9px; }
.submit-bar .primary-button { min-width: 136px; }

.product-picker { overflow: hidden; border: 1px solid #e8ebe8; border-radius: 11px; }
.product-picker-head { padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 14px; background: #fbfcfb; }
.product-picker-head strong, .product-picker-head small { display: block; }
.product-picker-head strong { font-size: 10px; }
.product-picker-head small { margin-top: 4px; color: #959ba2; font-size: 8px; }
.compact-button { width: auto !important; min-width: 102px; }
.product-actions { display: flex; gap: 7px; }
.product-list-wrap { max-height: 380px; overflow: auto; }
.product-table { width: 100%; min-width: 660px; border-collapse: collapse; }
.product-table th, .product-table td { padding: 10px 11px; border-bottom: 1px solid #f0f2ef; color: #656d76; font-size: 9px; text-align: left; }
.product-table th { position: sticky; z-index: 1; top: 0; color: #9aa0a7; background: #fff; }
.product-table tr:last-child td { border-bottom: 0; }
.product-table .check-column { width: 40px; }
.product-table .product-override-input { width: 112px; height: 31px; padding: 0 9px; color: #414952; border: 1px solid #dfe4df; border-radius: 7px; background: #fff; font-size: 9px; }
.product-copy { min-width: 220px; display: flex; align-items: center; gap: 9px; }
.product-copy img { width: 34px; height: 34px; object-fit: cover; border-radius: 7px; background: #f1f3f1; }
.product-copy strong { max-width: 330px; overflow: hidden; color: #394049; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }

.section-heading.compact { align-items: flex-end; }
.filter-tabs { padding: 3px; display: flex; gap: 2px; border-radius: 8px; background: #f1f4f1; }
.filter-tabs button { padding: 6px 9px; color: #858c94; border: 0; border-radius: 6px; background: transparent; font-size: 8px; cursor: pointer; }
.filter-tabs button.active { color: #157a59; background: #fff; box-shadow: 0 2px 6px rgba(35,48,42,.07); font-weight: 700; }
.order-table-wrap { margin-top: 16px; overflow-x: auto; }
.order-table { width: 100%; min-width: 690px; border-collapse: collapse; }
.order-table th { padding: 9px 11px; color: #a1a6ad; border-bottom: 1px solid var(--line); font-size: 8px; font-weight: 700; text-align: left; }
.order-table td { padding: 13px 11px; color: #59616b; border-bottom: 1px solid #f1f3f1; font-size: 9px; }
.order-table tr:last-child td { border-bottom: 0; }
.order-table td strong, .order-table td small { display: block; }
.order-table td strong { color: #343b44; font-size: 9px; }
.order-table td small { margin-top: 4px; color: #9da2a9; font-size: 8px; }
.order-status { padding: 5px 8px; border-radius: 7px; font-size: 8px; font-weight: 700; white-space: nowrap; }
.order-status.pending { color: #976a16; background: #fff4d9; }
.order-status.processing { color: #6750c8; background: #f0ebff; }
.order-status.completed { color: #167757; background: #e7f7f0; }
.order-status.failed { color: #ad3f4a; background: #fdebed; }
.order-status.canceled { color: #69717c; background: #edf0ed; }
.row-action { color: #159069; border: 0; background: none; font-size: 8px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.empty-state { padding: 32px !important; color: #9ba1a8 !important; text-align: center !important; }

.toast { position: fixed; z-index: 80; right: 24px; bottom: 24px; padding: 11px 15px; pointer-events: none; opacity: 0; transform: translateY(10px); border-radius: 10px; color: white; background: #29322f; font-size: 10px; transition: .2s ease; box-shadow: 0 12px 30px rgba(0,0,0,.16); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #ad3543; }
body.modal-open { overflow: hidden; }
.modal-layer { position: fixed; z-index: 50; inset: 0; padding: 24px; display: grid; place-items: center; background: rgba(28,35,32,.52); backdrop-filter: blur(5px); }
.modal-card { position: relative; width: min(460px, 100%); max-height: calc(100vh - 48px); padding: 27px; overflow-y: auto; border: 1px solid rgba(255,255,255,.7); border-radius: 17px; background: #fff; box-shadow: 0 24px 70px rgba(15,22,19,.25); }
.modal-card h2 { margin: 0; font-size: 20px; }
.modal-description { margin: 8px 0 19px; color: #7e858d; font-size: 10px; line-height: 1.6; }
.modal-close { position: absolute; top: 15px; right: 15px; width: 31px; height: 31px; color: #8e959c; border: 0; border-radius: 8px; background: #f2f4f2; cursor: pointer; font-size: 19px; }
.stack-form { display: grid; gap: 14px; }
.full-width { width: 100%; justify-content: center; margin-top: 3px; }
.auth-card { width: min(420px, 100%); }
.auth-brand { margin-bottom: 24px; display: flex; align-items: center; gap: 10px; }
.auth-brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; color: #fff; background: var(--accent); }
.auth-brand-mark i { font-size: 21px; }
.auth-brand strong, .auth-brand small { display: block; }
.auth-brand strong { font-size: 13px; }
.auth-brand small { margin-top: 3px; color: #9ba1a8; font-size: 8px; letter-spacing: .08em; }
.auth-tabs { margin-bottom: 17px; padding: 3px; display: grid; grid-template-columns: 1fr 1fr; border-radius: 9px; background: #f1f3f1; }
.auth-tabs button { height: 33px; color: #858c94; border: 0; border-radius: 7px; background: transparent; cursor: pointer; font-size: 10px; font-weight: 700; }
.auth-tabs button.active { color: #187a59; background: #fff; box-shadow: 0 2px 8px rgba(30,43,37,.08); }
.order-detail-card { width: min(560px, 100%); }
.detail-items { max-height: 380px; margin: 17px 0; overflow-y: auto; border: 1px solid #e7ebe7; border-radius: 10px; }
.detail-item { padding: 11px 13px; display: flex; align-items: center; justify-content: space-between; gap: 15px; border-bottom: 1px solid #eff2ef; }
.detail-item:last-child { border-bottom: 0; }
.detail-item strong, .detail-item small { display: block; }
.detail-item strong { color: #414952; font-size: 9px; }
.detail-item small { max-width: 390px; margin-top: 4px; color: #90979f; font-size: 8px; }
.item-result { padding: 4px 7px; flex: 0 0 auto; border-radius: 7px; font-size: 8px; font-weight: 700; }
.item-result.pending { color: #986b17; background: #fff3d7; }
.item-result.running { color: #6550c6; background: #f0ebff; }
.item-result.success { color: #157455; background: #e5f6ee; }
.item-result.failed { color: #ad3d49; background: #fdebed; }
.item-result.canceled { color: #69717c; background: #edf0ed; }
.danger-button { height: 40px; color: #ae3442; border: 1px solid #efc8ce; border-radius: 9px; background: #fff5f6; cursor: pointer; font-size: 10px; font-weight: 700; }
.order-detail-card .danger-button { margin-top: 9px; }

.admin-metrics .metric-card { min-height: 155px; }
.admin-section-gap { margin-top: 20px; }
.activation-code-heading { margin-top: 27px; }
.activation-code-heading h3 { margin: 0; color: #313941; font-size: 13px; }
.table-action-button { width: auto; min-width: 60px; height: 31px; padding: 0 11px; font-size: 8px; }
.generated-code { margin-top: 17px; padding: 15px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px 13px; border: 1px solid #bfe7d7; border-radius: 11px; background: #f2faf6; }
.generated-code span { color: #7d858d; font-size: 8px; }
.generated-code strong { grid-column: 1; overflow-wrap: anywhere; color: #137858; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; }
.generated-code button { grid-column: 2; grid-row: 1 / span 2; }

@media (max-width: 1180px) {
  :root { --page-gutter: 18px; }
  .app-shell { grid-template-columns: 190px minmax(0,1fr); }
  .sidebar { padding-inline: 18px; }
  .nav-item.active::before { left: -18px; }
  .main-content { padding-inline: 24px; }
  .hero-grid, .admin-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-search { display: none; }
}

@media (max-width: 760px) {
  :root { --page-gutter: 0px; }
  .app-shell { max-width: none; display: block; min-height: 100vh; border: 0; border-radius: 0; }
  .sidebar { position: static; width: 100%; height: auto; padding: 13px 16px; flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid #edf0ed; }
  .brand { margin: 0; }
  .brand > small { display: none; }
  .brand-word { font-size: 21px; }
  .nav-list { margin-left: auto; display: flex; gap: 3px; }
  .nav-item { width: 38px; height: 38px; padding: 0; justify-content: center; font-size: 0; }
  .nav-item i { font-size: 19px; }
  .nav-item.active::before, .sidebar-note, .profile-button { display: none; }
  .main-content { padding: 20px 15px 44px; }
  .topbar { min-height: auto; margin-bottom: 19px; align-items: flex-start; }
  h1 { font-size: 20px; }
  .sync-state { display: none; }
  .primary-button { padding: 0 12px; font-size: 9px; }
  .hero-grid, .admin-metrics { grid-template-columns: 1fr 1fr; gap: 11px; }
  .stat-card, .admin-metrics .metric-card { min-height: 138px; padding: 16px; }
  .stat-icon { top: 23px; right: 15px; font-size: 28px; }
  .metric-value { font-size: 26px; }
  .order-builder, .orders-section { padding: 19px 16px; }
  .section-heading { display: block; }
  .safe-badge { width: fit-content; margin-top: 13px; }
  .form-grid.two-columns, .form-grid.three-columns { grid-template-columns: 1fr; }
  .submit-bar { align-items: stretch; flex-direction: column; }
  .submit-bar .primary-button { width: 100%; }
  .section-heading.compact { display: flex; align-items: flex-end; }
  .filter-tabs { max-width: 100%; overflow-x: auto; }
  .quota-meta { gap: 7px; }
  .generated-code { grid-template-columns: 1fr; }
  .generated-code button { grid-column: 1; grid-row: auto; }
}

@media (max-width: 480px) {
  .hero-grid, .admin-metrics { grid-template-columns: 1fr; }
  .stat-card, .admin-metrics .metric-card { min-height: 128px; }
  .top-actions .primary-button { width: 40px; padding: 0; font-size: 0; }
  .top-actions .primary-button i { font-size: 16px; }
  .nav-list .nav-item:nth-child(n+5) { display: none; }
  .product-picker-head { align-items: flex-start; flex-direction: column; }
  .product-actions { width: 100%; }
  .product-actions button { flex: 1; min-width: 0; }
  .section-heading.compact { align-items: flex-start; flex-direction: column; }
}
