:root {
  color: #17212b;
  background: #eef2f0;
  font-family: Inter, "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 228px minmax(0, 1fr); }
.sidebar { background: #17212b; color: #dce5e7; padding: 18px 12px; display: flex; flex-direction: column; gap: 22px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; color: white; font-size: 17px; font-weight: 700; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 6px; background: #25a489; color: #072c28; font-weight: 900; }
.brand small { display: block; color: #8da0a6; font-size: 11px; font-weight: 500; margin-top: 2px; }
.nav { display: grid; gap: 4px; }
.nav button { min-height: 40px; border: 0; border-left: 3px solid transparent; border-radius: 4px; background: transparent; color: #b8c6c9; text-align: left; padding: 0 12px; font-size: 14px; }
.nav button:hover { background: #22333e; color: white; }
.nav button.active { border-left-color: #32c2a5; background: #223b42; color: white; font-weight: 650; }
.sidebar-foot { margin-top: auto; padding: 12px 8px; border-top: 1px solid #2b3c45; color: #8da0a6; font-size: 12px; line-height: 1.6; }

.main { min-width: 0; }
.topbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 26px; border-bottom: 1px solid #d9e0dc; background: #fbfcfb; }
.org-picker { display: flex; align-items: center; min-width: 0; gap: 10px; }
.org-picker label { color: #60716d; font-size: 12px; }
.org-picker select { max-width: 280px; border: 1px solid #cbd7d1; border-radius: 4px; background: white; color: #17212b; padding: 7px 28px 7px 9px; }
.account { display: flex; align-items: center; gap: 10px; min-width: 0; }
.account-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #40534f; font-size: 13px; }
.role { display: inline-flex; align-items: center; min-height: 22px; border: 1px solid #bfe1d6; border-radius: 999px; padding: 0 8px; color: #16765f; background: #effaf6; font-size: 12px; }

.content { width: min(1480px, 100%); margin: 0 auto; padding: 28px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-head h1 { margin: 0; font-size: 22px; line-height: 1.25; letter-spacing: 0; }
.page-head p { margin: 7px 0 0; color: #64746f; font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.button { min-height: 34px; border: 1px solid #cbd7d1; border-radius: 4px; background: #fff; color: #253430; padding: 0 11px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.button:hover { border-color: #87b9aa; background: #f5faf8; }
.button.primary { border-color: #168d74; background: #168d74; color: white; }
.button.primary:hover { background: #107762; }
.button.danger { border-color: #e4b9b6; color: #ae3a35; }
.button.danger:hover { background: #fff5f4; }
.button.quiet { border-color: transparent; background: transparent; color: #52635e; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid #d7e0db; border-radius: 6px; background: white; overflow: hidden; }
.metric { min-height: 112px; padding: 18px; border-right: 1px solid #e0e7e3; }
.metric:last-child { border-right: 0; }
.metric-label { color: #65746f; font-size: 12px; }
.metric-value { margin-top: 10px; color: #16231f; font-size: 26px; font-weight: 700; }
.metric-sub { margin-top: 5px; color: #83918d; font-size: 12px; }

.section { margin-top: 20px; border: 1px solid #d7e0db; border-radius: 6px; background: white; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 54px; padding: 0 18px; border-bottom: 1px solid #e1e8e4; }
.section-head h2 { margin: 0; font-size: 15px; }
.section-head span { color: #71817c; font-size: 12px; }
.section-body { padding: 18px; }
.split { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(310px, .65fr); gap: 20px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { border-bottom: 1px solid #dbe4df; color: #65746f; font-size: 11px; font-weight: 650; text-align: left; text-transform: uppercase; padding: 0 10px 10px; white-space: nowrap; }
td { border-bottom: 1px solid #edf1ef; padding: 13px 10px; color: #263632; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.cell-main { display: block; font-weight: 650; }
.cell-sub { display: block; max-width: 220px; overflow: hidden; color: #76847f; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; margin-top: 3px; }
.table-actions { display: flex; justify-content: flex-end; gap: 6px; min-width: max-content; white-space: nowrap; }

.status { display: inline-flex; align-items: center; min-height: 23px; border-radius: 999px; padding: 0 8px; font-size: 11px; font-weight: 650; }
.status.active, .status.authorized, .status.paid { color: #14735d; background: #e9f8f2; }
.status.inactive, .status.archived, .status.canceled { color: #687671; background: #edf1ef; }
.status.revoked, .status.expired { color: #ad3833; background: #fff0ef; }
.status.pending, .status.offline_grace { color: #896714; background: #fff8df; }

.feature-list { display: grid; gap: 1px; border: 1px solid #e0e8e3; border-radius: 5px; overflow: hidden; }
.feature { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 42px; padding: 0 12px; background: #fbfcfb; font-size: 13px; }
.feature:nth-child(even) { background: #f6f9f7; }
.feature code { color: #354743; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.feature-value { color: #17745f; font-weight: 700; }

.empty { padding: 42px 18px; text-align: center; color: #72817c; font-size: 14px; }
.notice { border-left: 3px solid #29a789; background: #f1faf6; padding: 12px 14px; color: #36534b; font-size: 13px; line-height: 1.55; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eaf0ed; }
.auth-panel { width: min(430px, 100%); border: 1px solid #ccd8d2; border-radius: 6px; background: white; padding: 28px; box-shadow: 0 18px 50px rgba(28, 52, 44, .12); }
.auth-panel h1 { margin: 0; font-size: 22px; }
.auth-panel p { color: #64746f; font-size: 13px; line-height: 1.6; }
.form { display: grid; gap: 14px; }
.inline-form { grid-template-columns: minmax(180px, 1.3fr) minmax(120px, .7fr) minmax(100px, .45fr) minmax(120px, .55fr) auto; align-items: end; margin-top: 16px; }
.inline-form .button { min-height: 38px; }
.inline-form .grow { min-width: 180px; }
.audit-filter { grid-template-columns: minmax(170px, 1fr) minmax(130px, .55fr) minmax(130px, .55fr); }
.audit-filter > .button { justify-self: start; }
.feature-editor { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; padding: 12px; border: 1px solid #dce5e0; border-radius: 5px; background: #fbfcfb; }
.feature-editor .scope-option { min-height: 38px; }
.field { display: grid; gap: 6px; }
.field label { color: #4e625c; font-size: 12px; font-weight: 650; }
.field input, .field select { min-height: 38px; width: 100%; border: 1px solid #cbd7d1; border-radius: 4px; padding: 0 10px; color: #1a2925; background: white; }
.field input:focus, .field select:focus { outline: 2px solid #c3e8dd; border-color: #249c83; }
.form-help { color: #7d8c87; font-size: 12px; line-height: 1.5; }
.scope-list { display: grid; gap: 6px; max-height: 150px; overflow-y: auto; padding: 8px; border: 1px solid #d4dfda; border-radius: 4px; background: #fbfcfb; }
.scope-option { display: flex; align-items: center; gap: 8px; min-height: 28px; color: #334741; font-size: 13px; }
.scope-option input { width: 15px; height: 15px; margin: 0; accent-color: #168d74; }

.modal-backdrop { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 18px; background: rgba(12, 25, 22, .42); }
.modal { width: min(500px, 100%); border-radius: 6px; background: white; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid #e1e8e4; }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid #e1e8e4; }
.payment-modal { width: min(360px, 100%); }
.payment-body { display: grid; justify-items: center; gap: 14px; color: #223b34; }
.payment-body strong { font-size: 20px; }
.payment-qr { display: block; width: min(224px, 70vw); height: auto; aspect-ratio: 1; image-rendering: pixelated; }
.token { display: block; overflow-wrap: anywhere; border: 1px solid #d5e3dd; border-radius: 4px; background: #f5faf8; padding: 12px; color: #175b4c; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.5; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; max-width: min(420px, calc(100vw - 40px)); border-radius: 5px; background: #1f3430; color: white; padding: 12px 14px; box-shadow: 0 12px 32px rgba(0, 0, 0, .2); font-size: 13px; }
.toast.error { background: #973c37; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; padding: 10px 12px; flex-direction: row; align-items: center; }
  .nav { display: flex; flex: 1; overflow-x: auto; }
  .nav button { min-width: 74px; border-left: 0; border-bottom: 3px solid transparent; text-align: center; padding: 0 8px; }
  .nav button.active { border-left-color: transparent; border-bottom-color: #32c2a5; }
  .sidebar-foot { display: none; }
  .content { padding: 20px 14px; }
  .topbar { padding: 9px 14px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid #e0e7e3; }
  .split { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .brand small, .org-picker label, .account-name { display: none; }
  .page-head { align-items: stretch; flex-direction: column; }
  .actions .button { flex: 1; }
  .metrics { grid-template-columns: 1fr; }
  .metric, .metric:nth-child(2) { border-right: 0; border-bottom: 1px solid #e0e7e3; }
  .metric:last-child { border-bottom: 0; }
  .inline-form, .feature-editor { grid-template-columns: 1fr; }
}
