/* AI Draft panel — full-viewport, no page scroll */

.grounded-draft-overlay {
  position: fixed;
  inset: 0;
  z-index: 100060;
  display: flex;
  background: rgba(15, 23, 42, 0.45);
  /* Fill the actual visible frame (not 100dvh, which can run under browser chrome). */
  width: auto;
  height: auto;
}

.grounded-draft-panel {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  color: var(--text-primary, var(--m-text, #0f172a));
  background: var(--surface-1, var(--m-surface, #fff));
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.gd-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border, #e2e8f0);
  flex-shrink: 0;
  min-height: 44px;
}

.gd-header-copy {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
}

.gd-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.gd-header-link {
  border: 0;
  background: transparent;
  color: #2563eb;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
}

.gd-header-link:hover {
  background: #eff6ff;
}

.gd-template-rail {
  flex-shrink: 0;
  padding: 8px 14px 10px;
  border-bottom: 1px solid var(--border, #e2e8f0);
  background:
    radial-gradient(1200px 120px at 0% 0%, rgba(37, 99, 235, 0.08), transparent 55%),
    linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
}

.gd-template-rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.gd-template-rail-head strong {
  display: block;
  font-size: 12px;
  font-weight: 750;
  color: #0f172a;
}

.gd-template-rail-head span {
  display: block;
  font-size: 11px;
  color: #64748b;
}

.gd-template-save-btn {
  flex-shrink: 0;
}

.gd-template-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.gd-template-chip {
  flex: 0 0 auto;
  display: grid;
  gap: 1px;
  min-width: 132px;
  max-width: 180px;
  padding: 8px 10px;
  border: 1px solid #dbe4f0;
  border-radius: 10px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.gd-template-chip:hover {
  border-color: #93c5fd;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.1);
  transform: translateY(-1px);
}

.gd-template-chip.is-active {
  border-color: #2563eb;
  background: linear-gradient(180deg, #eff6ff 0%, #ffffff 100%);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.gd-template-chip__name {
  font-size: 12px;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gd-template-chip__meta {
  font-size: 10px;
  font-weight: 600;
  color: #64748b;
}

.gd-template-manager {
  width: min(560px, 100%);
}

.gd-template-save-form {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  background: #f8fafc;
}

.gd-template-save-form label {
  display: grid;
  gap: 4px;
  font-size: 11px;
  font-weight: 650;
  color: #64748b;
}

.gd-template-save-form input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  color: #0f172a;
  background: #fff;
}

.gd-template-include {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 12px !important;
  font-weight: 500 !important;
  color: #334155 !important;
}

.gd-template-include input {
  width: 14px;
  height: 14px;
  accent-color: #2563eb;
}

.gd-template-list {
  display: grid;
  gap: 8px;
  max-height: min(42vh, 320px);
  overflow: auto;
}

.gd-template-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #fff;
}

.gd-template-row.is-active {
  border-color: #93c5fd;
  background: #f8fbff;
}

.gd-template-row__main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.gd-template-row__main strong {
  font-size: 13px;
  color: #0f172a;
}

.gd-template-row__main span {
  font-size: 11px;
  color: #64748b;
}

.gd-template-row__preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gd-template-row__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

.gd-generate-hint {
  margin-top: 4px;
  text-align: center;
  font-size: 10px;
}

.gd-empty-badge {
  display: inline-flex;
  align-items: center;
  justify-self: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #1d4ed8;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
}

.gd-empty-steps {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 4px;
}

.gd-empty-steps span {
  padding: 4px 8px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid #e2e8f0;
  color: #475569;
  font-size: 11px;
  font-weight: 650;
}

.gd-header h2,
.gd-header p,
.gd-grounding h3,
.gd-missing h3,
.gd-empty-state h3 {
  margin: 0;
}

.gd-header h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary, #0f172a);
  white-space: nowrap;
}

.gd-header p {
  color: var(--text-secondary, var(--m-muted, #64748b));
  font-size: 12px;
  line-height: 1.35;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.gd-status-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  color: #1e40af !important;
  -webkit-text-fill-color: #1e40af !important;
  background: #eff6ff !important;
  border: 1px solid #bfdbfe;
  white-space: nowrap;
}

.gd-icon-btn {
  border: 0;
  padding: 4px 10px;
  color: var(--text-secondary, #64748b);
  background: transparent;
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.gd-icon-btn:hover {
  background: var(--hover-bg, #f1f5f9);
  color: var(--text-primary, #0f172a);
}

.gd-layout {
  display: grid;
  grid-template-columns: minmax(300px, 34%) minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.gd-controls {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--surface-2, var(--m-bg, #f7f9fc));
  border-right: 1px solid var(--border, #e2e8f0);
}

.gd-controls-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 8px 12px 6px;
}

.gd-controls-footer {
  flex-shrink: 0;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border, #e2e8f0);
  background: var(--surface-2, var(--m-bg, #f7f9fc));
}

.gd-controls label,
.gd-editor label,
.gd-subject-wrap > label,
.gd-body-wrap > label {
  display: grid;
  gap: 4px;
  color: var(--text-secondary, #64748b);
  font-size: 11px;
  font-weight: 650;
}

.gd-subject-wrap > label,
.gd-body-wrap > label {
  display: block;
  margin: 0;
}

.gd-controls input,
.gd-controls select,
.gd-controls textarea,
.gd-editor input,
.gd-editor textarea {
  box-sizing: border-box;
  width: 100%;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: var(--mm-radius-sm, 8px);
  padding: 5px 8px;
  color: var(--text-primary, #0f172a);
  background: var(--surface-1, #fff);
  font: inherit;
  font-weight: 400;
  font-size: 12px;
  line-height: 1.35;
  min-height: 30px;
}

.gd-recipient {
  display: grid;
  gap: 2px;
}

.gd-recipient .gd-control-help {
  font-size: 10px;
  line-height: 1.3;
}

.gd-recipient-card {
  display: grid;
  gap: 1px;
  padding: 5px 8px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: var(--mm-radius-sm, 8px);
  background: var(--surface-1, #fff);
}

.gd-recipient-card strong {
  color: var(--text-primary, #0f172a);
  font-size: 12px;
  font-weight: 700;
}

.gd-recipient-card span {
  color: var(--text-secondary, #64748b);
  font-size: 11px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.gd-controls textarea[data-gd-objective] {
  min-height: 52px;
  max-height: 72px;
  resize: none;
}

.gd-controls input:focus,
.gd-controls select:focus,
.gd-controls textarea:focus,
.gd-editor input:focus,
.gd-editor textarea:focus,
.grounded-draft-panel button:focus-visible,
.gd-grounding summary:focus-visible {
  outline: none;
  box-shadow: var(--mm-focus-ring, 0 0 0 3px rgba(37, 99, 235, 0.2));
  border-color: var(--mm-accent, #2563eb);
}

.gd-control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.gd-cta-field {
  display: grid;
  gap: 3px;
}

.gd-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 20px;
}

.gd-cta-label {
  color: var(--text-secondary, #64748b);
  font-size: 10px;
  font-weight: 650;
}

.gd-gear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  flex: 0 0 auto;
}

.gd-gear-btn:hover,
.gd-gear-btn:focus-visible {
  color: #2563eb;
  background: #eff6ff;
  border-color: #bfdbfe;
  outline: none;
}

.gd-gear-btn svg {
  display: block;
}

.gd-config-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.35);
}

.gd-config-overlay[hidden] {
  display: none !important;
}

.gd-config-panel {
  width: min(420px, 100%);
  max-height: min(80dvh, 560px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px 16px;
  border-radius: 12px;
  border: 1px solid var(--border, #e2e8f0);
  background: var(--surface-1, #fff);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.22);
  box-sizing: border-box;
}

.gd-config-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.gd-config-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary, #0f172a);
}

.gd-config-panel textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  box-sizing: border-box;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-primary, #0f172a);
  background: var(--surface-1, #fff);
}

.gd-config-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.gd-config-actions-spacer {
  flex: 1 1 auto;
}

.gd-config-actions .gd-primary {
  width: auto;
}

.gd-cta-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: min-content;
  align-content: start;
  gap: 1px 6px;
  padding: 3px 6px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: var(--mm-radius-sm, 8px);
  background: var(--surface-1, #fff);
  /* Show all 8 defaults (4 rows × 2 cols) without inner scroll; sidebar scrolls if needed. */
  overflow: visible;
}

.gd-cta-option {
  display: flex !important;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 1px 1px;
  border-radius: 4px;
  color: var(--text-primary, #0f172a) !important;
  font-size: 10.5px !important;
  font-weight: 500 !important;
  line-height: 1.05;
  cursor: pointer;
}

.gd-cta-option:hover {
  background: var(--hover-bg, #f1f5f9);
}

.gd-cta-option input {
  width: 12px !important;
  height: 12px;
  margin: 0;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  accent-color: var(--mm-accent, #2563eb);
  flex: 0 0 auto;
  box-shadow: none !important;
  cursor: pointer;
}

.gd-cta-custom {
  margin-top: 0;
  min-height: 28px !important;
  padding: 4px 8px !important;
  font-size: 11px !important;
}

.gd-cta-custom[hidden] {
  display: none !important;
}

.gd-cta-buttons-toggle {
  display: flex !important;
  align-items: center;
  gap: 6px;
  margin: 2px 0 0;
  color: var(--text-secondary, #64748b) !important;
  font-size: 10px !important;
  font-weight: 600 !important;
  line-height: 1.35;
  cursor: pointer;
}

.gd-cta-buttons-toggle input {
  width: 12px !important;
  height: 12px;
  min-height: 12px;
  margin: 0;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  accent-color: var(--mm-accent, #2563eb);
  flex: 0 0 auto;
  box-shadow: none !important;
  cursor: pointer;
}

.gd-cta-url-fields {
  display: grid;
  gap: 4px;
  margin-top: 2px;
  padding: 6px 8px;
  border: 1px dashed var(--border, #e2e8f0);
  border-radius: var(--mm-radius-sm, 8px);
  background: var(--surface-1, #fff);
}

.gd-cta-url-fields[hidden] {
  display: none !important;
}

.gd-cta-url-fields label {
  gap: 2px !important;
  font-size: 10px !important;
}

.gd-cta-url-fields input {
  min-height: 28px !important;
  font-size: 11px !important;
}

.gd-booking-card {
  display: grid;
  gap: 8px;
  margin-top: 4px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #bfdbfe;
  background: linear-gradient(180deg, #eff6ff 0%, #fff 85%);
}

.gd-booking-card[hidden] {
  display: none !important;
}

.gd-booking-card__head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.gd-booking-card__icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #dbeafe;
  font-size: 14px;
  flex-shrink: 0;
}

.gd-booking-card__head strong {
  display: block;
  font-size: 12px;
  font-weight: 750;
  color: #1e3a8a;
}

.gd-booking-card__head .gd-control-help {
  margin-top: 2px;
  font-size: 10.5px;
  color: #64748b;
}

.gd-booking-card select {
  min-height: 32px !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  border-color: #93c5fd !important;
  background: #fff !important;
}

html[data-theme="dark"] .gd-booking-card {
  border-color: #1e3a8a;
  background: linear-gradient(180deg, #172554 0%, #0f172a 85%);
}

html[data-theme="dark"] .gd-booking-card__head strong {
  color: #bfdbfe;
}

html[data-theme="dark"] .gd-booking-card__icon {
  background: #1e3a8a;
}

html[data-theme="dark"] .gd-booking-card select {
  border-color: #1e40af !important;
  background: #0f172a !important;
  color: #e6e6e6 !important;
}

.gd-extras {
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  background: var(--surface-1, #fff);
  padding: 0 8px;
}

.gd-extras summary {
  cursor: pointer;
  list-style: none;
  padding: 5px 0;
  color: var(--text-secondary, #64748b);
  font-size: 10px;
  font-weight: 650;
}

.gd-extras summary::-webkit-details-marker {
  display: none;
}

.gd-extras[open] summary {
  border-bottom: 1px solid var(--border, #e2e8f0);
  margin-bottom: 8px;
}

.gd-extras label {
  margin-bottom: 8px;
}

.gd-primary,
.grounded-draft-panel .btn.primary {
  border: 0 !important;
  padding: 8px 12px !important;
  color: #fff !important;
  -webkit-text-fill-color: #fff !important;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
  border-radius: var(--mm-radius-sm, 8px) !important;
  font-weight: 700 !important;
  cursor: pointer;
  min-height: 34px;
  width: 100%;
}

.gd-actions .gd-primary,
.gd-actions .btn.primary {
  width: auto;
}

.gd-primary:hover:not(:disabled),
.grounded-draft-panel .btn.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;
}

.gd-primary:disabled {
  opacity: 0.55;
  cursor: default;
}

.gd-control-help,
.gd-empty,
.gd-count {
  margin: 0;
  color: var(--text-secondary, #64748b);
  font-size: 11px;
  line-height: 1.4;
}

.gd-workspace {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.gd-workspace-main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px 8px;
}

.gd-empty-state {
  flex: 1;
  display: grid;
  place-content: center;
  gap: 6px;
  min-height: 0;
  padding: 24px;
  text-align: center;
  color: var(--text-secondary, #64748b);
  background: var(--surface-2, #f8fafc);
  border: 1px dashed var(--border, #e2e8f0);
  border-radius: 10px;
}

.gd-empty-state[hidden] {
  display: none !important;
}

.gd-empty-state h3 {
  color: var(--text-primary, #0f172a);
  font-size: 15px;
  font-weight: 700;
}

.gd-empty-state p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  max-width: 36ch;
}

.gd-loading,
.gd-error,
.gd-missing {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.gd-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #1e40af !important;
  -webkit-text-fill-color: #1e40af !important;
  background: #eff6ff !important;
  border: 1px solid #bfdbfe !important;
  min-height: 56px;
  flex: 1;
}

.gd-loading[hidden] {
  display: none !important;
}

.gd-loading-copy {
  display: grid;
  gap: 2px;
}

.gd-loading-copy strong {
  font-size: 13px;
  font-weight: 700;
}

.gd-loading-copy span {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.85;
}

.gd-loading-dots {
  display: flex;
  gap: 7px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-height: 22px;
}

.gd-loading-dots span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #2563eb;
  animation: gd-loading-bounce 1.1s ease-in-out infinite;
}

.gd-loading-dots span:nth-child(2) {
  animation-delay: 0.14s;
  background: #10b981;
}

.gd-loading-dots span:nth-child(3) {
  animation-delay: 0.28s;
  background: #f59e0b;
}

@keyframes gd-loading-bounce {
  0%, 75%, 100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  35% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

.gd-error {
  color: #7f1d1d !important;
  -webkit-text-fill-color: #7f1d1d !important;
  background: #fee2e2 !important;
  border: 1px solid #fca5a5 !important;
}

.gd-missing {
  color: #78350f !important;
  -webkit-text-fill-color: #78350f !important;
  background: #fef3c7 !important;
  border: 1px solid #fbbf24 !important;
  overflow: auto;
  max-height: 30%;
}

.gd-editor {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
}

.gd-editor[hidden] {
  display: none !important;
}

.gd-subject-wrap {
  flex: 0 0 auto;
  display: grid;
  gap: 4px;
}

.gd-body-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gd-editor textarea,
.gd-body-wrap textarea {
  flex: 1 1 auto;
  min-height: 140px;
  height: auto;
  resize: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
}

.gd-editor-footer {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.gd-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.gd-actions .btn,
.gd-insert-choice .btn,
.gd-link-btn {
  min-height: 34px;
}

.gd-actions button:disabled {
  cursor: default;
  opacity: 0.45;
}

.gd-danger-text {
  color: #b42318 !important;
  -webkit-text-fill-color: #b42318 !important;
  background: transparent !important;
  border-color: transparent !important;
}

.gd-insert-choice {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px;
  color: #78350f !important;
  -webkit-text-fill-color: #78350f !important;
  background: #fef3c7 !important;
  border: 1px solid #fbbf24 !important;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 650;
  flex-shrink: 0;
}

.gd-insert-choice span {
  color: #78350f !important;
  -webkit-text-fill-color: #78350f !important;
  flex: 1 1 160px;
}

.gd-insert-choice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.gd-insert-choice .btn,
.gd-insert-choice-actions .btn {
  width: auto !important;
  min-width: 72px;
}

.gd-insert-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: #1e40af !important;
  -webkit-text-fill-color: #1e40af !important;
  background: #eff6ff !important;
  border: 1px solid #bfdbfe !important;
  font-size: 12px;
  font-weight: 650;
  flex-shrink: 0;
}

.gd-insert-loading[hidden] {
  display: none !important;
}

.gd-insert-loading .gd-loading-dots {
  min-height: 16px;
}

.gd-insert-loading .gd-loading-dots span {
  width: 7px;
  height: 7px;
}

.gd-grounding {
  flex: 0 0 auto;
  border-top: 1px solid var(--border, #e2e8f0);
  padding: 0 16px 12px;
  max-height: 36%;
  overflow: auto;
  background: var(--surface-1, #fff);
}

.gd-grounding[hidden] {
  display: none !important;
}

.gd-grounding summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-primary, #0f172a);
  font-size: 12px;
  font-weight: 700;
  padding: 8px 10px;
  margin: 8px 0 6px;
  list-style: none;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
  background: var(--surface-2, #f8fafc);
  user-select: none;
}

.gd-grounding summary::-webkit-details-marker {
  display: none;
}

.gd-grounding summary::marker {
  content: "";
}

.gd-grounding summary:hover {
  background: var(--hover-bg, #f1f5f9);
  border-color: #cbd5e1;
}

.gd-grounding-chevron {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #64748b;
  flex: 0 0 auto;
  transform: rotate(-90deg);
  transition: transform 0.15s ease;
}

.gd-grounding[open] > summary .gd-grounding-chevron {
  transform: rotate(0deg);
}

.gd-grounding-title {
  flex: 1 1 auto;
  min-width: 0;
}

.gd-grounding-action {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  color: #1d4ed8 !important;
  -webkit-text-fill-color: #1d4ed8 !important;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
}

.gd-grounding-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.gd-grounding-grid section {
  min-width: 0;
  padding: 8px 10px;
  background: var(--surface-2, #f8fafc);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px;
}

.gd-grounding h3 {
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--text-primary, #0f172a);
}

.gd-grounding ul,
.gd-missing ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 16px;
  color: var(--text-secondary, #64748b);
  font-size: 11px;
  line-height: 1.4;
}

.gd-grounding li {
  overflow-wrap: anywhere;
}

.gd-grounding li:has(.gd-link-btn) {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.gd-link-btn {
  flex: 0 0 auto;
  padding: 2px 6px;
  color: #2563eb !important;
  -webkit-text-fill-color: #2563eb !important;
  background: transparent !important;
  border: 0 !important;
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

html[data-theme="dark"] .grounded-draft-panel,
html[data-theme="dark"] .gd-header,
html[data-theme="dark"] .gd-controls,
html[data-theme="dark"] .gd-controls-footer,
html[data-theme="dark"] .gd-workspace,
html[data-theme="dark"] .gd-extras,
html[data-theme="dark"] .gd-empty-state,
html[data-theme="dark"] .gd-grounding,
html[data-theme="dark"] .gd-grounding-grid section {
  background: var(--surface-1, #181818) !important;
  color: var(--text-primary, #f0f0f0) !important;
  border-color: rgba(240, 240, 240, 0.18) !important;
}

html[data-theme="dark"] .gd-grounding summary {
  background: var(--surface-2, #1e1e1e) !important;
  border-color: rgba(240, 240, 240, 0.24) !important;
  color: #f0f0f0 !important;
}

html[data-theme="dark"] .gd-grounding-action {
  background: #1e3a5f !important;
  color: #dbeafe !important;
  -webkit-text-fill-color: #dbeafe !important;
  border-color: rgba(96, 165, 250, 0.4) !important;
}

html[data-theme="dark"] .gd-grounding-chevron {
  border-top-color: #8a8a8a;
}

html[data-theme="dark"] .gd-controls,
html[data-theme="dark"] .gd-controls-footer,
html[data-theme="dark"] .gd-empty-state,
html[data-theme="dark"] .gd-grounding-grid section {
  background: var(--surface-2, #1e1e1e) !important;
}

html[data-theme="dark"] .gd-header p,
html[data-theme="dark"] .gd-controls label,
html[data-theme="dark"] .gd-editor label,
html[data-theme="dark"] .gd-control-help,
html[data-theme="dark"] .gd-empty,
html[data-theme="dark"] .gd-count,
html[data-theme="dark"] .gd-extras summary,
html[data-theme="dark"] .gd-empty-state p {
  color: #8a8a8a !important;
  -webkit-text-fill-color: #8a8a8a !important;
}

html[data-theme="dark"] .gd-controls input,
html[data-theme="dark"] .gd-controls select,
html[data-theme="dark"] .gd-controls textarea,
html[data-theme="dark"] .gd-editor input,
html[data-theme="dark"] .gd-editor textarea,
html[data-theme="dark"] .gd-cta-options,
html[data-theme="dark"] .gd-recipient-card {
  background: #1e1e1e !important;
  color: #f0f0f0 !important;
  -webkit-text-fill-color: #f0f0f0 !important;
  border-color: rgba(240, 240, 240, 0.24) !important;
  color-scheme: dark;
}

html[data-theme="dark"] .gd-recipient-card span {
  color: #8a8a8a !important;
  -webkit-text-fill-color: #8a8a8a !important;
}

html[data-theme="dark"] .gd-gear-btn {
  color: #8a8a8a;
}

html[data-theme="dark"] .gd-gear-btn:hover,
html[data-theme="dark"] .gd-gear-btn:focus-visible {
  color: #93c5fd;
  background: #1e3a5f;
  border-color: rgba(96, 165, 250, 0.4);
}

html[data-theme="dark"] .gd-config-panel,
html[data-theme="dark"] .gd-config-panel textarea {
  background: #181818 !important;
  color: #f0f0f0 !important;
  border-color: rgba(240, 240, 240, 0.24) !important;
}

html[data-theme="dark"] .gd-config-header h3 {
  color: #f0f0f0 !important;
}

html[data-theme="dark"] .gd-template-rail {
  background:
    radial-gradient(1200px 120px at 0% 0%, rgba(59, 130, 246, 0.16), transparent 55%),
    linear-gradient(180deg, #121a27 0%, #181818 100%);
  border-bottom-color: rgba(240, 240, 240, 0.18);
}

html[data-theme="dark"] .gd-template-rail-head strong,
html[data-theme="dark"] .gd-template-chip__name,
html[data-theme="dark"] .gd-template-row__main strong {
  color: #f0f0f0;
}

html[data-theme="dark"] .gd-template-chip,
html[data-theme="dark"] .gd-template-row,
html[data-theme="dark"] .gd-template-save-form,
html[data-theme="dark"] .gd-empty-steps span {
  background: #1e1e1e;
  border-color: rgba(240, 240, 240, 0.22);
  color: #e6e6e6;
}

html[data-theme="dark"] .gd-template-chip.is-active,
html[data-theme="dark"] .gd-template-row.is-active {
  background: #1e3a5f;
  border-color: rgba(96, 165, 250, 0.45);
}

html[data-theme="dark"] .gd-header-link {
  color: #93c5fd;
}

html[data-theme="dark"] .gd-header-link:hover {
  background: #1e3a5f;
}

html[data-theme="dark"] .gd-template-save-form input[type="text"] {
  background: #181818;
  color: #f0f0f0;
  border-color: rgba(240, 240, 240, 0.24);
}

html[data-theme="dark"] .gd-cta-label {
  color: #8a8a8a !important;
  -webkit-text-fill-color: #8a8a8a !important;
}

html[data-theme="dark"] .gd-cta-option {
  color: #f0f0f0 !important;
  -webkit-text-fill-color: #f0f0f0 !important;
}

html[data-theme="dark"] .gd-cta-option:hover {
  background: rgba(240, 240, 240, 0.12);
}

html[data-theme="dark"] .gd-status-pill,
html[data-theme="dark"] .gd-loading,
html[data-theme="dark"] .gd-insert-loading {
  background: #1e3a5f !important;
  color: #dbeafe !important;
  -webkit-text-fill-color: #dbeafe !important;
  border-color: rgba(96, 165, 250, 0.4) !important;
}

html[data-theme="dark"] .gd-loading-dots span:nth-child(1) {
  background: #81a1c1;
}

html[data-theme="dark"] .gd-loading-dots span:nth-child(2) {
  background: #34d399;
}

html[data-theme="dark"] .gd-loading-dots span:nth-child(3) {
  background: #fbbf24;
}

html[data-theme="dark"] .gd-error {
  background: #7f1d1d !important;
  color: #fecaca !important;
  -webkit-text-fill-color: #fecaca !important;
  border-color: rgba(248, 113, 113, 0.5) !important;
}

html[data-theme="dark"] .gd-missing,
html[data-theme="dark"] .gd-insert-choice {
  background: #78350f !important;
  color: #fef3c7 !important;
  -webkit-text-fill-color: #fef3c7 !important;
  border-color: rgba(251, 191, 36, 0.5) !important;
}

html[data-theme="dark"] .gd-insert-choice span {
  color: #fef3c7 !important;
  -webkit-text-fill-color: #fef3c7 !important;
}

html[data-theme="dark"] .gd-insert-choice .btn {
  background: #fffbeb !important;
  color: #111827 !important;
  -webkit-text-fill-color: #111827 !important;
}

html[data-theme="dark"] .gd-link-btn {
  color: #93c5fd !important;
  -webkit-text-fill-color: #93c5fd !important;
}

@media (max-width: 900px) {
  .gd-layout {
    grid-template-columns: minmax(280px, 38%) minmax(0, 1fr);
  }

  .gd-grounding-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .gd-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 46%) minmax(0, 1fr);
  }

  .gd-controls {
    border-right: 0;
    border-bottom: 1px solid var(--border, #e2e8f0);
  }

  .gd-control-grid {
    grid-template-columns: 1fr 1fr;
  }

  .gd-cta-options {
    grid-template-columns: 1fr;
  }

  .gd-grounding-grid {
    grid-template-columns: 1fr;
  }

  .gd-actions .btn {
    min-height: 42px;
  }
}
