:root {
  --primary: #4263bc;
  --primary-deep: #3452a4;
  --paper: #fffaf4;
  --card: #ffffff;
  --ink: #171717;
  --muted: #747178;
  --line: #e6e0d8;
  --tint: #fbefdf;
  --success: #287a4b;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f2f1ef;
  color: var(--ink);
  font-family: -apple-system, "Noto Sans TC", BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.admin-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 42px 0 72px;
}

.admin-header,
.section-heading,
.account-heading,
.account-controls,
.account-footer,
.audit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.admin-header {
  align-items: flex-start;
  margin-bottom: 30px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--primary);
  font-family: "Baloo Bhaina 2", sans-serif;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 5px;
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1.15;
}

.admin-subtitle,
.section-note,
.access-state p,
.account-meta,
.account-usage,
.audit-meta {
  color: var(--muted);
}

.admin-subtitle {
  margin-bottom: 0;
}

.back-link,
.save-plan,
.copy-id {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
}

.back-link {
  flex: none;
  padding: 11px 18px;
  background: var(--ink);
  color: white;
  font-size: 14px;
  font-weight: 700;
}

.access-state,
.admin-section {
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: 0 16px 40px rgba(37, 33, 29, 0.06);
}

.access-state {
  padding: 26px;
}

.access-state p {
  margin: 7px 0 0;
}

.access-state.is-error strong {
  color: #a33a32;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.preview-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 20px;
  align-items: end;
  margin-bottom: 24px;
  padding: 24px;
  border: 1px solid #cfd8ff;
  border-radius: 26px;
  background: #f5f7ff;
}

.preview-panel h2 {
  margin: 0 0 7px;
  font-size: 22px;
}

.preview-panel p:not(.eyebrow):not(.preview-status) {
  max-width: 620px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.preview-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.preview-controls .save-plan {
  white-space: nowrap;
}

.preview-status {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--primary-deep);
  font-size: 13px;
  font-weight: 700;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  margin: 20px 0;
  overflow-x: auto;
  padding-bottom: 2px;
}

.admin-tab {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 17px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
}

.admin-tab:hover,
.admin-tab:focus-visible,
.admin-tab.is-active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
  outline: 0;
}

.permissions-section {
  margin-bottom: 24px;
  padding: 26px;
}

.permission-table-wrap {
  overflow-x: auto;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
}

.quota-setting {
  display: flex;
  align-items: end;
  gap: 12px;
  max-width: 620px;
  margin-top: 18px;
  padding: 16px;
  border: 1px solid #eadfcf;
  border-radius: 18px;
  background: #fffaf4;
}

.quota-setting .field {
  flex: 1;
}

.quota-setting .field span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.quota-setting input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}

.quota-setting-note {
  min-height: 1.4em;
  margin: 8px 0 0;
  color: var(--primary-deep);
  font-size: 13px;
}

.permission-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 14px;
}

.permission-table th,
.permission-table td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.permission-table thead th {
  color: var(--muted);
  background: #fcfaf7;
  font-size: 12px;
  line-height: 1.4;
}

.permission-table tbody tr:last-child th,
.permission-table tbody tr:last-child td {
  border-bottom: 0;
}

.permission-table .permission-feature-name {
  width: 26%;
  color: var(--ink);
  text-align: left;
}

.permission-feature-name strong,
.permission-feature-name small {
  display: block;
}

.permission-feature-name strong {
  font-weight: 700;
}

.permission-feature-name small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
}

.permission-cell input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.permission-cell--admin {
  background: #f5f7ff;
}

.permission-status {
  min-height: 1.4em;
  margin: 14px 0 0;
  color: var(--primary-deep);
  font-size: 13px;
  font-weight: 700;
}

.permission-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.permission-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.permission-reset {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.summary-card {
  min-height: 132px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--card);
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-card strong {
  display: block;
  margin-top: 8px;
  color: var(--primary);
  font-family: "Baloo Bhaina 2", sans-serif;
  font-size: 42px;
  line-height: 1;
}

.summary-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.operations-section {
  padding: 26px;
}

.operations-period {
  margin: 0;
  text-align: right;
}

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

.operation-summary-card {
  min-height: 126px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: white;
}

.operation-summary-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.operation-summary-card strong {
  display: block;
  margin-top: 9px;
  color: var(--primary);
  font-family: "Baloo Bhaina 2", sans-serif;
  font-size: 30px;
  line-height: 1;
}

.operation-summary-card small,
.metric-note {
  display: block;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.operations-grid {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

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

.metric-panel {
  min-width: 0;
  margin-top: 14px;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fff;
}

.metric-panel h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

.metric-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid #f0ece7;
}

.metric-row:last-child {
  border-bottom: 0;
}

.metric-row-copy {
  min-width: 0;
}

.metric-row-copy strong,
.metric-row-copy small {
  display: block;
}

.metric-row-copy strong {
  font-size: 13px;
}

.metric-row-copy small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.metric-row > b {
  flex: none;
  color: var(--primary-deep);
  font-size: 14px;
  text-align: right;
}

.quota-row {
  padding: 7px 0 11px;
}

.quota-row-label,
.daily-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
}

.quota-row-label b,
.daily-row b {
  color: var(--muted);
  font-size: 11px;
}

.quota-track,
.daily-track {
  height: 7px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 99px;
  background: #eeeaf4;
}

.quota-fill,
.daily-fill {
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: inherit;
  background: var(--primary);
}

.daily-row {
  grid-template-columns: 78px minmax(0, 1fr) auto;
  display: grid;
  padding: 7px 0;
}

.daily-track {
  margin-top: 0;
}

.daily-fill {
  background: #e0924c;
}

.error-log-row {
  padding: 10px 0;
  border-bottom: 1px solid #f0ece7;
}

.error-log-row:last-child {
  border-bottom: 0;
}

.error-log-row strong,
.error-log-row p,
.error-log-row small {
  display: block;
}

.error-log-row strong {
  font-size: 13px;
}

.error-log-row p {
  margin: 3px 0;
  color: #a33a32;
  font-size: 12px;
  line-height: 1.45;
}

.error-log-row small {
  color: var(--muted);
  font-size: 11px;
}

.admin-section {
  margin-top: 24px;
  padding: 26px;
}

.section-heading {
  align-items: flex-end;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: 24px;
}

.account-search input {
  width: min(340px, 42vw);
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 17px;
  background: white;
}

.section-note {
  margin: 16px 0 20px;
  font-size: 13px;
  line-height: 1.55;
}

.account-list,
.audit-list {
  display: grid;
  gap: 12px;
}

.account-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: white;
}

