/* ============================================================
   FlexNeur — Referência visual da janela Google Sheets
   Escopado estritamente a #sheets-modal.
   ============================================================ */

#sheets-modal .dialog {
  width: min(560px, 100%) !important;
  background: #141517;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 24px;
}

/* —— Cabeçalho com ícone verde e selo de status —— */
#sheets-modal .sheets-modal-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin-bottom: 12px;
}

#sheets-modal #sheets-modal-title {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #F4F4F5;
  font-size: 1.25rem;
  font-weight: 600;
}

#sheets-modal #sheets-modal-title::before {
  content: "";
  display: inline-block;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  background: #22D3EE;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6'/%3E%3Cpath d='M8 13h8M8 17h8M12 11v8'/%3E%3C/svg%3E") no-repeat center / contain;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6'/%3E%3Cpath d='M8 13h8M8 17h8M12 11v8'/%3E%3C/svg%3E") no-repeat center / contain;
}

#sheets-modal #sheets-connection-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #D4D4D8;
}

#sheets-modal #sheets-connection-status.sheets-status-on {
  background: rgba(34, 211, 238, 0.14);
  border-color: rgba(34, 211, 238, 0.30);
  color: #22D3EE;
}

/* —— Sublinha: descrição à esquerda e + Selecionar planilhas à direita —— */
#sheets-modal .sheets-modal-subrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

#sheets-modal .sheets-hint {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.45;
  color: #9CA3AF;
}

#sheets-modal #btn-create-sheet-link-start {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 9999px;
  background: #22D3EE !important;
  color: #091913 !important;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

#sheets-modal #sheets-container {
  max-height: 360px !important;
  overflow-y: auto;
  margin-bottom: 0 !important;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* —— Cartão da planilha —— */
#sheets-modal .sheet-item {
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 12px !important;
  padding: 16px !important;
  margin-bottom: 0 !important;
  background: #161B26 !important;
  border: 1px solid rgba(255, 255, 255, 0.10) !important;
  border-radius: 12px !important;
}

#sheets-modal .sheet-item > div:first-child {
  margin-right: 0 !important;
}

#sheets-modal .sheet-item > div:first-child > div:first-child {
  font-size: 0.9375rem !important;
  font-weight: 600 !important;
  color: #F4F4F5 !important;
}

#sheets-modal .sheet-item-meta {
  font-size: 0.875rem !important;
  color: #9CA3AF !important;
  margin-top: 4px;
}

#sheets-modal .sheet-item > div:last-child {
  display: flex !important;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px !important;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

#sheets-modal .sheet-item .dialog-btn {
  min-height: 44px;
  padding: 0 14px !important;
  border-radius: 9999px;
  font-size: 0.875rem !important;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #E5E7EB;
  white-space: nowrap;
}

#sheets-modal .sheet-item .btn-unlink-sheet {
  margin-left: auto;
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.40);
  color: #E07A5F !important;
}

/* —— Rodapé próximo ao cartão —— */
#sheets-modal #sheets-list-actions {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

#sheets-modal #btn-sheets-close,
#sheets-modal #btn-sheet-link-cancel,
#sheets-modal #btn-sheet-link-save {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 9999px;
  font-size: 0.875rem;
}

/* —— Compatibilidade com modo claro —— */
html[data-theme="light"] #sheets-modal .dialog {
  background: #FFFFFF;
  border-color: rgba(15, 23, 42, 0.12);
}

html[data-theme="light"] #sheets-modal #sheets-modal-title,
html[data-theme="light"] #sheets-modal .sheet-item > div:first-child > div:first-child {
  color: #0F172A !important;
}

html[data-theme="light"] #sheets-modal .sheets-hint,
html[data-theme="light"] #sheets-modal .sheet-item-meta {
  color: #4A5E56 !important;
}

html[data-theme="light"] #sheets-modal #sheets-connection-status.sheets-status-on {
  background: rgba(34, 211, 238, 0.14);
  border-color: rgba(10, 138, 102, 0.35);
  color: #0A7A59;
}

html[data-theme="light"] #sheets-modal .sheet-item {
  background: #F4F7F6 !important;
  border-color: rgba(15, 23, 42, 0.12) !important;
}

html[data-theme="light"] #sheets-modal .sheet-item > div:last-child,
html[data-theme="light"] #sheets-modal #sheets-list-actions {
  border-top-color: rgba(15, 23, 42, 0.10);
}

html[data-theme="light"] #sheets-modal .sheet-item .dialog-btn {
  background: #FFFFFF;
  border-color: rgba(15, 23, 42, 0.18);
  color: #0F172A;
}

html[data-theme="light"] #sheets-modal .sheet-item .btn-unlink-sheet {
  background: rgba(217, 107, 82, 0.08);
  border-color: rgba(185, 74, 52, 0.45);
  color: #B94A34 !important;
}

/* —— Celular (até 640px): ações empilhadas dentro do cartão —— */
@media (max-width: 640px) {
  #sheets-modal .sheets-modal-subrow {
    flex-direction: column;
    align-items: stretch;
  }

  #sheets-modal .sheet-item > div:last-child {
    flex-direction: column;
    align-items: stretch;
  }

  #sheets-modal .sheet-item .dialog-btn,
  #sheets-modal .sheet-item .btn-unlink-sheet {
    width: 100%;
    margin-left: 0;
  }
}

