:root {
  /* Feishu / Lark Web Design Tokens */
  --brand: #3370ff;
  --brand-hover: #245bdb;
  --brand-active: #1b49b8;
  --brand-soft: #ebf1ff;
  --brand-bubble: #d9e6ff;

  --bg-app: #f5f6f7;
  --bg-rail: #f0f2f5;
  --bg-surface: #ffffff;
  --bg-hover: #f2f3f5;
  --bg-subtle: #f7f8fa;
  --bg-bubble-other: #eff0f1;

  --border: #dee0e3;
  --border-light: #edeff2;

  --text-primary: #1f2329;
  --text-secondary: #646a73;
  --text-muted: #8f959e;
  --text-inverse: #ffffff;

  --success: #34c724;
  --warning: #ff8800;
  --warning-bg: #fff7e6;
  --danger: #f54a45;
  --danger-bg: #ffeceb;
  --purple: #6425d0;
  --purple-bg: #f4f0ff;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 8px rgba(31, 35, 41, 0.06);
  --shadow-md: 0 6px 20px rgba(31, 35, 41, 0.10);
  --shadow-lg: 0 12px 36px rgba(31, 35, 41, 0.16);

  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --rail-w: 64px;
  --sidebar-w: 292px;
  --drawer-w: 320px;
  --header-h: 60px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-app);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

a {
  color: var(--brand);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

/* Custom thin scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(31, 35, 41, 0.16);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(31, 35, 41, 0.28);
}

/* Reusable Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
}

.btn-secondary {
  background: #fff;
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: #d83931;
}

.btn-ghost {
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

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

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.btn-icon.active {
  background: var(--brand-soft);
  color: var(--brand);
}

/* Badges / Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  line-height: 16px;
  white-space: nowrap;
}
.badge-blue { background: var(--brand-soft); color: var(--brand); }
.badge-red { background: var(--danger-bg); color: var(--danger); }
.badge-silent { background: #fff2e8; color: #d4380d; border: 1px solid #ffbb96; }
.badge-warn { background: var(--warning-bg); color: #d46b08; }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-gray { background: #eff0f1; color: var(--text-secondary); }
.badge-green { background: #e8ffea; color: #009a29; }

/* Avatar */
.avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
  user-select: none;
}
.avatar-sm { width: 28px; height: 28px; font-size: 12px; }
.avatar-md { width: 38px; height: 38px; font-size: 14px; }
.avatar-lg { width: 46px; height: 46px; font-size: 16px; }
.avatar-xl { width: 64px; height: 64px; font-size: 22px; }
.avatar-square { border-radius: 10px; }
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}

.presence-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #bbbfca;
}
.avatar-lg:not(.avatar-square) .presence-dot {
  right: 1px;
  bottom: 1px;
  width: 11px;
  height: 11px;
}
.avatar-xl:not(.avatar-square) .presence-dot {
  right: 3px;
  bottom: 3px;
  width: 13px;
  height: 13px;
}
.presence-dot.online {
  background: var(--success);
}

input[type="range"],
input[type="checkbox"] {
  accent-color: var(--brand);
}

/* Form controls */
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(51, 112, 255, 0.14);
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}
.form-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-slider {
  position: absolute;
  inset: 0;
  background: #c9cdd4;
  border-radius: 999px;
  transition: 0.2s;
  cursor: pointer;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}
.switch input:checked + .switch-slider {
  background: var(--brand);
}
.switch input:checked + .switch-slider::before {
  transform: translateX(16px);
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10050;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #1f2329;
  color: #fff;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.18s ease-out;
}
.toast.success { background: #1e7e34; }
.toast.error { background: #d83931; }
.toast.warn { background: #c96a00; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