.account-card > summary {
  list-style: none;
}

.account-card > summary::-webkit-details-marker {
  display: none;
}

.account-card-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, auto) 22px;
  gap: 18px;
  align-items: center;
  padding: 20px;
  cursor: pointer;
}

.account-card-summary:hover,
.account-card-summary:focus-visible {
  background: #faf8f5;
  outline: 0;
}

.account-card-summary-meta {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.account-card-summary-meta span:first-child {
  color: var(--ink);
  font-weight: 800;
}

.account-card-chevron {
  color: var(--primary-deep);
  font-size: 28px;
  line-height: 1;
  transform: rotate(0deg);
  transition: transform 160ms ease;
}

.account-card[open] .account-card-chevron {
  transform: rotate(90deg);
}

.account-card-body {
  padding: 0 20px 20px;
}

.account-heading {
  align-items: flex-start;
}

.account-access-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
  padding: 13px 15px;
  border-radius: 16px;
  background: #faf8f5;
}

.account-access-summary .metric-row {
  display: block;
  padding: 0;
  border-bottom: 0;
}

.account-access-summary .metric-row > b {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  text-align: left;
  font-size: 13px;
}

.account-error-summary {
  margin-top: 12px;
  padding: 12px 15px;
  border-radius: 16px;
  background: #fff9f7;
}

.account-error-summary > strong {
  display: block;
  color: var(--ink);
  font-size: 13px;
}

.account-error-summary p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.account-error-summary p:not(:first-of-type) {
  color: #a33a32;
}

.account-name-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.account-name-row h3 {
  margin: 0;
  font-size: 18px;
}

.account-membership-icon {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 10px;
  background: #eef1ff;
  color: var(--primary);
}

.account-membership-icon svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.role-chip,
.plan-chip {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.role-chip {
  background: #e7ecff;
  color: var(--primary-deep);
}

.plan-chip {
  background: var(--tint);
  color: #80531f;
}

.account-meta {
  margin: 6px 0 0;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.account-usage {
  flex: none;
  margin: 0;
  text-align: right;
  font-size: 13px;
  line-height: 1.5;
}

.account-usage strong {
  display: block;
  color: var(--ink);
  font-size: 15px;
}

.account-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr)) auto;
  margin-top: 18px;
}

.internal-admin-note {
  grid-column: 1 / -1;
  margin: 0;
  padding: 13px 15px;
  border-radius: 14px;
  background: #f0f1f6;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field select,
.field input {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  background: white;
  color: var(--ink);
}

.field input:disabled,
.field select:disabled {
  background: #f2f1ef;
  color: #a09da1;
}

.save-plan {
  align-self: end;
  min-height: 44px;
  padding: 0 18px;
  background: var(--primary);
  color: white;
  font-weight: 800;
}

.save-plan:disabled {
  cursor: wait;
  opacity: 0.65;
}

.account-footer {
  margin-top: 15px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.account-more-details {
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
}

.account-more-details summary {
  cursor: pointer;
  color: var(--primary-deep);
  font-weight: 800;
}

.account-more-details .account-footer {
  align-items: flex-start;
  flex-wrap: wrap;
}

.copy-id {
  padding: 7px 11px;
  background: #f0f1f6;
  color: var(--primary-deep);
  font-size: 12px;
  font-weight: 800;
}

.audit-row {
  align-items: flex-start;
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
}

.audit-row:last-child {
  border-bottom: 0;
}

.audit-row p {
  margin: 0;
  line-height: 1.5;
}

.audit-meta {
  flex: none;
  font-size: 12px;
  text-align: right;
}

.empty-state {
  margin: 18px 0 0;
  color: var(--muted);
  text-align: center;
}

.status-toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 5;
  max-width: min(360px, calc(100% - 44px));
  padding: 14px 18px;
  border-radius: 16px;
  background: var(--ink);
  color: white;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.24);
  font-weight: 700;
}

@media (max-width: 820px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

  .account-access-summary {
    grid-template-columns: 1fr;
  }

  .account-card-summary {
    grid-template-columns: minmax(0, 1fr) 22px;
  }

  .account-card-summary .account-heading {
    grid-column: 1;
    grid-row: 1;
  }

  .account-card-summary .account-card-summary-meta {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .account-card-summary .account-card-chevron {
    grid-column: 2;
    grid-row: 1;
  }

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

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

  .preview-status {
    grid-column: auto;
  }

  .save-plan {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .admin-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 22px;
  }

  .admin-header,
  .section-heading,
  .account-heading,
  .account-footer,
  .audit-row {
    align-items: stretch;
    flex-direction: column;
  }

  .back-link {
    align-self: flex-start;
  }

  .account-search input {
    width: 100%;
  }

  .admin-section {
    padding: 18px;
  }

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

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

  .operations-period {
    text-align: left;
  }

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

  .save-plan {
    grid-column: auto;
  }

  .account-usage,
  .audit-meta {
    text-align: left;
  }
}
