:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-subtle: #f1f3f6;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --green: #059669;
  --green-bg: #ecfdf5;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --amber-bg: #fffbeb;
  --amber-text: #92400e;
  --amber-border: #fde68a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
  font-size: 13px;
}

.hint {
  color: var(--text-muted);
  font-size: 12px;
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.07);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.login-brand h1 {
  margin: 0;
  font-size: 20px;
}

.login-brand p {
  margin: 2px 0 0;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 22px;
  flex-shrink: 0;
}

.brand-icon.small {
  width: 36px;
  height: 36px;
  font-size: 18px;
  border-radius: 10px;
}

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-title {
  font-weight: 700;
  font-size: 16px;
}

.topbar-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Layout */
.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 16px 60px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.banner {
  background: var(--amber-bg);
  color: var(--amber-text);
  border: 1px solid var(--amber-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
}

.text-green {
  color: var(--green);
}

.text-red {
  color: var(--red);
}

/* Cards & Forms */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.card-header h2 {
  margin: 0;
  font-size: 15px;
}

.add-grid {
  display: grid;
  grid-template-columns: 1.4fr 1.2fr 0.8fr;
  gap: 12px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-wide {
  grid-column: span 2;
}

.field-actions {
  display: flex;
  justify-content: flex-end;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: #374151;
}

.input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.input:disabled {
  background: var(--surface-subtle);
  color: var(--text-muted);
}

.textarea {
  height: auto;
  padding: 10px 12px;
  resize: vertical;
  font-family: inherit;
}

.prefix-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.prefix-input-wrap .input {
  min-width: 0;
  flex: 1;
}

.prefix-suffix {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Buttons */
.btn {
  height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-full {
  width: 100%;
  margin-top: 14px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-subtle);
}

.btn-subtle {
  background: var(--surface-subtle);
  color: var(--text);
  padding: 0 10px;
}

.btn-subtle:hover:not(:disabled) {
  background: #e5e7eb;
}

.btn-sm {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-danger-outline {
  background: var(--surface);
  border-color: #fecaca;
  color: var(--red);
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--red-bg);
}

.btn-success-outline {
  background: var(--surface);
  border-color: #a7f3d0;
  color: var(--green);
}

.btn-success-outline:hover:not(:disabled) {
  background: var(--green-bg);
}

.error-text {
  color: var(--red);
  font-size: 13px;
  margin: 8px 0 0;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-wrap {
  flex: 1;
  min-width: 200px;
}

.filter-pills {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.pill {
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
}

.pill.active {
  background: var(--text);
  color: #fff;
}

.select-compact {
  width: auto;
  min-width: 112px;
}

/* Alias list */
.alias-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.alias-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  transition: border-color 0.15s;
}

.alias-card.is-blocked {
  border-color: #fecaca;
  background: #fffafa;
}

.alias-main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.alias-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.alias-email {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  word-break: break-all;
}

.alias-card.is-blocked .alias-email {
  text-decoration: line-through;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge-active {
  background: var(--green-bg);
  color: var(--green);
}

.badge-blocked {
  background: var(--red-bg);
  color: var(--red);
}

.badge-tag {
  background: var(--surface-subtle);
  color: #374151;
}

.alias-service {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
}

.alias-note {
  font-size: 13px;
  color: var(--text-muted);
  word-break: break-word;
}

.alias-meta {
  font-size: 12px;
  color: #9ca3af;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.alias-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-state p {
  margin: 0 0 6px;
  font-weight: 600;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.18);
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.btn-icon {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 100;
}

@media (max-width: 768px) {
  .add-grid {
    grid-template-columns: 1fr;
  }
  .field-wide {
    grid-column: span 1;
  }
  .field-actions .btn {
    width: 100%;
  }
  .alias-card {
    flex-direction: column;
    align-items: stretch;
  }
  .alias-actions {
    justify-content: flex-end;
    padding-top: 8px;
    border-top: 1px solid var(--surface-subtle);
  }
}
