/* SourceBinding uses the same calm, right-side workspace language as the
   document structure panel. It never changes page geometry while opening. */
.source-binding-drawer {
  position: fixed;
  z-index: 2147483200;
  top: var(--udoc-editor-top, 0);
  right: 0;
  width: min(408px, calc(100vw - 24px));
  height: 100dvh;
  box-sizing: border-box;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  color: #263244;
  background: #fff;
  border-left: 1px solid #dce4f0;
  box-shadow: -18px 0 46px rgba(29, 52, 85, .14);
  font: 14px/1.5 "Noto Sans SC", "Microsoft YaHei", sans-serif;
  contain: layout paint;
}
.source-binding-drawer[hidden], .source-conflict-backdrop[hidden] { display: none !important; }
.source-drawer-header {
  display: grid;
  grid-template-columns: 44px 1fr 36px;
  gap: 12px;
  align-items: center;
  min-height: 78px;
  padding: 14px 16px;
  border-bottom: 1px solid #e5eaf2;
}
.source-drawer-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  color: #0b57d0;
  background: #e8f0fe;
  font-size: 24px;
  font-weight: 700;
}
.source-drawer-header h2 { margin: 0; font-size: 18px; color: #202124; }
.source-drawer-header p { margin: 2px 0 0; color: #747c88; font-size: 12px; }
.source-drawer-header > button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #5f6368;
  font-size: 24px;
  cursor: pointer;
}
.source-drawer-header > button:hover { background: #f0f3f8; }
.source-drawer-body { min-height: 0; overflow: auto; padding: 18px 18px 24px; }
.source-drawer-body [hidden] { display: none !important; }
.source-target-label {
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid #d6e2f5;
  border-radius: 11px;
  color: #174ea6;
  background: #f4f8ff;
  font-weight: 650;
}
.source-drawer-body label { display: grid; gap: 6px; margin: 0 0 15px; color: #3c4043; font-weight: 600; }
.source-drawer-body label span { color: #7b8492; font-size: 11px; font-weight: 400; }
.source-drawer-body input, .source-drawer-body select {
  width: 100%;
  height: 40px;
  box-sizing: border-box;
  padding: 0 11px;
  border: 1px solid #cbd5e3;
  border-radius: 9px;
  outline: none;
  color: #253149;
  background: #fff;
  font: inherit;
  font-weight: 400;
}
.source-drawer-body input:focus, .source-drawer-body select:focus {
  border-color: #1a73e8;
  box-shadow: 0 0 0 3px rgba(26, 115, 232, .12);
}
.source-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.source-status-card {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 10px;
  padding: 14px;
  border: 1px solid #e0e6ef;
  border-radius: 12px;
  background: #f8fafc;
}
.source-status-card b { color: #27354a; }
.source-status-card p { margin: 3px 0 0; color: #6f7885; font-size: 12px; }
.source-status-dot { width: 9px; height: 9px; margin-top: 6px; border-radius: 50%; background: #9aa0a6; }
.source-binding-drawer[data-status="ready"] .source-status-dot { background: #1e8e3e; }
.source-binding-drawer[data-status="refreshing"] .source-status-dot { background: #1a73e8; animation: source-pulse 1s infinite; }
.source-binding-drawer[data-status="conflict"] .source-status-dot,
.source-binding-drawer[data-status="local"] .source-status-dot { background: #f9ab00; }
.source-binding-drawer[data-status="error"] .source-status-dot { background: #d93025; }
@keyframes source-pulse { 50% { opacity: .28; transform: scale(.72); } }
.source-drawer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 13px 16px;
  border-top: 1px solid #e5eaf2;
  background: #fff;
}
.source-drawer-actions button, .source-conflict-dialog button {
  min-height: 38px;
  padding: 0 15px;
  border: 1px solid #c7d1df;
  border-radius: 9px;
  color: #24549a;
  background: #fff;
  font: 600 14px/1 inherit;
  cursor: pointer;
}
.source-drawer-actions button.primary, .source-conflict-dialog button.primary {
  border-color: #0b57d0;
  color: #fff;
  background: #0b57d0;
}
.source-drawer-actions button:disabled { opacity: .55; cursor: wait; }

/* The badge is paint-only, so binding a source never changes Typst geometry. */
[data-source-binding] { position: relative; }
[data-source-binding]::before {
  content: "↻";
  position: absolute;
  z-index: 2147482000;
  top: -10px;
  right: -10px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  box-sizing: border-box;
  border: 1px solid #b9cff3;
  border-radius: 50%;
  color: #0b57d0;
  background: #fff;
  box-shadow: 0 2px 8px rgba(31, 61, 105, .17);
  font: 700 14px/1 sans-serif;
  pointer-events: auto;
}
[data-source-status="refreshing"]::before { animation: source-spin .8s linear infinite; }
[data-source-status="conflict"]::before, [data-source-status="local"]::before { color: #b06000; border-color: #f9c66b; }
[data-source-status="error"]::before { color: #c5221f; border-color: #efb6b2; }
@keyframes source-spin { to { transform: rotate(360deg); } }
.source-json, .source-code {
  margin: 0;
  padding: 14px;
  overflow: auto;
  border-radius: 9px;
  color: #d9e5f7;
  background: #111827;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 13px/1.6 "Cascadia Code", Consolas, monospace;
}

.source-conflict-backdrop {
  position: fixed;
  z-index: 2147483400;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(32, 33, 36, .42);
  backdrop-filter: blur(2px);
}
.source-conflict-dialog {
  width: min(900px, 100%);
  max-height: min(700px, 90dvh);
  overflow: auto;
  padding: 22px;
  border: 1px solid #dde4ee;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(20, 35, 60, .28);
}
.source-conflict-dialog small { color: #0b57d0; font-weight: 700; letter-spacing: .08em; }
.source-conflict-dialog h2 { margin: 3px 0 0; color: #202124; font-size: 22px; }
.source-conflict-dialog > p { color: #5f6368; }
.source-conflict-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.source-conflict-grid > div { min-width: 0; padding: 12px; border: 1px solid #e1e7ef; border-radius: 12px; }
.source-conflict-grid pre { max-height: 320px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: #364152; font: 12px/1.55 Consolas, monospace; }
.source-conflict-dialog footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
@media (max-width: 700px) { .source-conflict-grid, .source-form-row { grid-template-columns: 1fr; } }
