/* ── Design tokens ──────────────────────────────────────────────────────────── */
:root {
  /* Brand */
  --primary:         #2563eb;
  --primary-hover:   #1d4ed8;
  --primary-active:  #1e40af;
  --primary-soft:    #eff6ff;
  --primary-light:   #dbeafe;

  /* Semantic */
  --danger:          #dc2626;
  --danger-hover:    #b91c1c;
  --danger-soft:     #fef2f2;
  --danger-light:    #fecaca;
  --success:         #059669;
  --success-soft:    #ecfdf5;
  --success-light:   #a7f3d0;
  --warning:         #d97706;
  --warning-soft:    #fffbeb;
  --warning-light:   #fde68a;

  /* Surface */
  --bg:              #f4f7fb;
  --surface:         #ffffff;
  --surface-raised:  #f8fafc;
  --surface-low:     #f1f5f9;

  /* Border */
  --border:          #e4e8f0;
  --border-hover:    #c7d2e0;
  --border-strong:   #b0bbc9;

  /* Text */
  --text:            #111827;
  --text-secondary:  #374151;
  --text-muted:      #6b7280;
  --text-subtle:     #9ca3af;
  --text-disabled:   #d1d5db;

  /* Radius */
  --radius-xs:  4px;
  --radius-sm:  6px;
  --radius:     8px;
  --radius-md:  10px;
  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-2xl: 20px;

  /* Shadow */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow:    0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 28px rgba(0,0,0,.10), 0 4px 8px rgba(0,0,0,.04);
  --shadow-xl: 0 24px 56px rgba(0,0,0,.12), 0 8px 16px rgba(0,0,0,.06);

  /* Back-compat aliases (used by chat.css / older admin pages) */
  --muted:         var(--text-muted);
  --text-light:    var(--text-subtle);
  --surface-2:     var(--surface-low);
  --surface-high:  var(--surface-raised);
  --secondary-soft:#e0e7ff;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', Arial, sans-serif;
  background: var(--bg);
  color: var(--text-secondary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button { font-family: inherit; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background .15s ease, border-color .15s ease,
              color .15s ease, box-shadow .15s ease, transform .1s ease;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 3px rgba(37,99,235,.25);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 10px rgba(37,99,235,.30);
}

.btn-ghost {
  background: var(--surface);
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-low);
  border-color: var(--border-hover);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 1px 3px rgba(220,38,38,.2);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  box-shadow: 0 4px 10px rgba(220,38,38,.25);
}

.btn-soft-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger-light);
}
.btn-soft-danger:hover:not(:disabled) {
  background: #fee2e2;
}

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { width: 100%; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group  { margin-bottom: 20px; }
.form-label  {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 7px;
  letter-spacing: .01em;
}
.form-input, .input, .textarea, .select {
  display: block;
  width: 100%;
  padding: 10px 13px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  color: var(--text);
  line-height: 1.5;
  transition: border-color .15s, box-shadow .15s;
}
.form-input::placeholder, .input::placeholder, .textarea::placeholder {
  color: var(--text-subtle);
}
.form-input:focus, .input:focus, .textarea:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.textarea { min-height: 100px; resize: vertical; }

/* ── Alert ──────────────────────────────────────────────────────────────────── */
.alert {
  padding: 11px 15px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 18px;
  display: none;
  border: 1px solid transparent;
}
.alert.show { display: block; }
.alert-error   {
  background: var(--danger-soft);
  color: #991b1b;
  border-color: var(--danger-light);
}
.alert-success {
  background: var(--success-soft);
  color: #065f46;
  border-color: var(--success-light);
}

/* ── Badge ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-muted   { background: var(--surface-low);  color: var(--text-muted); }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
}
.modal-box {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 32px 28px 26px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-xl);
}
.modal-title  { font-size: 17px; font-weight: 700; color: var(--text); margin-bottom: 10px; }
.modal-body   { font-size: 14px; color: var(--text-muted); margin-bottom: 26px; line-height: 1.7; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; }

/* ── Utilities ──────────────────────────────────────────────────────────────── */
.text-muted   { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.small        { font-size: 12px; }
