/* ===== Design tokens ===== */
:root {
  --brand: #4f46e5;
  --brand-600: #4338ca;
  --brand-700: #3730a3;
  --brand-soft: #eef2ff;
  --teal: #0d9488;
  --teal-soft: #ecfdf5;
  --ink: #0f172a;
  --ink-2: #1e293b;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --line: #e6eaf2;
  --line-2: #d7ddea;
  --bg: #f4f6fb;
  --panel: #ffffff;
  --green: #16a34a;
  --green-soft: #ecfdf3;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 10px 30px -12px rgba(15, 23, 42, .18);
  --shadow-lg: 0 28px 70px -20px rgba(15, 23, 42, .28);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; }
.icon { width: 18px; height: 18px; flex: none; }
ul, ol { margin: 0; padding: 0; list-style: none; }

::selection { background: #c7d2fe; }

/* ===== Scrollbars ===== */
* { scrollbar-width: thin; scrollbar-color: #c8d0df transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: #c8d0df; border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #aab5c9; border: 2px solid transparent; background-clip: content-box; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 12px;
  padding: 10px 16px; font-size: 14px; font-weight: 600; line-height: 1.2;
  background: #fff; color: var(--ink-2); border-color: var(--line-2);
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
  white-space: nowrap; user-select: none;
}
.btn:hover { background: #f8fafc; border-color: #c3cbdb; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 8px 18px -8px rgba(79, 70, 229, .7); }
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn-soft { background: var(--brand-soft); border-color: transparent; color: var(--brand-600); }
.btn-soft:hover { background: #e0e7ff; border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #eef2f7; border-color: transparent; color: var(--ink); }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--red); }
.btn-danger:hover { background: var(--red-soft); border-color: #fca5a5; }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-sm { padding: 7px 11px; font-size: 12.5px; border-radius: 9px; }
.btn-lg { padding: 13px 22px; font-size: 15px; border-radius: 13px; }
.btn-block { width: 100%; }
.btn .icon { width: 16px; height: 16px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--muted);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: #eef2f7; color: var(--ink); }
.icon-btn.danger:hover { background: var(--red-soft); color: var(--red); }
.icon-btn .icon { width: 18px; height: 18px; }

/* ===== Forms ===== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--muted-2); }
.input, .textarea, .select {
  width: 100%; border: 1px solid var(--line-2); background: #fff;
  border-radius: 11px; padding: 10px 12px; font-size: 14px; outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.input::placeholder, .textarea::placeholder { color: #a2adc0; }
.input:focus, .textarea:focus, .select:focus {
  border-color: #a5b4fc; box-shadow: 0 0 0 4px rgba(79, 70, 229, .1);
}
.textarea { resize: vertical; min-height: 84px; line-height: 1.6; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
.input-lg { padding: 12px 14px; font-size: 15px; border-radius: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-error { color: var(--red); font-size: 13px; min-height: 20px; }
.form-success { color: var(--green); font-size: 13px; }

.switch { position: relative; display: inline-flex; align-items: center; width: 40px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 20px; background: #cbd5e1; transition: background .18s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: #fff; top: 3px; left: 3px; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .18s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ===== Badges / dots ===== */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; line-height: 1.5; background: #eef2f7; color: var(--muted); white-space: nowrap; }
.badge-green { background: var(--green-soft); color: #15803d; }
.badge-amber { background: var(--amber-soft); color: #b45309; }
.badge-red { background: var(--red-soft); color: #b91c1c; }
.badge-blue { background: var(--brand-soft); color: var(--brand-600); }
.badge-gray { background: #f1f5f9; color: #64748b; }
.stars { display: inline-flex; gap: 1px; color: #e2e8f0; font-size: 13px; line-height: 1; letter-spacing: .5px; }
.stars .on { color: #f59e0b; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.dot-green { color: var(--green); background: var(--green); }
.dot-amber { color: var(--amber); background: var(--amber); }
.dot-gray { color: #94a3b8; background: #94a3b8; }
.dot-red { color: var(--red); background: var(--red); }
.pulse { animation: pulse 2.2s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, .35); } 50% { box-shadow: 0 0 0 5px rgba(22, 163, 74, 0); } }

.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; border-radius: 12px; font-weight: 700; font-size: 15px;
  color: #fff; background: linear-gradient(135deg, #6366f1, #8b5cf6);
  letter-spacing: .5px; user-select: none;
}
.avatar-sm { width: 32px; height: 32px; border-radius: 9px; font-size: 12px; }
.avatar-lg { width: 52px; height: 52px; border-radius: 15px; font-size: 19px; }

/* ===== Cards / panels ===== */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }

.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 42px 20px; color: var(--muted); gap: 8px; }
.empty .empty-icon { width: 54px; height: 54px; border-radius: 18px; background: #eef2ff; color: var(--brand); display: grid; place-items: center; margin-bottom: 4px; }
.empty .empty-icon .icon { width: 26px; height: 26px; }
.empty h4 { color: var(--ink-2); font-size: 15px; }
.empty p { font-size: 13px; max-width: 280px; }

/* ===== Toast ===== */
.toast-stack { position: fixed; z-index: 120; top: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; pointer-events: none; width: min(92vw, 420px); }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px; border-radius: 12px; background: #111827; color: #fff; box-shadow: var(--shadow-lg); font-size: 13.5px; animation: toastIn .18s ease-out; }
.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }
.toast.warning { background: #92400e; }
.toast .icon { width: 17px; height: 17px; flex: none; margin-top: 1px; }
.toast.out { animation: toastOut .2s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px) scale(.98); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px) scale(.98); } }

/* ===== Modal ===== */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(15, 23, 42, .5); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fadeIn .15s; }
.modal { width: min(100%, 480px); max-height: 90vh; overflow: auto; background: #fff; border-radius: 20px; box-shadow: var(--shadow-lg); animation: modalIn .18s ease-out; }
.modal.modal-wide { width: min(100%, 680px); }
.modal-header { display: flex; align-items: flex-start; gap: 12px; padding: 20px 22px 0; }
.modal-header h3 { font-size: 17px; }
.modal-header p { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.modal-body { padding: 18px 22px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 0 22px 22px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ===== Drawer ===== */
.drawer-backdrop { position: fixed; inset: 0; z-index: 95; background: rgba(15, 23, 42, .42); display: flex; justify-content: flex-end; animation: fadeIn .15s; }
.drawer { width: min(100%, 620px); height: 100%; background: #fff; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: drawerIn .2s ease-out; }
@keyframes drawerIn { from { transform: translateX(20px); opacity: .6; } }
.drawer-header { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-header h3 { font-size: 16px; }
.drawer-body { flex: 1; overflow: auto; padding: 20px; }
.drawer-footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }

/* ===== Misc ===== */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.copy-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 7px; background: #f1f5f9; border: 1px dashed #cbd5e1; font-family: var(--mono); font-size: 12px; color: #475569; max-width: 100%; overflow: hidden; }
.copy-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spin { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.spin.dark { border-color: #cbd5e1; border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-block { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 60px 20px; color: var(--muted); font-size: 13px; }

@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
  .modal { border-radius: 16px; }
}

/* Image lightbox */
.image-lightbox { position: fixed; inset: 0; z-index: 300; background: rgba(9, 13, 24, .82); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; padding: 28px; animation: fadeIn .16s ease; }
.image-lightbox img { max-width: min(92vw, 1100px); max-height: 86vh; border-radius: 14px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.6); background: #fff; object-fit: contain; }
.image-lightbox-close { position: absolute; top: 18px; right: 18px; width: 40px; height: 40px; border-radius: 12px; border: 0; background: rgba(255,255,255,.14); color: #fff; display: grid; place-items: center; cursor: pointer; }
.image-lightbox-close:hover { background: rgba(255,255,255,.24); }
.image-lightbox-close .icon { width: 20px; height: 20px; }
