:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #f8faf8;
  --border: #dce4df;
  --text: #18221d;
  --muted: #65726a;
  --teal: #08766a;
  --teal-soft: #d9f0e8;
  --blue: #2469a6;
  --blue-soft: #e2effb;
  --orange: #b8611d;
  --orange-soft: #fff0dd;
  --red: #b23b45;
  --red-soft: #fbe7e8;
  --shadow: 0 10px 28px rgba(28, 50, 38, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }
.empty { padding: 24px; color: var(--muted); text-align: center; }

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: #edf3ef;
}

.auth-panel {
  width: min(420px, 100%);
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #ffffff;
  background: var(--teal);
  border-radius: 8px;
}

.brand-mark svg { width: 22px; }
.brand-mark.small { width: 30px; height: 30px; border-radius: 6px; }
.brand-mark.small svg { width: 17px; }
.auth-panel h1 { margin: 18px 0 24px; font-size: 25px; line-height: 1.2; }

.auth-panel form,
.form-panel form { display: grid; gap: 10px; }

.auth-panel label,
.form-panel label,
.modal label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 11px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid #cbd7d0;
  border-radius: 5px;
  outline: 0;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(8, 118, 106, 0.13);
}

.key-input,
.filter-input { position: relative; }

.key-input svg,
.filter-input svg {
  position: absolute;
  top: 50%;
  left: 10px;
  width: 16px;
  color: var(--muted);
  transform: translateY(-50%);
}

.key-input input { padding-left: 34px; }
.filter-input { width: min(330px, 100%); }
.filter-input input { padding: 8px 10px 8px 32px; }

.primary-button,
.secondary-button,
.text-button,
.icon-button,
.nav-item,
.stage-switch button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  cursor: pointer;
  letter-spacing: 0;
}

.primary-button,
.secondary-button {
  min-height: 36px;
  padding: 8px 13px;
  border-radius: 5px;
  font-weight: 600;
  white-space: nowrap;
}