/* —— Diálogo de permissões da planilha (visual de referência) —— */
.dialog-overlay.sheets-perm-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: 16px;
}

.dialog-overlay.sheets-perm-overlay .dialog.sheets-perm-dialog {
  width: min(440px, 100%);
  background: #1E1F20;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  padding: 24px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.sheets-perm-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.sheets-perm-title-group {
  min-width: 0;
  flex: 1;
}

.dialog.sheets-perm-dialog .sheets-perm-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
  color: #FFFFFF;
}

.sheets-perm-subtitle {
  margin: 4px 0 0;
  font-size: 0.875rem;
  line-height: 1.4;
  color: #9CA3AF;
  word-break: break-word;
}

.sheets-perm-close {
  width: 44px;
  height: 44px;
  margin: -10px -12px 0 0;
  border: none;
  background: transparent;
  color: #9CA3AF;
  font-size: 1.4rem;
  line-height: 1;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.sheets-perm-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #FFFFFF;
}

.sheets-perm-options {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.sheets-perm-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  min-height: 44px;
  padding: 2px 0;
}

.sheets-perm-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  min-width: 20px;
  margin: 2px 0 0;
  border-radius: 5px;
  border: 1.5px solid #6B7280;
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.sheets-perm-checkbox:checked {
  background: linear-gradient(135deg, #22D3EE 0%, #8B5CF6 100%);
  border-color: #22D3EE;
}

.sheets-perm-checkbox:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: solid #FFFFFF;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.sheets-perm-option-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sheets-perm-option-title {
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.35;
  color: #FFFFFF;
}

.sheets-perm-option-desc {
  font-size: 0.8125rem;
  line-height: 1.45;
  color: #A1A1AA;
}

.dialog.sheets-perm-dialog .sheets-perm-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 0;
}

.dialog.sheets-perm-dialog .sheets-perm-cancel {
  min-height: 44px;
  padding: 9px 18px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #E4E4E7;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.dialog.sheets-perm-dialog .sheets-perm-cancel:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #FFFFFF;
}

.dialog.sheets-perm-dialog .sheets-perm-save {
  min-height: 44px;
  padding: 9px 20px;
  border-radius: 999px;
  background: linear-gradient(135deg, #22D3EE 0%, #8B5CF6 100%);
  border: none;
  color: #FFFFFF;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.dialog.sheets-perm-dialog .sheets-perm-save:hover:not(:disabled) {
  filter: brightness(1.08);
}

html[data-theme="light"] .sheets-perm-checkbox:checked,
html[data-theme="light"] .dialog.sheets-perm-dialog .sheets-perm-save {
  background: linear-gradient(135deg, #0891B2 0%, #7C3AED 100%);
  border-color: #0891B2;
  color: #FFFFFF;
}

.dialog.sheets-perm-dialog .sheets-perm-save:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

html[data-theme="light"] .dialog-overlay.sheets-perm-overlay .dialog.sheets-perm-dialog {
  background: #FFFFFF;
  border-color: rgba(15, 23, 42, 0.12);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.16);
}

html[data-theme="light"] .dialog.sheets-perm-dialog .sheets-perm-title,
html[data-theme="light"] .sheets-perm-option-title {
  color: #0F172A;
}

html[data-theme="light"] .sheets-perm-subtitle,
html[data-theme="light"] .sheets-perm-option-desc,
html[data-theme="light"] .sheets-perm-close {
  color: #4A5E56;
}

html[data-theme="light"] .sheets-perm-close:hover {
  background: rgba(15, 23, 42, 0.06);
  color: #0F172A;
}

html[data-theme="light"] .sheets-perm-checkbox {
  border-color: rgba(15, 23, 42, 0.35);
}

html[data-theme="light"] .sheets-perm-checkbox:checked {
  background: linear-gradient(135deg, #0891B2 0%, #7C3AED 100%);
  border-color: #0891B2;
}

html[data-theme="light"] .dialog.sheets-perm-dialog .sheets-perm-cancel {
  background: #FFFFFF;
  border-color: rgba(15, 23, 42, 0.18);
  color: #0F172A;
}

html[data-theme="light"] .dialog.sheets-perm-dialog .sheets-perm-cancel:hover {
  background: #F1F5F9;
}

html[data-theme="light"] .dialog.sheets-perm-dialog .sheets-perm-save {
  background: linear-gradient(135deg, #0891B2 0%, #7C3AED 100%);
  color: #FFFFFF;
}

@media (max-width: 640px) {
  .dialog-overlay.sheets-perm-overlay {
    align-items: center;
    justify-content: center;
    padding: 16px;
  }

  .dialog-overlay.sheets-perm-overlay .dialog.sheets-perm-dialog {
    padding: 20px;
  }

  .dialog.sheets-perm-dialog .sheets-perm-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .dialog.sheets-perm-dialog .sheets-perm-cancel,
  .dialog.sheets-perm-dialog .sheets-perm-save {
    width: 100%;
  }
}
