/* =========================================
 * 共享 CSS - 基础样式、变量、组件
 * ========================================= */

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #ff6b9d;
  --primary-dark: #e85a8a;
  --primary-light: #ffd6e5;
  --secondary: #c44569;
  --accent: #ffd93d;
  --bg: #fff8fb;
  --bg-card: #ffffff;
  --bg-soft: #fef0f5;
  --text: #2d2d3a;
  --text-soft: #6b6b7e;
  --text-muted: #9999a6;
  --border: #eee2eb;
  --shadow-sm: 0 2px 6px rgba(196, 69, 105, 0.06);
  --shadow: 0 6px 20px rgba(196, 69, 105, 0.08);
  --shadow-lg: 0 12px 32px rgba(196, 69, 105, 0.16);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --gradient-primary: linear-gradient(135deg, #ff6b9d 0%, #c44569 100%);
  --gradient-warm: linear-gradient(135deg, #ffd93d 0%, #ff9a76 50%, #ff6b9d 100%);
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: 14px;
}

img { max-width: 100%; display: block; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: #f5f5f7;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--gradient-primary); color: #fff; }
.btn-secondary { background: #f1f5f9; color: #475569; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warn { background: var(--warning); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost { background: transparent; color: var(--primary-dark); padding: 4px 8px; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
}
.btn-icon:hover { background: var(--bg-soft); color: var(--text); }

/* ===== Form ===== */
.form-row {
  margin-bottom: 14px;
}
.form-row label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}
.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="password"],
.form-row input[type="email"],
.form-row input[type="url"],
.form-row textarea,
.form-row select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.form-row input:focus,
.form-row textarea:focus,
.form-row select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 107, 157, 0.12);
}
.form-row textarea { resize: vertical; min-height: 80px; }
.form-row .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== Card ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.card-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.card-header .actions {
  display: flex;
  gap: 8px;
}

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 10px;
  color: #fff;
  background: var(--info);
  font-weight: 500;
}

/* ===== Tables ===== */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid var(--border);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 600px;
}
.table th,
.table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th {
  background: #fafafa;
  font-weight: 600;
  color: var(--text-soft);
  font-size: 12px;
}
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #fff8fb; }
.table .row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.pagination button {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}
.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.pagination button.active {
  background: var(--gradient-primary);
  color: #fff;
  border-color: var(--primary);
}

/* ===== Search ===== */
.search-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.search-bar input {
  flex: 1;
  min-width: 160px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
}

/* ===== Empty ===== */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }

/* ===== Loading ===== */
.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadein 0.2s;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow: auto;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: zoomin 0.2s;
}
@keyframes zoomin { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-card.wide { max-width: 720px; }
.modal-card h3 {
  margin: 0 0 16px;
  font-size: 18px;
}
.modal-card .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ===== Avatar ===== */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 50%;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar-sm { width: 28px; height: 28px; font-size: 14px; }
.avatar-md { width: 40px; height: 40px; font-size: 18px; }
.avatar-lg { width: 56px; height: 56px; font-size: 26px; }
.avatar-xl { width: 80px; height: 80px; font-size: 36px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ===== Stat card ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 18px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.stat-card .label {
  font-size: 12px;
  color: var(--text-soft);
  margin-bottom: 8px;
}
.stat-card .value {
  font-size: 26px;
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: transparent;
}
.stat-card .extra { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== Toast ===== */
.toast { z-index: 9999; }

/* ===== Switch ===== */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #d4d4d8;
  border-radius: 999px;
  transition: 0.2s;
}
.switch .slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider:before { transform: translateX(20px); }

/* ===== Radio group ===== */
.radio-group {
  display: inline-flex;
  gap: 8px;
  background: #f5f5f7;
  padding: 4px;
  border-radius: 999px;
}
.radio-group label {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-soft);
  user-select: none;
}
.radio-group label.active {
  background: #fff;
  color: var(--primary-dark);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.radio-group input { display: none; }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}
.tabs button {
  background: transparent;
  padding: 10px 14px;
  color: var(--text-soft);
  font-size: 14px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs button.active {
  color: var(--primary-dark);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ===== Avatar picker ===== */
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}
.avatar-grid .item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  font-size: 20px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  cursor: pointer;
  margin: 0 auto;
}
.avatar-grid .item.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* ===== Utilities ===== */
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.center { display: flex; align-items: center; justify-content: center; }
.between { display: flex; align-items: center; justify-content: space-between; }
.text-muted { color: var(--text-muted); }
.text-soft { color: var(--text-soft); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-lg { font-size: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.hidden { display: none !important; }
.scroll-x { overflow-x: auto; }
.ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* responsive */
@media (max-width: 768px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 14px; }
  .avatar-grid { grid-template-columns: repeat(6, 1fr); }
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