.primary-button { color: #ffffff; background: var(--teal); }
.primary-button:hover { background: #066357; }
.secondary-button { color: #294338; background: #eef3ef; border: 1px solid #d1ded5; }
.secondary-button:hover { background: #e2ebe4; }
.primary-button svg, .secondary-button svg { width: 16px; }
.auth-panel .primary-button { width: 100%; margin-top: 6px; }
button:disabled { cursor: wait; opacity: 0.68; }
.primary-button.is-loading::before,
.secondary-button.is-loading::before {
  width: 13px;
  height: 13px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: '';
  animation: spin 0.7s linear infinite;
}

.icon-button {
  width: 34px;
  height: 34px;
  color: var(--muted);
  background: transparent;
  border-radius: 5px;
}

.icon-button:hover { color: var(--text); background: #eef3ef; }
.icon-button svg { width: 18px; }
.text-button { padding: 4px 0; color: var(--teal); background: none; font-size: 12px; }
.text-button svg { width: 14px; }
.auth-error, .modal-error { min-height: 18px; margin: 3px 0 0; color: var(--red); font-size: 12px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-brand,
.topbar-actions,
.button-row { display: flex; align-items: center; gap: 10px; }
.topbar-brand { font-size: 16px; font-weight: 700; }
.connection { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.connection span { width: 7px; height: 7px; background: var(--teal); border-radius: 50%; }

.workspace {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  min-height: calc(100vh - 58px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 16px 10px;
  background: #f8faf8;
  border-right: 1px solid var(--border);
}

.nav-list { display: grid; gap: 4px; }
.nav-item {
  justify-content: flex-start;
  min-height: 38px;
  padding: 0 11px;
  color: #526158;
  background: transparent;
  border-radius: 5px;
}

.nav-item svg { width: 17px; }
.nav-item:hover { color: var(--text); background: #e9f0eb; }
.nav-item.active { color: #075f55; background: var(--teal-soft); font-weight: 650; }
.sidebar-footer { display: flex; justify-content: space-between; margin-top: auto; padding: 14px 10px 2px; color: #869189; font-size: 11px; }

.content { width: min(1480px, 100%); margin: 0 auto; padding: 28px; }
.view { display: none; }
.view.active { display: block; }

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.section-heading h2 { margin: 0; font-size: 22px; line-height: 1.2; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric-card {
  display: flex;
  flex-direction: column;
  min-height: 120px;
  padding: 17px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
}

.metric-card span { color: var(--muted); font-size: 12px; }
.metric-card strong { margin-top: 10px; font-size: 30px; line-height: 1; }
.metric-card small { margin-top: auto; color: var(--muted); font-size: 12px; }
.metric-card.teal { border-top: 3px solid var(--teal); }
.metric-card.blue { border-top: 3px solid var(--blue); }
.metric-card.orange { border-top: 3px solid var(--orange); }
.metric-card.red { border-top: 3px solid var(--red); }

.split-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 7px; }
.status-panel, .sender-panel, .form-panel, .activity-panel { padding: 17px; }
.activity-panel { margin-top: 14px; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-title h3, .form-panel h3 { margin: 0; font-size: 14px; }
.status-bars { display: grid; gap: 13px; margin-top: 19px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 42px; align-items: center; gap: 10px; font-size: 12px; }
.bar-track { height: 7px; overflow: hidden; background: #e8eeea; border-radius: 4px; }
.bar-fill { height: 100%; background: var(--teal); border-radius: 4px; }
.bar-fill.blue { background: var(--blue); }
.bar-fill.orange { background: var(--orange); }
.bar-fill.red { background: var(--red); }

.import-feed { display: grid; gap: 8px; margin-top: 14px; }
.import-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 11px; background: var(--surface-2); border-radius: 4px; font-size: 12px; }

.table-panel, .sender-panel { position: relative; overflow: hidden; }
.table-panel.is-loading .table-wrap { opacity: 0.52; pointer-events: none; }
.table-panel.is-loading::after {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 13px;
  height: 13px;
  border: 2px solid var(--teal);
  border-right-color: transparent;
  border-radius: 50%;
  content: '';
  animation: spin 0.7s linear infinite;
}
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.table-meta, .pager { display: flex; align-items: center; gap: 8px; }
.table-wrap { overflow: auto; }
.table-wrap.compact { max-height: 282px; }
table { width: 100%; border-collapse: collapse; text-align: left; white-space: nowrap; }
th { padding: 11px 14px; color: var(--muted); font-size: 11px; font-weight: 650; text-transform: uppercase; }
td { max-width: 330px; padding: 12px 14px; overflow: hidden; border-top: 1px solid #edf1ee; font-size: 13px; text-overflow: ellipsis; }

.badge { display: inline-flex; align-items: center; min-height: 22px; padding: 2px 8px; color: #526158; background: #eaf0ec; border-radius: 11px; font-size: 11px; font-weight: 650; }
.badge.ready, .badge.completed, .badge.active { color: #086154; background: var(--teal-soft); }
.badge.provisioning, .badge.waiting { color: #205d94; background: var(--blue-soft); }
.badge.scan_failed, .badge.timed_out, .badge.failed, .badge.cancelled { color: #9c3340; background: var(--red-soft); }
.badge.cooldown { color: #a9571d; background: var(--orange-soft); }

.access-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.form-panel form { margin-top: 15px; }
.modal { width: min(650px, calc(100vw - 28px)); padding: 0; border: 0; border-radius: 8px; box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(16, 31, 23, 0.42); }
.modal-card { padding: 20px; background: var(--surface); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 19px; }
.stage-switch { display: flex; width: 100%; margin-bottom: 16px; overflow: hidden; border: 1px solid var(--border); border-radius: 5px; }
.stage-switch button { flex: 1; min-height: 34px; color: var(--muted); background: #f8faf8; border-right: 1px solid var(--border); }
.stage-switch button:last-child { border-right: 0; }
.stage-switch button.active { color: #ffffff; background: var(--teal); }
textarea { min-height: 160px; resize: vertical; font: 12px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; }
.file-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.file-row input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.key-result code { display: block; padding: 12px; overflow: auto; color: #075f55; background: #edf4ef; border-radius: 4px; white-space: nowrap; }

.request-filters { display: flex; align-items: end; gap: 10px; min-width: 0; }
.request-filters label { display: grid; gap: 4px; min-width: 150px; color: var(--muted); font-size: 11px; font-weight: 600; }
.request-filters select { padding: 7px 30px 7px 9px; font-size: 13px; }
.request-summary { display: flex; align-items: center; gap: 0; padding: 0 14px; overflow: auto; border-bottom: 1px solid var(--border); }
.request-summary > span { display: grid; gap: 2px; min-width: 98px; padding: 11px 14px 11px 0; }
.request-summary small { color: var(--muted); font-size: 11px; }
.request-summary strong { font-size: 17px; line-height: 1.1; }
.request-status-summary { display: flex; align-items: center; gap: 7px; padding: 11px 0 11px 12px; border-left: 1px solid var(--border); white-space: nowrap; }
.request-status-summary span { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }

.loading-overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(244, 246, 244, 0.56); opacity: 0; pointer-events: none; transition: opacity 0.15s ease; }
.loading-overlay.active { opacity: 1; pointer-events: auto; }
.loading-indicator { display: inline-flex; align-items: center; gap: 9px; padding: 10px 12px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 5px; box-shadow: var(--shadow); font-size: 13px; }
.loading-spinner { width: 16px; height: 16px; border: 2px solid var(--teal); border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 50; max-width: min(420px, calc(100vw - 40px)); padding: 11px 14px; color: #ffffff; background: #23352a; border-radius: 5px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(12px); transition: 0.18s ease; }
.toast.show { opacity: 1; transform: none; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: sticky; bottom: 0; z-index: 5; order: 2; height: 58px; padding: 6px; border-top: 1px solid var(--border); border-right: 0; }
  .nav-list { grid-template-columns: repeat(4, 1fr); gap: 2px; }
  .nav-item { flex-direction: column; gap: 2px; min-height: 44px; padding: 4px; font-size: 10px; }
  .nav-item svg { width: 16px; }
  .sidebar-footer, .connection { display: none; }
  .content { padding: 20px 14px 82px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-grid, .access-grid { grid-template-columns: 1fr; }
  .topbar { padding: 0 14px; }
  .request-toolbar { align-items: stretch; flex-direction: column; }
  .request-filters { width: 100%; }
  .request-filters label { flex: 1; }
}

@media (max-width: 580px) {
  .topbar-brand { font-size: 14px; }
  .section-heading { flex-direction: column; gap: 12px; }
  .button-row { display: grid; width: 100%; grid-template-columns: 1fr 1fr; }
  .button-row button { width: 100%; }
  .metric-card { min-height: 105px; }
  .metric-card strong { font-size: 25px; }
  .content { padding-top: 18px; }
  .auth-panel { padding: 25px 22px; }
  th, td { padding-right: 11px; padding-left: 11px; }
  .file-row { align-items: flex-start; flex-wrap: wrap; }
  .request-filters { display: grid; grid-template-columns: 1fr; }
  .request-summary { align-items: stretch; }
  .request-summary > span { min-width: 86px; }
  .request-status-summary { padding-left: 0; border-left: 0; }
}

/* Billing view */
.inline-input { width: auto; min-width: 140px; }
.table-meta .inline-input { margin-right: 6px; }
#card-codes { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 13px; resize: vertical; }

/* 邮件查看器（管理员直读任意邮箱） */
.mail-viewer-panel .mail-viewer-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.mail-viewer-panel .mail-viewer-form input[type="email"] { flex: 1 1 260px; }
.mail-viewer-panel .mail-viewer-form input[type="number"] { width: 90px; }
.mail-viewer-result { display: flex; flex-direction: column; gap: 14px; }
.mail-item { border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 12px 14px; background: var(--surface, #fff); }
.mail-item .mail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.mail-item .mail-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mail-item .mail-meta strong { word-break: break-word; }
.mail-code { border: 1px solid #16a34a; color: #16a34a; background: #f0fdf4; border-radius: 6px; padding: 4px 10px; font-weight: 600; cursor: pointer; white-space: nowrap; font-size: 13px; }
.mail-code:hover { background: #dcfce7; }
.mail-body-frame { width: 100%; min-height: 220px; border: 1px solid var(--border, #e2e8f0); border-radius: 8px; background: #fff; }
.mail-body-text { white-space: pre-wrap; word-break: break-word; margin: 0; padding: 8px; background: #f8fafc; border-radius: 8px; font-size: 13px; max-height: 480px; overflow: auto; }

/* 邮箱池多选导出 */
.col-select { width: 36px; text-align: center; }
.col-select input[type="checkbox"] { cursor: pointer; }
#asset-export-count { font-variant-numeric: tabular-nums; }

/* 租用视图：套餐表单栅格 */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.text-button.danger { color: #dc2626; }
