:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-2: #1d4ed8;
  --success: #0f9f6e;
  --warning: #d97706;
  --danger: #dc2626;
  --violet: #7c3aed;
  --shadow: 0 18px 50px rgba(15, 23, 42, .08);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, textarea, select {
  font: inherit;
  letter-spacing: 0;
}

button, select { cursor: pointer; }
input, textarea, select {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea { resize: vertical; min-height: 120px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }
.muted { color: var(--muted); }

.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, .08), rgba(15, 159, 110, .06)),
    var(--bg);
}
.auth-panel {
  width: min(420px, 100%);
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.brand-lockup h1 { margin: 0; font-size: 24px; line-height: 1.1; }
.brand-lockup p { margin: 4px 0 0; color: var(--muted); }
.brand-lockup.compact { margin-bottom: 26px; }
.brand-lockup.compact strong { display: block; font-size: 16px; }
.brand-lockup.compact small { color: var(--muted); }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--text);
  color: #fff;
  font-weight: 800;
}
.field-stack { display: grid; gap: 12px; margin-bottom: 16px; }
.field-stack label, .field {
  display: grid;
  gap: 7px;
  color: #334155;
  font-weight: 600;
}
.field input, .field textarea { width: 100%; font-weight: 400; }
.form-error { color: var(--danger); min-height: 20px; margin: 10px 0 0; }

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--border);
  background: rgba(255,255,255,.86);
  backdrop-filter: blur(18px);
  padding: 18px;
  display: flex;
  flex-direction: column;
}
.nav-list { display: grid; gap: 6px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #475569;
  padding: 10px 11px;
  text-align: left;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active {
  background: #eaf2ff;
  color: var(--primary-2);
  font-weight: 700;
}
.bottom-action { margin-top: auto; }
.workspace {
  min-width: 0;
  padding: 22px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.topbar h1 { margin: 0; font-size: 27px; line-height: 1.15; }
.topbar p { margin: 5px 0 0; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.user-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  background: #fff;
  color: #334155;
  box-shadow: 0 3px 12px rgba(15, 23, 42, .04);
}

.tab-panel { display: none; }
.tab-panel.active { display: grid; gap: 16px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.grid.tight { gap: 10px; margin-top: 12px; }
.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(128px, 1fr));
  gap: 14px;
}
.metric-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: 0 8px 26px rgba(15,23,42,.04);
  cursor: pointer;
}
.metric-card:hover { border-color: #bfdbfe; }
.metric-card strong { display: block; font-size: 26px; line-height: 1; margin-bottom: 9px; }
.metric-card span { color: var(--muted); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 26px rgba(15,23,42,.04);
  padding: 16px;
  min-width: 0;
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.panel-head h2 { margin: 0; font-size: 17px; line-height: 1.25; }
.panel-head p { margin: 3px 0 0; }

.button, .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: #334155;
  min-height: 38px;
  padding: 8px 12px;
  font-weight: 600;
  text-decoration: none;
}
.button:hover, .icon-button:hover { background: #f8fafc; text-decoration: none; }
.button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-2); }
.button.secondary { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }
.button.ghost { background: transparent; }
.button.danger { border-color: #fecaca; color: var(--danger); background: #fff5f5; }
.button:disabled { opacity: .55; cursor: not-allowed; }
.button.wide { width: 100%; }
.auth-panel .button + .button { margin-top: 9px; }
.icon-button {
  width: 38px;
  padding: 0;
}
.button-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.button-row.end { justify-content: flex-end; }
.icon {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  display: inline-block;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: min(320px, 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 0 10px;
}
.search-box input {
  border: 0;
  box-shadow: none;
  padding-left: 0;
  flex: 1;
  min-width: 0;
}
.mini-field {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  white-space: nowrap;
}
.mini-field input {
  width: 76px;
  padding: 8px 9px;
}
.delivery-test-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(360px, 1.5fr);
  gap: 14px;
  align-items: start;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 13px;
  margin: 12px 0;
  background: #f8fafc;
}
.delivery-test-panel h3 {
  margin: 0 0 5px;
  font-size: 15px;
}
.delivery-test-panel p { margin: 0; }
.delivery-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}
.delivery-controls input {
  flex: 1 1 260px;
  min-width: 220px;
}
.delivery-controls select {
  width: 150px;
}
.delivery-result {
  grid-column: 1 / -1;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  white-space: pre-wrap;
}
.delivery-result.success strong { color: #047857; }
.delivery-result.error strong, .delivery-result.error { color: #b91c1c; }
.inline-guide {
  margin: 8px 0 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 9px;
  color: #334155;
  white-space: pre-wrap;
}
.row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.user-role-select {
  min-width: 110px;
  padding: 7px 9px;
}
.delivery-batch {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.delivery-batch-head {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.delivery-summary {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.delivery-results {
  max-height: 260px;
  overflow: auto;
}
.mini-table th, .mini-table td {
  padding: 8px 9px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 9px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
th {
  background: #f8fafc;
  color: #64748b;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}
tbody tr:hover { background: #fafcff; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }
.email-cell strong { display: block; }
.email-cell small { color: var(--muted); }
.reason-cell { max-width: 440px; color: #475569; word-break: break-word; }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  background: #f1f5f9;
  color: #475569;
  font-weight: 700;
  font-size: 12px;
}
.badge.safe { background: #ecfdf5; color: #047857; }
.badge.free { background: #eff6ff; color: #1d4ed8; }
.badge.plus, .badge.pro, .badge.team, .badge.plan { background: #f5f3ff; color: #6d28d9; }
.badge.error, .badge.invalid { background: #fef2f2; color: #b91c1c; }
.badge.new { background: #f8fafc; color: #64748b; }
.badge.used { background: #f1f5f9; color: #334155; }
.badge.code-healthy { background: #ecfdf5; color: #047857; }
.badge.code-suspect { background: #fffbeb; color: #b45309; }
.badge.code-no_code, .badge.code-blocked, .badge.code-unhealthy { background: #fef2f2; color: #b91c1c; }
.badge.code-unknown { background: #eef2ff; color: #4338ca; }
.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 12px;
}

.progress-block { display: grid; gap: 9px; margin-bottom: 12px; }
.progress-line { display: flex; justify-content: space-between; color: var(--muted); }
.progress {
  height: 9px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}
.progress div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--primary), var(--success));
  transition: width .2s ease;
}
.log-box {
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #0f172a;
  color: #cbd5e1;
  padding: 12px;
  overflow: auto;
  white-space: pre-wrap;
  min-height: 130px;
  max-height: 260px;
}
.log-box.compact { min-height: 120px; max-height: 210px; }

.stack-list { display: grid; gap: 9px; }
.stack-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 11px;
  background: #fff;
}
.stack-item strong { display: block; margin-bottom: 3px; }
.stack-item span { color: var(--muted); }
.recent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.recent-card {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px;
  background: #fff;
}
.recent-card strong { display: block; margin-bottom: 6px; word-break: break-all; }

.mail-layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 16px;
}
.mailbox-pane { min-height: 600px; }
.mailbox-list { display: grid; gap: 8px; margin-top: 12px; max-height: 640px; overflow: auto; }
.mailbox-group {
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
}
.mailbox-group summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  padding: 10px 11px;
  cursor: pointer;
  background: #f8fafc;
  font-weight: 700;
}
.mailbox-group summary::-webkit-details-marker { display: none; }
.mailbox-group-body { display: grid; gap: 4px; padding: 7px; }
.mailbox-item {
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 9px;
  text-align: left;
  color: #334155;
}
.mailbox-item:hover, .mailbox-item.active { background: #eff6ff; color: #1d4ed8; }
.mailbox-item strong { display: block; word-break: break-all; }
.mailbox-item span { color: var(--muted); font-size: 12px; }
.message-list { display: grid; gap: 10px; }
.message-item {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 13px;
  background: #fff;
}
.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 5px;
}
.message-meta strong { font-size: 14px; }
.message-meta span { color: var(--muted); white-space: nowrap; }
.message-item p { margin: 8px 0 0; color: #475569; line-height: 1.55; }

.rule-rows { display: grid; gap: 9px; margin: 12px 0; }
.rule-row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) auto;
  gap: 8px;
}
.result-card, .notice {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e3a8a;
  border-radius: 9px;
  padding: 12px;
  margin: 12px 0;
  word-break: break-word;
}
.json-details { margin-top: 12px; color: var(--muted); }
.json-details textarea { width: 100%; margin-top: 8px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

.drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
}
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15,23,42,.32);
}
.drawer-panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(560px, 100%);
  background: #fff;
  padding: 18px;
  box-shadow: var(--shadow);
  overflow: auto;
}
.file-drop {
  display: grid;
  place-items: center;
  gap: 8px;
  border: 1px dashed #bfdbfe;
  border-radius: 10px;
  padding: 22px;
  color: #1d4ed8;
  background: #eff6ff;
  margin-bottom: 10px;
}
.file-drop input { display: none; }
.import-area {
  width: 100%;
  min-height: 360px;
  margin: 10px 0;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #0f172a;
  color: #fff;
  border-radius: 9px;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  z-index: 70;
}
.empty {
  border: 1px dashed var(--border);
  border-radius: 9px;
  padding: 22px;
  color: var(--muted);
  text-align: center;
}
.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #334155;
}
.switch input { display: none; }
.switch span {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #cbd5e1;
  position: relative;
}
.switch span::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  left: 2px;
  top: 2px;
  transition: transform .15s ease;
}
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(16px); }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(128px, 1fr)); }
  .grid.two, .mail-layout { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .nav-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace { padding: 14px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .rule-row { grid-template-columns: 1fr; }
  table { min-width: 920px; }
}
